47 lines
1.4 KiB
Ruby
47 lines
1.4 KiB
Ruby
require 'erb' # for url_encode()
|
|
require 'net/http'
|
|
require 'uri'
|
|
|
|
class RepostsController < ApplicationController
|
|
def index
|
|
end
|
|
|
|
# TODO: to secure the cronjob call test for 'InvokationPassword' header.
|
|
# store this password in client.yml for comparison
|
|
# crontab: curl -H 'InvokationPassword: ...' http://localhost/reposts/new
|
|
def new
|
|
# get user auth token
|
|
access_token = Repost.obtain_user_token
|
|
|
|
# retrieve latest reposts. this uses the real ADN stream.
|
|
res = Repost.get_most_recent_user_post(access_token)
|
|
api_res = ApiResponse.new(:raw_json => res.body)
|
|
latest_post = PostData.most_recent_post(api_res.data)
|
|
|
|
# retrieve new mentions.
|
|
res = Repost.get_mentions_stream(access_token)
|
|
api_res = ApiResponse.new(:raw_json => res.body)
|
|
todo_posts_array = PostData.extract_not_yet_reposted(api_res.data, latest_post.post_id)
|
|
|
|
Repost.repost_this_array(todo_posts_array, access_token)
|
|
|
|
# TODO store all reposts locally for later reuse.
|
|
# TODO insert into reposts values("karlsruher", post.id, latestid)
|
|
end
|
|
|
|
private
|
|
|
|
def dump_api_response(api_response)
|
|
puts "====> meta:"
|
|
api_response.meta.each do |mline|
|
|
puts "--- meta line: " + mline.to_s
|
|
puts ""
|
|
end
|
|
puts ""
|
|
puts "====> data:"
|
|
api_response.data.each do |dline|
|
|
puts "--- data line: " + dline.to_s
|
|
puts ""
|
|
end
|
|
end
|
|
end
|