Class: Tweeb::Client
Instance Attribute Summary collapse
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#rate_limit_remaining ⇒ Object
readonly
Returns the value of attribute rate_limit_remaining.
-
#rate_limit_reset ⇒ Object
readonly
Returns the value of attribute rate_limit_reset.
-
#rate_limit_total ⇒ Object
readonly
Returns the value of attribute rate_limit_total.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #am_i_following?(target) ⇒ Boolean
- #befriend(user, options = {:follow => true}) ⇒ Object (also: #follow)
- #delete_direct_message(id) ⇒ Object
- #delete_status(id) ⇒ Object
- #direct_message(recipient, message) ⇒ Object
- #direct_message_inbox(options = {}) ⇒ Object
- #direct_messages_sent(options = {}) ⇒ Object
- #following_me?(target) ⇒ Boolean
- #friends(options = {}) ⇒ Object
- #friends_timeline(options = {}) ⇒ Object
- #friendship_exists?(target, source = nil) ⇒ Boolean
- #friendship_info(target, source = nil) ⇒ Object
- #get_status(id) ⇒ Object
-
#initialize(username, password, options = {}) ⇒ Client
constructor
A new instance of Client.
- #mentions(options = {}) ⇒ Object
- #public_timeline(options = {}) ⇒ Object
- #rate_limits ⇒ Object
- #search(query, options = {}) ⇒ Object
- #show_user(id) ⇒ Object
- #timeline(type, options = {}) ⇒ Object
- #trends(type = :trends) ⇒ Object
- #unfriend(user) ⇒ Object (also: #unfollow)
- #update_rate_limits ⇒ Object
- #update_status(message, reply_id = nil) ⇒ Object
- #user_timeline(options = {}) ⇒ Object
Constructor Details
#initialize(username, password, options = {}) ⇒ Client
Returns a new instance of Client.
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/tweeb_client.rb', line 27 def initialize(username, password, ={}) @username = username @password = password @options = { :public_refresh => 60 }.merge() self.class.basic_auth(@username, @password) @symbolizer = lambda {|hash| hash['user'].symbolize_keys; hash.symbolize_keys; return hash } @masher = lambda {|hash| Mash.new(hash) } @rate_limit_total = 150 @rate_limit_reset = nil @rate_limit_remaining = nil end |
Instance Attribute Details
#password ⇒ Object (readonly)
Returns the value of attribute password.
22 23 24 |
# File 'lib/tweeb_client.rb', line 22 def password @password end |
#rate_limit_remaining ⇒ Object (readonly)
Returns the value of attribute rate_limit_remaining.
22 23 24 |
# File 'lib/tweeb_client.rb', line 22 def rate_limit_remaining @rate_limit_remaining end |
#rate_limit_reset ⇒ Object (readonly)
Returns the value of attribute rate_limit_reset.
22 23 24 |
# File 'lib/tweeb_client.rb', line 22 def rate_limit_reset @rate_limit_reset end |
#rate_limit_total ⇒ Object (readonly)
Returns the value of attribute rate_limit_total.
22 23 24 |
# File 'lib/tweeb_client.rb', line 22 def rate_limit_total @rate_limit_total end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
22 23 24 |
# File 'lib/tweeb_client.rb', line 22 def username @username end |
Instance Method Details
#am_i_following?(target) ⇒ Boolean
258 259 260 261 262 |
# File 'lib/tweeb_client.rb', line 258 def am_i_following?(target) rel = friendship_info(target) return true if rel[:source][:following] false end |
#befriend(user, options = {:follow => true}) ⇒ Object Also known as: follow
214 215 216 217 |
# File 'lib/tweeb_client.rb', line 214 def befriend(user, ={:follow => true}) json = self.class.post("/friendships/create.json", :query => {:id => user}.merge()) @masher.call(json) end |
#delete_direct_message(id) ⇒ Object
209 210 211 212 |
# File 'lib/tweeb_client.rb', line 209 def (id) json = self.class.delete("/direct_messages/destroy.json", :query => {:id => id}) @masher.call(json) end |
#delete_status(id) ⇒ Object
129 130 131 132 |
# File 'lib/tweeb_client.rb', line 129 def delete_status(id) json = self.class.delete("/statuses/destroy/#{id}.json") @masher.call(json) end |
#direct_message(recipient, message) ⇒ Object
204 205 206 207 |
# File 'lib/tweeb_client.rb', line 204 def (recipient, ) json = self.class.post("/direct_messages/new.json", :query => {:user => recipient, :text => }) @masher.call(json) end |
#direct_message_inbox(options = {}) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/tweeb_client.rb', line 171 def (={}) if .empty? json = self.class.get("/direct_messages.json") else if [:count] and [:count] > 200 raise Tweeb::ClientError, "Count must be less than 200" end json = self.class.get("/direct_messages.json", :query => ) end timeline = Array.new json.each do |tweet| mash = @masher.call(tweet) timeline << mash end timeline end |
#direct_messages_sent(options = {}) ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/tweeb_client.rb', line 188 def (={}) if .empty? json = self.class.get("/direct_messages/sent.json") else if [:count] and [:count] > 200 raise Tweeb::ClientError, "Count must be less than 200" end json = self.class.get("/direct_messages/sent.json", :query => ) end json.each do |tweet| mash = @masher.call(tweet) timeline << mash end timeline end |
#following_me?(target) ⇒ Boolean
252 253 254 255 256 |
# File 'lib/tweeb_client.rb', line 252 def following_me?(target) rel = friendship_info(target) return true if rel[:source][:followed_by] false end |
#friends(options = {}) ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/tweeb_client.rb', line 152 def friends(={}) if .empty? json = self.class.get("/statuses/friends.json") else json = self.class.get("/statuses/friends.json", :query => ) end timeline = Array.new json.each do |tweet| mash = @masher.call(tweet) timeline << mash end timeline end |
#friends_timeline(options = {}) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/tweeb_client.rb', line 83 def friends_timeline(={}) if .empty? json = self.class.get("/statuses/friends_timeline.json") else if [:count] && [:count] > 200 raise Tweeb::ClientError, "Count must be less than 200" end json = self.class.get("/statuses/friends_timeline.json", :query => ) end timeline = Array.new json.each do |tweet| mash = @masher.call(tweet) timeline << mash end timeline end |
#friendship_exists?(target, source = nil) ⇒ Boolean
246 247 248 249 250 |
# File 'lib/tweeb_client.rb', line 246 def friendship_exists?(target, source=nil) rel = source.nil? ? friendship_info(target) : friendship_info(target, source) return true if rel[:source][:following] && rel[:target][:following] false end |
#friendship_info(target, source = nil) ⇒ Object
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/tweeb_client.rb', line 226 def friendship_info(target, source=nil) query = Hash.new if source if source.is_a?(Fixnum) query[:source_id] = source elsif source.is_a?(String) query[:source_screen_name] = source end end if target.is_a?(Fixnum) query[:target_id] = target elsif target.is_a?(String) query[:target_screen_name] = target end json = self.class.get("/friendships/show.json", :query => query) @masher.call(json) end |
#get_status(id) ⇒ Object
147 148 149 150 |
# File 'lib/tweeb_client.rb', line 147 def get_status(id) json = self.class.get("/statuses/show/#{id}.json") @masher.call(json) end |
#mentions(options = {}) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/tweeb_client.rb', line 100 def mentions(={}) if .empty? json = self.class.get("/statuses/mentions.json") else if [:count] and [:count] > 200 raise Tweeb::ClientError, "Count must be less than 200" end json = self.class.get("/statuses/mentions.json", :query => ) end timeline = Array.new json.each do |tweet| mash = @masher.call(tweet) timeline << mash end timeline end |
#public_timeline(options = {}) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/tweeb_client.rb', line 49 def public_timeline(={}) if .empty? json = self.class.get("/statuses/public_timeline.json") else if [:count] && [:count] > 200 raise Tweeb::ClientError, "Count must be less than 200" end json = self.class.get("/statuses/public_timeline.json", :query => ) end timeline = Array.new json.each do |tweet| mash = @masher.call(tweet) timeline << mash end timeline end |
#rate_limits ⇒ Object
272 273 274 |
# File 'lib/tweeb_client.rb', line 272 def rate_limits {:total => @rate_limit_total, :remaining => @rate_limit_remaining, :reset_time => @rate_limit_reset} end |
#search(query, options = {}) ⇒ Object
134 135 136 |
# File 'lib/tweeb_client.rb', line 134 def search(query, ={}) Tweeb::Search.search(query, ) end |
#show_user(id) ⇒ Object
166 167 168 169 |
# File 'lib/tweeb_client.rb', line 166 def show_user(id) json = self.class.get("/users/show/#{id}.json") @masher.call(json) end |
#timeline(type, options = {}) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/tweeb_client.rb', line 41 def timeline(type, ={}) case type when :public then public_timeline() when :user then user_timeline() when :friends then friends_timeline() end end |
#trends(type = :trends) ⇒ Object
138 139 140 141 142 143 144 145 |
# File 'lib/tweeb_client.rb', line 138 def trends(type=:trends) case type when :trends then Tweeb::Search.trends when :current then Tweeb::Search.current_trends when :daily then Tweeb::Search.daily_trends when :weekly then Tweeb::Search.weekly_trends end end |
#unfriend(user) ⇒ Object Also known as: unfollow
220 221 222 223 |
# File 'lib/tweeb_client.rb', line 220 def unfriend(user) json = self.class.delete("/friendships/destroy.json", :query => {:id => user}) @masher.call(json) end |
#update_rate_limits ⇒ Object
264 265 266 267 268 269 270 |
# File 'lib/tweeb_client.rb', line 264 def update_rate_limits json = self.class.get("/account/rate_limit_status.json") @rate_limit_total = json["hourly_limit"].to_i @rate_limit_remaining = json["remaining_hits"].to_i @rate_limit_reset = Time.parse(json["reset_time"]) rate_limits end |
#update_status(message, reply_id = nil) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/tweeb_client.rb', line 117 def update_status(, reply_id=nil) if .length > 140 raise Tweeb::ClientError, "Message must be 140 characters or less" end if reply_id json = self.class.post("/statuses/update.json", :query => {:status => , :in_reply_to_status_id => reply_id}) else json = self.class.post("/statuses/update.json", :query => {:status => }) end @masher.call(json) end |
#user_timeline(options = {}) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/tweeb_client.rb', line 66 def user_timeline(={}) if .empty? json = self.class.get("/statuses/user_timeline.json") else if [:count] && [:count] > 200 raise Tweeb::ClientError, "Count must be less than 200" end json = self.class.get("/statuses/user_timeline.json", :query => ) end timeline = Array.new json.each do |tweet| mash = @masher.call(tweet) timeline << mash end timeline end |