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
222 223 224 |
# File 'lib/twitter/base.rb', line 222 def block(id) perform_post("/blocks/create/#{id}.json") end |
#blocked_ids ⇒ Object
308 309 310 |
# File 'lib/twitter/base.rb', line 308 def blocked_ids perform_get("/blocks/blocking/ids.json", :mash => false) end |
#blocking(options = {}) ⇒ Object
312 313 314 |
# File 'lib/twitter/base.rb', line 312 def blocking(={}) perform_get("/blocks/blocking.json", ) end |
#direct_message_create(user, text) ⇒ Object
129 130 131 |
# File 'lib/twitter/base.rb', line 129 def (user, text) perform_post("/direct_messages/new.json", :body => {:user => user, :text => text}) end |
#direct_message_destroy(id) ⇒ Object
133 134 135 |
# File 'lib/twitter/base.rb', line 133 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
218 219 220 |
# File 'lib/twitter/base.rb', line 218 def disable_notifications(id) perform_post("/notifications/leave/#{id}.json") end |
#enable_notifications(id) ⇒ Object
214 215 216 |
# File 'lib/twitter/base.rb', line 214 def enable_notifications(id) perform_post("/notifications/follow/#{id}.json") end |
#favorite_create(id) ⇒ Object
206 207 208 |
# File 'lib/twitter/base.rb', line 206 def favorite_create(id) perform_post("/favorites/create/#{id}.json") end |
#favorite_destroy(id) ⇒ Object
210 211 212 |
# File 'lib/twitter/base.rb', line 210 def favorite_destroy(id) perform_post("/favorites/destroy/#{id}.json") end |
#favorites(query = {}) ⇒ Object
Options: id, page
202 203 204 |
# File 'lib/twitter/base.rb', line 202 def favorites(query={}) perform_get("/favorites.json", :query => query) end |
#follower_ids(query = {}) ⇒ Object
Options: id, user_id, screen_name
161 162 163 |
# File 'lib/twitter/base.rb', line 161 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
156 157 158 |
# File 'lib/twitter/base.rb', line 156 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
137 138 139 140 141 |
# File 'lib/twitter/base.rb', line 137 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
143 144 145 |
# File 'lib/twitter/base.rb', line 143 def friendship_destroy(id) perform_post("/friendships/destroy/#{id}.json") end |
#friendship_exists?(a, b) ⇒ Boolean
147 148 149 |
# File 'lib/twitter/base.rb', line 147 def friendship_exists?(a, b) perform_get("/friendships/exists.json", :query => {:user_a => a, :user_b => b}) end |
#friendship_show(query) ⇒ Object
151 152 153 |
# File 'lib/twitter/base.rb', line 151 def friendship_show(query) perform_get("/friendships/show.json", :query => query) end |
#help ⇒ Object
235 236 237 |
# File 'lib/twitter/base.rb', line 235 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
292 293 294 |
# File 'lib/twitter/base.rb', line 292 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
262 263 264 |
# File 'lib/twitter/base.rb', line 262 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
284 285 286 |
# File 'lib/twitter/base.rb', line 284 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
239 240 241 |
# File 'lib/twitter/base.rb', line 239 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
247 248 249 |
# File 'lib/twitter/base.rb', line 247 def list_delete(list_owner_username, slug) perform_delete("/#{list_owner_username}/lists/#{slug}.json") end |
#list_members(list_owner_username, slug, query = {}) ⇒ Object
280 281 282 |
# File 'lib/twitter/base.rb', line 280 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
288 289 290 |
# File 'lib/twitter/base.rb', line 288 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
300 301 302 |
# File 'lib/twitter/base.rb', line 300 def list_subscribe(list_owner_username, slug) perform_post("/#{list_owner_username}/#{slug}/subscribers.json") end |
#list_subscribers(list_owner_username, slug) ⇒ Object
296 297 298 |
# File 'lib/twitter/base.rb', line 296 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
268 269 270 |
# File 'lib/twitter/base.rb', line 268 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
304 305 306 |
# File 'lib/twitter/base.rb', line 304 def list_unsubscribe(list_owner_username, slug) perform_delete("/#{list_owner_username}/#{slug}/subscribers.json") end |
#list_update(list_owner_username, slug, options) ⇒ Object
243 244 245 |
# File 'lib/twitter/base.rb', line 243 def list_update(list_owner_username, slug, ) perform_put("/#{list_owner_username}/lists/#{slug}.json", :body => ) end |
#lists(list_owner_username = nil, query = {}) ⇒ Object
251 252 253 254 255 256 257 258 259 260 |
# File 'lib/twitter/base.rb', line 251 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
272 273 274 |
# File 'lib/twitter/base.rb', line 272 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
191 192 193 |
# File 'lib/twitter/base.rb', line 191 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
231 232 233 |
# File 'lib/twitter/base.rb', line 231 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
320 321 322 |
# File 'lib/twitter/base.rb', line 320 def saved_search(id) perform_get("/saved_searches/show/#{id}.json") end |
#saved_search_create(query) ⇒ Object
324 325 326 |
# File 'lib/twitter/base.rb', line 324 def saved_search_create(query) perform_post("/saved_searches/create.json", :body => {:query => query}) end |
#saved_search_destroy(id) ⇒ Object
328 329 330 |
# File 'lib/twitter/base.rb', line 328 def saved_search_destroy(id) perform_delete("/saved_searches/destroy/#{id}.json") end |
#saved_searches ⇒ Object
316 317 318 |
# File 'lib/twitter/base.rb', line 316 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
276 277 278 |
# File 'lib/twitter/base.rb', line 276 def subscriptions(list_owner_username, query = {}) perform_get("/#{list_owner_username}/lists/subscriptions.json", :query => query) end |
#unblock(id) ⇒ Object
226 227 228 |
# File 'lib/twitter/base.rb', line 226 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
170 171 172 |
# File 'lib/twitter/base.rb', line 170 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
197 198 199 |
# File 'lib/twitter/base.rb', line 197 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
187 188 189 |
# File 'lib/twitter/base.rb', line 187 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
177 178 179 |
# File 'lib/twitter/base.rb', line 177 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
182 183 184 |
# File 'lib/twitter/base.rb', line 182 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
165 166 167 |
# File 'lib/twitter/base.rb', line 165 def verify_credentials perform_get("/account/verify_credentials.json") end |