twitter 4.8.1 → 5.0.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (197) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG.md +30 -0
  3. data/LICENSE.md +1 -1
  4. data/README.md +386 -266
  5. data/lib/twitter.rb +4 -39
  6. data/lib/twitter/arguments.rb +11 -0
  7. data/lib/twitter/base.rb +89 -68
  8. data/lib/twitter/client.rb +69 -110
  9. data/lib/twitter/configuration.rb +7 -3
  10. data/lib/twitter/creatable.rb +2 -4
  11. data/lib/twitter/cursor.rb +50 -42
  12. data/lib/twitter/direct_message.rb +2 -11
  13. data/lib/twitter/entity/uri.rb +13 -0
  14. data/lib/twitter/enumerable.rb +15 -0
  15. data/lib/twitter/error.rb +55 -7
  16. data/lib/twitter/error/already_favorited.rb +1 -1
  17. data/lib/twitter/error/already_posted.rb +10 -0
  18. data/lib/twitter/error/already_retweeted.rb +1 -1
  19. data/lib/twitter/error/bad_gateway.rb +2 -3
  20. data/lib/twitter/error/bad_request.rb +2 -2
  21. data/lib/twitter/error/forbidden.rb +2 -2
  22. data/lib/twitter/error/gateway_timeout.rb +2 -3
  23. data/lib/twitter/error/internal_server_error.rb +2 -3
  24. data/lib/twitter/error/not_acceptable.rb +2 -2
  25. data/lib/twitter/error/not_found.rb +2 -2
  26. data/lib/twitter/error/service_unavailable.rb +2 -3
  27. data/lib/twitter/error/too_many_requests.rb +2 -2
  28. data/lib/twitter/error/unauthorized.rb +2 -2
  29. data/lib/twitter/error/unprocessable_entity.rb +2 -2
  30. data/lib/twitter/factory.rb +2 -8
  31. data/lib/twitter/geo_factory.rb +2 -2
  32. data/lib/twitter/geo_results.rb +36 -0
  33. data/lib/twitter/identity.rb +0 -22
  34. data/lib/twitter/list.rb +18 -4
  35. data/lib/twitter/media/photo.rb +3 -3
  36. data/lib/twitter/media_factory.rb +2 -2
  37. data/lib/twitter/null_object.rb +24 -0
  38. data/lib/twitter/oembed.rb +3 -2
  39. data/lib/twitter/place.rb +15 -9
  40. data/lib/twitter/profile_banner.rb +5 -3
  41. data/lib/twitter/rate_limit.rb +1 -17
  42. data/lib/twitter/relationship.rb +2 -10
  43. data/lib/twitter/rest/api/direct_messages.rb +135 -0
  44. data/lib/twitter/rest/api/favorites.rb +120 -0
  45. data/lib/twitter/rest/api/friends_and_followers.rb +290 -0
  46. data/lib/twitter/rest/api/help.rb +58 -0
  47. data/lib/twitter/rest/api/lists.rb +491 -0
  48. data/lib/twitter/rest/api/oauth.rb +45 -0
  49. data/lib/twitter/rest/api/places_and_geo.rb +104 -0
  50. data/lib/twitter/rest/api/saved_searches.rb +91 -0
  51. data/lib/twitter/rest/api/search.rb +37 -0
  52. data/lib/twitter/rest/api/spam_reporting.rb +29 -0
  53. data/lib/twitter/rest/api/suggested_users.rb +51 -0
  54. data/lib/twitter/rest/api/timelines.rb +202 -0
  55. data/lib/twitter/rest/api/trends.rb +58 -0
  56. data/lib/twitter/rest/api/tweets.rb +293 -0
  57. data/lib/twitter/rest/api/undocumented.rb +52 -0
  58. data/lib/twitter/rest/api/users.rb +383 -0
  59. data/lib/twitter/rest/api/utils.rb +219 -0
  60. data/lib/twitter/rest/client.rb +193 -0
  61. data/lib/twitter/rest/request/multipart_with_file.rb +36 -0
  62. data/lib/twitter/rest/response/parse_json.rb +27 -0
  63. data/lib/twitter/{response → rest/response}/raise_error.rb +8 -11
  64. data/lib/twitter/search_results.rb +33 -21
  65. data/lib/twitter/settings.rb +1 -6
  66. data/lib/twitter/size.rb +1 -1
  67. data/lib/twitter/streaming/client.rb +77 -0
  68. data/lib/twitter/streaming/connection.rb +22 -0
  69. data/lib/twitter/streaming/response.rb +30 -0
  70. data/lib/twitter/suggestion.rb +4 -2
  71. data/lib/twitter/token.rb +8 -0
  72. data/lib/twitter/trend.rb +2 -1
  73. data/lib/twitter/trend_results.rb +59 -0
  74. data/lib/twitter/tweet.rb +41 -85
  75. data/lib/twitter/user.rb +51 -41
  76. data/lib/twitter/version.rb +4 -4
  77. data/spec/fixtures/already_posted.json +1 -0
  78. data/spec/fixtures/ids_list.json +1 -1
  79. data/spec/fixtures/ids_list2.json +1 -1
  80. data/spec/fixtures/search.json +1 -1
  81. data/spec/fixtures/search_malformed.json +1 -1
  82. data/spec/fixtures/track_streaming.json +3 -0
  83. data/spec/helper.rb +8 -13
  84. data/spec/twitter/base_spec.rb +25 -99
  85. data/spec/twitter/configuration_spec.rb +1 -1
  86. data/spec/twitter/cursor_spec.rb +13 -31
  87. data/spec/twitter/direct_message_spec.rb +41 -8
  88. data/spec/twitter/entity/uri_spec.rb +74 -0
  89. data/spec/twitter/error_spec.rb +59 -11
  90. data/spec/twitter/geo/point_spec.rb +1 -1
  91. data/spec/twitter/geo_factory_spec.rb +3 -3
  92. data/spec/twitter/geo_results_spec.rb +35 -0
  93. data/spec/twitter/identifiable_spec.rb +0 -21
  94. data/spec/twitter/list_spec.rb +51 -8
  95. data/spec/twitter/media/photo_spec.rb +118 -3
  96. data/spec/twitter/media_factory_spec.rb +2 -2
  97. data/spec/twitter/null_object_spec.rb +26 -0
  98. data/spec/twitter/oembed_spec.rb +69 -45
  99. data/spec/twitter/place_spec.rb +68 -12
  100. data/spec/twitter/profile_banner_spec.rb +1 -1
  101. data/spec/twitter/rate_limit_spec.rb +12 -12
  102. data/spec/twitter/relationship_spec.rb +31 -9
  103. data/spec/twitter/{api → rest/api}/direct_messages_spec.rb +22 -9
  104. data/spec/twitter/{api → rest/api}/favorites_spec.rb +80 -7
  105. data/spec/twitter/{api → rest/api}/friends_and_followers_spec.rb +104 -65
  106. data/spec/twitter/{api → rest/api}/geo_spec.rb +10 -10
  107. data/spec/twitter/{api → rest/api}/help_spec.rb +6 -6
  108. data/spec/twitter/{api → rest/api}/lists_spec.rb +77 -56
  109. data/spec/twitter/{api → rest/api}/oauth_spec.rb +6 -6
  110. data/spec/twitter/{api → rest/api}/saved_searches_spec.rb +7 -7
  111. data/spec/twitter/{api → rest/api}/search_spec.rb +8 -9
  112. data/spec/twitter/{api → rest/api}/spam_reporting_spec.rb +3 -3
  113. data/spec/twitter/{api → rest/api}/suggested_users_spec.rb +5 -5
  114. data/spec/twitter/{api → rest/api}/timelines_spec.rb +9 -9
  115. data/spec/twitter/{api → rest/api}/trends_spec.rb +6 -6
  116. data/spec/twitter/rest/api/tweets_spec.rb +503 -0
  117. data/spec/twitter/{api → rest/api}/undocumented_spec.rb +19 -45
  118. data/spec/twitter/{api → rest/api}/users_spec.rb +60 -35
  119. data/spec/twitter/rest/client_spec.rb +193 -0
  120. data/spec/twitter/saved_search_spec.rb +11 -0
  121. data/spec/twitter/search_results_spec.rb +29 -42
  122. data/spec/twitter/settings_spec.rb +17 -6
  123. data/spec/twitter/streaming/client_spec.rb +75 -0
  124. data/spec/twitter/token_spec.rb +16 -0
  125. data/spec/twitter/trend_results_spec.rb +89 -0
  126. data/spec/twitter/trend_spec.rb +23 -0
  127. data/spec/twitter/tweet_spec.rb +122 -115
  128. data/spec/twitter/user_spec.rb +136 -77
  129. data/spec/twitter_spec.rb +0 -119
  130. data/twitter.gemspec +8 -5
  131. metadata +148 -141
  132. metadata.gz.sig +0 -0
  133. data/lib/twitter/action/favorite.rb +0 -19
  134. data/lib/twitter/action/follow.rb +0 -30
  135. data/lib/twitter/action/list_member_added.rb +0 -39
  136. data/lib/twitter/action/mention.rb +0 -46
  137. data/lib/twitter/action/reply.rb +0 -27
  138. data/lib/twitter/action/retweet.rb +0 -27
  139. data/lib/twitter/action/tweet.rb +0 -20
  140. data/lib/twitter/action_factory.rb +0 -22
  141. data/lib/twitter/api/arguments.rb +0 -13
  142. data/lib/twitter/api/direct_messages.rb +0 -148
  143. data/lib/twitter/api/favorites.rb +0 -126
  144. data/lib/twitter/api/friends_and_followers.rb +0 -334
  145. data/lib/twitter/api/help.rb +0 -64
  146. data/lib/twitter/api/lists.rb +0 -618
  147. data/lib/twitter/api/oauth.rb +0 -44
  148. data/lib/twitter/api/places_and_geo.rb +0 -121
  149. data/lib/twitter/api/saved_searches.rb +0 -99
  150. data/lib/twitter/api/search.rb +0 -37
  151. data/lib/twitter/api/spam_reporting.rb +0 -30
  152. data/lib/twitter/api/suggested_users.rb +0 -55
  153. data/lib/twitter/api/timelines.rb +0 -214
  154. data/lib/twitter/api/trends.rb +0 -63
  155. data/lib/twitter/api/tweets.rb +0 -304
  156. data/lib/twitter/api/undocumented.rb +0 -97
  157. data/lib/twitter/api/users.rb +0 -439
  158. data/lib/twitter/api/utils.rb +0 -187
  159. data/lib/twitter/configurable.rb +0 -96
  160. data/lib/twitter/default.rb +0 -102
  161. data/lib/twitter/entity/url.rb +0 -9
  162. data/lib/twitter/error/client_error.rb +0 -35
  163. data/lib/twitter/error/decode_error.rb +0 -9
  164. data/lib/twitter/error/identity_map_key_error.rb +0 -9
  165. data/lib/twitter/error/server_error.rb +0 -28
  166. data/lib/twitter/exceptable.rb +0 -36
  167. data/lib/twitter/identity_map.rb +0 -22
  168. data/lib/twitter/request/multipart_with_file.rb +0 -34
  169. data/lib/twitter/response/parse_json.rb +0 -25
  170. data/spec/fixtures/about_me.json +0 -1
  171. data/spec/fixtures/activity_summary.json +0 -1
  172. data/spec/fixtures/bad_gateway.json +0 -1
  173. data/spec/fixtures/bad_request.json +0 -1
  174. data/spec/fixtures/by_friends.json +0 -1
  175. data/spec/fixtures/end_session.json +0 -1
  176. data/spec/fixtures/forbidden.json +0 -1
  177. data/spec/fixtures/internal_server_error.json +0 -1
  178. data/spec/fixtures/not_acceptable.json +0 -1
  179. data/spec/fixtures/phoenix_search.phoenix +0 -1
  180. data/spec/fixtures/resolve.json +0 -1
  181. data/spec/fixtures/service_unavailable.json +0 -1
  182. data/spec/fixtures/totals.json +0 -1
  183. data/spec/fixtures/trends.json +0 -1
  184. data/spec/fixtures/unauthorized.json +0 -1
  185. data/spec/fixtures/video_facets.json +0 -1
  186. data/spec/twitter/action/favorite_spec.rb +0 -29
  187. data/spec/twitter/action/follow_spec.rb +0 -29
  188. data/spec/twitter/action/list_member_added_spec.rb +0 -41
  189. data/spec/twitter/action/mention_spec.rb +0 -52
  190. data/spec/twitter/action/reply_spec.rb +0 -41
  191. data/spec/twitter/action/retweet_spec.rb +0 -41
  192. data/spec/twitter/action_factory_spec.rb +0 -35
  193. data/spec/twitter/action_spec.rb +0 -16
  194. data/spec/twitter/api/tweets_spec.rb +0 -285
  195. data/spec/twitter/client_spec.rb +0 -223
  196. data/spec/twitter/error/client_error_spec.rb +0 -23
  197. data/spec/twitter/error/server_error_spec.rb +0 -20
@@ -1,223 +0,0 @@
1
- require 'helper'
2
-
3
- describe Twitter::Client do
4
-
5
- subject do
6
- Twitter::Client.new(:consumer_key => "CK", :consumer_secret => "CS", :oauth_token => "OT", :oauth_token_secret => "OS")
7
- end
8
-
9
- context "with module configuration" do
10
-
11
- before do
12
- Twitter.configure do |config|
13
- Twitter::Configurable.keys.each do |key|
14
- config.send("#{key}=", key)
15
- end
16
- end
17
- end
18
-
19
- after do
20
- Twitter.reset!
21
- end
22
-
23
- it "inherits the module configuration" do
24
- client = Twitter::Client.new
25
- Twitter::Configurable.keys.each do |key|
26
- expect(client.instance_variable_get(:"@#{key}")).to eq key
27
- end
28
- end
29
-
30
- context "with class configuration" do
31
-
32
- before do
33
- @configuration = {
34
- :connection_options => {:timeout => 10},
35
- :consumer_key => 'CK',
36
- :consumer_secret => 'CS',
37
- :endpoint => 'http://tumblr.com/',
38
- :middleware => Proc.new{},
39
- :oauth_token => 'OT',
40
- :oauth_token_secret => 'OS',
41
- :bearer_token => 'BT',
42
- :identity_map => ::Hash
43
- }
44
- end
45
-
46
- context "during initialization" do
47
- it "overrides the module configuration" do
48
- client = Twitter::Client.new(@configuration)
49
- Twitter::Configurable.keys.each do |key|
50
- expect(client.instance_variable_get(:"@#{key}")).to eq @configuration[key]
51
- end
52
- end
53
- end
54
-
55
- context "after initialization" do
56
- it "overrides the module configuration after initialization" do
57
- client = Twitter::Client.new
58
- client.configure do |config|
59
- @configuration.each do |key, value|
60
- config.send("#{key}=", value)
61
- end
62
- end
63
- Twitter::Configurable.keys.each do |key|
64
- expect(client.instance_variable_get(:"@#{key}")).to eq @configuration[key]
65
- end
66
- end
67
- end
68
-
69
- end
70
- end
71
-
72
- it "does not cache the screen name across clients" do
73
- stub_get("/1.1/account/verify_credentials.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
74
- client1 = Twitter::Client.new
75
- expect(client1.verify_credentials.id).to eq 7505382
76
- stub_get("/1.1/account/verify_credentials.json").to_return(:body => fixture("pengwynn.json"), :headers => {:content_type => "application/json; charset=utf-8"})
77
- client2 = Twitter::Client.new
78
- expect(client2.verify_credentials.id).to eq 14100886
79
- end
80
-
81
- describe "#delete" do
82
- before do
83
- stub_delete("/custom/delete").with(:query => {:deleted => "object"})
84
- end
85
- it "allows custom delete requests" do
86
- subject.delete("/custom/delete", {:deleted => "object"})
87
- expect(a_delete("/custom/delete").with(:query => {:deleted => "object"})).to have_been_made
88
- end
89
- end
90
-
91
- describe "#put" do
92
- before do
93
- stub_put("/custom/put").with(:body => {:updated => "object"})
94
- end
95
- it "allows custom put requests" do
96
- subject.put("/custom/put", {:updated => "object"})
97
- expect(a_put("/custom/put").with(:body => {:updated => "object"})).to have_been_made
98
- end
99
- end
100
-
101
- describe "#user_token?" do
102
- it "returns true if the user token/secret are present" do
103
- client = Twitter::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :oauth_token => 'OT', :oauth_token_secret => 'OS')
104
- expect(client.user_token?).to be_true
105
- end
106
- it "returns false if the user token/secret are not completely present" do
107
- client = Twitter::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :oauth_token => 'OT')
108
- expect(client.user_token?).to be_false
109
- end
110
- end
111
-
112
- describe "#bearer_token?" do
113
- it "returns true if the app token is present" do
114
- client = Twitter::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :bearer_token => 'BT')
115
- expect(client.bearer_token?).to be_true
116
- end
117
- it "returns false if the bearer_token is not present" do
118
- client = Twitter::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS')
119
- expect(client.bearer_token?).to be_false
120
- end
121
- end
122
-
123
- describe "#credentials?" do
124
- it "returns true if all credentials are present" do
125
- client = Twitter::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :oauth_token => 'OT', :oauth_token_secret => 'OS')
126
- expect(client.credentials?).to be_true
127
- end
128
- it "returns false if any credentials are missing" do
129
- client = Twitter::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :oauth_token => 'OT')
130
- expect(client.credentials?).to be_false
131
- end
132
- end
133
-
134
- describe "#connection" do
135
- it "looks like Faraday connection" do
136
- expect(subject.send(:connection)).to respond_to(:run_request)
137
- end
138
- it "memoizes the connection" do
139
- c1, c2 = subject.send(:connection), subject.send(:connection)
140
- expect(c1.object_id).to eq c2.object_id
141
- end
142
- end
143
-
144
- describe "#request" do
145
- it "encodes the entire body when no uploaded media is present" do
146
- stub_post("/1.1/statuses/update.json").with(:body => {:status => "Update"}).to_return(:body => fixture("status.json"), :headers => {:content_type => "application/json; charset=utf-8"})
147
- subject.update("Update")
148
- expect(a_post("/1.1/statuses/update.json").with(:body => {:status => "Update"})).to have_been_made
149
- end
150
- it "encodes none of the body when uploaded media is present" do
151
- stub_post("/1.1/statuses/update_with_media.json")
152
- subject.update_with_media("Update", fixture("pbjt.gif"))
153
- expect(a_post("/1.1/statuses/update_with_media.json")).to have_been_made
154
- end
155
- it "catches Faraday errors" do
156
- subject.stub!(:connection).and_raise(Faraday::Error::ClientError.new("Oops"))
157
- expect{subject.send(:request, :get, "/path")}.to raise_error Twitter::Error::ClientError
158
- end
159
- it "catches MultiJson::DecodeError errors" do
160
- subject.stub!(:connection).and_raise(MultiJson::DecodeError.new("unexpected token", [], "<!DOCTYPE html>"))
161
- expect{subject.send(:request, :get, "/path")}.to raise_error Twitter::Error::DecodeError
162
- end
163
- end
164
-
165
- describe "#oauth_auth_header" do
166
- it "creates the correct auth headers" do
167
- uri = "/1.1/direct_messages.json"
168
- authorization = subject.send(:oauth_auth_header, :get, uri)
169
- expect(authorization.options[:signature_method]).to eq "HMAC-SHA1"
170
- expect(authorization.options[:version]).to eq "1.0"
171
- expect(authorization.options[:consumer_key]).to eq "CK"
172
- expect(authorization.options[:consumer_secret]).to eq "CS"
173
- expect(authorization.options[:token]).to eq "OT"
174
- expect(authorization.options[:token_secret]).to eq "OS"
175
- end
176
- it "submits the correct auth header when no media is present" do
177
- # We use static values for nounce and timestamp to get a stable signature
178
- secret = {:consumer_key => 'CK', :consumer_secret => 'CS',
179
- :token => 'OT', :token_secret => 'OS',
180
- :nonce => 'b6ebe4c2a11af493f8a2290fe1296965', :timestamp => '1370968658'}
181
- header = {"Authorization" => /oauth_signature="FbthwmgGq02iQw%2FuXGEWaL6V6eM%3D"/}
182
-
183
- subject.stub(:credentials).and_return(secret)
184
- stub_post("/1.1/statuses/update.json")
185
- subject.update("Just a test")
186
- expect(a_post("/1.1/statuses/update.json").
187
- with(:headers => header)).to have_been_made
188
- end
189
- it "submits the correct auth header when media is present" do
190
- # We use static values for nounce and timestamp to get a stable signature
191
- secret = {:consumer_key => 'CK', :consumer_secret => 'CS',
192
- :token => 'OT', :token_secret => 'OS',
193
- :nonce => 'e08201ad0dab4897c99445056feefd95', :timestamp => '1370967652'}
194
- header = {"Authorization" => /oauth_signature="9ziouUPwZT9IWWRbJL8r0BerKYA%3D"/}
195
-
196
- subject.stub(:credentials).and_return(secret)
197
- stub_post("/1.1/statuses/update_with_media.json")
198
- subject.update_with_media("Just a test", fixture("pbjt.gif"))
199
- expect(a_post("/1.1/statuses/update_with_media.json").
200
- with(:headers => header)).to have_been_made
201
- end
202
- end
203
-
204
- describe "#bearer_auth_header" do
205
- subject do
206
- Twitter::Client.new(:bearer_token => "BT")
207
- end
208
-
209
- it "creates the correct auth headers with supplied bearer_token" do
210
- uri = "/1.1/direct_messages.json"
211
- authorization = subject.send(:bearer_auth_header)
212
- expect(authorization).to eq "Bearer BT"
213
- end
214
- end
215
-
216
- describe "#bearer_token_credentials_auth_header" do
217
- it "creates the correct auth header with supplied consumer_key and consumer_secret" do
218
- uri = "/1.1/direct_messages.json"
219
- authorization = subject.send(:bearer_token_credentials_auth_header)
220
- expect(authorization).to eq "Basic Q0s6Q1M="
221
- end
222
- end
223
- end
@@ -1,23 +0,0 @@
1
- require 'helper'
2
-
3
- describe Twitter::Error::ClientError do
4
-
5
- before do
6
- @client = Twitter::Client.new
7
- end
8
-
9
- Twitter::Error::ClientError.errors.each do |status, exception|
10
- [nil, "error", "errors"].each do |body|
11
- context "when HTTP status is #{status} and body is #{body.inspect}" do
12
- before do
13
- body_message = '{"' + body + '":"Client Error"}' unless body.nil?
14
- stub_get("/1.1/statuses/user_timeline.json").with(:query => {:screen_name => 'sferik'}).to_return(:status => status, :body => body_message)
15
- end
16
- it "raises #{exception.name}" do
17
- expect{@client.user_timeline('sferik')}.to raise_error exception
18
- end
19
- end
20
- end
21
- end
22
-
23
- end
@@ -1,20 +0,0 @@
1
- require 'helper'
2
-
3
- describe Twitter::Error::ServerError do
4
-
5
- before do
6
- @client = Twitter::Client.new
7
- end
8
-
9
- Twitter::Error::ServerError.errors.each do |status, exception|
10
- context "when HTTP status is #{status}" do
11
- before do
12
- stub_get("/1.1/statuses/user_timeline.json").with(:query => {:screen_name => 'sferik'}).to_return(:status => status)
13
- end
14
- it "raises #{exception.name}" do
15
- expect{@client.user_timeline('sferik')}.to raise_error exception
16
- end
17
- end
18
- end
19
-
20
- end