49 lines
1.4 KiB
Ruby
49 lines
1.4 KiB
Ruby
require 'net/http'
|
|
require 'uri'
|
|
|
|
class RepostsController < ApplicationController
|
|
def index
|
|
config = YAML.load_file('config/client.yml')
|
|
client_id = config["client_id"]
|
|
client_secret = config["client_secret"]
|
|
|
|
# connect to ADN via a user token
|
|
uri = URI.parse("https://account.app.net/oauth/authenticate")
|
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
http.use_ssl = true
|
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
|
|
response = Net::HTTP::post_form( uri, {"client_id" => client_id, "response_type" => "code", "redirect_uri" => "http://localhost:3000/", "scope" => "stream"})
|
|
|
|
# [temp] status
|
|
@res_code = response.code
|
|
@res_message = response.message
|
|
@res_class = response.class.name
|
|
|
|
if not response.is_a?(Net::HTTPSuccess)
|
|
flash[:error] = "Could not connect to ADN."
|
|
return
|
|
end
|
|
|
|
# ...
|
|
end
|
|
|
|
# TODO rework from file handling to use of 'reposts' model.
|
|
def new
|
|
# retrieve latest repost
|
|
# TODO: select max(postid) from reposts;
|
|
#history = YAML.load('history.yml', :safe => true)
|
|
#lastrepostid = history["lastrepost"]
|
|
#latestid = lastrepostid
|
|
|
|
# fetch all mentions since last one
|
|
## API - fetch( since_id=previous max_id )
|
|
#new_mentions.each do | post |
|
|
## API - repost(post)
|
|
#latestid = post.id
|
|
#end
|
|
|
|
# store latest repost for next time
|
|
# TODO insert into reposts values("karlsruher", post.id, latestid)
|
|
end
|
|
end
|