Class: LikeBomb
- Inherits:
-
Object
- Object
- LikeBomb
- Defined in:
- lib/like_bomb.rb
Overview
lb.post_likes(unliked_statuses)
Instance Attribute Summary collapse
-
#fb_name ⇒ Object
readonly
Returns the value of attribute fb_name.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
-
#get_friends ⇒ Hash<String,String>
A method that can be used to retrieve user_id’s of your friends.
-
#get_photos(user_id) ⇒ Hash<Symbol,Array<String>>
Grabs all photos of a specific user when provided a user_id.
-
#get_statuses(user_id) ⇒ Hash<Symbol,Array<String>>
Grabs all statuses of a specific user when provided a user_id.
-
#initialize(key) ⇒ LikeBomb
constructor
Default String constructor.
-
#post_cools(obj_ids) ⇒ Object
Posts the comment “Cool!” on any provided object_id.
-
#post_likes(obj_ids) ⇒ Object
Likes any provided object_id.
Constructor Details
#initialize(key) ⇒ LikeBomb
Use watir-webdriver to automate grabbing of keys from Graph API site.
Default String constructor
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/like_bomb.rb', line 33 def initialize(key) begin = Oj.load(Typhoeus::Request.get( "https://graph.facebook.com/me/permissions?access_token=#{key}").body)["data"].first if is_valid?() @key = key @fb_name = Oj.load(Typhoeus::Request.get( "https://graph.facebook.com/me?access_token=#{@key}").body)["name"] else raise ArgumentError , "The provided key is invalid, please consult the README for how to generate a valid API key" end rescue raise ArgumentError , "The provided key is invalid, please consult the README for how to generate a valid API key" end end |
Instance Attribute Details
#fb_name ⇒ Object (readonly)
Returns the value of attribute fb_name.
20 21 22 |
# File 'lib/like_bomb.rb', line 20 def fb_name @fb_name end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
20 21 22 |
# File 'lib/like_bomb.rb', line 20 def key @key end |
Instance Method Details
#get_friends ⇒ Hash<String,String>
A method that can be used to retrieve user_id’s of your friends. You will need to use these ids to get status and/or photo object_ids
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/like_bomb.rb', line 58 def get_friends res = Typhoeus::Request.get( "https://graph.facebook.com/me/friends?access_token=#{@key}") unless res.nil? json_data = Oj.load res.body friend_hash = Hash.new json_data["data"].each do |x| friend_hash[x["name"]] = x["id"] end return friend_hash end end |
#get_photos(user_id) ⇒ Hash<Symbol,Array<String>>
Grabs all photos of a specific user when provided a user_id
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/like_bomb.rb', line 120 def get_photos(user_id) result_hash = Hash.new result_hash[:all] = [] result_hash[:liked] = [] result_hash[:cooled] = [] all_links = [] res = Typhoeus::Request.get("https://graph.facebook.com/#{user_id}/photos?access_token=#{@key}") take_photos = Oj.load(res.body)["data"].empty? ? false : true while take_photos unless Oj.load(res.body)["data"].nil? Oj.load(res.body)["data"].each do |photo| unless result_hash[:all].include? photo["id"] result_hash[:all].push photo["id"] result_hash[:liked].push photo["id"] if liked?(photo) result_hash[:cooled].push photo["id"] if cooled?(photo) end end end begin next_url = Oj.load(res.body)["paging"]["next"] rescue NoMethodError break end if all_links.include? next_url || next_url.nil? take_photos = false else all_links.push next_url res = Typhoeus::Request.get("#{Oj.load(res.body)["paging"]["next"]}?access_token=#{@key}") end end result_hash[:not_liked] = result_hash[:all] - result_hash[:liked] result_hash[:not_cooled] = result_hash[:all] - result_hash[:cooled] result_hash end |
#get_statuses(user_id) ⇒ Hash<Symbol,Array<String>>
Grabs all statuses of a specific user when provided a user_id
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/like_bomb.rb', line 81 def get_statuses(user_id) result_hash = Hash.new result_hash[:all] = [] result_hash[:liked] = [] result_hash[:cooled] = [] all_links = [] res = Typhoeus::Request.get("https://graph.facebook.com/#{user_id}/statuses?access_token=#{@key}") take_statuses = Oj.load(res.body)["data"].empty? ? false : true while take_statuses Oj.load(res.body)["data"].each do |status| unless result_hash[:all].include? status["id"] result_hash[:all].push status["id"] result_hash[:liked].push status["id"] if liked?(status) result_hash[:cooled].push status["id"] if cooled?(status) end end next_url = Oj.load(res.body)["paging"]["next"] if all_links.include? next_url || next_url.nil? take_statuses = false else all_links.push next_url res = Typhoeus::Request.get("#{Oj.load(res.body)["paging"]["next"]}?access_token=#{@key}") end end result_hash[:not_liked] = result_hash[:all] - result_hash[:liked] result_hash[:not_cooled] = result_hash[:all] - result_hash[:cooled] result_hash end |
#post_cools(obj_ids) ⇒ Object
Posts the comment “Cool!” on any provided object_id
178 179 180 181 182 183 184 |
# File 'lib/like_bomb.rb', line 178 def post_cools(obj_ids) hydra = Typhoeus::Hydra.new complete_urls = obj_ids.collect{|id| "https://graph.facebook.com/#{id}/comments?access_token=#{@key}&publish_stream&message=Cool!"} complete_urls.each do |url| Typhoeus::Request.post url end end |
#post_likes(obj_ids) ⇒ Object
Likes any provided object_id
160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/like_bomb.rb', line 160 def post_likes(obj_ids) hydra = Typhoeus::Hydra.new complete_urls = obj_ids.collect{|id| "https://graph.facebook.com/#{id}/likes?access_token=#{@key}&publish_stream"} complete_urls.each do |url| hydra.queue Typhoeus::Request.new(url, :method => :post, :timeout => 50000, :cache_timeout => 60) end hydra.run end |