Class: Turrialba::Client
- Inherits:
-
Object
- Object
- Turrialba::Client
- Includes:
- HTTParty
- Defined in:
- lib/turrialba/client.rb
Instance Method Summary collapse
-
#initialize(auth_token = 'hashlol') ⇒ Client
constructor
A new instance of Client.
- #next_possessed_user ⇒ Object
- #post_tweet_distribution(id_str, source, mining_cost, distribution) ⇒ Object
- #post_user_distribution(uid, source, mining_cost, distribution) ⇒ Object
- #put_favorite(uid, id_str) ⇒ Object
- #put_follower_connection(uid, follower_uid) ⇒ Object
- #put_retweet(uid, id_str) ⇒ Object
- #put_tweet(uid, hash) ⇒ Object
- #put_user(hash) ⇒ Object
- #tweet(id_str) ⇒ Object
- #user(uid) ⇒ Object
Constructor Details
#initialize(auth_token = 'hashlol') ⇒ Client
Returns a new instance of Client.
8 9 10 |
# File 'lib/turrialba/client.rb', line 8 def initialize(auth_token = 'hashlol') @auth_header = { 'X-AUTH-TOKEN': auth_token } end |
Instance Method Details
#next_possessed_user ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/turrialba/client.rb', line 40 def next_possessed_user response = self.class.get("/next_possessed_user", headers: @auth_header) if response.code == 200 User.new(response.parsed_response) else nil end end |
#post_tweet_distribution(id_str, source, mining_cost, distribution) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/turrialba/client.rb', line 61 def post_tweet_distribution(id_str, source, mining_cost, distribution) response = self.class.post("/tweet/#{id_str}/distribution", body: { source: source, mining_cost: mining_cost, followers: distribution[:followers].to_json, following: distribution[:following].to_json, favorites: distribution[:favorites].to_json, statuses: distribution[:statuses].to_json }, headers: @auth_header) response.code == 200 end |
#post_user_distribution(uid, source, mining_cost, distribution) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/turrialba/client.rb', line 25 def post_user_distribution(uid, source, mining_cost, distribution) params = { source: source, mining_cost: mining_cost, } params[:followers] = distribution[:followers].to_json if !distribution[:followers].nil? params[:following] = distribution[:following].to_json if !distribution[:following].nil? params[:favorites] = distribution[:favorites].to_json if !distribution[:favorites].nil? params[:statuses] = distribution[:statuses].to_json if !distribution[:statuses].nil? params[:retweets] = distribution[:retweets].to_json if !distribution[:retweets].nil? response = self.class.post("/user/#{uid}/distribution", body: params, headers: @auth_header) response.code == 200 end |
#put_favorite(uid, id_str) ⇒ Object
75 76 77 78 79 |
# File 'lib/turrialba/client.rb', line 75 def put_favorite(uid, id_str) response = self.class.put("/user/#{uid}/favorite/#{id_str}", headers: @auth_header) response.code == 200 end |
#put_follower_connection(uid, follower_uid) ⇒ Object
87 88 89 90 91 |
# File 'lib/turrialba/client.rb', line 87 def put_follower_connection(uid, follower_uid) response = self.class.put("/user/#{uid}/follows/#{follower_uid}/", headers: @auth_header) response.code == 200 end |
#put_retweet(uid, id_str) ⇒ Object
81 82 83 84 85 |
# File 'lib/turrialba/client.rb', line 81 def put_retweet(uid, id_str) response = self.class.put("/user/#{uid}/retweet/#{id_str}", headers: @auth_header) response.code == 200 end |
#put_tweet(uid, hash) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/turrialba/client.rb', line 54 def put_tweet(uid, hash) response = self.class.put("/user/#{uid}/tweet/#{hash[:id_str]}", body: filter_tweet_params(hash), headers: @auth_header) Tweet.new(response.parsed_response) end |
#put_user(hash) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/turrialba/client.rb', line 17 def put_user(hash) uid = hash[:uid] || hash[:id_str] response = self.class.put("/user/#{uid}", body: filter_user_params(hash), headers: @auth_header) User.new(response.parsed_response) end |