Actually do the reposting.
This commit is contained in:
parent
c0fb73ca03
commit
1218fa9495
2 changed files with 12 additions and 19 deletions
|
|
@ -14,7 +14,7 @@ class RepostsController < ApplicationController
|
||||||
http.use_ssl = true
|
http.use_ssl = true
|
||||||
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
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"})
|
response = Net::HTTP::post_form( uri, {"client_id" => client_id, "response_type" => "code", "redirect_uri" => "http://repostmentions.sr-rolando.com/", "scope" => "stream"})
|
||||||
|
|
||||||
# [temp] status
|
# [temp] status
|
||||||
@res_code = response.code
|
@res_code = response.code
|
||||||
|
|
@ -37,33 +37,18 @@ class RepostsController < ApplicationController
|
||||||
access_token = Repost.obtain_user_token
|
access_token = Repost.obtain_user_token
|
||||||
|
|
||||||
# retrieve latest reposts. this uses the real ADN stream.
|
# retrieve latest reposts. this uses the real ADN stream.
|
||||||
puts "===< retrieve latest post >==="
|
|
||||||
res = Repost.get_most_recent_user_post(access_token)
|
res = Repost.get_most_recent_user_post(access_token)
|
||||||
api_res = ApiResponse.new(:raw_json => res.body)
|
api_res = ApiResponse.new(:raw_json => res.body)
|
||||||
latest_post = PostData.most_recent_post(api_res.data)
|
latest_post = PostData.most_recent_post(api_res.data)
|
||||||
puts "=== latest postid: " + latest_post.post_id.to_s + ", created at: " + latest_post.created_at.to_s
|
|
||||||
|
|
||||||
# retrieve new mentions.
|
# retrieve new mentions.
|
||||||
# TODO restrict to: fetch( since_id=previous max_id )
|
|
||||||
puts "===< retrieve new mentions >==="
|
|
||||||
res = Repost.get_mentions_stream(access_token)
|
res = Repost.get_mentions_stream(access_token)
|
||||||
api_res = ApiResponse.new(:raw_json => res.body)
|
api_res = ApiResponse.new(:raw_json => res.body)
|
||||||
todo_posts_array = PostData.extract_not_yet_reposted(api_res.data, latest_post.post_id)
|
todo_posts_array = PostData.extract_not_yet_reposted(api_res.data, latest_post.post_id)
|
||||||
|
|
||||||
# tmp
|
Repost.repost_this_array(todo_posts_array, access_token)
|
||||||
puts "===> " + todo_posts_array.length.to_s + " noch offene posts."
|
|
||||||
todo_posts_array.each do |post_id|
|
|
||||||
puts "--- reposten: " + post_id.to_s
|
|
||||||
end
|
|
||||||
|
|
||||||
# TODO: res.body contains the mentions in JSON. Proceed from there.
|
|
||||||
#new_mentions.each do | post |
|
|
||||||
## API - repost(post) # http://developers.app.net/docs/resources/post/reposts/
|
|
||||||
#repost_uri = "https://alpha-api.app.net/stream/0/posts/" + post.id + "/repost"
|
|
||||||
#latestid = post.id
|
|
||||||
#end
|
|
||||||
|
|
||||||
# store all reposts locally for later reuse.
|
# TODO store all reposts locally for later reuse.
|
||||||
# TODO insert into reposts values("karlsruher", post.id, latestid)
|
# TODO insert into reposts values("karlsruher", post.id, latestid)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,13 +17,21 @@ class Repost < ActiveRecord::Base
|
||||||
self.make_api_get_call(uri, access_token)
|
self.make_api_get_call(uri, access_token)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# http://developers.app.net/docs/resources/post/streams/#retrieve-posts-mentioning-a-user
|
# http://developers.app.net/docs/resources/post/streams/#retrieve-posts-mentioning-a-user
|
||||||
def self.get_mentions_stream(access_token)
|
def self.get_mentions_stream(access_token)
|
||||||
uri = "https://alpha-api.app.net/stream/0/users/me/mentions?since_id=16899626"
|
uri = "https://alpha-api.app.net/stream/0/users/me/mentions?since_id=16899626"
|
||||||
self.make_api_get_call(uri, access_token)
|
self.make_api_get_call(uri, access_token)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# http://developers.app.net/docs/resources/post/reposts/#repost-a-post
|
||||||
|
def self.repost_this_array(repost_array, access_token)
|
||||||
|
repost_array.each do |post_id|
|
||||||
|
uri = "https://alpha-api.app.net/stream/0/posts/" + post_id.to_s + "/repost"
|
||||||
|
self.make_api_post_call(uri, nil, access_token)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
def self.make_api_get_call(uri_string, access_token)
|
def self.make_api_get_call(uri_string, access_token)
|
||||||
# uri = URI("https://alpha-api.app.net/stream/0/users/me/mentions")
|
# uri = URI("https://alpha-api.app.net/stream/0/users/me/mentions")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue