twitter 4.2.0 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/CHANGELOG.md +4 -0
  2. data/lib/twitter/api/direct_messages.rb +150 -0
  3. data/lib/twitter/api/favorites.rb +132 -0
  4. data/lib/twitter/api/friends_and_followers.rb +259 -0
  5. data/lib/twitter/api/help.rb +64 -0
  6. data/lib/twitter/api/lists.rb +570 -0
  7. data/lib/twitter/api/places_and_geo.rb +121 -0
  8. data/lib/twitter/api/saved_searches.rb +98 -0
  9. data/lib/twitter/api/search.rb +37 -0
  10. data/lib/twitter/api/spam_reporting.rb +30 -0
  11. data/lib/twitter/api/suggested_users.rb +54 -0
  12. data/lib/twitter/api/timelines.rb +213 -0
  13. data/lib/twitter/api/trends.rb +63 -0
  14. data/lib/twitter/api/tweets.rb +284 -0
  15. data/lib/twitter/api/undocumented.rb +116 -0
  16. data/lib/twitter/api/users.rb +427 -0
  17. data/lib/twitter/api/utils.rb +111 -0
  18. data/lib/twitter/client.rb +41 -13
  19. data/lib/twitter/core_ext/enumerable.rb +1 -1
  20. data/lib/twitter/default.rb +16 -18
  21. data/lib/twitter/error/already_favorited.rb +1 -1
  22. data/lib/twitter/error/already_retweeted.rb +1 -1
  23. data/lib/twitter/profile_banner.rb +18 -0
  24. data/lib/twitter/version.rb +1 -1
  25. data/spec/fixtures/profile_banner.json +1 -0
  26. data/spec/twitter/api/direct_messages_spec.rb +32 -32
  27. data/spec/twitter/api/favorites_spec.rb +114 -0
  28. data/spec/twitter/api/{friendships_spec.rb → friends_and_followers_spec.rb} +146 -146
  29. data/spec/twitter/api/geo_spec.rb +28 -28
  30. data/spec/twitter/api/help_spec.rb +1 -1
  31. data/spec/twitter/api/lists_spec.rb +82 -82
  32. data/spec/twitter/api/saved_searches_spec.rb +1 -1
  33. data/spec/twitter/api/search_spec.rb +1 -17
  34. data/spec/twitter/api/{report_spam_spec.rb → spam_reporting_spec.rb} +1 -1
  35. data/spec/twitter/api/suggested_users_spec.rb +94 -0
  36. data/spec/twitter/api/timelines_spec.rb +138 -0
  37. data/spec/twitter/api/trends_spec.rb +1 -1
  38. data/spec/twitter/api/tweets_spec.rb +249 -0
  39. data/spec/twitter/api/undocumented_spec.rb +103 -0
  40. data/spec/twitter/api/users_spec.rb +308 -17
  41. data/spec/twitter/client_spec.rb +1 -1
  42. data/spec/twitter/profile_banner_spec.rb +13 -0
  43. data/twitter.gemspec +3 -2
  44. metadata +44 -21
  45. data/lib/twitter/api.rb +0 -2558
  46. data/spec/twitter/api/account_spec.rb +0 -152
  47. data/spec/twitter/api/activity_spec.rb +0 -37
  48. data/spec/twitter/api/blocks_spec.rb +0 -122
  49. data/spec/twitter/api/statuses_spec.rb +0 -541
@@ -83,7 +83,7 @@ describe Twitter::Client do
83
83
  before do
84
84
  stub_delete("/custom/delete").with(:query => {:deleted => "object"})
85
85
  end
86
- it "allows custom put requests" do
86
+ it "allows custom delete requests" do
87
87
  subject.delete("/custom/delete", {:deleted => "object"})
88
88
  expect(a_delete("/custom/delete").with(:query => {:deleted => "object"})).to have_been_made
89
89
  end
@@ -0,0 +1,13 @@
1
+ require 'helper'
2
+
3
+ describe Twitter::ProfileBanner do
4
+
5
+ describe "#sizes" do
6
+ it "returns a hash of Sizes when sizes is set" do
7
+ sizes = Twitter::ProfileBanner.new(:sizes => {:small => {:h => 226, :w => 340, :resize => 'fit'}, :large => {:h => 466, :w => 700, :resize => 'fit'}, :medium => {:h => 399, :w => 600, :resize => 'fit'}, :thumb => {:h => 150, :w => 150, :resize => 'crop'}}).sizes
8
+ expect(sizes).to be_a Hash
9
+ expect(sizes[:small]).to be_a Twitter::Size
10
+ end
11
+ end
12
+
13
+ end
@@ -6,9 +6,9 @@ Gem::Specification.new do |spec|
6
6
  spec.add_dependency 'multi_json', '~> 1.3'
7
7
  spec.add_dependency 'simple_oauth', '~> 0.1.6'
8
8
  spec.add_development_dependency 'json'
9
- spec.add_development_dependency 'maruku'
10
9
  spec.add_development_dependency 'pry'
11
10
  spec.add_development_dependency 'rake'
11
+ spec.add_development_dependency 'redcarpet'
12
12
  spec.add_development_dependency 'rspec'
13
13
  spec.add_development_dependency 'simplecov'
14
14
  spec.add_development_dependency 'timecop'
@@ -20,7 +20,8 @@ Gem::Specification.new do |spec|
20
20
  spec.files = %w(CHANGELOG.md LICENSE.md README.md Rakefile twitter.gemspec)
21
21
  spec.files += Dir.glob("lib/**/*.rb")
22
22
  spec.files += Dir.glob("spec/**/*")
23
- spec.homepage = 'https://github.com/sferik/twitter'
23
+ spec.homepage = 'http://sferik.github.com/twitter/'
24
+ spec.licenses = ['MIT']
24
25
  spec.name = 'twitter'
25
26
  spec.require_paths = ['lib']
26
27
  spec.required_rubygems_version = Gem::Requirement.new('>= 1.3.6')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twitter
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0
4
+ version: 4.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2012-10-30 00:00:00.000000000 Z
15
+ date: 2012-11-20 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: faraday
@@ -79,7 +79,7 @@ dependencies:
79
79
  - !ruby/object:Gem::Version
80
80
  version: '0'
81
81
  - !ruby/object:Gem::Dependency
82
- name: maruku
82
+ name: pry
83
83
  requirement: !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
@@ -95,7 +95,7 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: pry
98
+ name: rake
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  none: false
101
101
  requirements:
@@ -111,7 +111,7 @@ dependencies:
111
111
  - !ruby/object:Gem::Version
112
112
  version: '0'
113
113
  - !ruby/object:Gem::Dependency
114
- name: rake
114
+ name: redcarpet
115
115
  requirement: !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
@@ -229,7 +229,22 @@ files:
229
229
  - lib/twitter/action/retweet.rb
230
230
  - lib/twitter/action/tweet.rb
231
231
  - lib/twitter/action_factory.rb
232
- - lib/twitter/api.rb
232
+ - lib/twitter/api/direct_messages.rb
233
+ - lib/twitter/api/favorites.rb
234
+ - lib/twitter/api/friends_and_followers.rb
235
+ - lib/twitter/api/help.rb
236
+ - lib/twitter/api/lists.rb
237
+ - lib/twitter/api/places_and_geo.rb
238
+ - lib/twitter/api/saved_searches.rb
239
+ - lib/twitter/api/search.rb
240
+ - lib/twitter/api/spam_reporting.rb
241
+ - lib/twitter/api/suggested_users.rb
242
+ - lib/twitter/api/timelines.rb
243
+ - lib/twitter/api/trends.rb
244
+ - lib/twitter/api/tweets.rb
245
+ - lib/twitter/api/undocumented.rb
246
+ - lib/twitter/api/users.rb
247
+ - lib/twitter/api/utils.rb
233
248
  - lib/twitter/base.rb
234
249
  - lib/twitter/basic_user.rb
235
250
  - lib/twitter/client.rb
@@ -280,6 +295,7 @@ files:
280
295
  - lib/twitter/metadata.rb
281
296
  - lib/twitter/oembed.rb
282
297
  - lib/twitter/place.rb
298
+ - lib/twitter/profile_banner.rb
283
299
  - lib/twitter/rate_limit.rb
284
300
  - lib/twitter/relationship.rb
285
301
  - lib/twitter/request/multipart_with_file.rb
@@ -343,6 +359,7 @@ files:
343
359
  - spec/fixtures/place.json
344
360
  - spec/fixtures/places.json
345
361
  - spec/fixtures/privacy.json
362
+ - spec/fixtures/profile_banner.json
346
363
  - spec/fixtures/profile_image.text
347
364
  - spec/fixtures/rate_limit_status.json
348
365
  - spec/fixtures/recommendations.json
@@ -387,19 +404,20 @@ files:
387
404
  - spec/twitter/action/retweet_spec.rb
388
405
  - spec/twitter/action_factory_spec.rb
389
406
  - spec/twitter/action_spec.rb
390
- - spec/twitter/api/account_spec.rb
391
- - spec/twitter/api/activity_spec.rb
392
- - spec/twitter/api/blocks_spec.rb
393
407
  - spec/twitter/api/direct_messages_spec.rb
394
- - spec/twitter/api/friendships_spec.rb
408
+ - spec/twitter/api/favorites_spec.rb
409
+ - spec/twitter/api/friends_and_followers_spec.rb
395
410
  - spec/twitter/api/geo_spec.rb
396
411
  - spec/twitter/api/help_spec.rb
397
412
  - spec/twitter/api/lists_spec.rb
398
- - spec/twitter/api/report_spam_spec.rb
399
413
  - spec/twitter/api/saved_searches_spec.rb
400
414
  - spec/twitter/api/search_spec.rb
401
- - spec/twitter/api/statuses_spec.rb
415
+ - spec/twitter/api/spam_reporting_spec.rb
416
+ - spec/twitter/api/suggested_users_spec.rb
417
+ - spec/twitter/api/timelines_spec.rb
402
418
  - spec/twitter/api/trends_spec.rb
419
+ - spec/twitter/api/tweets_spec.rb
420
+ - spec/twitter/api/undocumented_spec.rb
403
421
  - spec/twitter/api/users_spec.rb
404
422
  - spec/twitter/base_spec.rb
405
423
  - spec/twitter/basic_user_spec.rb
@@ -420,6 +438,7 @@ files:
420
438
  - spec/twitter/media_factory_spec.rb
421
439
  - spec/twitter/oembed_spec.rb
422
440
  - spec/twitter/place_spec.rb
441
+ - spec/twitter/profile_banner_spec.rb
423
442
  - spec/twitter/rate_limit_spec.rb
424
443
  - spec/twitter/relationship_spec.rb
425
444
  - spec/twitter/saved_search_spec.rb
@@ -433,8 +452,9 @@ files:
433
452
  - spec/twitter/tweet_spec.rb
434
453
  - spec/twitter/user_spec.rb
435
454
  - spec/twitter_spec.rb
436
- homepage: https://github.com/sferik/twitter
437
- licenses: []
455
+ homepage: http://sferik.github.com/twitter/
456
+ licenses:
457
+ - MIT
438
458
  post_install_message:
439
459
  rdoc_options: []
440
460
  require_paths:
@@ -453,7 +473,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
453
473
  version: 1.3.6
454
474
  requirements: []
455
475
  rubyforge_project:
456
- rubygems_version: 1.8.23
476
+ rubygems_version: 1.8.24
457
477
  signing_key:
458
478
  specification_version: 3
459
479
  summary: A Ruby interface to the Twitter API.
@@ -504,6 +524,7 @@ test_files:
504
524
  - spec/fixtures/place.json
505
525
  - spec/fixtures/places.json
506
526
  - spec/fixtures/privacy.json
527
+ - spec/fixtures/profile_banner.json
507
528
  - spec/fixtures/profile_image.text
508
529
  - spec/fixtures/rate_limit_status.json
509
530
  - spec/fixtures/recommendations.json
@@ -548,19 +569,20 @@ test_files:
548
569
  - spec/twitter/action/retweet_spec.rb
549
570
  - spec/twitter/action_factory_spec.rb
550
571
  - spec/twitter/action_spec.rb
551
- - spec/twitter/api/account_spec.rb
552
- - spec/twitter/api/activity_spec.rb
553
- - spec/twitter/api/blocks_spec.rb
554
572
  - spec/twitter/api/direct_messages_spec.rb
555
- - spec/twitter/api/friendships_spec.rb
573
+ - spec/twitter/api/favorites_spec.rb
574
+ - spec/twitter/api/friends_and_followers_spec.rb
556
575
  - spec/twitter/api/geo_spec.rb
557
576
  - spec/twitter/api/help_spec.rb
558
577
  - spec/twitter/api/lists_spec.rb
559
- - spec/twitter/api/report_spam_spec.rb
560
578
  - spec/twitter/api/saved_searches_spec.rb
561
579
  - spec/twitter/api/search_spec.rb
562
- - spec/twitter/api/statuses_spec.rb
580
+ - spec/twitter/api/spam_reporting_spec.rb
581
+ - spec/twitter/api/suggested_users_spec.rb
582
+ - spec/twitter/api/timelines_spec.rb
563
583
  - spec/twitter/api/trends_spec.rb
584
+ - spec/twitter/api/tweets_spec.rb
585
+ - spec/twitter/api/undocumented_spec.rb
564
586
  - spec/twitter/api/users_spec.rb
565
587
  - spec/twitter/base_spec.rb
566
588
  - spec/twitter/basic_user_spec.rb
@@ -581,6 +603,7 @@ test_files:
581
603
  - spec/twitter/media_factory_spec.rb
582
604
  - spec/twitter/oembed_spec.rb
583
605
  - spec/twitter/place_spec.rb
606
+ - spec/twitter/profile_banner_spec.rb
584
607
  - spec/twitter/rate_limit_spec.rb
585
608
  - spec/twitter/relationship_spec.rb
586
609
  - spec/twitter/saved_search_spec.rb
@@ -1,2558 +0,0 @@
1
- require 'twitter/action_factory'
2
- require 'twitter/configuration'
3
- require 'twitter/core_ext/array'
4
- require 'twitter/core_ext/enumerable'
5
- require 'twitter/core_ext/hash'
6
- require 'twitter/core_ext/kernel'
7
- require 'twitter/cursor'
8
- require 'twitter/direct_message'
9
- require 'twitter/error/already_favorited'
10
- require 'twitter/error/already_retweeted'
11
- require 'twitter/error/forbidden'
12
- require 'twitter/error/not_found'
13
- require 'twitter/language'
14
- require 'twitter/list'
15
- require 'twitter/oembed'
16
- require 'twitter/place'
17
- require 'twitter/relationship'
18
- require 'twitter/saved_search'
19
- require 'twitter/search_results'
20
- require 'twitter/settings'
21
- require 'twitter/suggestion'
22
- require 'twitter/trend'
23
- require 'twitter/tweet'
24
- require 'twitter/user'
25
-
26
- module Twitter
27
- module API
28
- DEFAULT_CURSOR = -1
29
- DEFAULT_TWEETS_PER_REQUEST = 20
30
- MAX_USERS_PER_REQUEST = 100
31
- MAX_TWEETS_PER_REQUEST = 200
32
-
33
- # Returns the requesting user if authentication was successful, otherwise raises {Twitter::Error::Unauthorized}
34
- #
35
- # @see https://dev.twitter.com/docs/api/1.1/get/account/verify_credentials
36
- # @rate_limited Yes
37
- # @authentication_required Requires user context
38
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
39
- # @return [Twitter::User] The authenticated user.
40
- # @param options [Hash] A customizable set of options.
41
- # @option options [Boolean, String, Integer] :skip_status Do not include user's Tweets when set to true, 't' or 1.
42
- # @example Return the requesting user if authentication was successful
43
- # Twitter.verify_credentials
44
- def verify_credentials(options={})
45
- object_from_response(Twitter::User, :get, "/1.1/account/verify_credentials.json", options)
46
- end
47
- alias current_user verify_credentials
48
-
49
- # Sets which device Twitter delivers updates to for the authenticating user
50
- #
51
- # @see https://dev.twitter.com/docs/api/1.1/post/account/update_delivery_device
52
- # @rate_limited No
53
- # @authentication_required Requires user context
54
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
55
- # @return [Twitter::User] The authenticated user.
56
- # @param device [String] Must be one of: 'sms', 'none'.
57
- # @param options [Hash] A customizable set of options.
58
- # @example Turn SMS updates on for the authenticating user
59
- # Twitter.update_delivery_device('sms')
60
- def update_delivery_device(device, options={})
61
- object_from_response(Twitter::User, :post, "/1.1/account/update_delivery_device.json", options.merge(:device => device))
62
- end
63
-
64
- # Sets values that users are able to set under the "Account" tab of their settings page
65
- #
66
- # @see https://dev.twitter.com/docs/api/1.1/post/account/update_profile
67
- # @note Only the options specified will be updated.
68
- # @rate_limited No
69
- # @authentication_required Requires user context
70
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
71
- # @return [Twitter::User] The authenticated user.
72
- # @param options [Hash] A customizable set of options.
73
- # @option options [String] :name Full name associated with the profile. Maximum of 20 characters.
74
- # @option options [String] :url URL associated with the profile. Will be prepended with "http://" if not present. Maximum of 100 characters.
75
- # @option options [String] :location The city or country describing where the user of the account is located. The contents are not normalized or geocoded in any way. Maximum of 30 characters.
76
- # @option options [String] :description A description of the user owning the account. Maximum of 160 characters.
77
- # @example Set authenticating user's name to Erik Michaels-Ober
78
- # Twitter.update_profile(:name => "Erik Michaels-Ober")
79
- def update_profile(options={})
80
- object_from_response(Twitter::User, :post, "/1.1/account/update_profile.json", options)
81
- end
82
-
83
- # Updates the authenticating user's profile background image
84
- #
85
- # @see https://dev.twitter.com/docs/api/1.1/post/account/update_profile_background_image
86
- # @rate_limited No
87
- # @authentication_required Requires user context
88
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
89
- # @return [Twitter::User] The authenticated user.
90
- # @param image [File] The background image for the profile, base64-encoded. Must be a valid GIF, JPG, or PNG image of less than 800 kilobytes in size. Images with width larger than 2048 pixels will be forcibly scaled down. The image must be provided as raw multipart data, not a URL.
91
- # @param options [Hash] A customizable set of options.
92
- # @option options [Boolean] :tile Whether or not to tile the background image. If set to true the background image will be displayed tiled. The image will not be tiled otherwise.
93
- # @example Update the authenticating user's profile background image
94
- # Twitter.update_profile_background_image(File.new("we_concept_bg2.png"))
95
- def update_profile_background_image(image, options={})
96
- object_from_response(Twitter::User, :post, "/1.1/account/update_profile_background_image.json", options.merge(:image => image))
97
- end
98
-
99
- # Sets one or more hex values that control the color scheme of the authenticating user's profile
100
- #
101
- # @see https://dev.twitter.com/docs/api/1.1/post/account/update_profile_colors
102
- # @rate_limited No
103
- # @authentication_required Requires user context
104
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
105
- # @return [Twitter::User] The authenticated user.
106
- # @param options [Hash] A customizable set of options.
107
- # @option options [String] :profile_background_color Profile background color.
108
- # @option options [String] :profile_text_color Profile text color.
109
- # @option options [String] :profile_link_color Profile link color.
110
- # @option options [String] :profile_sidebar_fill_color Profile sidebar's background color.
111
- # @option options [String] :profile_sidebar_border_color Profile sidebar's border color.
112
- # @example Set authenticating user's profile background to black
113
- # Twitter.update_profile_colors(:profile_background_color => '000000')
114
- def update_profile_colors(options={})
115
- object_from_response(Twitter::User, :post, "/1.1/account/update_profile_colors.json", options)
116
- end
117
-
118
- # Updates the authenticating user's profile image
119
- #
120
- # @see https://dev.twitter.com/docs/api/1.1/post/account/update_profile_image
121
- # @note Updates the authenticating user's profile image. Note that this method expects raw multipart data, not a URL to an image.
122
- # @note This method asynchronously processes the uploaded file before updating the user's profile image URL. You can either update your local cache the next time you request the user's information, or, at least 5 seconds after uploading the image, ask for the updated URL using GET users/show.
123
- # @rate_limited No
124
- # @authentication_required Requires user context
125
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
126
- # @return [Twitter::User] The authenticated user.
127
- # @param image [File] The avatar image for the profile, base64-encoded. Must be a valid GIF, JPG, or PNG image of less than 700 kilobytes in size. Images with width larger than 500 pixels will be scaled down. Animated GIFs will be converted to a static GIF of the first frame, removing the animation.
128
- # @param options [Hash] A customizable set of options.
129
- # @example Update the authenticating user's profile image
130
- # Twitter.update_profile_image(File.new("me.jpeg"))
131
- def update_profile_image(image, options={})
132
- object_from_response(Twitter::User, :post, "/1.1/account/update_profile_image.json", options.merge(:image => image))
133
- end
134
-
135
- # Updates the authenticating user's profile banner image
136
- #
137
- # @see https://dev.twitter.com/docs/api/1.1/post/account/update_profile_banner
138
- # @note Uploads a profile banner on behalf of the authenticating user. For best results, upload an <5MB image that is exactly 1252px by 626px. Images will be resized for a number of display options. Users with an uploaded profile banner will have a profile_banner_url node in their Users objects. More information about sizing variations can be found in User Profile Images and Banners.
139
- # @note Profile banner images are processed asynchronously. The profile_banner_url and its variant sizes will not necessary be available directly after upload.
140
- # @rate_limited No
141
- # @authentication_required Requires user context
142
- # @raise [Twitter::Error::BadRequest] Error raised when either an image was not provided or the image data could not be processed.
143
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
144
- # @raise [Twitter::Error::UnprocessableEntity] Error raised when the image could not be resized or is too large.
145
- # @return [nil]
146
- # @param image [File] The Base64-encoded or raw image data being uploaded as the user's new profile banner.
147
- # @param options [Hash] A customizable set of options.
148
- # @option options [Integer] :width The width of the preferred section of the image being uploaded in pixels. Use with height, offset_left, and offset_top to select the desired region of the image to use.
149
- # @option options [Integer] :height The height of the preferred section of the image being uploaded in pixels. Use with width, offset_left, and offset_top to select the desired region of the image to use.
150
- # @option options [Integer] :offset_left The number of pixels by which to offset the uploaded image from the left. Use with height, width, and offset_top to select the desired region of the image to use.
151
- # @option options [Integer] :offset_top The number of pixels by which to offset the uploaded image from the top. Use with height, width, and offset_left to select the desired region of the image to use.
152
- # @example Update the authenticating user's profile banner
153
- # Twitter.update_profile_banner(File.new("me.jpeg"))
154
- def update_profile_banner(banner, options={})
155
- post("/1.1/account/update_profile_banner.json", options.merge(:banner => banner))[:body]
156
- end
157
-
158
- # Removes the authenticating user's profile banner image
159
- #
160
- # @see https://dev.twitter.com/docs/api/1.1/post/account/remove_profile_banner
161
- # @rate_limited No
162
- # @authentication_required Requires user context
163
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
164
- # @return [nil]
165
- # @param options [Hash] A customizable set of options.
166
- # @example Remove the authenticating user's profile banner image
167
- # Twitter.remove_profile_banner
168
- def remove_profile_banner(options={})
169
- post("/1.1/account/remove_profile_banner.json", options)[:body]
170
- end
171
-
172
- # Updates the authenticating user's settings.
173
- # Or, if no options supplied, returns settings (including current trend, geo and sleep time information) for the authenticating user.
174
- #
175
- # @see https://dev.twitter.com/docs/api/1.1/post/account/settings
176
- # @see https://dev.twitter.com/docs/api/1.1/get/account/settings
177
- # @rate_limited Yes
178
- # @authentication_required Requires user context
179
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
180
- # @return [Twitter::Settings]
181
- # @param options [Hash] A customizable set of options.
182
- # @option options [Integer] :trend_location_woeid The Yahoo! Where On Earth ID to use as the user's default trend location. Global information is available by using 1 as the WOEID. The woeid must be one of the locations returned by {https://dev.twitter.com/docs/api/1.1/get/trends/available GET trends/available}.
183
- # @option options [Boolean, String, Integer] :sleep_time_enabled When set to true, 't' or 1, will enable sleep time for the user. Sleep time is the time when push or SMS notifications should not be sent to the user.
184
- # @option options [Integer] :start_sleep_time The hour that sleep time should begin if it is enabled. The value for this parameter should be provided in {http://en.wikipedia.org/wiki/ISO_8601 ISO8601} format (i.e. 00-23). The time is considered to be in the same timezone as the user's time_zone setting.
185
- # @option options [Integer] :end_sleep_time The hour that sleep time should end if it is enabled. The value for this parameter should be provided in {http://en.wikipedia.org/wiki/ISO_8601 ISO8601} format (i.e. 00-23). The time is considered to be in the same timezone as the user's time_zone setting.
186
- # @option options [String] :time_zone The timezone dates and times should be displayed in for the user. The timezone must be one of the {http://api.rubyonrails.org/classes/ActiveSupport/TimeZone.html Rails TimeZone} names.
187
- # @option options [String] :lang The language which Twitter should render in for this user. The language must be specified by the appropriate two letter ISO 639-1 representation. Currently supported languages are provided by {https://dev.twitter.com/docs/api/1.1/get/help/languages GET help/languages}.
188
- # @example Return the settings for the authenticating user.
189
- # Twitter.settings
190
- def settings(options={})
191
- request_method = options.size.zero? ? :get : :post
192
- object_from_response(Twitter::Settings, request_method, "/1.1/account/settings.json", options)
193
- end
194
-
195
- # Returns activity about me
196
- #
197
- # @note Undocumented
198
- # @rate_limited Yes
199
- # @authentication_required Requires user context
200
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
201
- # @return [Array] An array of actions
202
- # @param options [Hash] A customizable set of options.
203
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
204
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
205
- # @example Return activity about me
206
- # Twitter.activity_about_me
207
- def activity_about_me(options={})
208
- collection_from_response(Twitter::ActionFactory, :get, "/i/activity/about_me.json", options)
209
- end
210
-
211
- # Returns activity by friends
212
- #
213
- # @note Undocumented
214
- # @rate_limited Yes
215
- # @authentication_required Requires user context
216
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid./
217
- # @return [Array] An array of actions
218
- # @param options [Hash] A customizable set of options.
219
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
220
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
221
- # @example Return activity by friends
222
- # Twitter.activity_by_friends
223
- def activity_by_friends(options={})
224
- collection_from_response(Twitter::ActionFactory, :get, "/i/activity/by_friends.json", options)
225
- end
226
-
227
- # Returns the 20 most recent direct messages sent to the authenticating user
228
- #
229
- # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages
230
- # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
231
- # @rate_limited Yes
232
- # @authentication_required Requires user context
233
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
234
- # @return [Array<Twitter::DirectMessage>] Direct messages sent to the authenticating user.
235
- # @param options [Hash] A customizable set of options.
236
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
237
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
238
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
239
- # @option options [Integer] :page Specifies the page of results to retrieve.
240
- # @example Return the 20 most recent direct messages sent to the authenticating user
241
- # Twitter.direct_messages_received
242
- def direct_messages_received(options={})
243
- collection_from_response(Twitter::DirectMessage, :get, "/1.1/direct_messages.json", options)
244
- end
245
-
246
- # Returns the 20 most recent direct messages sent by the authenticating user
247
- #
248
- # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages/sent
249
- # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
250
- # @rate_limited Yes
251
- # @authentication_required Requires user context
252
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
253
- # @return [Array<Twitter::DirectMessage>] Direct messages sent by the authenticating user.
254
- # @param options [Hash] A customizable set of options.
255
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
256
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
257
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
258
- # @option options [Integer] :page Specifies the page of results to retrieve.
259
- # @example Return the 20 most recent direct messages sent by the authenticating user
260
- # Twitter.direct_messages_sent
261
- def direct_messages_sent(options={})
262
- collection_from_response(Twitter::DirectMessage, :get, "/1.1/direct_messages/sent.json", options)
263
- end
264
-
265
- # Destroys direct messages
266
- #
267
- # @see https://dev.twitter.com/docs/api/1.1/post/direct_messages/destroy
268
- # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
269
- # @rate_limited No
270
- # @authentication_required Requires user context
271
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
272
- # @return [Array<Twitter::DirectMessage>] Deleted direct message.
273
- # @overload direct_message_destroy(*ids)
274
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
275
- # @example Destroys the direct message with the ID 1825785544
276
- # Twitter.direct_message_destroy(1825785544)
277
- # @overload direct_message_destroy(*ids, options)
278
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
279
- # @param options [Hash] A customizable set of options.
280
- def direct_message_destroy(*args)
281
- options = args.extract_options!
282
- args.flatten.threaded_map do |id|
283
- object_from_response(Twitter::DirectMessage, :post, "/1.1/direct_messages/destroy.json", options.merge(:id => id))
284
- end
285
- end
286
-
287
- # Sends a new direct message to the specified user from the authenticating user
288
- #
289
- # @see https://dev.twitter.com/docs/api/1.1/post/direct_messages/new
290
- # @rate_limited No
291
- # @authentication_required Requires user context
292
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
293
- # @return [Twitter::DirectMessage] The sent message.
294
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
295
- # @param text [String] The text of your direct message, up to 140 characters.
296
- # @param options [Hash] A customizable set of options.
297
- # @example Send a direct message to @sferik from the authenticating user
298
- # Twitter.direct_message_create('sferik', "I'm sending you this message via @gem!")
299
- # Twitter.direct_message_create(7505382, "I'm sending you this message via @gem!") # Same as above
300
- def direct_message_create(user, text, options={})
301
- options.merge_user!(user)
302
- options[:text] = text
303
- object_from_response(Twitter::DirectMessage, :post, "/1.1/direct_messages/new.json", options)
304
- end
305
- alias d direct_message_create
306
- alias m direct_message_create
307
-
308
- # Returns a direct message
309
- #
310
- # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages/show
311
- # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
312
- # @rate_limited Yes
313
- # @authentication_required Requires user context
314
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
315
- # @return [Twitter::DirectMessage] The requested messages.
316
- # @param id [Integer] A Tweet IDs.
317
- # @param options [Hash] A customizable set of options.
318
- # @example Return the direct message with the id 1825786345
319
- # Twitter.direct_message(1825786345)
320
- def direct_message(id, options={})
321
- options[:id] = id
322
- object_from_response(Twitter::DirectMessage, :get, "/1.1/direct_messages/show.json", options)
323
- end
324
-
325
- # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
326
- # @rate_limited Yes
327
- # @authentication_required Requires user context
328
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
329
- # @return [Array<Twitter::DirectMessage>] The requested messages.
330
- # @overload direct_messages(options={})
331
- # Returns the 20 most recent direct messages sent to the authenticating user
332
- #
333
- # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages
334
- # @param options [Hash] A customizable set of options.
335
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
336
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
337
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
338
- # @option options [Integer] :page Specifies the page of results to retrieve.
339
- # @example Return the 20 most recent direct messages sent to the authenticating user
340
- # Twitter.direct_messages
341
- # @overload direct_messages(*ids)
342
- # Returns direct messages
343
- #
344
- # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages/show
345
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
346
- # @example Return the direct message with the id 1825786345
347
- # Twitter.direct_messages(1825786345)
348
- # @overload direct_messages(*ids, options)
349
- # Returns direct messages
350
- #
351
- # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages/show
352
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
353
- # @param options [Hash] A customizable set of options.
354
- def direct_messages(*args)
355
- options = args.extract_options!
356
- if args.empty?
357
- direct_messages_received(options)
358
- else
359
- args.flatten.threaded_map do |id|
360
- direct_message(id, options)
361
- end
362
- end
363
- end
364
-
365
- # @see https://dev.twitter.com/docs/api/1.1/get/followers/ids
366
- # @rate_limited Yes
367
- # @authentication_required Requires user context
368
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
369
- # @return [Twitter::Cursor]
370
- # @overload follower_ids(options={})
371
- # Returns an array of numeric IDs for every user following the authenticated user
372
- #
373
- # @param options [Hash] A customizable set of options.
374
- # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
375
- # @example Return the authenticated user's followers' IDs
376
- # Twitter.follower_ids
377
- # @overload follower_ids(user, options={})
378
- # Returns an array of numeric IDs for every user following the specified user
379
- #
380
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
381
- # @param options [Hash] A customizable set of options.
382
- # @option options [Integer] :cursor (-1) Breaks the results into pages. This is recommended for users who are following many users. Provide a value of -1 to begin paging. Provide values as returned in the response body's next_cursor and previous_cursor attributes to page back and forth in the list.
383
- # @example Return @sferik's followers' IDs
384
- # Twitter.follower_ids('sferik')
385
- # Twitter.follower_ids(7505382) # Same as above
386
- def follower_ids(*args)
387
- ids_from_response(:get, "/1.1/followers/ids.json", args)
388
- end
389
-
390
- # @see https://dev.twitter.com/docs/api/1.1/get/friends/ids
391
- # @rate_limited Yes
392
- # @authentication_required Requires user context
393
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
394
- # @return [Twitter::Cursor]
395
- # @overload friend_ids(options={})
396
- # Returns an array of numeric IDs for every user the authenticated user is following
397
- #
398
- # @param options [Hash] A customizable set of options.
399
- # @option options [Integer] :cursor (-1) Breaks the results into pages. This is recommended for users who are following many users. Provide a value of -1 to begin paging. Provide values as returned in the response body's next_cursor and previous_cursor attributes to page back and forth in the list.
400
- # @example Return the authenticated user's friends' IDs
401
- # Twitter.friend_ids
402
- # @overload friend_ids(user, options={})
403
- # Returns an array of numeric IDs for every user the specified user is following
404
- #
405
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
406
- # @param options [Hash] A customizable set of options.
407
- # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
408
- # @example Return @sferik's friends' IDs
409
- # Twitter.friend_ids('sferik')
410
- # Twitter.friend_ids(7505382) # Same as above
411
- def friend_ids(*args)
412
- ids_from_response(:get, "/1.1/friends/ids.json", args)
413
- end
414
-
415
- # Test for the existence of friendship between two users
416
- #
417
- # @see https://dev.twitter.com/docs/api/1.1/get/friendships/show
418
- # @rate_limited Yes
419
- # @authentication_required Requires user context
420
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
421
- # @return [Boolean] true if user_a follows user_b, otherwise false.
422
- # @param source [Integer, String, Twitter::User] The Twitter user ID, screen name, or object of the source user.
423
- # @param target [Integer, String, Twitter::User] The Twitter user ID, screen name, or object of the target user.
424
- # @param options [Hash] A customizable set of options.
425
- # @example Return true if @sferik follows @pengwynn
426
- # Twitter.friendship?('sferik', 'pengwynn')
427
- # Twitter.friendship?('sferik', 14100886) # Same as above
428
- # Twitter.friendship?(7505382, 14100886) # Same as above
429
- def friendship?(source, target, options={})
430
- friendship(source, target, options).source.following?
431
- end
432
-
433
- # Returns an array of numeric IDs for every user who has a pending request to follow the authenticating user
434
- #
435
- # @see https://dev.twitter.com/docs/api/1.1/get/friendships/incoming
436
- # @rate_limited Yes
437
- # @authentication_required Requires user context
438
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
439
- # @return [Twitter::Cursor]
440
- # @param options [Hash] A customizable set of options.
441
- # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
442
- # @example Return an array of numeric IDs for every user who has a pending request to follow the authenticating user
443
- # Twitter.friendships_incoming
444
- def friendships_incoming(options={})
445
- merge_default_cursor!(options)
446
- cursor_from_response(:ids, nil, :get, "/1.1/friendships/incoming.json", options)
447
- end
448
-
449
- # Returns an array of numeric IDs for every protected user for whom the authenticating user has a pending follow request
450
- #
451
- # @see https://dev.twitter.com/docs/api/1.1/get/friendships/outgoing
452
- # @rate_limited Yes
453
- # @authentication_required Requires user context
454
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
455
- # @return [Twitter::Cursor]
456
- # @param options [Hash] A customizable set of options.
457
- # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
458
- # @example Return an array of numeric IDs for every protected user for whom the authenticating user has a pending follow request
459
- # Twitter.friendships_outgoing
460
- def friendships_outgoing(options={})
461
- merge_default_cursor!(options)
462
- cursor_from_response(:ids, nil, :get, "/1.1/friendships/outgoing.json", options)
463
- end
464
-
465
- # Returns detailed information about the relationship between two users
466
- #
467
- # @see https://dev.twitter.com/docs/api/1.1/get/friendships/show
468
- # @rate_limited Yes
469
- # @authentication_required Requires user context
470
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
471
- # @return [Twitter::Relationship]
472
- # @param source [Integer, String, Twitter::User] The Twitter user ID, screen name, or object of the source user.
473
- # @param target [Integer, String, Twitter::User] The Twitter user ID, screen name, or object of the target user.
474
- # @param options [Hash] A customizable set of options.
475
- # @example Return the relationship between @sferik and @pengwynn
476
- # Twitter.friendship('sferik', 'pengwynn')
477
- # Twitter.friendship('sferik', 14100886) # Same as above
478
- # Twitter.friendship(7505382, 14100886) # Same as above
479
- def friendship(source, target, options={})
480
- options.merge_user!(source, "source")
481
- options[:source_id] = options.delete(:source_user_id) unless options[:source_user_id].nil?
482
- options.merge_user!(target, "target")
483
- options[:target_id] = options.delete(:target_user_id) unless options[:target_user_id].nil?
484
- object_from_response(Twitter::Relationship, :get, "/1.1/friendships/show.json", options)
485
- end
486
- alias friendship_show friendship
487
- alias relationship friendship
488
-
489
- # Allows the authenticating user to follow the specified users, unless they are already followed
490
- #
491
- # @see https://dev.twitter.com/docs/api/1.1/post/friendships/create
492
- # @rate_limited No
493
- # @authentication_required Requires user context
494
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
495
- # @return [Array<Twitter::User>] The followed users.
496
- # @overload(*users)
497
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
498
- # @example Follow @sferik
499
- # Twitter.follow('sferik')
500
- # @overload(*users, options)
501
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
502
- # @param options [Hash] A customizable set of options.
503
- # @option options [Boolean] :follow (false) Enable notifications for the target user.
504
- def follow(*args)
505
- options = args.extract_options!
506
- # Twitter always turns on notifications if the "follow" option is present, even if it's set to false
507
- # so only send follow if it's true
508
- options[:follow] = true if !!options.delete(:follow)
509
- existing_friends = Thread.new do
510
- friend_ids.ids
511
- end
512
- new_friends = Thread.new do
513
- users(args).map(&:id)
514
- end
515
- follow!(new_friends.value - existing_friends.value, options)
516
- end
517
- alias friendship_create follow
518
-
519
- # Allows the authenticating user to follow the specified users
520
- #
521
- # @see https://dev.twitter.com/docs/api/1.1/post/friendships/create
522
- # @rate_limited No
523
- # @authentication_required Requires user context
524
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
525
- # @return [Array<Twitter::User>] The followed users.
526
- # @overload follow!(*users)
527
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
528
- # @example Follow @sferik
529
- # Twitter.follow!('sferik')
530
- # @overload follow!(*users, options)
531
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
532
- # @param options [Hash] A customizable set of options.
533
- # @option options [Boolean] :follow (false) Enable notifications for the target user.
534
- def follow!(*args)
535
- options = args.extract_options!
536
- # Twitter always turns on notifications if the "follow" option is present, even if it's set to false
537
- # so only send follow if it's true
538
- options[:follow] = true if !!options.delete(:follow)
539
- args.flatten.threaded_map do |user|
540
- begin
541
- options.merge_user!(user)
542
- object_from_response(Twitter::User, :post, "/1.1/friendships/create.json", options)
543
- rescue Twitter::Error::Forbidden
544
- # This error will be raised if the user doesn't have permission to
545
- # follow list_member, for whatever reason.
546
- end
547
- end.compact
548
- end
549
- alias friendship_create! follow!
550
-
551
- # Allows the authenticating user to unfollow the specified users
552
- #
553
- # @see https://dev.twitter.com/docs/api/1.1/post/friendships/destroy
554
- # @rate_limited No
555
- # @authentication_required Requires user context
556
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
557
- # @return [Array<Twitter::User>] The unfollowed users.
558
- # @overload unfollow(*users)
559
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
560
- # @example Unfollow @sferik
561
- # Twitter.unfollow('sferik')
562
- # @overload unfollow(*users)
563
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
564
- # @param options [Hash] A customizable set of options.
565
- def unfollow(*args)
566
- threaded_users_from_response(:post, "/1.1/friendships/destroy.json", args)
567
- end
568
- alias friendship_destroy unfollow
569
-
570
- # Returns the relationship of the authenticating user to the comma separated list of up to 100 screen_names or user_ids provided. Values for connections can be: following, following_requested, followed_by, none.
571
- #
572
- # @see https://dev.twitter.com/docs/api/1.1/get/friendships/lookup
573
- # @rate_limited Yes
574
- # @authentication_required Requires user context
575
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
576
- # @return [Array<Twitter::User>] The requested users.
577
- # @overload friendships(*users)
578
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
579
- # @example Return extended information for @sferik and @pengwynn
580
- # Twitter.friendships('sferik', 'pengwynn')
581
- # Twitter.friendships('sferik', 14100886) # Same as above
582
- # Twitter.friendships(7505382, 14100886) # Same as above
583
- # @overload friendships(*users, options)
584
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
585
- # @param options [Hash] A customizable set of options.
586
- def friendships(*args)
587
- options = args.extract_options!
588
- options.merge_users!(Array(args))
589
- collection_from_response(Twitter::User, :get, "/1.1/friendships/lookup.json", options)
590
- end
591
-
592
- # Allows one to enable or disable retweets and device notifications from the specified user.
593
- #
594
- # @see https://dev.twitter.com/docs/api/1.1/post/friendships/update
595
- # @rate_limited No
596
- # @authentication_required Requires user context
597
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
598
- # @return [Twitter::Relationship]
599
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
600
- # @param options [Hash] A customizable set of options.
601
- # @option options [Boolean] :device Enable/disable device notifications from the target user.
602
- # @option options [Boolean] :retweets Enable/disable retweets from the target user.
603
- # @example Enable rewteets and devise notifications for @sferik
604
- # Twitter.friendship_update('sferik', :device => true, :retweets => true)
605
- def friendship_update(user, options={})
606
- options.merge_user!(user)
607
- object_from_response(Twitter::Relationship, :post, "/1.1/friendships/update.json", options)
608
- end
609
-
610
- # Search for places that can be attached to a {Twitter::API::Statuses#update}
611
- #
612
- # @see https://dev.twitter.com/docs/api/1.1/get/geo/search
613
- # @rate_limited Yes
614
- # @authentication_required Requires user context
615
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
616
- # @param options [Hash] A customizable set of options.
617
- # @option options [Float] :lat The latitude to search around. This option will be ignored unless it is inside the range -90.0 to +90.0 (North is positive) inclusive. It will also be ignored if there isn't a corresponding :long option.
618
- # @option options [Float] :long The longitude to search around. The valid range for longitude is -180.0 to +180.0 (East is positive) inclusive. This option will be ignored if outside that range, if it is not a number, if geo_enabled is disabled, or if there not a corresponding :lat option.
619
- # @option options [String] :query Free-form text to match against while executing a geo-based query, best suited for finding nearby locations by name.
620
- # @option options [String] :ip An IP address. Used when attempting to fix geolocation based off of the user's IP address.
621
- # @option options [String] :granularity ('neighborhood') This is the minimal granularity of place types to return and must be one of: 'poi', 'neighborhood', 'city', 'admin' or 'country'.
622
- # @option options [String] :accuracy ('0m') A hint on the "region" in which to search. If a number, then this is a radius in meters, but it can also take a string that is suffixed with ft to specify feet. If coming from a device, in practice, this value is whatever accuracy the device has measuring its location (whether it be coming from a GPS, WiFi triangulation, etc.).
623
- # @option options [Integer] :max_results A hint as to the number of results to return. This does not guarantee that the number of results returned will equal max_results, but instead informs how many "nearby" results to return. Ideally, only pass in the number of places you intend to display to the user here.
624
- # @option options [String] :contained_within This is the place_id which you would like to restrict the search results to. Setting this value means only places within the given place_id will be found.
625
- # @option options [String] :"attribute:street_address" This option searches for places which have this given street address. There are other well-known and application-specific attributes available. Custom attributes are also permitted.
626
- # @return [Array<Twitter::Place>]
627
- # @example Return an array of places near the IP address 74.125.19.104
628
- # Twitter.places_nearby(:ip => "74.125.19.104")
629
- def places_nearby(options={})
630
- geo_collection_from_response(:get, "/1.1/geo/search.json", options)
631
- end
632
- alias geo_search places_nearby
633
-
634
- # Locates places near the given coordinates which are similar in name
635
- #
636
- # @see https://dev.twitter.com/docs/api/1.1/get/geo/similar_places
637
- # @note Conceptually, you would use this method to get a list of known places to choose from first. Then, if the desired place doesn't exist, make a request to {Twitter::API::Geo#place} to create a new one. The token contained in the response is the token necessary to create a new place.
638
- # @rate_limited Yes
639
- # @authentication_required Requires user context
640
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
641
- # @param options [Hash] A customizable set of options.
642
- # @option options [Float] :lat The latitude to search around. This option will be ignored unless it is inside the range -90.0 to +90.0 (North is positive) inclusive. It will also be ignored if there isn't a corresponding :long option.
643
- # @option options [Float] :long The longitude to search around. The valid range for longitude is -180.0 to +180.0 (East is positive) inclusive. This option will be ignored if outside that range, if it is not a number, if geo_enabled is disabled, or if there not a corresponding :lat option.
644
- # @option options [String] :name The name a place is known as.
645
- # @option options [String] :contained_within This is the place_id which you would like to restrict the search results to. Setting this value means only places within the given place_id will be found.
646
- # @option options [String] :"attribute:street_address" This option searches for places which have this given street address. There are other well-known and application-specific attributes available. Custom attributes are also permitted.
647
- # @return [Array<Twitter::Place>]
648
- # @example Return an array of places similar to Twitter HQ
649
- # Twitter.places_similar(:lat => "37.7821120598956", :long => "-122.400612831116", :name => "Twitter HQ")
650
- def places_similar(options={})
651
- geo_collection_from_response(:get, "/1.1/geo/similar_places.json", options)
652
- end
653
-
654
- # Searches for up to 20 places that can be used as a place_id
655
- #
656
- # @see https://dev.twitter.com/docs/api/1.1/get/geo/reverse_geocode
657
- # @note This request is an informative call and will deliver generalized results about geography.
658
- # @rate_limited Yes
659
- # @authentication_required Requires user context
660
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
661
- # @param options [Hash] A customizable set of options.
662
- # @option options [Float] :lat The latitude to search around. This option will be ignored unless it is inside the range -90.0 to +90.0 (North is positive) inclusive. It will also be ignored if there isn't a corresponding :long option.
663
- # @option options [Float] :long The longitude to search around. The valid range for longitude is -180.0 to +180.0 (East is positive) inclusive. This option will be ignored if outside that range, if it is not a number, if geo_enabled is disabled, or if there not a corresponding :lat option.
664
- # @option options [String] :accuracy ('0m') A hint on the "region" in which to search. If a number, then this is a radius in meters, but it can also take a string that is suffixed with ft to specify feet. If coming from a device, in practice, this value is whatever accuracy the device has measuring its location (whether it be coming from a GPS, WiFi triangulation, etc.).
665
- # @option options [String] :granularity ('neighborhood') This is the minimal granularity of place types to return and must be one of: 'poi', 'neighborhood', 'city', 'admin' or 'country'.
666
- # @option options [Integer] :max_results A hint as to the number of results to return. This does not guarantee that the number of results returned will equal max_results, but instead informs how many "nearby" results to return. Ideally, only pass in the number of places you intend to display to the user here.
667
- # @return [Array<Twitter::Place>]
668
- # @example Return an array of places within the specified region
669
- # Twitter.reverse_geocode(:lat => "37.7821120598956", :long => "-122.400612831116")
670
- def reverse_geocode(options={})
671
- geo_collection_from_response(:get, "/1.1/geo/reverse_geocode.json", options)
672
- end
673
-
674
- # Returns all the information about a known place
675
- #
676
- # @see https://dev.twitter.com/docs/api/1.1/get/geo/id/:place_id
677
- # @rate_limited Yes
678
- # @authentication_required Requires user context
679
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
680
- # @param place_id [String] A place in the world. These IDs can be retrieved from {Twitter::API::Geo#reverse_geocode}.
681
- # @param options [Hash] A customizable set of options.
682
- # @return [Twitter::Place] The requested place.
683
- # @example Return all the information about Twitter HQ
684
- # Twitter.place("247f43d441defc03")
685
- def place(place_id, options={})
686
- object_from_response(Twitter::Place, :get, "/1.1/geo/id/#{place_id}.json", options)
687
- end
688
-
689
- # Creates a new place at the given latitude and longitude
690
- #
691
- # @see https://dev.twitter.com/docs/api/1.1/post/geo/place
692
- # @rate_limited Yes
693
- # @authentication_required Requires user context
694
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
695
- # @param options [Hash] A customizable set of options.
696
- # @option options [String] :name The name a place is known as.
697
- # @option options [String] :contained_within This is the place_id which you would like to restrict the search results to. Setting this value means only places within the given place_id will be found.
698
- # @option options [String] :token The token found in the response from {Twitter::API::Geo#places_similar}.
699
- # @option options [Float] :lat The latitude to search around. This option will be ignored unless it is inside the range -90.0 to +90.0 (North is positive) inclusive. It will also be ignored if there isn't a corresponding :long option.
700
- # @option options [Float] :long The longitude to search around. The valid range for longitude is -180.0 to +180.0 (East is positive) inclusive. This option will be ignored if outside that range, if it is not a number, if geo_enabled is disabled, or if there not a corresponding :lat option.
701
- # @option options [String] :"attribute:street_address" This option searches for places which have this given street address. There are other well-known and application-specific attributes available. Custom attributes are also permitted.
702
- # @return [Twitter::Place] The created place.
703
- # @example Create a new place
704
- # Twitter.place_create(:name => "@sferik's Apartment", :token => "22ff5b1f7159032cf69218c4d8bb78bc", :contained_within => "41bcb736f84a799e", :lat => "37.783699", :long => "-122.393581")
705
- def place_create(options={})
706
- object_from_response(Twitter::Place, :post, "/1.1/geo/place.json", options)
707
- end
708
-
709
- # Returns the current configuration used by Twitter
710
- #
711
- # @see https://dev.twitter.com/docs/api/1.1/get/help/configuration
712
- # @rate_limited Yes
713
- # @authentication_required Requires user context
714
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
715
- # @return [Twitter::Configuration] Twitter's configuration.
716
- # @example Return the current configuration used by Twitter
717
- # Twitter.configuration
718
- def configuration(options={})
719
- object_from_response(Twitter::Configuration, :get, "/1.1/help/configuration.json", options)
720
- end
721
-
722
- # Returns the list of languages supported by Twitter
723
- #
724
- # @see https://dev.twitter.com/docs/api/1.1/get/help/languages
725
- # @rate_limited Yes
726
- # @authentication_required Requires user context
727
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
728
- # @return [Array<Twitter::Language>]
729
- # @example Return the list of languages Twitter supports
730
- # Twitter.languages
731
- def languages(options={})
732
- collection_from_response(Twitter::Language, :get, "/1.1/help/languages.json", options)
733
- end
734
-
735
- # Returns {https://twitter.com/privacy Twitter's Privacy Policy}
736
- #
737
- # @see https://dev.twitter.com/docs/api/1.1/get/help/privacy
738
- # @rate_limited Yes
739
- # @authentication_required Requires user context
740
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
741
- # @return [String]
742
- # @example Return {https://twitter.com/privacy Twitter's Privacy Policy}
743
- # Twitter.privacy
744
- def privacy(options={})
745
- get("/1.1/help/privacy.json", options)[:body][:privacy]
746
- end
747
-
748
- # Returns {https://twitter.com/tos Twitter's Terms of Service}
749
- #
750
- # @see https://dev.twitter.com/docs/api/1.1/get/help/tos
751
- # @rate_limited Yes
752
- # @authentication_required Requires user context
753
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
754
- # @return [String]
755
- # @example Return {https://twitter.com/tos Twitter's Terms of Service}
756
- # Twitter.tos
757
- def tos(options={})
758
- get("/1.1/help/tos.json", options)[:body][:tos]
759
- end
760
-
761
- # Show tweet timeline for members of the specified list
762
- #
763
- # @see https://dev.twitter.com/docs/api/1.1/get/lists/statuses
764
- # @rate_limited Yes
765
- # @authentication_required Requires user context
766
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
767
- # @return [Array<Twitter::Tweet>]
768
- # @overload list_timeline(list, options={})
769
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
770
- # @param options [Hash] A customizable set of options.
771
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
772
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
773
- # @option options [Integer] :count The number of results to retrieve.
774
- # @example Show tweet timeline for members of the authenticated user's "presidents" list
775
- # Twitter.list_timeline('presidents')
776
- # Twitter.list_timeline(8863586)
777
- # @overload list_timeline(user, list, options={})
778
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
779
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
780
- # @param options [Hash] A customizable set of options.
781
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
782
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
783
- # @option options [Integer] :count The number of results to retrieve.
784
- # @example Show tweet timeline for members of @sferik's "presidents" list
785
- # Twitter.list_timeline('sferik', 'presidents')
786
- # Twitter.list_timeline('sferik', 8863586)
787
- # Twitter.list_timeline(7505382, 'presidents')
788
- # Twitter.list_timeline(7505382, 8863586)
789
- def list_timeline(*args)
790
- options = args.extract_options!
791
- options.merge_list!(args.pop)
792
- options.merge_owner!(args.pop || screen_name) unless options[:owner_id] || options[:owner_screen_name]
793
- collection_from_response(Twitter::Tweet, :get, "/1.1/lists/statuses.json", options)
794
- end
795
-
796
- # Removes the specified member from the list
797
- #
798
- # @see https://dev.twitter.com/docs/api/1.1/post/lists/members/destroy
799
- # @rate_limited No
800
- # @authentication_required Requires user context
801
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
802
- # @return [Twitter::List] The list.
803
- # @overload list_remove_member(list, user_to_remove, options={})
804
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
805
- # @param user_to_remove [Integer, String] The user id or screen name of the list member to remove.
806
- # @param options [Hash] A customizable set of options.
807
- # @example Remove @BarackObama from the authenticated user's "presidents" list
808
- # Twitter.list_remove_member('presidents', 813286)
809
- # Twitter.list_remove_member('presidents', 'BarackObama')
810
- # Twitter.list_remove_member(8863586, 'BarackObama')
811
- # @overload list_remove_member(user, list, user_to_remove, options={})
812
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
813
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
814
- # @param user_to_remove [Integer, String] The user id or screen name of the list member to remove.
815
- # @param options [Hash] A customizable set of options.
816
- # @example Remove @BarackObama from @sferik's "presidents" list
817
- # Twitter.list_remove_member('sferik', 'presidents', 813286)
818
- # Twitter.list_remove_member('sferik', 'presidents', 'BarackObama')
819
- # Twitter.list_remove_member('sferik', 8863586, 'BarackObama')
820
- # Twitter.list_remove_member(7505382, 'presidents', 813286)
821
- def list_remove_member(*args)
822
- list_modify_member(:post, "/1.1/lists/members/destroy.json", args)
823
- end
824
-
825
- # List the lists the specified user has been added to
826
- #
827
- # @see https://dev.twitter.com/docs/api/1.1/get/lists/memberships
828
- # @rate_limited Yes
829
- # @authentication_required Requires user context
830
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
831
- # @return [Twitter::Cursor]
832
- # @overload memberships(options={})
833
- # @param options [Hash] A customizable set of options.
834
- # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
835
- # @option options [Boolean, String, Integer] :filter_to_owned_lists When set to true, t or 1, will return just lists the authenticating user owns, and the user represented by user_id or screen_name is a member of.
836
- # @example List the lists the authenticated user has been added to
837
- # Twitter.memberships
838
- # @overload memberships(user, options={})
839
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
840
- # @param options [Hash] A customizable set of options.
841
- # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
842
- # @option options [Boolean, String, Integer] :filter_to_owned_lists When set to true, t or 1, will return just lists the authenticating user owns, and the user represented by user_id or screen_name is a member of.
843
- # @example List the lists that @sferik has been added to
844
- # Twitter.memberships('sferik')
845
- # Twitter.memberships(7505382)
846
- def memberships(*args)
847
- lists_from_response(:get, "/1.1/lists/memberships.json", args)
848
- end
849
-
850
- # Returns the subscribers of the specified list
851
- #
852
- # @see https://dev.twitter.com/docs/api/1.1/get/lists/subscribers
853
- # @rate_limited Yes
854
- # @authentication_required Requires user context
855
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
856
- # @return [Twitter::Cursor] The subscribers of the specified list.
857
- # @overload list_subscribers(list, options={})
858
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
859
- # @param options [Hash] A customizable set of options.
860
- # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
861
- # @example Return the subscribers of the authenticated user's "presidents" list
862
- # Twitter.list_subscribers('presidents')
863
- # Twitter.list_subscribers(8863586)
864
- # @overload list_subscribers(user, list, options={})
865
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
866
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
867
- # @param options [Hash] A customizable set of options.
868
- # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
869
- # @example Return the subscribers of @sferik's "presidents" list
870
- # Twitter.list_subscribers('sferik', 'presidents')
871
- # Twitter.list_subscribers('sferik', 8863586)
872
- # Twitter.list_subscribers(7505382, 'presidents')
873
- def list_subscribers(*args)
874
- list_users(:get, "/1.1/lists/subscribers.json", args)
875
- end
876
-
877
- # List the lists the specified user follows
878
- #
879
- # @see https://dev.twitter.com/docs/api/1.1/get/lists/subscriptions
880
- # @rate_limited Yes
881
- # @authentication_required Requires user context
882
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
883
- # @return [Twitter::Cursor]
884
- # @overload subscriptions(options={})
885
- # @param options [Hash] A customizable set of options.
886
- # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
887
- # @example List the lists the authenticated user follows
888
- # Twitter.subscriptions
889
- # @overload subscriptions(user, options={})
890
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
891
- # @param options [Hash] A customizable set of options.
892
- # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
893
- # @example List the lists that @sferik follows
894
- # Twitter.subscriptions('sferik')
895
- # Twitter.subscriptions(7505382)
896
- def subscriptions(*args)
897
- lists_from_response(:get, "/1.1/lists/subscriptions.json", args)
898
- end
899
-
900
- # Make the authenticated user follow the specified list
901
- #
902
- # @see https://dev.twitter.com/docs/api/1.1/post/lists/subscribers/create
903
- # @rate_limited No
904
- # @authentication_required Requires user context
905
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
906
- # @return [Twitter::List] The specified list.
907
- # @overload list_subscribe(list, options={})
908
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
909
- # @param options [Hash] A customizable set of options.
910
- # @example Subscribe to the authenticated user's "presidents" list
911
- # Twitter.list_subscribe('presidents')
912
- # Twitter.list_subscribe(8863586)
913
- # @overload list_subscribe(user, list, options={})
914
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
915
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
916
- # @param options [Hash] A customizable set of options.
917
- # @example Subscribe to @sferik's "presidents" list
918
- # Twitter.list_subscribe('sferik', 'presidents')
919
- # Twitter.list_subscribe('sferik', 8863586)
920
- # Twitter.list_subscribe(7505382, 'presidents')
921
- def list_subscribe(*args)
922
- list_from_response(:post, "/1.1/lists/subscribers/create.json", args)
923
- end
924
-
925
- # Check if a user is a subscriber of the specified list
926
- #
927
- # @see https://dev.twitter.com/docs/api/1.1/get/lists/subscribers/show
928
- # @rate_limited Yes
929
- # @authentication_required Requires user context
930
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
931
- # @return [Boolean] true if user is a subscriber of the specified list, otherwise false.
932
- # @overload list_subscriber?(list, user_to_check, options={})
933
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
934
- # @param user_to_check [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
935
- # @param options [Hash] A customizable set of options.
936
- # @example Check if @BarackObama is a subscriber of the authenticated user's "presidents" list
937
- # Twitter.list_subscriber?('presidents', 813286)
938
- # Twitter.list_subscriber?(8863586, 813286)
939
- # Twitter.list_subscriber?('presidents', 'BarackObama')
940
- # @overload list_subscriber?(user, list, user_to_check, options={})
941
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
942
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
943
- # @param user_to_check [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
944
- # @param options [Hash] A customizable set of options.
945
- # @example Check if @BarackObama is a subscriber of @sferik's "presidents" list
946
- # Twitter.list_subscriber?('sferik', 'presidents', 813286)
947
- # Twitter.list_subscriber?('sferik', 8863586, 813286)
948
- # Twitter.list_subscriber?(7505382, 'presidents', 813286)
949
- # Twitter.list_subscriber?('sferik', 'presidents', 'BarackObama')
950
- # @return [Boolean] true if user is a subscriber of the specified list, otherwise false.
951
- def list_subscriber?(*args)
952
- list_user?(:get, "/1.1/lists/subscribers/show.json", args)
953
- end
954
-
955
- # Unsubscribes the authenticated user form the specified list
956
- #
957
- # @see https://dev.twitter.com/docs/api/1.1/post/lists/subscribers/destroy
958
- # @rate_limited No
959
- # @authentication_required Requires user context
960
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
961
- # @return [Twitter::List] The specified list.
962
- # @overload list_unsubscribe(list, options={})
963
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
964
- # @param options [Hash] A customizable set of options.
965
- # @example Unsubscribe from the authenticated user's "presidents" list
966
- # Twitter.list_unsubscribe('presidents')
967
- # Twitter.list_unsubscribe(8863586)
968
- # @overload list_unsubscribe(user, list, options={})
969
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
970
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
971
- # @param options [Hash] A customizable set of options.
972
- # @example Unsubscribe from @sferik's "presidents" list
973
- # Twitter.list_unsubscribe('sferik', 'presidents')
974
- # Twitter.list_unsubscribe('sferik', 8863586)
975
- # Twitter.list_unsubscribe(7505382, 'presidents')
976
- def list_unsubscribe(*args)
977
- list_from_response(:post, "/1.1/lists/subscribers/destroy.json", args)
978
- end
979
-
980
- # Adds specified members to a list
981
- #
982
- # @see https://dev.twitter.com/docs/api/1.1/post/lists/members/create_all
983
- # @note Lists are limited to having 500 members, and you are limited to adding up to 100 members to a list at a time with this method.
984
- # @rate_limited No
985
- # @authentication_required Requires user context
986
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
987
- # @return [Twitter::List] The list.
988
- # @overload list_add_members(list, users, options={})
989
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
990
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
991
- # @param options [Hash] A customizable set of options.
992
- # @example Add @BarackObama and @pengwynn to the authenticated user's "presidents" list
993
- # Twitter.list_add_members('presidents', ['BarackObama', 'pengwynn'])
994
- # Twitter.list_add_members('presidents', [813286, 18755393])
995
- # Twitter.list_add_members(8863586, ['BarackObama', 'pengwynn'])
996
- # Twitter.list_add_members(8863586, [813286, 18755393])
997
- # @overload list_add_members(user, list, users, options={})
998
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
999
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
1000
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
1001
- # @param options [Hash] A customizable set of options.
1002
- # @example Add @BarackObama and @pengwynn to @sferik's "presidents" list
1003
- # Twitter.list_add_members('sferik', 'presidents', ['BarackObama', 'pengwynn'])
1004
- # Twitter.list_add_members('sferik', 'presidents', [813286, 18755393])
1005
- # Twitter.list_add_members(7505382, 'presidents', ['BarackObama', 'pengwynn'])
1006
- # Twitter.list_add_members(7505382, 'presidents', [813286, 18755393])
1007
- # Twitter.list_add_members(7505382, 8863586, ['BarackObama', 'pengwynn'])
1008
- # Twitter.list_add_members(7505382, 8863586, [813286, 18755393])
1009
- def list_add_members(*args)
1010
- list_modify_members(:post, "/1.1/lists/members/create_all.json", args)
1011
- end
1012
-
1013
- # Removes specified members from the list
1014
- #
1015
- # @see https://dev.twitter.com/docs/api/1.1/post/lists/members/destroy_all
1016
- # @rate_limited No
1017
- # @authentication_required Requires user context
1018
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1019
- # @return [Twitter::List] The list.
1020
- # @overload list_remove_members(list, users, options={})
1021
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
1022
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
1023
- # @param options [Hash] A customizable set of options.
1024
- # @example Remove @BarackObama and @pengwynn from the authenticated user's "presidents" list
1025
- # Twitter.list_remove_members('presidents', ['BarackObama', 'pengwynn'])
1026
- # Twitter.list_remove_members('presidents', [813286, 18755393])
1027
- # Twitter.list_remove_members(8863586, ['BarackObama', 'pengwynn'])
1028
- # Twitter.list_remove_members(8863586, [813286, 18755393])
1029
- # @overload list_remove_members(user, list, users, options={})
1030
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
1031
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
1032
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
1033
- # @param options [Hash] A customizable set of options.
1034
- # @example Remove @BarackObama and @pengwynn from @sferik's "presidents" list
1035
- # Twitter.list_remove_members('sferik', 'presidents', ['BarackObama', 'pengwynn'])
1036
- # Twitter.list_remove_members('sferik', 'presidents', [813286, 18755393])
1037
- # Twitter.list_remove_members(7505382, 'presidents', ['BarackObama', 'pengwynn'])
1038
- # Twitter.list_remove_members(7505382, 'presidents', [813286, 18755393])
1039
- # Twitter.list_remove_members(7505382, 8863586, ['BarackObama', 'pengwynn'])
1040
- # Twitter.list_remove_members(7505382, 8863586, [813286, 18755393])
1041
- def list_remove_members(*args)
1042
- list_modify_members(:post, "/1.1/lists/members/destroy_all.json", args)
1043
- end
1044
-
1045
- # Check if a user is a member of the specified list
1046
- #
1047
- # @see https://dev.twitter.com/docs/api/1.1/get/lists/members/show
1048
- # @authentication_required Requires user context
1049
- # @rate_limited Yes
1050
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1051
- # @return [Boolean] true if user is a member of the specified list, otherwise false.
1052
- # @overload list_member?(list, user_to_check, options={})
1053
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
1054
- # @param user_to_check [Integer, String] The user ID or screen name of the list member.
1055
- # @param options [Hash] A customizable set of options.
1056
- # @example Check if @BarackObama is a member of the authenticated user's "presidents" list
1057
- # Twitter.list_member?('presidents', 813286)
1058
- # Twitter.list_member?(8863586, 'BarackObama')
1059
- # @overload list_member?(user, list, user_to_check, options={})
1060
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
1061
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
1062
- # @param user_to_check [Integer, String] The user ID or screen name of the list member.
1063
- # @param options [Hash] A customizable set of options.
1064
- # @example Check if @BarackObama is a member of @sferik's "presidents" list
1065
- # Twitter.list_member?('sferik', 'presidents', 813286)
1066
- # Twitter.list_member?('sferik', 8863586, 'BarackObama')
1067
- # Twitter.list_member?(7505382, 'presidents', 813286)
1068
- def list_member?(*args)
1069
- list_user?(:get, "/1.1/lists/members/show.json", args)
1070
- end
1071
-
1072
- # Returns the members of the specified list
1073
- #
1074
- # @see https://dev.twitter.com/docs/api/1.1/get/lists/members
1075
- # @rate_limited Yes
1076
- # @authentication_required Requires user context
1077
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1078
- # @return [Twitter::Cursor]
1079
- # @overload list_members(list, options={})
1080
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
1081
- # @param options [Hash] A customizable set of options.
1082
- # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
1083
- # @example Return the members of the authenticated user's "presidents" list
1084
- # Twitter.list_members('presidents')
1085
- # Twitter.list_members(8863586)
1086
- # @overload list_members(user, list, options={})
1087
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
1088
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
1089
- # @param options [Hash] A customizable set of options.
1090
- # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
1091
- # @example Return the members of @sferik's "presidents" list
1092
- # Twitter.list_members('sferik', 'presidents')
1093
- # Twitter.list_members('sferik', 8863586)
1094
- # Twitter.list_members(7505382, 'presidents')
1095
- # Twitter.list_members(7505382, 8863586)
1096
- def list_members(*args)
1097
- list_users(:get, "/1.1/lists/members.json", args)
1098
- end
1099
-
1100
- # Add a member to a list
1101
- #
1102
- # @see https://dev.twitter.com/docs/api/1.1/post/lists/members/create
1103
- # @note Lists are limited to having 500 members.
1104
- # @rate_limited No
1105
- # @authentication_required Requires user context
1106
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1107
- # @return [Twitter::List] The list.
1108
- # @overload list_add_member(list, user_to_add, options={})
1109
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
1110
- # @param user_to_add [Integer, String] The user id or screen name to add to the list.
1111
- # @param options [Hash] A customizable set of options.
1112
- # @example Add @BarackObama to the authenticated user's "presidents" list
1113
- # Twitter.list_add_member('presidents', 813286)
1114
- # Twitter.list_add_member(8863586, 813286)
1115
- # @overload list_add_member(user, list, user_to_add, options={})
1116
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
1117
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
1118
- # @param user_to_add [Integer, String] The user id or screen name to add to the list.
1119
- # @param options [Hash] A customizable set of options.
1120
- # @example Add @BarackObama to @sferik's "presidents" list
1121
- # Twitter.list_add_member('sferik', 'presidents', 813286)
1122
- # Twitter.list_add_member('sferik', 8863586, 813286)
1123
- # Twitter.list_add_member(7505382, 'presidents', 813286)
1124
- # Twitter.list_add_member(7505382, 8863586, 813286)
1125
- def list_add_member(*args)
1126
- list_modify_member(:post, "/1.1/lists/members/create.json", args)
1127
- end
1128
-
1129
- # Deletes the specified list
1130
- #
1131
- # @see https://dev.twitter.com/docs/api/1.1/post/lists/destroy
1132
- # @note Must be owned by the authenticated user.
1133
- # @rate_limited No
1134
- # @authentication_required Requires user context
1135
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1136
- # @return [Twitter::List] The deleted list.
1137
- # @overload list_destroy(list, options={})
1138
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
1139
- # @param options [Hash] A customizable set of options.
1140
- # @example Delete the authenticated user's "presidents" list
1141
- # Twitter.list_destroy('presidents')
1142
- # Twitter.list_destroy(8863586)
1143
- # @overload list_destroy(user, list, options={})
1144
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
1145
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
1146
- # @param options [Hash] A customizable set of options.
1147
- # @example Delete @sferik's "presidents" list
1148
- # Twitter.list_destroy('sferik', 'presidents')
1149
- # Twitter.list_destroy('sferik', 8863586)
1150
- # Twitter.list_destroy(7505382, 'presidents')
1151
- # Twitter.list_destroy(7505382, 8863586)
1152
- def list_destroy(*args)
1153
- list_from_response(:post, "/1.1/lists/destroy.json", args)
1154
- end
1155
-
1156
- # Updates the specified list
1157
- #
1158
- # @see https://dev.twitter.com/docs/api/1.1/post/lists/update
1159
- # @rate_limited No
1160
- # @authentication_required Requires user context
1161
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1162
- # @return [Twitter::List] The created list.
1163
- # @overload list_update(list, options={})
1164
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
1165
- # @param options [Hash] A customizable set of options.
1166
- # @option options [String] :mode ('public') Whether your list is public or private. Values can be 'public' or 'private'.
1167
- # @option options [String] :description The description to give the list.
1168
- # @example Update the authenticated user's "presidents" list to have the description "Presidents of the United States of America"
1169
- # Twitter.list_update('presidents', :description => "Presidents of the United States of America")
1170
- # Twitter.list_update(8863586, :description => "Presidents of the United States of America")
1171
- # @overload list_update(user, list, options={})
1172
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
1173
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
1174
- # @param options [Hash] A customizable set of options.
1175
- # @option options [String] :mode ('public') Whether your list is public or private. Values can be 'public' or 'private'.
1176
- # @option options [String] :description The description to give the list.
1177
- # @example Update the @sferik's "presidents" list to have the description "Presidents of the United States of America"
1178
- # Twitter.list_update('sferik', 'presidents', :description => "Presidents of the United States of America")
1179
- # Twitter.list_update(7505382, 'presidents', :description => "Presidents of the United States of America")
1180
- # Twitter.list_update('sferik', 8863586, :description => "Presidents of the United States of America")
1181
- # Twitter.list_update(7505382, 8863586, :description => "Presidents of the United States of America")
1182
- def list_update(*args)
1183
- list_from_response(:post, "/1.1/lists/update.json", args)
1184
- end
1185
-
1186
- # Creates a new list for the authenticated user
1187
- #
1188
- # @see https://dev.twitter.com/docs/api/1.1/post/lists/create
1189
- # @note Accounts are limited to 20 lists.
1190
- # @rate_limited No
1191
- # @authentication_required Requires user context
1192
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1193
- # @return [Twitter::List] The created list.
1194
- # @param name [String] The name for the list.
1195
- # @param options [Hash] A customizable set of options.
1196
- # @option options [String] :mode ('public') Whether your list is public or private. Values can be 'public' or 'private'.
1197
- # @option options [String] :description The description to give the list.
1198
- # @example Create a list named 'presidents'
1199
- # Twitter.list_create('presidents')
1200
- def list_create(name, options={})
1201
- object_from_response(Twitter::List, :post, "/1.1/lists/create.json", options.merge(:name => name))
1202
- end
1203
-
1204
- # Returns all lists the authenticating or specified user subscribes to, including their own
1205
- #
1206
- # @see https://dev.twitter.com/docs/api/1.1/get/lists/list
1207
- # @rate_limited Yes
1208
- # @authentication_required Requires user context
1209
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1210
- # @return [Array<Twitter::List>]
1211
- # @overload memberships(options={})
1212
- # @param options [Hash] A customizable set of options.
1213
- # @example Returns all lists the authenticating user subscribes to
1214
- # Twitter.lists
1215
- # @overload memberships(user, options={})
1216
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
1217
- # @param options [Hash] A customizable set of options.
1218
- # @example Returns all lists that @sferik subscribes to
1219
- # Twitter.lists('sferik')
1220
- # Twitter.lists(7505382)
1221
- def lists(*args)
1222
- objects_from_response(Twitter::List, :get, "/1.1/lists/list.json", args)
1223
- end
1224
- alias lists_subscribed_to lists
1225
-
1226
- # Show the specified list
1227
- #
1228
- # @see https://dev.twitter.com/docs/api/1.1/get/lists/show
1229
- # @note Private lists will only be shown if the authenticated user owns the specified list.
1230
- # @rate_limited Yes
1231
- # @authentication_required Requires user context
1232
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1233
- # @return [Twitter::List] The specified list.
1234
- # @overload list(list, options={})
1235
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
1236
- # @param options [Hash] A customizable set of options.
1237
- # @example Show the authenticated user's "presidents" list
1238
- # Twitter.list('presidents')
1239
- # Twitter.list(8863586)
1240
- # @overload list(user, list, options={})
1241
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
1242
- # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
1243
- # @param options [Hash] A customizable set of options.
1244
- # @example Show @sferik's "presidents" list
1245
- # Twitter.list('sferik', 'presidents')
1246
- # Twitter.list('sferik', 8863586)
1247
- # Twitter.list(7505382, 'presidents')
1248
- # Twitter.list(7505382, 8863586)
1249
- def list(*args)
1250
- list_from_response(:get, "/1.1/lists/show.json", args)
1251
- end
1252
-
1253
- # The users specified are blocked by the authenticated user and reported as spammers
1254
- #
1255
- # @see https://dev.twitter.com/docs/api/1.1/post/report_spam
1256
- # @rate_limited Yes
1257
- # @authentication_required Requires user context
1258
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1259
- # @return [Array<Twitter::User>] The reported users.
1260
- # @overload report_spam(*users)
1261
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
1262
- # @example Report @spam for spam
1263
- # Twitter.report_spam("spam")
1264
- # Twitter.report_spam(14589771) # Same as above
1265
- # @overload report_spam(*users, options)
1266
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
1267
- # @param options [Hash] A customizable set of options.
1268
- def report_spam(*args)
1269
- threaded_users_from_response(:post, "/1.1/report_spam.json", args)
1270
- end
1271
-
1272
- # @rate_limited Yes
1273
- # @authentication_required Requires user context
1274
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1275
- # @return [Array<Twitter::SavedSearch>] The saved searches.
1276
- # @overload saved_search(options={})
1277
- # Returns the authenticated user's saved search queries
1278
- #
1279
- # @see https://dev.twitter.com/docs/api/1.1/get/saved_searches/list
1280
- # @param options [Hash] A customizable set of options.
1281
- # @example Return the authenticated user's saved search queries
1282
- # Twitter.saved_searches
1283
- # @overload saved_search(*ids)
1284
- # Retrieve the data for saved searches owned by the authenticating user
1285
- #
1286
- # @see https://dev.twitter.com/docs/api/1.1/get/saved_searches/show/:id
1287
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1288
- # @example Retrieve the data for a saved search owned by the authenticating user with the ID 16129012
1289
- # Twitter.saved_search(16129012)
1290
- # @overload saved_search(*ids, options)
1291
- # Retrieve the data for saved searches owned by the authenticating user
1292
- #
1293
- # @see https://dev.twitter.com/docs/api/1.1/get/saved_searches/show/:id
1294
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1295
- # @param options [Hash] A customizable set of options.
1296
- def saved_searches(*args)
1297
- options = args.extract_options!
1298
- if args.empty?
1299
- collection_from_response(Twitter::SavedSearch, :get, "/1.1/saved_searches/list.json", options)
1300
- else
1301
- args.flatten.threaded_map do |id|
1302
- object_from_response(Twitter::SavedSearch, :get, "/1.1/saved_searches/show/#{id}.json", options)
1303
- end
1304
- end
1305
- end
1306
-
1307
- # Retrieve the data for saved searches owned by the authenticating user
1308
- #
1309
- # @see https://dev.twitter.com/docs/api/1.1/get/saved_searches/show/:id
1310
- # @rate_limited Yes
1311
- # @authentication_required Requires user context
1312
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1313
- # @return [Twitter::SavedSearch] The saved searches.
1314
- # @param id [Integer] A Tweet IDs.
1315
- # @param options [Hash] A customizable set of options.
1316
- # @example Retrieve the data for a saved search owned by the authenticating user with the ID 16129012
1317
- # Twitter.saved_search(16129012)
1318
- def saved_search(id, options={})
1319
- object_from_response(Twitter::SavedSearch, :get, "/1.1/saved_searches/show/#{id}.json", options)
1320
- end
1321
-
1322
- # Creates a saved search for the authenticated user
1323
- #
1324
- # @see https://dev.twitter.com/docs/api/1.1/post/saved_searches/create
1325
- # @rate_limited No
1326
- # @authentication_required Requires user context
1327
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1328
- # @return [Twitter::SavedSearch] The created saved search.
1329
- # @param query [String] The query of the search the user would like to save.
1330
- # @param options [Hash] A customizable set of options.
1331
- # @example Create a saved search for the authenticated user with the query "twitter"
1332
- # Twitter.saved_search_create("twitter")
1333
- def saved_search_create(query, options={})
1334
- object_from_response(Twitter::SavedSearch, :post, "/1.1/saved_searches/create.json", options.merge(:query => query))
1335
- end
1336
-
1337
- # Destroys saved searches for the authenticated user
1338
- #
1339
- # @see https://dev.twitter.com/docs/api/1.1/post/saved_searches/destroy/:id
1340
- # @note The search specified by ID must be owned by the authenticating user.
1341
- # @rate_limited No
1342
- # @authentication_required Requires user context
1343
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1344
- # @return [Array<Twitter::SavedSearch>] The deleted saved searches.
1345
- # @overload saved_search_destroy(*ids)
1346
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1347
- # @example Destroys a saved search for the authenticated user with the ID 16129012
1348
- # Twitter.saved_search_destroy(16129012)
1349
- # @overload saved_search_destroy(*ids, options)
1350
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1351
- # @param options [Hash] A customizable set of options.
1352
- def saved_search_destroy(*args)
1353
- options = args.extract_options!
1354
- args.flatten.threaded_map do |id|
1355
- object_from_response(Twitter::SavedSearch, :post, "/1.1/saved_searches/destroy/#{id}.json", options)
1356
- end
1357
- end
1358
-
1359
- # Returns tweets that match a specified query.
1360
- #
1361
- # @see https://dev.twitter.com/docs/api/1.1/get/search/tweets
1362
- # @see https://dev.twitter.com/docs/using-search
1363
- # @note Please note that Twitter's search service and, by extension, the Search API is not meant to be an exhaustive source of Tweets. Not all Tweets will be indexed or made available via the search interface.
1364
- # @rate_limited Yes
1365
- # @authentication_required Requires user context
1366
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1367
- # @param q [String] A search term.
1368
- # @param options [Hash] A customizable set of options.
1369
- # @option options [String] :geocode Returns tweets by users located within a given radius of the given latitude/longitude. The location is preferentially taking from the Geotagging API, but will fall back to their Twitter profile. The parameter value is specified by "latitude,longitude,radius", where radius units must be specified as either "mi" (miles) or "km" (kilometers). Note that you cannot use the near operator via the API to geocode arbitrary locations; however you can use this geocode parameter to search near geocodes directly.
1370
- # @option options [String] :lang Restricts tweets to the given language, given by an ISO 639-1 code.
1371
- # @option options [String] :locale Specify the language of the query you are sending (only ja is currently effective). This is intended for language-specific clients and the default should work in the majority of cases.
1372
- # @option options [String] :result_type Specifies what type of search results you would prefer to receive. Options are "mixed", "recent", and "popular". The current default is "mixed."
1373
- # @option options [Integer] :count The number of tweets to return per page, up to a maximum of 100.
1374
- # @option options [String] :until Optional. Returns tweets generated before the given date. Date should be formatted as YYYY-MM-DD.
1375
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID. There are limits to the number of Tweets which can be accessed through the API. If the limit of Tweets has occured since the since_id, the since_id will be forced to the oldest ID available.
1376
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
1377
- # @option options [Boolean, String, Integer] :include_entities The tweet entities node will be disincluded when set to false.
1378
- # @return [Twitter::SearchResults] Return tweets that match a specified query with search metadata
1379
- # @example Returns tweets related to twitter
1380
- # Twitter.search('twitter')
1381
- def search(q, options={})
1382
- object_from_response(Twitter::SearchResults, :get, "/1.1/search/tweets.json", options.merge(:q => q))
1383
- end
1384
-
1385
- # Returns recent Tweets related to a query with images and videos embedded
1386
- #
1387
- # @note Undocumented
1388
- # @rate_limited Yes
1389
- # @authentication_required No
1390
- # @param q [String] A search term.
1391
- # @param options [Hash] A customizable set of options.
1392
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
1393
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
1394
- # @return [Array<Twitter::Tweet>] An array of Tweets that contain videos
1395
- # @example Return recent Tweets related to twitter with images and videos embedded
1396
- # Twitter.phoenix_search('twitter')
1397
- def phoenix_search(q, options={})
1398
- search_collection_from_response(:get, "/phoenix_search.phoenix", options.merge(:q => q))
1399
- end
1400
-
1401
- # @see https://dev.twitter.com/docs/api/1.1/get/favorites/list
1402
- # @rate_limited Yes
1403
- # @authentication_required Requires user context
1404
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1405
- # @return [Array<Twitter::Tweet>] favorite Tweets.
1406
- # @overload favorites(options={})
1407
- # Returns the 20 most recent favorite Tweets for the authenticating user
1408
- #
1409
- # @param options [Hash] A customizable set of options.
1410
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
1411
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
1412
- # @example Return the 20 most recent favorite Tweets for the authenticating user
1413
- # Twitter.favorites
1414
- # @overload favorites(user, options={})
1415
- # Returns the 20 most recent favorite Tweets for the specified user
1416
- #
1417
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
1418
- # @param options [Hash] A customizable set of options.
1419
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
1420
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
1421
- # @example Return the 20 most recent favorite Tweets for @sferik
1422
- # Twitter.favorites('sferik')
1423
- def favorites(*args)
1424
- options = args.extract_options!
1425
- if user = args.pop
1426
- options.merge_user!(user)
1427
- end
1428
- collection_from_response(Twitter::Tweet, :get, "/1.1/favorites/list.json", options)
1429
- end
1430
-
1431
- # Favorites the specified Tweets as the authenticating user
1432
- #
1433
- # @see https://dev.twitter.com/docs/api/1.1/post/favorites/create
1434
- # @rate_limited No
1435
- # @authentication_required Requires user context
1436
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1437
- # @return [Array<Twitter::Tweet>] The favorited Tweets.
1438
- # @overload favorite(*ids)
1439
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1440
- # @example Favorite the Tweet with the ID 25938088801
1441
- # Twitter.favorite(25938088801)
1442
- # @overload favorite(*ids, options)
1443
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1444
- # @param options [Hash] A customizable set of options.
1445
- def favorite(*args)
1446
- options = args.extract_options!
1447
- args.flatten.threaded_map do |id|
1448
- begin
1449
- object_from_response(Twitter::Tweet, :post, "/1.1/favorites/create.json", options.merge(:id => id))
1450
- rescue Twitter::Error::Forbidden => error
1451
- raise unless error.message == Twitter::Error::AlreadyFavorited::MESSAGE
1452
- end
1453
- end.compact
1454
- end
1455
- alias fav favorite
1456
- alias fave favorite
1457
- alias favorite_create favorite
1458
-
1459
- # Favorites the specified Tweets as the authenticating user and raises an error if one has already been favorited
1460
- #
1461
- # @see https://dev.twitter.com/docs/api/1.1/post/favorites/create
1462
- # @rate_limited No
1463
- # @authentication_required Requires user context
1464
- # @raise [Twitter::Error::AlreadyFavorited] Error raised when tweet has already been favorited.
1465
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1466
- # @return [Array<Twitter::Tweet>] The favorited Tweets.
1467
- # @overload favorite(*ids)
1468
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1469
- # @example Favorite the Tweet with the ID 25938088801
1470
- # Twitter.favorite(25938088801)
1471
- # @overload favorite(*ids, options)
1472
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1473
- # @param options [Hash] A customizable set of options.
1474
- def favorite!(*args)
1475
- options = args.extract_options!
1476
- args.flatten.threaded_map do |id|
1477
- begin
1478
- object_from_response(Twitter::Tweet, :post, "/1.1/favorites/create.json", options.merge(:id => id))
1479
- rescue Twitter::Error::Forbidden => error
1480
- if error.message == "You have already favorited this status"
1481
- raise Twitter::Error::AlreadyFavorited.new("Tweet with the ID #{id} has already been favorited by the authenticated user.")
1482
- else
1483
- raise
1484
- end
1485
- end
1486
- end
1487
- end
1488
- alias fav! favorite!
1489
- alias fave! favorite!
1490
- alias favorite_create! favorite!
1491
-
1492
- # Un-favorites the specified Tweets as the authenticating user
1493
- #
1494
- # @see https://dev.twitter.com/docs/api/1.1/post/favorites/destroy
1495
- # @rate_limited No
1496
- # @authentication_required Requires user context
1497
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1498
- # @return [Array<Twitter::Tweet>] The un-favorited Tweets.
1499
- # @overload unfavorite(*ids)
1500
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1501
- # @example Un-favorite the tweet with the ID 25938088801
1502
- # Twitter.unfavorite(25938088801)
1503
- # @overload unfavorite(*ids, options)
1504
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1505
- # @param options [Hash] A customizable set of options.
1506
- def unfavorite(*args)
1507
- options = args.extract_options!
1508
- args.flatten.threaded_map do |id|
1509
- object_from_response(Twitter::Tweet, :post, "/1.1/favorites/destroy.json", options.merge(:id => id))
1510
- end
1511
- end
1512
- alias favorite_destroy unfavorite
1513
-
1514
- # Returns the 20 most recent Tweets, including retweets if they exist, posted by the authenticating user and the users they follow
1515
- #
1516
- # @see https://dev.twitter.com/docs/api/1.1/get/statuses/home_timeline
1517
- # @note This method can only return up to 800 Tweets, including retweets.
1518
- # @rate_limited Yes
1519
- # @authentication_required Requires user context
1520
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1521
- # @return [Array<Twitter::Tweet>]
1522
- # @param options [Hash] A customizable set of options.
1523
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
1524
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
1525
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
1526
- # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
1527
- # @option options [Boolean, String, Integer] :exclude_replies This parameter will prevent replies from appearing in the returned timeline. Using exclude_replies with the count parameter will mean you will receive up-to count tweets - this is because the count parameter retrieves that many tweets before filtering out retweets and replies.
1528
- # @option options [Boolean, String, Integer] :include_rts Specifies that the timeline should include native retweets in addition to regular tweets. Note: If you're using the trim_user parameter in conjunction with include_rts, the retweets will no longer contain a full user object.
1529
- # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor.
1530
- # @option options [Boolean, String, Integer] :include_entities The tweet entities node will be disincluded when set to false.
1531
- # @example Return the 20 most recent Tweets, including retweets if they exist, posted by the authenticating user and the users they follow
1532
- # Twitter.home_timeline
1533
- def home_timeline(options={})
1534
- collection_from_response(Twitter::Tweet, :get, "/1.1/statuses/home_timeline.json", options)
1535
- end
1536
-
1537
- # Returns the 20 most recent mentions (statuses containing @username) for the authenticating user
1538
- #
1539
- # @see https://dev.twitter.com/docs/api/1.1/get/statuses/mentions_timeline
1540
- # @note This method can only return up to 800 Tweets.
1541
- # @rate_limited Yes
1542
- # @authentication_required Requires user context
1543
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1544
- # @return [Array<Twitter::Tweet>]
1545
- # @param options [Hash] A customizable set of options.
1546
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
1547
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
1548
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
1549
- # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
1550
- # @example Return the 20 most recent mentions (statuses containing @username) for the authenticating user
1551
- # Twitter.mentions
1552
- def mentions_timeline(options={})
1553
- collection_from_response(Twitter::Tweet, :get, "/1.1/statuses/mentions_timeline.json", options)
1554
- end
1555
- alias mentions mentions_timeline
1556
-
1557
- # Returns the 20 most recent retweets posted by the specified user
1558
- #
1559
- # @see https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline
1560
- # @note This method can only return up to 3,200 Tweets.
1561
- # @rate_limited Yes
1562
- # @authentication_required Requires user context
1563
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1564
- # @return [Array<Twitter::Tweet>]
1565
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
1566
- # @param options [Hash] A customizable set of options.
1567
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
1568
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
1569
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
1570
- # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
1571
- # @option options [Boolean, String, Integer] :exclude_replies This parameter will prevent replies from appearing in the returned timeline. Using exclude_replies with the count parameter will mean you will receive up-to count tweets - this is because the count parameter retrieves that many tweets before filtering out retweets and replies.
1572
- # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor.
1573
- # @example Return the 20 most recent retweets posted by @sferik
1574
- # Twitter.retweeted_by_user('sferik')
1575
- def retweeted_by_user(user, options={})
1576
- options[:include_rts] = true
1577
- count = options[:count] || DEFAULT_TWEETS_PER_REQUEST
1578
- collect_with_count(count) do |count_options|
1579
- select_retweets(user_timeline(user, options.merge(count_options)))
1580
- end
1581
- end
1582
- alias retweeted_by retweeted_by_user
1583
-
1584
- # Returns the 20 most recent retweets posted by the authenticating user
1585
- #
1586
- # @see https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline
1587
- # @note This method can only return up to 3,200 Tweets.
1588
- # @rate_limited Yes
1589
- # @authentication_required Requires user context
1590
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1591
- # @return [Array<Twitter::Tweet>]
1592
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
1593
- # @param options [Hash] A customizable set of options.
1594
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
1595
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
1596
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
1597
- # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
1598
- # @option options [Boolean, String, Integer] :exclude_replies This parameter will prevent replies from appearing in the returned timeline. Using exclude_replies with the count parameter will mean you will receive up-to count tweets - this is because the count parameter retrieves that many tweets before filtering out retweets and replies.
1599
- # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor.
1600
- # @example Return the 20 most recent retweets posted by the authenticating user
1601
- # Twitter.retweeted_by_me
1602
- def retweeted_by_me(options={})
1603
- options[:include_rts] = true
1604
- count = options[:count] || DEFAULT_TWEETS_PER_REQUEST
1605
- collect_with_count(count) do |count_options|
1606
- select_retweets(user_timeline(options.merge(count_options)))
1607
- end
1608
- end
1609
-
1610
- # Returns the 20 most recent retweets posted by users the authenticating user follow.
1611
- #
1612
- # @see https://dev.twitter.com/docs/api/1.1/get/statuses/home_timeline
1613
- # @note This method can only return up to 800 Tweets, including retweets.
1614
- # @rate_limited Yes
1615
- # @authentication_required Requires user context
1616
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1617
- # @return [Array<Twitter::Tweet>]
1618
- # @param options [Hash] A customizable set of options.
1619
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
1620
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
1621
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
1622
- # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
1623
- # @option options [Boolean, String, Integer] :exclude_replies This parameter will prevent replies from appearing in the returned timeline. Using exclude_replies with the count parameter will mean you will receive up-to count tweets - this is because the count parameter retrieves that many tweets before filtering out retweets and replies.
1624
- # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor.
1625
- # @option options [Boolean, String, Integer] :include_entities The tweet entities node will be disincluded when set to false.
1626
- # @example Return the 20 most recent retweets posted by users followed by the authenticating user
1627
- # Twitter.retweeted_to_me
1628
- def retweeted_to_me(options={})
1629
- options[:include_rts] = true
1630
- count = options[:count] || DEFAULT_TWEETS_PER_REQUEST
1631
- collect_with_count(count) do |count_options|
1632
- select_retweets(home_timeline(options.merge(count_options)))
1633
- end
1634
- end
1635
-
1636
- # Returns the 20 most recent tweets of the authenticated user that have been retweeted by others
1637
- #
1638
- # @see https://dev.twitter.com/docs/api/1.1/get/statuses/retweets_of_me
1639
- # @rate_limited Yes
1640
- # @authentication_required Requires user context
1641
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1642
- # @return [Array<Twitter::Tweet>]
1643
- # @param options [Hash] A customizable set of options.
1644
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
1645
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
1646
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
1647
- # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
1648
- # @option options [Boolean, String, Integer] :include_entities The tweet entities node will be disincluded when set to false.
1649
- # @option options [Boolean, String, Integer] :include_user_entities The user entities node will be disincluded when set to false.
1650
- # @example Return the 20 most recent tweets of the authenticated user that have been retweeted by others
1651
- # Twitter.retweets_of_me
1652
- def retweets_of_me(options={})
1653
- collection_from_response(Twitter::Tweet, :get, "/1.1/statuses/retweets_of_me.json", options)
1654
- end
1655
-
1656
- # Returns the 20 most recent Tweets posted by the specified user
1657
- #
1658
- # @see https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline
1659
- # @note This method can only return up to 3,200 Tweets.
1660
- # @rate_limited Yes
1661
- # @authentication_required Requires user context
1662
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1663
- # @return [Array<Twitter::Tweet>]
1664
- # @overload user_timeline(user, options={})
1665
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
1666
- # @param options [Hash] A customizable set of options.
1667
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
1668
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
1669
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
1670
- # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
1671
- # @option options [Boolean, String, Integer] :exclude_replies This parameter will prevent replies from appearing in the returned timeline. Using exclude_replies with the count parameter will mean you will receive up-to count tweets - this is because the count parameter retrieves that many tweets before filtering out retweets and replies.
1672
- # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor.
1673
- # @option options [Boolean, String, Integer] :include_rts Specifies that the timeline should include native retweets in addition to regular tweets. Note: If you're using the trim_user parameter in conjunction with include_rts, the retweets will no longer contain a full user object.
1674
- # @example Return the 20 most recent Tweets posted by @sferik
1675
- # Twitter.user_timeline('sferik')
1676
- def user_timeline(*args)
1677
- objects_from_response(Twitter::Tweet, :get, "/1.1/statuses/user_timeline.json", args)
1678
- end
1679
-
1680
- # Returns the 20 most recent images posted by the specified user
1681
- #
1682
- # @see https://support.twitter.com/articles/20169409
1683
- # @note This method can only return up to the 100 most recent images.
1684
- # @note Images will not be returned from tweets posted before January 1, 2010.
1685
- # @rate_limited Yes
1686
- # @authentication_required Requires user context
1687
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1688
- # @return [Array<Twitter::Tweet>]
1689
- # @overload media_timeline(user, options={})
1690
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
1691
- # @param options [Hash] A customizable set of options.
1692
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
1693
- # @option options [Boolean] :filter Include possibly sensitive media when set to false, 'f' or 0.
1694
- # @example Return the 20 most recent Tweets posted by @sferik
1695
- # Twitter.media_timeline('sferik')
1696
- def media_timeline(*args)
1697
- objects_from_response(Twitter::Tweet, :get, "/1.1/statuses/media_timeline.json", args)
1698
- end
1699
-
1700
- # Show up to 100 users who retweeted the Tweet
1701
- #
1702
- # @see https://dev.twitter.com/docs/api/1.1/get/statuses/retweets/:id
1703
- # @rate_limited Yes
1704
- # @authentication_required Requires user context
1705
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1706
- # @return [Array]
1707
- # @param id [Integer] The numerical ID of the desired Tweet.
1708
- # @param options [Hash] A customizable set of options.
1709
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
1710
- # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
1711
- # @option options [Boolean] :ids_only ('false') Only return user ids instead of full user objects.
1712
- # @example Show up to 100 users who retweeted the Tweet with the ID 28561922516
1713
- # Twitter.retweeters_of(28561922516)
1714
- def retweeters_of(id, options={})
1715
- if ids_only = !!options.delete(:ids_only)
1716
- retweets(id, options).map(&:user).map(&:id)
1717
- else
1718
- retweets(id, options).map(&:user)
1719
- end
1720
- end
1721
-
1722
- # Returns up to 100 of the first retweets of a given tweet
1723
- #
1724
- # @see https://dev.twitter.com/docs/api/1.1/get/statuses/retweets/:id
1725
- # @rate_limited Yes
1726
- # @authentication_required Requires user context
1727
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1728
- # @return [Array<Twitter::Tweet>]
1729
- # @param id [Integer] The numerical ID of the desired Tweet.
1730
- # @param options [Hash] A customizable set of options.
1731
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
1732
- # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
1733
- # @example Return up to 100 of the first retweets of the Tweet with the ID 28561922516
1734
- # Twitter.retweets(28561922516)
1735
- def retweets(id, options={})
1736
- collection_from_response(Twitter::Tweet, :get, "/1.1/statuses/retweets/#{id}.json", options)
1737
- end
1738
-
1739
- # Returns a Tweet
1740
- #
1741
- # @see https://dev.twitter.com/docs/api/1.1/get/statuses/show/:id
1742
- # @rate_limited Yes
1743
- # @authentication_required Requires user context
1744
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1745
- # @return [Twitter::Tweet] The requested Tweet.
1746
- # @param id [Integer] A Tweet ID.
1747
- # @param options [Hash] A customizable set of options.
1748
- # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
1749
- # @example Return the Tweet with the ID 25938088801
1750
- # Twitter.status(25938088801)
1751
- def status(id, options={})
1752
- object_from_response(Twitter::Tweet, :get, "/1.1/statuses/show/#{id}.json", options)
1753
- end
1754
-
1755
- # Returns Tweets
1756
- #
1757
- # @see https://dev.twitter.com/docs/api/1.1/get/statuses/show/:id
1758
- # @rate_limited Yes
1759
- # @authentication_required Requires user context
1760
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1761
- # @return [Array<Twitter::Tweet>] The requested Tweets.
1762
- # @overload statuses(*ids)
1763
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1764
- # @example Return the Tweet with the ID 25938088801
1765
- # Twitter.statuses(25938088801)
1766
- # @overload statuses(*ids, options)
1767
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1768
- # @param options [Hash] A customizable set of options.
1769
- # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
1770
- def statuses(*args)
1771
- threaded_tweets_from_response(:get, "/1.1/statuses/show", args)
1772
- end
1773
-
1774
- # Returns activity summary for a Tweet
1775
- #
1776
- # @note Undocumented
1777
- # @rate_limited Yes
1778
- # @authentication_required Requires user context
1779
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1780
- # @return [Twitter::Tweet] The requested Tweet.
1781
- # @param id [Integer] A Tweet ID.
1782
- # @param options [Hash] A customizable set of options.
1783
- # @example Return activity summary for the Tweet with the ID 25938088801
1784
- # Twitter.status_activity(25938088801)
1785
- def status_activity(id, options={})
1786
- response = get("/i/statuses/#{id}/activity/summary.json", options)
1787
- response[:body].merge!(:id => id) if response[:body]
1788
- Twitter::Tweet.from_response(response)
1789
- end
1790
- alias tweet_activity status_activity
1791
-
1792
- # Returns activity summary for Tweets
1793
- #
1794
- # @note Undocumented
1795
- # @rate_limited Yes
1796
- # @authentication_required Requires user context
1797
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1798
- # @return [Array<Twitter::Tweet>] The requested Tweets.
1799
- # @overload statuses_activity(*ids)
1800
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1801
- # @example Return activity summary for the Tweet with the ID 25938088801
1802
- # Twitter.statuses_activity(25938088801)
1803
- # @overload statuses_activity(*ids, options)
1804
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1805
- # @param options [Hash] A customizable set of options.
1806
- def statuses_activity(*args)
1807
- options = args.extract_options!
1808
- args.flatten.threaded_map do |id|
1809
- status_activity(id, options)
1810
- end
1811
- end
1812
-
1813
- # Returns oEmbed for a Tweet
1814
- #
1815
- # @see https://dev.twitter.com/docs/api/1.1/get/statuses/oembed
1816
- # @rate_limited Yes
1817
- # @authentication_required Requires user context
1818
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1819
- # @return [Twitter::OEmbed] OEmbed for the requested Tweet.
1820
- # @param id [Integer, String] A Tweet ID.
1821
- # @param options [Hash] A customizable set of options.
1822
- # @option options [Integer] :maxwidth The maximum width in pixels that the embed should be rendered at. This value is constrained to be between 250 and 550 pixels.
1823
- # @option options [Boolean, String, Integer] :hide_media Specifies whether the embedded Tweet should automatically expand images which were uploaded via {https://dev.twitter.com/docs/api/1.1/post/statuses/update_with_media POST statuses/update_with_media}. When set to either true, t or 1 images will not be expanded. Defaults to false.
1824
- # @option options [Boolean, String, Integer] :hide_thread Specifies whether the embedded Tweet should automatically show the original message in the case that the embedded Tweet is a reply. When set to either true, t or 1 the original Tweet will not be shown. Defaults to false.
1825
- # @option options [Boolean, String, Integer] :omit_script Specifies whether the embedded Tweet HTML should include a `<script>` element pointing to widgets.js. In cases where a page already includes widgets.js, setting this value to true will prevent a redundant script element from being included. When set to either true, t or 1 the `<script>` element will not be included in the embed HTML, meaning that pages must include a reference to widgets.js manually. Defaults to false.
1826
- # @option options [String] :align Specifies whether the embedded Tweet should be left aligned, right aligned, or centered in the page. Valid values are left, right, center, and none. Defaults to none, meaning no alignment styles are specified for the Tweet.
1827
- # @option options [String] :related A value for the TWT related parameter, as described in {https://dev.twitter.com/docs/intents Web Intents}. This value will be forwarded to all Web Intents calls.
1828
- # @option options [String] :lang Language code for the rendered embed. This will affect the text and localization of the rendered HTML.
1829
- # @example Return oEmbeds for Tweet with the ID 25938088801
1830
- # Twitter.status_with_activity(25938088801)
1831
- def oembed(id, options={})
1832
- object_from_response(Twitter::OEmbed, :get, "/1.1/statuses/oembed.json?id=#{id}", options)
1833
- end
1834
-
1835
- # Returns oEmbeds for Tweets
1836
- #
1837
- # @see https://dev.twitter.com/docs/api/1.1/get/statuses/oembed
1838
- # @rate_limited Yes
1839
- # @authentication_required Requires user context
1840
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1841
- # @return [Array<Twitter::OEmbed>] OEmbeds for the requested Tweets.
1842
- # @overload oembed(*ids_or_urls)
1843
- # @param ids_or_urls [Array<Integer, String>, Set<Integer, String>] An array of Tweet IDs or URLs.
1844
- # @example Return oEmbeds for Tweets with the ID 25938088801
1845
- # Twitter.status_with_activity(25938088801)
1846
- # @overload oembed(*ids_or_urls, options)
1847
- # @param ids_or_urls [Array<Integer, String>, Set<Integer, String>] An array of Tweet IDs or URLs.
1848
- # @param options [Hash] A customizable set of options.
1849
- # @option options [Integer] :maxwidth The maximum width in pixels that the embed should be rendered at. This value is constrained to be between 250 and 550 pixels.
1850
- # @option options [Boolean, String, Integer] :hide_media Specifies whether the embedded Tweet should automatically expand images which were uploaded via {https://dev.twitter.com/docs/api/1.1/post/statuses/update_with_media POST statuses/update_with_media}. When set to either true, t or 1 images will not be expanded. Defaults to false.
1851
- # @option options [Boolean, String, Integer] :hide_thread Specifies whether the embedded Tweet should automatically show the original message in the case that the embedded Tweet is a reply. When set to either true, t or 1 the original Tweet will not be shown. Defaults to false.
1852
- # @option options [Boolean, String, Integer] :omit_script Specifies whether the embedded Tweet HTML should include a `<script>` element pointing to widgets.js. In cases where a page already includes widgets.js, setting this value to true will prevent a redundant script element from being included. When set to either true, t or 1 the `<script>` element will not be included in the embed HTML, meaning that pages must include a reference to widgets.js manually. Defaults to false.
1853
- # @option options [String] :align Specifies whether the embedded Tweet should be left aligned, right aligned, or centered in the page. Valid values are left, right, center, and none. Defaults to none, meaning no alignment styles are specified for the Tweet.
1854
- # @option options [String] :related A value for the TWT related parameter, as described in {https://dev.twitter.com/docs/intents Web Intents}. This value will be forwarded to all Web Intents calls.
1855
- # @option options [String] :lang Language code for the rendered embed. This will affect the text and localization of the rendered HTML.
1856
- def oembeds(*args)
1857
- options = args.extract_options!
1858
- args.flatten.threaded_map do |id|
1859
- object_from_response(Twitter::OEmbed, :get, "/1.1/statuses/oembed.json?id=#{id}", options)
1860
- end
1861
- end
1862
-
1863
- # Destroys the specified Tweets
1864
- #
1865
- # @see https://dev.twitter.com/docs/api/1.1/post/statuses/destroy/:id
1866
- # @note The authenticating user must be the author of the specified Tweets.
1867
- # @rate_limited No
1868
- # @authentication_required Requires user context
1869
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1870
- # @return [Array<Twitter::Tweet>] The deleted Tweets.
1871
- # @overload status_destroy(*ids)
1872
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1873
- # @example Destroy the Tweet with the ID 25938088801
1874
- # Twitter.status_destroy(25938088801)
1875
- # @overload status_destroy(*ids, options)
1876
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1877
- # @param options [Hash] A customizable set of options.
1878
- # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
1879
- def status_destroy(*args)
1880
- threaded_tweets_from_response(:post, "/1.1/statuses/destroy", args)
1881
- end
1882
- alias tweet_destroy status_destroy
1883
-
1884
- # Retweets the specified Tweets as the authenticating user
1885
- #
1886
- # @see https://dev.twitter.com/docs/api/1.1/post/statuses/retweet/:id
1887
- # @rate_limited Yes
1888
- # @authentication_required Requires user context
1889
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1890
- # @return [Array<Twitter::Tweet>] The original tweets with retweet details embedded.
1891
- # @overload retweet(*ids)
1892
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1893
- # @example Retweet the Tweet with the ID 28561922516
1894
- # Twitter.retweet(28561922516)
1895
- # @overload retweet(*ids, options)
1896
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1897
- # @param options [Hash] A customizable set of options.
1898
- # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
1899
- def retweet(*args)
1900
- options = args.extract_options!
1901
- args.flatten.threaded_map do |id|
1902
- begin
1903
- response = post("/1.1/statuses/retweet/#{id}.json", options)
1904
- retweeted_status = response.dup
1905
- retweeted_status[:body] = response[:body].delete(:retweeted_status)
1906
- retweeted_status[:body][:retweeted_status] = response[:body]
1907
- Twitter::Tweet.from_response(retweeted_status)
1908
- rescue Twitter::Error::Forbidden => error
1909
- raise unless error.message == Twitter::Error::AlreadyRetweeted::MESSAGE
1910
- end
1911
- end.compact
1912
- end
1913
-
1914
- # Retweets the specified Tweets as the authenticating user and raises an error if one has already been retweeted
1915
- #
1916
- # @see https://dev.twitter.com/docs/api/1.1/post/statuses/retweet/:id
1917
- # @rate_limited Yes
1918
- # @authentication_required Requires user context
1919
- # @raise [Twitter::Error::AlreadyRetweeted] Error raised when tweet has already been retweeted.
1920
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1921
- # @return [Array<Twitter::Tweet>] The original tweets with retweet details embedded.
1922
- # @overload retweet(*ids)
1923
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1924
- # @example Retweet the Tweet with the ID 28561922516
1925
- # Twitter.retweet(28561922516)
1926
- # @overload retweet(*ids, options)
1927
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1928
- # @param options [Hash] A customizable set of options.
1929
- # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
1930
- def retweet!(*args)
1931
- options = args.extract_options!
1932
- args.flatten.threaded_map do |id|
1933
- begin
1934
- response = post("/1.1/statuses/retweet/#{id}.json", options)
1935
- retweeted_status = response.dup
1936
- retweeted_status[:body] = response[:body].delete(:retweeted_status)
1937
- retweeted_status[:body][:retweeted_status] = response[:body]
1938
- Twitter::Tweet.from_response(retweeted_status)
1939
- rescue Twitter::Error::Forbidden => error
1940
- if error.message == "sharing is not permissible for this status (Share validations failed)"
1941
- raise Twitter::Error::AlreadyRetweeted.new("Tweet with the ID #{id} has already been retweeted by the authenticated user.")
1942
- else
1943
- raise
1944
- end
1945
- end
1946
- end.compact
1947
- end
1948
-
1949
- # Updates the authenticating user's status
1950
- #
1951
- # @see https://dev.twitter.com/docs/api/1.1/post/statuses/update
1952
- # @note A status update with text identical to the authenticating user's current status will be ignored to prevent duplicates.
1953
- # @rate_limited No
1954
- # @authentication_required Requires user context
1955
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1956
- # @return [Twitter::Tweet] The created Tweet.
1957
- # @param status [String] The text of your status update, up to 140 characters.
1958
- # @param options [Hash] A customizable set of options.
1959
- # @option options [Integer] :in_reply_to_status_id The ID of an existing status that the update is in reply to.
1960
- # @option options [Float] :lat The latitude of the location this tweet refers to. This option will be ignored unless it is inside the range -90.0 to +90.0 (North is positive) inclusive. It will also be ignored if there isn't a corresponding :long option.
1961
- # @option options [Float] :long The longitude of the location this tweet refers to. The valid ranges for longitude is -180.0 to +180.0 (East is positive) inclusive. This option will be ignored if outside that range, if it is not a number, if geo_enabled is disabled, or if there not a corresponding :lat option.
1962
- # @option options [String] :place_id A place in the world. These IDs can be retrieved from {Twitter::API::Geo#reverse_geocode}.
1963
- # @option options [String] :display_coordinates Whether or not to put a pin on the exact coordinates a tweet has been sent from.
1964
- # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
1965
- # @example Update the authenticating user's status
1966
- # Twitter.update("I'm tweeting with @gem!")
1967
- def update(status, options={})
1968
- object_from_response(Twitter::Tweet, :post, "/1.1/statuses/update.json", options.merge(:status => status))
1969
- end
1970
-
1971
- # Updates the authenticating user's status with media
1972
- #
1973
- # @see https://dev.twitter.com/docs/api/1.1/post/statuses/update_with_media
1974
- # @note A status update with text/media identical to the authenticating user's current status will NOT be ignored
1975
- # @rate_limited No
1976
- # @authentication_required Requires user context
1977
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1978
- # @return [Twitter::Tweet] The created Tweet.
1979
- # @param status [String] The text of your status update, up to 140 characters.
1980
- # @param media [File, Hash] A File object with your picture (PNG, JPEG or GIF)
1981
- # @param options [Hash] A customizable set of options.
1982
- # @option options [Integer] :in_reply_to_status_id The ID of an existing Tweet that the update is in reply to.
1983
- # @option options [Float] :lat The latitude of the location this tweet refers to. This option will be ignored unless it is inside the range -90.0 to +90.0 (North is positive) inclusive. It will also be ignored if there isn't a corresponding :long option.
1984
- # @option options [Float] :long The longitude of the location this tweet refers to. The valid ranges for longitude is -180.0 to +180.0 (East is positive) inclusive. This option will be ignored if outside that range, if it is not a number, if geo_enabled is disabled, or if there not a corresponding :lat option.
1985
- # @option options [String] :place_id A place in the world. These IDs can be retrieved from {Twitter::API::Geo#reverse_geocode}.
1986
- # @option options [String] :display_coordinates Whether or not to put a pin on the exact coordinates a tweet has been sent from.
1987
- # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
1988
- # @example Update the authenticating user's status
1989
- # Twitter.update_with_media("I'm tweeting with @gem!", File.new('my_awesome_pic.jpeg'))
1990
- def update_with_media(status, media, options={})
1991
- object_from_response(Twitter::Tweet, :post, "/1.1/statuses/update_with_media.json", options.merge('media[]' => media, 'status' => status))
1992
- end
1993
-
1994
- # Returns the top 10 trending topics for a specific WOEID
1995
- #
1996
- # @see https://dev.twitter.com/docs/api/1.1/get/trends/place
1997
- # @rate_limited Yes
1998
- # @authentication_required Requires user context
1999
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
2000
- # @param id [Integer] The {https://developer.yahoo.com/geo/geoplanet Yahoo! Where On Earth ID} of the location to return trending information for. WOEIDs can be retrieved by calling {Twitter::API::Trends#trend_locations}. Global information is available by using 1 as the WOEID.
2001
- # @param options [Hash] A customizable set of options.
2002
- # @option options [String] :exclude Setting this equal to 'hashtags' will remove all hashtags from the trends list.
2003
- # @return [Array<Twitter::Trend>]
2004
- # @example Return the top 10 trending topics for San Francisco
2005
- # Twitter.trends(2487956)
2006
- def trends(id=1, options={})
2007
- options[:id] = id
2008
- response = get("/1.1/trends/place.json", options)
2009
- collection_from_array(Twitter::Trend, response[:body].first[:trends])
2010
- end
2011
- alias local_trends trends
2012
- alias trends_place trends
2013
-
2014
- # Returns the locations that Twitter has trending topic information for
2015
- #
2016
- # @see https://dev.twitter.com/docs/api/1.1/get/trends/available
2017
- # @rate_limited Yes
2018
- # @authentication_required Requires user context
2019
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
2020
- # @param options [Hash] A customizable set of options.
2021
- # @return [Array<Twitter::Place>]
2022
- # @example Return the locations that Twitter has trending topic information for
2023
- # Twitter.trends_available
2024
- def trends_available(options={})
2025
- collection_from_response(Twitter::Place, :get, "/1.1/trends/available.json", options)
2026
- end
2027
- alias trend_locations trends_available
2028
-
2029
- # Returns the locations that Twitter has trending topic information for, closest to a specified location.
2030
- #
2031
- # @see https://dev.twitter.com/docs/api/1.1/get/trends/closest
2032
- # @rate_limited Yes
2033
- # @authentication_required Requires user context
2034
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
2035
- # @param options [Hash] A customizable set of options.
2036
- # @option options [Float] :lat If provided with a :long option the available trend locations will be sorted by distance, nearest to furthest, to the co-ordinate pair. The valid ranges for latitude are -90.0 to +90.0 (North is positive) inclusive.
2037
- # @option options [Float] :long If provided with a :lat option the available trend locations will be sorted by distance, nearest to furthest, to the co-ordinate pair. The valid ranges for longitude are -180.0 to +180.0 (East is positive) inclusive.
2038
- # @return [Array<Twitter::Place>]
2039
- # @example Return the locations that Twitter has trending topic information for
2040
- # Twitter.trends_closest
2041
- def trends_closest(options={})
2042
- collection_from_response(Twitter::Place, :get, "/1.1/trends/closest.json", options)
2043
- end
2044
-
2045
- # Returns an array of user objects that the authenticating user is blocking
2046
- #
2047
- # @see https://dev.twitter.com/docs/api/1.1/get/blocks/list
2048
- # @rate_limited Yes
2049
- # @authentication_required Requires user context
2050
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
2051
- # @return [Array<Twitter::User>] User objects that the authenticating user is blocking.
2052
- # @param options [Hash] A customizable set of options.
2053
- # @option options [Integer] :page Specifies the page of results to retrieve.
2054
- # @example Return an array of user objects that the authenticating user is blocking
2055
- # Twitter.blocking
2056
- def blocking(options={})
2057
- merge_default_cursor!(options)
2058
- cursor_from_response(:users, Twitter::User, :get, "/1.1/blocks/list.json", options)
2059
- end
2060
-
2061
- # Returns an array of numeric user ids the authenticating user is blocking
2062
- #
2063
- # @see https://dev.twitter.com/docs/api/1.1/get/blocks/ids
2064
- # @rate_limited Yes
2065
- # @authentication_required Requires user context
2066
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
2067
- # @return [Array] Numeric user ids the authenticating user is blocking.
2068
- # @param options [Hash] A customizable set of options.
2069
- # @example Return an array of numeric user ids the authenticating user is blocking
2070
- # Twitter.blocking_ids
2071
- def blocked_ids(*args)
2072
- ids_from_response(:get, "/1.1/blocks/ids.json", args)
2073
- end
2074
-
2075
- # Returns true if the authenticating user is blocking a target user
2076
- #
2077
- # @see https://dev.twitter.com/docs/api/1.1/get/blocks/ids
2078
- # @rate_limited Yes
2079
- # @authentication_required Requires user context
2080
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
2081
- # @return [Boolean] true if the authenticating user is blocking the target user, otherwise false.
2082
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
2083
- # @param options [Hash] A customizable set of options.
2084
- # @example Check whether the authenticating user is blocking @sferik
2085
- # Twitter.block?('sferik')
2086
- # Twitter.block?(7505382) # Same as above
2087
- def block?(user, options={})
2088
- merge_default_cursor!(options)
2089
- user_id = case user
2090
- when Integer
2091
- user
2092
- when String
2093
- user(user).id
2094
- when Twitter::User
2095
- user.id
2096
- end
2097
- blocked_ids(options).all.map(&:to_i).include?(user_id)
2098
- end
2099
-
2100
- # Blocks the users specified by the authenticating user
2101
- #
2102
- # @see https://dev.twitter.com/docs/api/1.1/post/blocks/create
2103
- # @note Destroys a friendship to the blocked user if it exists.
2104
- # @rate_limited Yes
2105
- # @authentication_required Requires user context
2106
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
2107
- # @return [Array<Twitter::User>] The blocked users.
2108
- # @overload block(*users)
2109
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
2110
- # @example Block and unfriend @sferik as the authenticating user
2111
- # Twitter.block('sferik')
2112
- # Twitter.block(7505382) # Same as above
2113
- # @overload block(*users, options)
2114
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
2115
- # @param options [Hash] A customizable set of options.
2116
- def block(*args)
2117
- threaded_users_from_response(:post, "/1.1/blocks/create.json", args)
2118
- end
2119
-
2120
- # Un-blocks the users specified by the authenticating user
2121
- #
2122
- # @see https://dev.twitter.com/docs/api/1.1/post/blocks/destroy
2123
- # @rate_limited No
2124
- # @authentication_required Requires user context
2125
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
2126
- # @return [Array<Twitter::User>] The un-blocked users.
2127
- # @overload unblock(*users)
2128
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
2129
- # @example Un-block @sferik as the authenticating user
2130
- # Twitter.unblock('sferik')
2131
- # Twitter.unblock(7505382) # Same as above
2132
- # @overload unblock(*users, options)
2133
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
2134
- # @param options [Hash] A customizable set of options.
2135
- def unblock(*args)
2136
- threaded_users_from_response(:post, "/1.1/blocks/destroy.json", args)
2137
- end
2138
-
2139
- # @return [Array<Twitter::Suggestion>]
2140
- # @rate_limited Yes
2141
- # @authentication_required Requires user context
2142
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
2143
- # @overload suggestions(options={})
2144
- # Returns the list of suggested user categories
2145
- #
2146
- # @see https://dev.twitter.com/docs/api/1.1/get/users/suggestions
2147
- # @param options [Hash] A customizable set of options.
2148
- # @example Return the list of suggested user categories
2149
- # Twitter.suggestions
2150
- # @overload suggestions(slug, options={})
2151
- # Returns the users in a given category
2152
- #
2153
- # @see https://dev.twitter.com/docs/api/1.1/get/users/suggestions/:slug
2154
- # @param slug [String] The short name of list or a category.
2155
- # @param options [Hash] A customizable set of options.
2156
- # @example Return the users in the Art & Design category
2157
- # Twitter.suggestions("art-design")
2158
- def suggestions(*args)
2159
- options = args.extract_options!
2160
- if slug = args.pop
2161
- object_from_response(Twitter::Suggestion, :get, "/1.1/users/suggestions/#{slug}.json", options)
2162
- else
2163
- collection_from_response(Twitter::Suggestion, :get, "/1.1/users/suggestions.json", options)
2164
- end
2165
- end
2166
-
2167
- # Access the users in a given category of the Twitter suggested user list and return their most recent Tweet if they are not a protected user
2168
- #
2169
- # @see https://dev.twitter.com/docs/api/1.1/get/users/suggestions/:slug/members
2170
- # @rate_limited Yes
2171
- # @authentication_required Requires user context
2172
- # @param slug [String] The short name of list or a category.
2173
- # @param options [Hash] A customizable set of options.
2174
- # @return [Array<Twitter::User>]
2175
- # @example Return the users in the Art & Design category and their most recent Tweet if they are not a protected user
2176
- # Twitter.suggest_users("art-design")
2177
- def suggest_users(slug, options={})
2178
- collection_from_response(Twitter::User, :get, "/1.1/users/suggestions/#{slug}/members.json", options)
2179
- end
2180
-
2181
- # Returns extended information for up to 100 users
2182
- #
2183
- # @see https://dev.twitter.com/docs/api/1.1/get/users/lookup
2184
- # @rate_limited Yes
2185
- # @authentication_required Requires user context
2186
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
2187
- # @return [Array<Twitter::User>] The requested users.
2188
- # @overload users(*users)
2189
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
2190
- # @example Return extended information for @sferik and @pengwynn
2191
- # Twitter.users('sferik', 'pengwynn')
2192
- # Twitter.users(7505382, 14100886) # Same as above
2193
- # @overload users(*users, options)
2194
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
2195
- # @param options [Hash] A customizable set of options.
2196
- def users(*args)
2197
- options = args.extract_options!
2198
- args.flatten.each_slice(MAX_USERS_PER_REQUEST).threaded_map do |users|
2199
- collection_from_response(Twitter::User, :post, "/1.1/users/lookup.json", options.merge_users(users))
2200
- end.flatten
2201
- end
2202
-
2203
- # Returns users that match the given query
2204
- #
2205
- # @see https://dev.twitter.com/docs/api/1.1/get/users/search
2206
- # @rate_limited Yes
2207
- # @authentication_required Requires user context
2208
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
2209
- # @return [Array<Twitter::User>]
2210
- # @param query [String] The search query to run against people search.
2211
- # @param options [Hash] A customizable set of options.
2212
- # @option options [Integer] :count The number of people to retrieve. Maxiumum of 20 allowed per page.
2213
- # @option options [Integer] :page Specifies the page of results to retrieve.
2214
- # @example Return users that match "Erik Michaels-Ober"
2215
- # Twitter.user_search("Erik Michaels-Ober")
2216
- def user_search(query, options={})
2217
- collection_from_response(Twitter::User, :get, "/1.1/users/search.json", options.merge(:q => query))
2218
- end
2219
-
2220
- # @see https://dev.twitter.com/docs/api/1.1/get/users/show
2221
- # @rate_limited Yes
2222
- # @authentication_required Requires user context
2223
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
2224
- # @return [Twitter::User] The requested user.
2225
- # @overload user(options={})
2226
- # Returns extended information for the authenticated user
2227
- #
2228
- # @param options [Hash] A customizable set of options.
2229
- # @option options [Boolean, String, Integer] :skip_status Do not include user's Tweets when set to true, 't' or 1.
2230
- # @example Return extended information for the authenticated user
2231
- # Twitter.user
2232
- # @overload user(user, options={})
2233
- # Returns extended information for a given user
2234
- #
2235
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
2236
- # @param options [Hash] A customizable set of options.
2237
- # @example Return extended information for @sferik
2238
- # Twitter.user('sferik')
2239
- # Twitter.user(7505382) # Same as above
2240
- def user(*args)
2241
- options = args.extract_options!
2242
- if user = args.pop
2243
- options.merge_user!(user)
2244
- object_from_response(Twitter::User, :get, "/1.1/users/show.json", options)
2245
- else
2246
- verify_credentials(options)
2247
- end
2248
- end
2249
-
2250
- # Returns true if the specified user exists
2251
- #
2252
- # @rate_limited Yes
2253
- # @authentication_required Requires user context
2254
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
2255
- # @return [Boolean] true if the user exists, otherwise false.
2256
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
2257
- # @example Return true if @sferik exists
2258
- # Twitter.user?('sferik')
2259
- # Twitter.user?(7505382) # Same as above
2260
- def user?(user, options={})
2261
- options.merge_user!(user)
2262
- get("/1.1/users/show.json", options)
2263
- true
2264
- rescue Twitter::Error::NotFound
2265
- false
2266
- end
2267
-
2268
- # Returns an array of users that the specified user can contribute to
2269
- #
2270
- # @see https://dev.twitter.com/docs/api/1.1/get/users/contributees
2271
- # @rate_limited Yes
2272
- # @authentication_required Requires user context
2273
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
2274
- # @return [Array<Twitter::User>]
2275
- # @overload contributees(options={})
2276
- # @param options [Hash] A customizable set of options.
2277
- # @option options [Boolean, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1.
2278
- # @example Return the authenticated user's contributees
2279
- # Twitter.contributees
2280
- # @overload contributees(user, options={})
2281
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
2282
- # @param options [Hash] A customizable set of options.
2283
- # @option options [Boolean, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1.
2284
- # @example Return users @sferik can contribute to
2285
- # Twitter.contributees('sferik')
2286
- # Twitter.contributees(7505382) # Same as above
2287
- def contributees(*args)
2288
- users_from_response(:get, "/1.1/users/contributees.json", args)
2289
- end
2290
-
2291
- # Returns an array of users who can contribute to the specified account
2292
- #
2293
- # @see https://dev.twitter.com/docs/api/1.1/get/users/contributors
2294
- # @rate_limited Yes
2295
- # @authentication_required Requires user context
2296
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
2297
- # @return [Array<Twitter::User>]
2298
- # @overload contributors(options={})
2299
- # @param options [Hash] A customizable set of options.
2300
- # @option options [Boolean, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1.
2301
- # @example Return the authenticated user's contributors
2302
- # Twitter.contributors
2303
- # @overload contributors(user, options={})
2304
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
2305
- # @param options [Hash] A customizable set of options.
2306
- # @option options [Boolean, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1.
2307
- # @example Return users who can contribute to @sferik's account
2308
- # Twitter.contributors('sferik')
2309
- # Twitter.contributors(7505382) # Same as above
2310
- def contributors(*args)
2311
- users_from_response(:get, "/1.1/users/contributors.json", args)
2312
- end
2313
-
2314
- # @note Undocumented
2315
- # @rate_limited Yes
2316
- # @authentication_required Requires user context
2317
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
2318
- #
2319
- # @overload following_followers_of(options={})
2320
- # Returns users following followers of the specified user
2321
- #
2322
- # @param options [Hash] A customizable set of options.
2323
- # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
2324
- # @return [Twitter::Cursor]
2325
- # @example Return users follow followers of @sferik
2326
- # Twitter.following_followers_of
2327
- #
2328
- # @overload following_followers_of(user, options={})
2329
- # Returns users following followers of the authenticated user
2330
- #
2331
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
2332
- # @param options [Hash] A customizable set of options.
2333
- # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
2334
- # @return [Twitter::Cursor]
2335
- # @example Return users follow followers of @sferik
2336
- # Twitter.following_followers_of('sferik')
2337
- # Twitter.following_followers_of(7505382) # Same as above
2338
- def following_followers_of(*args)
2339
- options = args.extract_options!
2340
- merge_default_cursor!(options)
2341
- options.merge_user!(args.pop || screen_name)
2342
- cursor_from_response(:users, Twitter::User, :get, "/users/following_followers_of.json", options)
2343
- end
2344
-
2345
- private
2346
-
2347
- # @param tweets [Array]
2348
- # @return [Array]
2349
- def select_retweets(tweets)
2350
- tweets.select(&:retweet?)
2351
- end
2352
-
2353
- # @param collection [Array]
2354
- # @param max_id [Integer, NilClass]
2355
- # @return [Array]
2356
- def collect_with_max_id(collection=[], max_id=nil, &block)
2357
- tweets = yield(max_id)
2358
- return collection if tweets.nil?
2359
- collection += tweets
2360
- tweets.empty? ? collection.flatten : collect_with_max_id(collection, tweets.last.id - 1, &block)
2361
- end
2362
-
2363
- # @param count [Integer]
2364
- # @return [Array]
2365
- def collect_with_count(count, &block)
2366
- options = {}
2367
- options[:count] = MAX_TWEETS_PER_REQUEST
2368
- collect_with_max_id do |max_id|
2369
- options[:max_id] = max_id unless max_id.nil?
2370
- if count > 0
2371
- tweets = yield(options)
2372
- count -= tweets.length
2373
- tweets
2374
- end
2375
- end.flatten.compact[0...count]
2376
- end
2377
-
2378
- # @param klass [Class]
2379
- # @param array [Array]
2380
- # @return [Array]
2381
- def collection_from_array(klass, array)
2382
- array.map do |element|
2383
- klass.fetch_or_new(element)
2384
- end
2385
- end
2386
-
2387
- # @param klass [Class]
2388
- # @param request_method [Symbol]
2389
- # @param url [String]
2390
- # @param params [Hash]
2391
- # @param options [Hash]
2392
- # @return [Array]
2393
- def collection_from_response(klass, request_method, url, params={}, options={})
2394
- collection_from_array(klass, send(request_method.to_sym, url, params, options)[:body])
2395
- end
2396
-
2397
- # @param request_method [Symbol]
2398
- # @param url [String]
2399
- # @param options [Hash]
2400
- # @return [Array]
2401
- def geo_collection_from_response(request_method, url, options)
2402
- collection_from_array(Twitter::Place, send(request_method.to_sym, url, options)[:body][:result][:places])
2403
- end
2404
-
2405
- # @param request_method [Symbol]
2406
- # @param url [String]
2407
- # @param options [Hash]
2408
- # @return [Array]
2409
- def search_collection_from_response(request_method, url, options)
2410
- collection_from_array(Twitter::Tweet, send(request_method.to_sym, url, options)[:body][:statuses])
2411
- end
2412
-
2413
- # @param klass [Class]
2414
- # @param request_method [Symbol]
2415
- # @param url [String]
2416
- # @param params [Hash]
2417
- # @param options [Hash]
2418
- # @return [Object]
2419
- def object_from_response(klass, request_method, url, params={}, options={})
2420
- response = send(request_method.to_sym, url, params, options)
2421
- klass.from_response(response)
2422
- end
2423
-
2424
- # @param klass [Class]
2425
- # @param request_method [Symbol]
2426
- # @param url [String]
2427
- # @param args [Array]
2428
- # @return [Array]
2429
- def objects_from_response(klass, request_method, url, args)
2430
- options = args.extract_options!
2431
- options.merge_user!(args.pop)
2432
- collection_from_response(klass, request_method, url, options)
2433
- end
2434
-
2435
- # @param request_method [Symbol]
2436
- # @param url [String]
2437
- # @param args [Array]
2438
- # @return [Array<Integer>]
2439
- def ids_from_response(request_method, url, args)
2440
- options = args.extract_options!
2441
- merge_default_cursor!(options)
2442
- options.merge_user!(args.pop)
2443
- cursor_from_response(:ids, nil, request_method, url, options, {}, calling_method)
2444
- end
2445
-
2446
- # @param collection_name [Symbol]
2447
- # @param klass [Class]
2448
- # @param request_method [Symbol]
2449
- # @param url [String]
2450
- # @param params [Hash]
2451
- # @param options [Hash]
2452
- # @return [Twitter::Cursor]
2453
- def cursor_from_response(collection_name, klass, request_method, url, params={}, options={}, method_name=calling_method)
2454
- response = send(request_method.to_sym, url, params, options)
2455
- Twitter::Cursor.from_response(response, collection_name.to_sym, klass, self, method_name, params)
2456
- end
2457
-
2458
- # @param request_method [Symbol]
2459
- # @param url [String]
2460
- # @param args [Array]
2461
- # @return [Array<Twitter::User>]
2462
- def list_from_response(request_method, url, args)
2463
- options = args.extract_options!
2464
- options.merge_list!(args.pop)
2465
- options.merge_owner!(args.pop || screen_name) unless options[:owner_id] || options[:owner_screen_name]
2466
- object_from_response(Twitter::List, request_method, url, options)
2467
- end
2468
-
2469
- # @param request_method [Symbol]
2470
- # @param url [String]
2471
- # @param args [Array]
2472
- # @return [Array<Twitter::List>]
2473
- def lists_from_response(request_method, url, args)
2474
- options = args.extract_options!
2475
- merge_default_cursor!(options)
2476
- options.merge_user!(args.pop)
2477
- cursor_from_response(:lists, Twitter::List, request_method, url, options, {}, calling_method)
2478
- end
2479
-
2480
- # @param request_method [Symbol]
2481
- # @param url [String]
2482
- # @param args [Array]
2483
- # @return [Array<Twitter::User>]
2484
- def users_from_response(request_method, url, args)
2485
- options = args.extract_options!
2486
- options.merge_user!(args.pop || screen_name)
2487
- collection_from_response(Twitter::User, request_method, url, options)
2488
- end
2489
-
2490
- # @param request_method [Symbol]
2491
- # @param url [String]
2492
- # @param args [Array]
2493
- # @return [Array<Twitter::Tweet>]
2494
- def threaded_tweets_from_response(request_method, url, args)
2495
- options = args.extract_options!
2496
- args.flatten.threaded_map do |id|
2497
- object_from_response(Twitter::Tweet, request_method, url + "/#{id}.json", options)
2498
- end
2499
- end
2500
-
2501
- # @param request_method [Symbol]
2502
- # @param url [String]
2503
- # @param args [Array]
2504
- # @return [Array<Twitter::User>]
2505
- def threaded_users_from_response(request_method, url, args)
2506
- options = args.extract_options!
2507
- args.flatten.threaded_map do |user|
2508
- object_from_response(Twitter::User, request_method, url, options.merge_user(user))
2509
- end
2510
- end
2511
-
2512
- def list_users(request_method, url, args)
2513
- options = args.extract_options!
2514
- merge_default_cursor!(options)
2515
- options.merge_list!(args.pop)
2516
- options.merge_owner!(args.pop || screen_name) unless options[:owner_id] || options[:owner_screen_name]
2517
- cursor_from_response(:users, Twitter::User, request_method, url, options, {}, calling_method)
2518
- end
2519
-
2520
- def list_user?(request_method, url, args)
2521
- options = args.extract_options!
2522
- options.merge_user!(args.pop)
2523
- options.merge_list!(args.pop)
2524
- options.merge_owner!(args.pop || screen_name) unless options[:owner_id] || options[:owner_screen_name]
2525
- send(request_method.to_sym, url, options)
2526
- true
2527
- rescue Twitter::Error::NotFound, Twitter::Error::Forbidden
2528
- false
2529
- end
2530
-
2531
- def list_modify_member(request_method, url, args)
2532
- options = args.extract_options!
2533
- options.merge_user!(args.pop)
2534
- options.merge_list!(args.pop)
2535
- options.merge_owner!(args.pop || screen_name) unless options[:owner_id] || options[:owner_screen_name]
2536
- object_from_response(Twitter::List, request_method, url, options)
2537
- end
2538
-
2539
- def list_modify_members(request_method, url, args)
2540
- options = args.extract_options!
2541
- members = args.pop
2542
- options.merge_list!(args.pop)
2543
- options.merge_owner!(args.pop || screen_name) unless options[:owner_id] || options[:owner_screen_name]
2544
- members.flatten.each_slice(MAX_USERS_PER_REQUEST).threaded_map do |users|
2545
- object_from_response(Twitter::List, request_method, url, options.merge_users(users))
2546
- end.last
2547
- end
2548
-
2549
- def merge_default_cursor!(options)
2550
- options[:cursor] = DEFAULT_CURSOR unless options[:cursor]
2551
- end
2552
-
2553
- def screen_name
2554
- @screen_name ||= verify_credentials.screen_name
2555
- end
2556
-
2557
- end
2558
- end