Class: Twitter::Base
- Inherits:
-
Object
- Object
- Twitter::Base
- Extended by:
- Forwardable
- Defined in:
- lib/twitter/base.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #block(id) ⇒ Object
- #blocked_ids ⇒ Object
- #blocking(options = {}) ⇒ Object
- #direct_message_create(user, text) ⇒ Object
- #direct_message_destroy(id) ⇒ Object
-
#direct_messages(query = {}) ⇒ Object
Options: since, since_id, page.
-
#direct_messages_sent(query = {}) ⇒ Object
Options: since, since_id, page.
- #disable_notifications(id) ⇒ Object
- #enable_notifications(id) ⇒ Object
- #favorite_create(id) ⇒ Object
- #favorite_destroy(id) ⇒ Object
-
#favorites(query = {}) ⇒ Object
Options: id, page.
-
#follower_ids(query = {}) ⇒ Object
Options: id, user_id, screen_name.
-
#followers(query = {}) ⇒ Object
Options: id, user_id, screen_name, page.
-
#friend_ids(query = {}) ⇒ Object
Options: id, user_id, screen_name.
-
#friends(query = {}) ⇒ Object
Options: id, user_id, screen_name, page.
-
#friends_timeline(query = {}) ⇒ Object
Options: since_id, max_id, count, page, since.
- #friendship_create(id, follow = false) ⇒ Object
- #friendship_destroy(id) ⇒ Object
- #friendship_exists?(a, b) ⇒ Boolean
- #friendship_show(query) ⇒ Object
- #help ⇒ Object
-
#home_timeline(query = {}) ⇒ Object
Options: since_id, max_id, count, page.
-
#initialize(client) ⇒ Base
constructor
A new instance of Base.
- #is_list_member?(list_owner_username, slug, id) ⇒ Boolean
- #list(list_owner_username, slug) ⇒ Object
- #list_add_member(list_owner_username, slug, new_id) ⇒ Object
- #list_create(list_owner_username, options) ⇒ Object
- #list_delete(list_owner_username, slug) ⇒ Object
- #list_members(list_owner_username, slug, query = {}) ⇒ Object
- #list_remove_member(list_owner_username, slug, id) ⇒ Object
- #list_subscribe(list_owner_username, slug) ⇒ Object
- #list_subscribers(list_owner_username, slug) ⇒ Object
-
#list_timeline(list_owner_username, slug, query = {}) ⇒ Object
:per_page = max number of statues to get at once :page = which page of tweets you wish to get.
- #list_unsubscribe(list_owner_username, slug) ⇒ Object
- #list_update(list_owner_username, slug, options) ⇒ Object
- #lists(list_owner_username = nil, query = {}) ⇒ Object
- #memberships(list_owner_username, query = {}) ⇒ Object
-
#mentions(query = {}) ⇒ Object
Options: since_id, max_id, count, page.
- #rate_limit_status ⇒ Object
-
#replies(query = {}) ⇒ Object
DEPRECATED: Use #mentions instead.
-
#report_spam(options) ⇒ Object
When reporting a user for spam, specify one or more of id, screen_name, or user_id.
- #retweet(id) ⇒ Object
-
#retweeted_by_me(query = {}) ⇒ Object
Options: since_id, max_id, count, page.
-
#retweeted_to_me(query = {}) ⇒ Object
Options: since_id, max_id, count, page.
-
#retweeters_of(id, options = {}) ⇒ Object
options: count, page, ids_only.
-
#retweets(id, query = {}) ⇒ Object
Options: count.
-
#retweets_of_me(query = {}) ⇒ Object
Options: since_id, max_id, count, page.
- #saved_search(id) ⇒ Object
- #saved_search_create(query) ⇒ Object
- #saved_search_destroy(id) ⇒ Object
- #saved_searches ⇒ Object
- #status(id) ⇒ Object
- #status_destroy(id) ⇒ Object
- #subscriptions(list_owner_username, query = {}) ⇒ Object
- #unblock(id) ⇒ Object
-
#update(status, query = {}) ⇒ Object
Options: in_reply_to_status_id.
-
#update_delivery_device(device) ⇒ Object
Device must be sms, im or none.
-
#update_profile(body = {}) ⇒ Object
One or more of the following must be present: name, email, url, location, description.
-
#update_profile_background(file, tile = false) ⇒ Object
file should respond to #read and #path.
-
#update_profile_colors(colors = {}) ⇒ Object
One or more of the following must be present: profile_background_color, profile_text_color, profile_link_color, profile_sidebar_fill_color, profile_sidebar_border_color.
-
#update_profile_image(file) ⇒ Object
file should respond to #read and #path.
- #user(id, query = {}) ⇒ Object
-
#user_search(q, query = {}) ⇒ Object
Options: page, per_page.
-
#user_timeline(query = {}) ⇒ Object
Options: id, user_id, screen_name, since_id, max_id, page, since, count.
- #users(*ids_or_usernames) ⇒ Object
- #verify_credentials ⇒ Object
Constructor Details
#initialize(client) ⇒ Base
Returns a new instance of Base.
9 10 11 |
# File 'lib/twitter/base.rb', line 9 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
7 8 9 |
# File 'lib/twitter/base.rb', line 7 def client @client end |
Instance Method Details
#block(id) ⇒ Object
225 226 227 |
# File 'lib/twitter/base.rb', line 225 def block(id) perform_post("/blocks/create/#{id}.json") end |
#blocked_ids ⇒ Object
311 312 313 |
# File 'lib/twitter/base.rb', line 311 def blocked_ids perform_get("/blocks/blocking/ids.json", :mash => false) end |
#blocking(options = {}) ⇒ Object
315 316 317 |
# File 'lib/twitter/base.rb', line 315 def blocking(={}) perform_get("/blocks/blocking.json", ) end |
#direct_message_create(user, text) ⇒ Object
129 130 131 132 133 134 |
# File 'lib/twitter/base.rb', line 129 def (user, text) body = {:text => text} body[:screen_name] = user.screen_name if user.respond_to?(:screen_name) && !user.screen_name.blank? body[:id] = user.id if user.respond_to?(:id) && !user.id.blank? perform_post("/direct_messages/new.json", :body => body) end |
#direct_message_destroy(id) ⇒ Object
136 137 138 |
# File 'lib/twitter/base.rb', line 136 def (id) perform_post("/direct_messages/destroy/#{id}.json") end |
#direct_messages(query = {}) ⇒ Object
Options: since, since_id, page
120 121 122 |
# File 'lib/twitter/base.rb', line 120 def (query={}) perform_get("/direct_messages.json", :query => query) end |
#direct_messages_sent(query = {}) ⇒ Object
Options: since, since_id, page
125 126 127 |
# File 'lib/twitter/base.rb', line 125 def (query={}) perform_get("/direct_messages/sent.json", :query => query) end |
#disable_notifications(id) ⇒ Object
221 222 223 |
# File 'lib/twitter/base.rb', line 221 def disable_notifications(id) perform_post("/notifications/leave/#{id}.json") end |
#enable_notifications(id) ⇒ Object
217 218 219 |
# File 'lib/twitter/base.rb', line 217 def enable_notifications(id) perform_post("/notifications/follow/#{id}.json") end |
#favorite_create(id) ⇒ Object
209 210 211 |
# File 'lib/twitter/base.rb', line 209 def favorite_create(id) perform_post("/favorites/create/#{id}.json") end |
#favorite_destroy(id) ⇒ Object
213 214 215 |
# File 'lib/twitter/base.rb', line 213 def favorite_destroy(id) perform_post("/favorites/destroy/#{id}.json") end |
#favorites(query = {}) ⇒ Object
Options: id, page
205 206 207 |
# File 'lib/twitter/base.rb', line 205 def favorites(query={}) perform_get("/favorites.json", :query => query) end |
#follower_ids(query = {}) ⇒ Object
Options: id, user_id, screen_name
164 165 166 |
# File 'lib/twitter/base.rb', line 164 def follower_ids(query={}) perform_get("/followers/ids.json", :query => query) end |
#followers(query = {}) ⇒ Object
Options: id, user_id, screen_name, page
90 91 92 |
# File 'lib/twitter/base.rb', line 90 def followers(query={}) perform_get("/statuses/followers.json", :query => query) end |
#friend_ids(query = {}) ⇒ Object
Options: id, user_id, screen_name
159 160 161 |
# File 'lib/twitter/base.rb', line 159 def friend_ids(query={}) perform_get("/friends/ids.json", :query => query) end |
#friends(query = {}) ⇒ Object
Options: id, user_id, screen_name, page
85 86 87 |
# File 'lib/twitter/base.rb', line 85 def friends(query={}) perform_get("/statuses/friends.json", :query => query) end |
#friends_timeline(query = {}) ⇒ Object
Options: since_id, max_id, count, page, since
19 20 21 |
# File 'lib/twitter/base.rb', line 19 def friends_timeline(query={}) perform_get("/statuses/friends_timeline.json", :query => query) end |
#friendship_create(id, follow = false) ⇒ Object
140 141 142 143 144 |
# File 'lib/twitter/base.rb', line 140 def friendship_create(id, follow=false) body = {} body.merge!(:follow => follow) if follow perform_post("/friendships/create/#{id}.json", :body => body) end |
#friendship_destroy(id) ⇒ Object
146 147 148 |
# File 'lib/twitter/base.rb', line 146 def friendship_destroy(id) perform_post("/friendships/destroy/#{id}.json") end |
#friendship_exists?(a, b) ⇒ Boolean
150 151 152 |
# File 'lib/twitter/base.rb', line 150 def friendship_exists?(a, b) perform_get("/friendships/exists.json", :query => {:user_a => a, :user_b => b}) end |
#friendship_show(query) ⇒ Object
154 155 156 |
# File 'lib/twitter/base.rb', line 154 def friendship_show(query) perform_get("/friendships/show.json", :query => query) end |
#help ⇒ Object
238 239 240 |
# File 'lib/twitter/base.rb', line 238 def help perform_get("/help/test.json") end |
#home_timeline(query = {}) ⇒ Object
Options: since_id, max_id, count, page
14 15 16 |
# File 'lib/twitter/base.rb', line 14 def home_timeline(query={}) perform_get("/statuses/home_timeline.json", :query => query) end |
#is_list_member?(list_owner_username, slug, id) ⇒ Boolean
295 296 297 |
# File 'lib/twitter/base.rb', line 295 def is_list_member?(list_owner_username, slug, id) perform_get("/#{list_owner_username}/#{slug}/members/#{id}.json").error.nil? end |
#list(list_owner_username, slug) ⇒ Object
265 266 267 |
# File 'lib/twitter/base.rb', line 265 def list(list_owner_username, slug) perform_get("/#{list_owner_username}/lists/#{slug}.json") end |
#list_add_member(list_owner_username, slug, new_id) ⇒ Object
287 288 289 |
# File 'lib/twitter/base.rb', line 287 def list_add_member(list_owner_username, slug, new_id) perform_post("/#{list_owner_username}/#{slug}/members.json", :body => {:id => new_id}) end |
#list_create(list_owner_username, options) ⇒ Object
242 243 244 |
# File 'lib/twitter/base.rb', line 242 def list_create(list_owner_username, ) perform_post("/#{list_owner_username}/lists.json", :body => {:user => list_owner_username}.merge()) end |
#list_delete(list_owner_username, slug) ⇒ Object
250 251 252 |
# File 'lib/twitter/base.rb', line 250 def list_delete(list_owner_username, slug) perform_delete("/#{list_owner_username}/lists/#{slug}.json") end |
#list_members(list_owner_username, slug, query = {}) ⇒ Object
283 284 285 |
# File 'lib/twitter/base.rb', line 283 def list_members(list_owner_username, slug, query = {}) perform_get("/#{list_owner_username}/#{slug}/members.json", :query => query) end |
#list_remove_member(list_owner_username, slug, id) ⇒ Object
291 292 293 |
# File 'lib/twitter/base.rb', line 291 def list_remove_member(list_owner_username, slug, id) perform_delete("/#{list_owner_username}/#{slug}/members.json", :query => {:id => id}) end |
#list_subscribe(list_owner_username, slug) ⇒ Object
303 304 305 |
# File 'lib/twitter/base.rb', line 303 def list_subscribe(list_owner_username, slug) perform_post("/#{list_owner_username}/#{slug}/subscribers.json") end |
#list_subscribers(list_owner_username, slug) ⇒ Object
299 300 301 |
# File 'lib/twitter/base.rb', line 299 def list_subscribers(list_owner_username, slug) perform_get("/#{list_owner_username}/#{slug}/subscribers.json") end |
#list_timeline(list_owner_username, slug, query = {}) ⇒ Object
:per_page = max number of statues to get at once :page = which page of tweets you wish to get
271 272 273 |
# File 'lib/twitter/base.rb', line 271 def list_timeline(list_owner_username, slug, query = {}) perform_get("/#{list_owner_username}/lists/#{slug}/statuses.json", :query => query) end |
#list_unsubscribe(list_owner_username, slug) ⇒ Object
307 308 309 |
# File 'lib/twitter/base.rb', line 307 def list_unsubscribe(list_owner_username, slug) perform_delete("/#{list_owner_username}/#{slug}/subscribers.json") end |
#list_update(list_owner_username, slug, options) ⇒ Object
246 247 248 |
# File 'lib/twitter/base.rb', line 246 def list_update(list_owner_username, slug, ) perform_put("/#{list_owner_username}/lists/#{slug}.json", :body => ) end |
#lists(list_owner_username = nil, query = {}) ⇒ Object
254 255 256 257 258 259 260 261 262 263 |
# File 'lib/twitter/base.rb', line 254 def lists(list_owner_username = nil, query = {}) path = case list_owner_username when nil, Hash query = list_owner_username "/lists.json" else "/#{list_owner_username}/lists.json" end perform_get(path, :query => query) end |
#memberships(list_owner_username, query = {}) ⇒ Object
275 276 277 |
# File 'lib/twitter/base.rb', line 275 def memberships(list_owner_username, query={}) perform_get("/#{list_owner_username}/lists/memberships.json", :query => query) end |
#mentions(query = {}) ⇒ Object
Options: since_id, max_id, count, page
51 52 53 |
# File 'lib/twitter/base.rb', line 51 def mentions(query={}) perform_get("/statuses/mentions.json", :query => query) end |
#rate_limit_status ⇒ Object
194 195 196 |
# File 'lib/twitter/base.rb', line 194 def rate_limit_status perform_get("/account/rate_limit_status.json") end |
#replies(query = {}) ⇒ Object
DEPRECATED: Use #mentions instead
Options: since_id, max_id, since, page
45 46 47 48 |
# File 'lib/twitter/base.rb', line 45 def replies(query={}) warn("DEPRECATED: #replies is deprecated by Twitter; use #mentions instead") perform_get("/statuses/replies.json", :query => query) end |
#report_spam(options) ⇒ Object
When reporting a user for spam, specify one or more of id, screen_name, or user_id
234 235 236 |
# File 'lib/twitter/base.rb', line 234 def report_spam() perform_post("/report_spam.json", :body => ) end |
#retweet(id) ⇒ Object
80 81 82 |
# File 'lib/twitter/base.rb', line 80 def retweet(id) perform_post("/statuses/retweet/#{id}.json") end |
#retweeted_by_me(query = {}) ⇒ Object
Options: since_id, max_id, count, page
56 57 58 |
# File 'lib/twitter/base.rb', line 56 def retweeted_by_me(query={}) perform_get("/statuses/retweeted_by_me.json", :query => query) end |
#retweeted_to_me(query = {}) ⇒ Object
Options: since_id, max_id, count, page
61 62 63 |
# File 'lib/twitter/base.rb', line 61 def retweeted_to_me(query={}) perform_get("/statuses/retweeted_to_me.json", :query => query) end |
#retweeters_of(id, options = {}) ⇒ Object
options: count, page, ids_only
71 72 73 74 |
# File 'lib/twitter/base.rb', line 71 def retweeters_of(id, ={}) ids_only = !!(.delete(:ids_only)) perform_get("/statuses/#{id}/retweeted_by#{"/ids" if ids_only}.json", :query => ) end |
#retweets(id, query = {}) ⇒ Object
Options: count
33 34 35 |
# File 'lib/twitter/base.rb', line 33 def retweets(id, query={}) perform_get("/statuses/retweets/#{id}.json", :query => query) end |
#retweets_of_me(query = {}) ⇒ Object
Options: since_id, max_id, count, page
66 67 68 |
# File 'lib/twitter/base.rb', line 66 def retweets_of_me(query={}) perform_get("/statuses/retweets_of_me.json", :query => query) end |
#saved_search(id) ⇒ Object
323 324 325 |
# File 'lib/twitter/base.rb', line 323 def saved_search(id) perform_get("/saved_searches/show/#{id}.json") end |
#saved_search_create(query) ⇒ Object
327 328 329 |
# File 'lib/twitter/base.rb', line 327 def saved_search_create(query) perform_post("/saved_searches/create.json", :body => {:query => query}) end |
#saved_search_destroy(id) ⇒ Object
331 332 333 |
# File 'lib/twitter/base.rb', line 331 def saved_search_destroy(id) perform_delete("/saved_searches/destroy/#{id}.json") end |
#saved_searches ⇒ Object
319 320 321 |
# File 'lib/twitter/base.rb', line 319 def saved_searches perform_get("/saved_searches.json") end |
#status(id) ⇒ Object
28 29 30 |
# File 'lib/twitter/base.rb', line 28 def status(id) perform_get("/statuses/show/#{id}.json") end |
#status_destroy(id) ⇒ Object
76 77 78 |
# File 'lib/twitter/base.rb', line 76 def status_destroy(id) perform_post("/statuses/destroy/#{id}.json") end |
#subscriptions(list_owner_username, query = {}) ⇒ Object
279 280 281 |
# File 'lib/twitter/base.rb', line 279 def subscriptions(list_owner_username, query = {}) perform_get("/#{list_owner_username}/lists/subscriptions.json", :query => query) end |
#unblock(id) ⇒ Object
229 230 231 |
# File 'lib/twitter/base.rb', line 229 def unblock(id) perform_post("/blocks/destroy/#{id}.json") end |
#update(status, query = {}) ⇒ Object
Options: in_reply_to_status_id
38 39 40 |
# File 'lib/twitter/base.rb', line 38 def update(status, query={}) perform_post("/statuses/update.json", :body => {:status => status}.merge(query)) end |
#update_delivery_device(device) ⇒ Object
Device must be sms, im or none
173 174 175 |
# File 'lib/twitter/base.rb', line 173 def update_delivery_device(device) perform_post("/account/update_delivery_device.json", :body => {:device => device}) end |
#update_profile(body = {}) ⇒ Object
One or more of the following must be present:
name, email, url, location, description
200 201 202 |
# File 'lib/twitter/base.rb', line 200 def update_profile(body={}) perform_post("/account/update_profile.json", :body => body) end |
#update_profile_background(file, tile = false) ⇒ Object
file should respond to #read and #path
190 191 192 |
# File 'lib/twitter/base.rb', line 190 def update_profile_background(file, tile = false) perform_post("/account/update_profile_background_image.json", build_multipart_bodies(:image => file).merge(:tile => tile)) end |
#update_profile_colors(colors = {}) ⇒ Object
One or more of the following must be present:
profile_background_color, profile_text_color, profile_link_color,
profile_sidebar_fill_color, profile_sidebar_border_color
180 181 182 |
# File 'lib/twitter/base.rb', line 180 def update_profile_colors(colors={}) perform_post("/account/update_profile_colors.json", :body => colors) end |
#update_profile_image(file) ⇒ Object
file should respond to #read and #path
185 186 187 |
# File 'lib/twitter/base.rb', line 185 def update_profile_image(file) perform_post("/account/update_profile_image.json", build_multipart_bodies(:image => file)) end |
#user(id, query = {}) ⇒ Object
94 95 96 |
# File 'lib/twitter/base.rb', line 94 def user(id, query={}) perform_get("/users/show/#{id}.json", :query => query) end |
#user_search(q, query = {}) ⇒ Object
Options: page, per_page
114 115 116 117 |
# File 'lib/twitter/base.rb', line 114 def user_search(q, query={}) q = URI.escape(q) perform_get("/users/search.json", :query => ({:q => q}.merge(query))) end |
#user_timeline(query = {}) ⇒ Object
Options: id, user_id, screen_name, since_id, max_id, page, since, count
24 25 26 |
# File 'lib/twitter/base.rb', line 24 def user_timeline(query={}) perform_get("/statuses/user_timeline.json", :query => query) end |
#users(*ids_or_usernames) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/twitter/base.rb', line 98 def users(*ids_or_usernames) ids, usernames = [], [] ids_or_usernames.each do |id_or_username| if id_or_username.is_a?(Integer) ids << id_or_username elsif id_or_username.is_a?(String) usernames << id_or_username end end query = {} query[:user_id] = ids.join(",") unless ids.empty? query[:screen_name] = usernames.join(",") unless usernames.empty? perform_get("/users/lookup.json", :query => query) end |
#verify_credentials ⇒ Object
168 169 170 |
# File 'lib/twitter/base.rb', line 168 def verify_credentials perform_get("/account/verify_credentials.json") end |