twitter 5.11.0 → 5.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -1
  3. data/README.md +7 -5
  4. data/lib/twitter/arguments.rb +1 -0
  5. data/lib/twitter/base.rb +4 -5
  6. data/lib/twitter/basic_user.rb +1 -0
  7. data/lib/twitter/client.rb +10 -9
  8. data/lib/twitter/configuration.rb +4 -2
  9. data/lib/twitter/cursor.rb +3 -2
  10. data/lib/twitter/direct_message.rb +1 -0
  11. data/lib/twitter/entity.rb +1 -0
  12. data/lib/twitter/entity/hashtag.rb +1 -0
  13. data/lib/twitter/entity/symbol.rb +1 -0
  14. data/lib/twitter/entity/user_mention.rb +4 -1
  15. data/lib/twitter/error.rb +22 -19
  16. data/lib/twitter/geo.rb +1 -0
  17. data/lib/twitter/geo_results.rb +3 -2
  18. data/lib/twitter/identity.rb +1 -0
  19. data/lib/twitter/language.rb +1 -0
  20. data/lib/twitter/list.rb +12 -5
  21. data/lib/twitter/media/photo.rb +1 -0
  22. data/lib/twitter/metadata.rb +1 -0
  23. data/lib/twitter/null_object.rb +22 -0
  24. data/lib/twitter/oembed.rb +5 -2
  25. data/lib/twitter/place.rb +4 -1
  26. data/lib/twitter/profile.rb +1 -1
  27. data/lib/twitter/rest/client.rb +4 -4
  28. data/lib/twitter/rest/favorites.rb +4 -3
  29. data/lib/twitter/rest/lists.rb +18 -3
  30. data/lib/twitter/rest/request/multipart_with_file.rb +1 -1
  31. data/lib/twitter/rest/response/parse_json.rb +1 -1
  32. data/lib/twitter/rest/response/raise_error.rb +4 -5
  33. data/lib/twitter/rest/tweets.rb +2 -1
  34. data/lib/twitter/rest/users.rb +10 -7
  35. data/lib/twitter/saved_search.rb +1 -0
  36. data/lib/twitter/search_results.rb +3 -2
  37. data/lib/twitter/settings.rb +7 -3
  38. data/lib/twitter/size.rb +4 -1
  39. data/lib/twitter/streaming/deleted_tweet.rb +1 -0
  40. data/lib/twitter/streaming/event.rb +2 -2
  41. data/lib/twitter/streaming/message_parser.rb +1 -1
  42. data/lib/twitter/suggestion.rb +4 -1
  43. data/lib/twitter/token.rb +1 -0
  44. data/lib/twitter/trend.rb +1 -0
  45. data/lib/twitter/trend_results.rb +3 -2
  46. data/lib/twitter/tweet.rb +9 -6
  47. data/lib/twitter/user.rb +15 -13
  48. data/lib/twitter/utils.rb +2 -6
  49. data/lib/twitter/version.rb +1 -1
  50. data/twitter.gemspec +6 -9
  51. metadata +6 -259
  52. data/Rakefile +0 -37
  53. data/spec/fixtures/already_favorited.json +0 -1
  54. data/spec/fixtures/already_posted.json +0 -1
  55. data/spec/fixtures/already_retweeted.json +0 -1
  56. data/spec/fixtures/bearer_token.json +0 -1
  57. data/spec/fixtures/category.json +0 -1
  58. data/spec/fixtures/configuration.json +0 -1
  59. data/spec/fixtures/contributees.json +0 -1
  60. data/spec/fixtures/count.json +0 -1
  61. data/spec/fixtures/direct_message.json +0 -1
  62. data/spec/fixtures/direct_messages.json +0 -1
  63. data/spec/fixtures/empty.json +0 -0
  64. data/spec/fixtures/followers_list.json +0 -1
  65. data/spec/fixtures/followers_list2.json +0 -1
  66. data/spec/fixtures/following.json +0 -1
  67. data/spec/fixtures/forbidden.json +0 -1
  68. data/spec/fixtures/friends_list.json +0 -1
  69. data/spec/fixtures/friends_list2.json +0 -1
  70. data/spec/fixtures/friendships.json +0 -1
  71. data/spec/fixtures/ids.json +0 -1
  72. data/spec/fixtures/ids_list.json +0 -1
  73. data/spec/fixtures/ids_list2.json +0 -1
  74. data/spec/fixtures/languages.json +0 -1
  75. data/spec/fixtures/list.json +0 -1
  76. data/spec/fixtures/lists.json +0 -1
  77. data/spec/fixtures/locations.json +0 -1
  78. data/spec/fixtures/matching_trends.json +0 -1
  79. data/spec/fixtures/me.jpeg +0 -0
  80. data/spec/fixtures/members.json +0 -1
  81. data/spec/fixtures/memberships.json +0 -1
  82. data/spec/fixtures/memberships2.json +0 -1
  83. data/spec/fixtures/not_following.json +0 -1
  84. data/spec/fixtures/not_found.json +0 -1
  85. data/spec/fixtures/oembed.json +0 -1
  86. data/spec/fixtures/ownerships.json +0 -1
  87. data/spec/fixtures/pbjt.gif +0 -0
  88. data/spec/fixtures/pengwynn.json +0 -1
  89. data/spec/fixtures/place.json +0 -1
  90. data/spec/fixtures/places.json +0 -1
  91. data/spec/fixtures/privacy.json +0 -1
  92. data/spec/fixtures/profile_banner.json +0 -1
  93. data/spec/fixtures/request_token.txt +0 -6
  94. data/spec/fixtures/retweet.json +0 -1
  95. data/spec/fixtures/retweets.json +0 -1
  96. data/spec/fixtures/saved_search.json +0 -1
  97. data/spec/fixtures/saved_searches.json +0 -1
  98. data/spec/fixtures/search.json +0 -1
  99. data/spec/fixtures/search2.json +0 -1
  100. data/spec/fixtures/search_malformed.json +0 -1
  101. data/spec/fixtures/settings.json +0 -1
  102. data/spec/fixtures/sferik.json +0 -1
  103. data/spec/fixtures/status.json +0 -1
  104. data/spec/fixtures/statuses.json +0 -1
  105. data/spec/fixtures/subscriptions.json +0 -1
  106. data/spec/fixtures/subscriptions2.json +0 -1
  107. data/spec/fixtures/suggestions.json +0 -1
  108. data/spec/fixtures/tos.json +0 -1
  109. data/spec/fixtures/track_streaming.json +0 -3
  110. data/spec/fixtures/track_streaming_user.json +0 -6
  111. data/spec/fixtures/upload.json +0 -1
  112. data/spec/fixtures/user_search.json +0 -1
  113. data/spec/fixtures/user_timeline.json +0 -1
  114. data/spec/fixtures/users.json +0 -1
  115. data/spec/fixtures/users_list.json +0 -1
  116. data/spec/fixtures/users_list2.json +0 -1
  117. data/spec/fixtures/we_concept_bg2.png +0 -0
  118. data/spec/fixtures/wildcomet2.jpe +0 -0
  119. data/spec/helper.rb +0 -68
  120. data/spec/twitter/base_spec.rb +0 -39
  121. data/spec/twitter/basic_user_spec.rb +0 -23
  122. data/spec/twitter/configuration_spec.rb +0 -17
  123. data/spec/twitter/cursor_spec.rb +0 -30
  124. data/spec/twitter/direct_message_spec.rb +0 -232
  125. data/spec/twitter/entity/uri_spec.rb +0 -75
  126. data/spec/twitter/error_spec.rb +0 -52
  127. data/spec/twitter/geo/point_spec.rb +0 -41
  128. data/spec/twitter/geo/polygon_spec.rb +0 -29
  129. data/spec/twitter/geo_factory_spec.rb +0 -19
  130. data/spec/twitter/geo_results_spec.rb +0 -35
  131. data/spec/twitter/geo_spec.rb +0 -29
  132. data/spec/twitter/identifiable_spec.rb +0 -29
  133. data/spec/twitter/list_spec.rb +0 -88
  134. data/spec/twitter/media/photo_spec.rb +0 -151
  135. data/spec/twitter/media_factory_spec.rb +0 -15
  136. data/spec/twitter/oembed_spec.rb +0 -170
  137. data/spec/twitter/place_spec.rb +0 -168
  138. data/spec/twitter/profile_banner_spec.rb +0 -13
  139. data/spec/twitter/rate_limit_spec.rb +0 -59
  140. data/spec/twitter/relationship_spec.rb +0 -49
  141. data/spec/twitter/rest/client_spec.rb +0 -217
  142. data/spec/twitter/rest/direct_messages_spec.rb +0 -133
  143. data/spec/twitter/rest/favorites_spec.rb +0 -188
  144. data/spec/twitter/rest/friends_and_followers_spec.rb +0 -667
  145. data/spec/twitter/rest/geo_spec.rb +0 -68
  146. data/spec/twitter/rest/help_spec.rb +0 -68
  147. data/spec/twitter/rest/lists_spec.rb +0 -910
  148. data/spec/twitter/rest/media_spec.rb +0 -54
  149. data/spec/twitter/rest/oauth_spec.rb +0 -63
  150. data/spec/twitter/rest/saved_searches_spec.rb +0 -98
  151. data/spec/twitter/rest/search_spec.rb +0 -42
  152. data/spec/twitter/rest/spam_reporting_spec.rb +0 -25
  153. data/spec/twitter/rest/suggested_users_spec.rb +0 -59
  154. data/spec/twitter/rest/timelines_spec.rb +0 -138
  155. data/spec/twitter/rest/trends_spec.rb +0 -68
  156. data/spec/twitter/rest/tweets_spec.rb +0 -614
  157. data/spec/twitter/rest/undocumented_spec.rb +0 -103
  158. data/spec/twitter/rest/users_spec.rb +0 -797
  159. data/spec/twitter/saved_search_spec.rb +0 -45
  160. data/spec/twitter/search_results_spec.rb +0 -30
  161. data/spec/twitter/settings_spec.rb +0 -27
  162. data/spec/twitter/size_spec.rb +0 -28
  163. data/spec/twitter/source_user_spec.rb +0 -23
  164. data/spec/twitter/streaming/client_spec.rb +0 -123
  165. data/spec/twitter/streaming/connection_spec.rb +0 -32
  166. data/spec/twitter/streaming/deleted_tweet_spec.rb +0 -23
  167. data/spec/twitter/streaming/event_spec.rb +0 -43
  168. data/spec/twitter/streaming/friend_list_spec.rb +0 -11
  169. data/spec/twitter/streaming/message_parser_spec.rb +0 -54
  170. data/spec/twitter/streaming/response_spec.rb +0 -21
  171. data/spec/twitter/suggestion_spec.rb +0 -40
  172. data/spec/twitter/target_user_spec.rb +0 -23
  173. data/spec/twitter/token_spec.rb +0 -16
  174. data/spec/twitter/trend_results_spec.rb +0 -89
  175. data/spec/twitter/trend_spec.rb +0 -51
  176. data/spec/twitter/tweet_spec.rb +0 -456
  177. data/spec/twitter/user_spec.rb +0 -447
  178. data/spec/twitter/utils_spec.rb +0 -34
@@ -1,217 +0,0 @@
1
- require 'helper'
2
-
3
- describe Twitter::REST::Client do
4
-
5
- before do
6
- @client = Twitter::REST::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :access_token => 'AT', :access_token_secret => 'AS')
7
- end
8
-
9
- describe '.new' do
10
- context 'when invalid credentials are provided' do
11
- it 'raises a ConfigurationError exception' do
12
- expect { Twitter::REST::Client.new(:consumer_key => [12_345, 54_321]) }.to raise_exception(Twitter::Error::ConfigurationError)
13
- end
14
- end
15
-
16
- context 'when no credentials are provided' do
17
- it 'does not raise an exception' do
18
- expect { Twitter::REST::Client.new }.not_to raise_error
19
- end
20
- end
21
- end
22
-
23
- describe '.credentials?' do
24
- it 'returns true if only bearer_token is supplied' do
25
- client = Twitter::REST::Client.new(:bearer_token => 'BT')
26
- expect(client.credentials?).to be true
27
- end
28
- it 'returns true if all OAuth credentials are present' do
29
- client = Twitter::REST::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :access_token => 'AT', :access_token_secret => 'AS')
30
- expect(client.credentials?).to be true
31
- end
32
- it 'returns false if any credentials are missing' do
33
- client = Twitter::REST::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :access_token => 'AT')
34
- expect(client.credentials?).to be false
35
- end
36
- end
37
-
38
- it 'does not cache the screen name across clients' do
39
- stub_get('/1.1/account/verify_credentials.json').to_return(:body => fixture('sferik.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
40
- user1 = Twitter::REST::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :access_token => 'AT', :access_token_secret => 'AS').current_user
41
- stub_get('/1.1/account/verify_credentials.json').to_return(:body => fixture('pengwynn.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
42
- user2 = Twitter::REST::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :access_token => 'AT', :access_token_secret => 'AS').current_user
43
- expect(user1).not_to eq(user2)
44
- end
45
-
46
- describe '#user_token?' do
47
- it 'returns true if the user token/secret are present' do
48
- client = Twitter::REST::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :access_token => 'AT', :access_token_secret => 'AS')
49
- expect(client.user_token?).to be true
50
- end
51
- it 'returns false if the user token/secret are not completely present' do
52
- client = Twitter::REST::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :access_token => 'AT')
53
- expect(client.user_token?).to be false
54
- end
55
- end
56
-
57
- describe '#bearer_token?' do
58
- it 'returns true if the app token is present' do
59
- client = Twitter::REST::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :bearer_token => 'BT')
60
- expect(client.bearer_token?).to be true
61
- end
62
- it 'returns false if the bearer_token is not present' do
63
- client = Twitter::REST::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS')
64
- expect(client.bearer_token?).to be false
65
- end
66
- end
67
-
68
- describe '#connection_options=' do
69
- it 'sets connection options' do
70
- capture_warning do
71
- @client.connection_options = 'connection options'
72
- end
73
- expect(@client.connection_options).to eq('connection options')
74
- end
75
- it 'outputs a warning' do
76
- warning = capture_warning do
77
- @client.connection_options = nil
78
- end
79
- expect(warning).to match(/\[DEPRECATION\] Twitter::REST::Client#connection_options= is deprecated and will be removed in version 6\.0\.0\.$/)
80
- end
81
- end
82
-
83
- describe '#connection_options' do
84
- it 'returns the connection options hash with proxy and user_agent' do
85
- client = Twitter::REST::Client.new do |config|
86
- config.consumer_key = 'CK'
87
- config.consumer_secret = 'CS'
88
- config.access_token = 'AT'
89
- config.access_token_secret = 'ATS'
90
- config.proxy = 'http://localhost:99'
91
- config.user_agent = 'My Twitter Ruby Gem'
92
- end
93
-
94
- expect(client.connection_options[:proxy]).to eql('http://localhost:99')
95
- expect(client.connection_options[:headers][:user_agent]).to eql('My Twitter Ruby Gem')
96
- end
97
- end
98
-
99
- describe '#middleware=' do
100
- it 'sets middleware' do
101
- capture_warning do
102
- @client.middleware = 'middleware'
103
- end
104
- expect(@client.middleware).to eq 'middleware'
105
- end
106
- it 'outputs a warning' do
107
- warning = capture_warning do
108
- @client.middleware = nil
109
- end
110
- expect(warning).to match(/\[DEPRECATION\] Twitter::REST::Client#middleware= is deprecated and will be removed in version 6\.0\.0\.$/)
111
- end
112
- end
113
-
114
- describe '#credentials?' do
115
- it 'returns true if all credentials are present' do
116
- client = Twitter::REST::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :access_token => 'AT', :access_token_secret => 'AS')
117
- expect(client.credentials?).to be true
118
- end
119
- it 'returns false if any credentials are missing' do
120
- client = Twitter::REST::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :access_token => 'AT')
121
- expect(client.credentials?).to be false
122
- end
123
- end
124
-
125
- describe '#connection' do
126
- it 'looks like Faraday connection' do
127
- expect(@client.send(:connection)).to respond_to(:run_request)
128
- end
129
- it 'memoizes the connection' do
130
- c1, c2 = @client.send(:connection), @client.send(:connection)
131
- expect(c1.object_id).to eq(c2.object_id)
132
- end
133
- end
134
-
135
- describe '#request' do
136
- it 'encodes the entire body when no uploaded media is present' do
137
- 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'})
138
- @client.update('Update')
139
- expect(a_post('/1.1/statuses/update.json').with(:body => {:status => 'Update'})).to have_been_made
140
- end
141
- it 'encodes none of the body when uploaded media is present' do
142
- stub_post('/1.1/statuses/update_with_media.json').to_return(:body => fixture('status.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
143
- @client.update_with_media('Update', fixture('pbjt.gif'))
144
- expect(a_post('/1.1/statuses/update_with_media.json')).to have_been_made
145
- end
146
- it 'catches and reraises Faraday timeout errors' do
147
- allow(@client).to receive(:connection).and_raise(Faraday::Error::TimeoutError.new('execution expired'))
148
- expect { @client.send(:request, :get, '/path') }.to raise_error(Twitter::Error::RequestTimeout)
149
- end
150
- it 'catches and reraises Timeout errors' do
151
- allow(@client).to receive(:connection).and_raise(Timeout::Error.new('execution expired'))
152
- expect { @client.send(:request, :get, '/path') }.to raise_error(Twitter::Error::RequestTimeout)
153
- end
154
- it 'catches and reraises Faraday client errors' do
155
- allow(@client).to receive(:connection).and_raise(Faraday::Error::ClientError.new('connection failed'))
156
- expect { @client.send(:request, :get, '/path') }.to raise_error(Twitter::Error)
157
- end
158
- it 'catches and reraises JSON::ParserError errors' do
159
- allow(@client).to receive(:connection).and_raise(JSON::ParserError.new('unexpected token'))
160
- expect { @client.send(:request, :get, '/path') }.to raise_error(Twitter::Error)
161
- end
162
- end
163
-
164
- describe '#oauth_auth_header' do
165
- it 'creates the correct auth headers' do
166
- uri = Twitter::REST::Client::URL_PREFIX + '/1.1/direct_messages.json'
167
- authorization = @client.send(:oauth_auth_header, :get, uri)
168
- expect(authorization.options[:signature_method]).to eq('HMAC-SHA1')
169
- expect(authorization.options[:version]).to eq('1.0')
170
- expect(authorization.options[:consumer_key]).to eq('CK')
171
- expect(authorization.options[:consumer_secret]).to eq('CS')
172
- expect(authorization.options[:token]).to eq('AT')
173
- expect(authorization.options[:token_secret]).to eq('AS')
174
- end
175
- it 'submits the correct auth header when no media is present' do
176
- # We use static values for nounce and timestamp to get a stable signature
177
- secret = {:consumer_key => 'CK', :consumer_secret => 'CS', :token => 'OT', :token_secret => 'OS', :nonce => 'b6ebe4c2a11af493f8a2290fe1296965', :timestamp => '1370968658'}
178
- headers = {:authorization => /oauth_signature="FbthwmgGq02iQw%2FuXGEWaL6V6eM%3D"/, :content_type => 'application/json; charset=utf-8'}
179
-
180
- allow(@client).to receive(:credentials).and_return(secret)
181
- stub_post('/1.1/statuses/update.json').with(:body => {:status => 'Just a test'}).to_return(:body => fixture('status.json'), :headers => headers)
182
- @client.update('Just a test')
183
- expect(a_post('/1.1/statuses/update.json').with(:headers => {:authorization => headers[:authorization]})).to have_been_made
184
- end
185
- it 'submits the correct auth header when media is present' do
186
- # We use static values for nounce and timestamp to get a stable signature
187
- secret = {:consumer_key => 'CK', :consumer_secret => 'CS', :token => 'OT', :token_secret => 'OS', :nonce => 'e08201ad0dab4897c99445056feefd95', :timestamp => '1370967652'}
188
- headers = {:authorization => /oauth_signature="9ziouUPwZT9IWWRbJL8r0BerKYA%3D"/, :content_type => 'application/json; charset=utf-8'}
189
-
190
- allow(@client).to receive(:credentials).and_return(secret)
191
- stub_post('/1.1/statuses/update_with_media.json').to_return(:body => fixture('status.json'), :headers => headers)
192
- @client.update_with_media('Just a test', fixture('pbjt.gif'))
193
- expect(a_post('/1.1/statuses/update_with_media.json').with(:headers => {:authorization => headers[:authorization]})).to have_been_made
194
- end
195
- end
196
-
197
- describe '#bearer_auth_header' do
198
- it 'creates the correct auth headers with supplied bearer_token' do
199
- client = Twitter::REST::Client.new(:bearer_token => 'BT')
200
- authorization = client.send(:bearer_auth_header)
201
- expect(authorization).to eq('Bearer BT')
202
- end
203
- it 'creates the correct auth headers with supplied bearer token' do
204
- token = Twitter::Token.new(:token_type => 'bearer', :access_token => 'BT')
205
- client = Twitter::REST::Client.new(:bearer_token => token)
206
- authorization = client.send(:bearer_auth_header)
207
- expect(authorization).to eq('Bearer BT')
208
- end
209
- end
210
-
211
- describe '#bearer_token_credentials_auth_header' do
212
- it 'creates the correct auth header with supplied consumer_key and consumer_secret' do
213
- authorization = @client.send(:bearer_token_credentials_auth_header)
214
- expect(authorization).to eq('Basic Q0s6Q1M=')
215
- end
216
- end
217
- end
@@ -1,133 +0,0 @@
1
- require 'helper'
2
-
3
- describe Twitter::REST::DirectMessages do
4
-
5
- before do
6
- @client = Twitter::REST::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :access_token => 'AT', :access_token_secret => 'AS')
7
- end
8
-
9
- describe '#direct_messages_received' do
10
- before do
11
- stub_get('/1.1/direct_messages.json').to_return(:body => fixture('direct_messages.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
12
- end
13
- it 'requests the correct resource' do
14
- @client.direct_messages_received
15
- expect(a_get('/1.1/direct_messages.json')).to have_been_made
16
- end
17
- it 'returns the 20 most recent direct messages sent to the authenticating user' do
18
- direct_messages = @client.direct_messages_received
19
- expect(direct_messages).to be_an Array
20
- expect(direct_messages.first).to be_a Twitter::DirectMessage
21
- expect(direct_messages.first.sender.id).to eq(7_505_382)
22
- end
23
- end
24
-
25
- describe '#direct_messages_sent' do
26
- before do
27
- stub_get('/1.1/direct_messages/sent.json').to_return(:body => fixture('direct_messages.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
28
- end
29
- it 'requests the correct resource' do
30
- @client.direct_messages_sent
31
- expect(a_get('/1.1/direct_messages/sent.json')).to have_been_made
32
- end
33
- it 'returns the 20 most recent direct messages sent by the authenticating user' do
34
- direct_messages = @client.direct_messages_sent
35
- expect(direct_messages).to be_an Array
36
- expect(direct_messages.first).to be_a Twitter::DirectMessage
37
- expect(direct_messages.first.sender.id).to eq(7_505_382)
38
- end
39
- end
40
-
41
- describe '#direct_message' do
42
- before do
43
- stub_get('/1.1/direct_messages/show.json').with(:query => {:id => '1825786345'}).to_return(:body => fixture('direct_message.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
44
- end
45
- it 'requests the correct resource' do
46
- @client.direct_message(1_825_786_345)
47
- expect(a_get('/1.1/direct_messages/show.json').with(:query => {:id => '1825786345'})).to have_been_made
48
- end
49
- it 'returns the specified direct message' do
50
- direct_message = @client.direct_message(1_825_786_345)
51
- expect(direct_message).to be_a Twitter::DirectMessage
52
- expect(direct_message.sender.id).to eq(14_471_007)
53
- end
54
- end
55
-
56
- describe '#direct_messages' do
57
- context 'with ids passed' do
58
- before do
59
- stub_get('/1.1/direct_messages/show.json').with(:query => {:id => '1825786345'}).to_return(:body => fixture('direct_message.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
60
- end
61
- it 'requests the correct resource' do
62
- @client.direct_messages(1_825_786_345)
63
- expect(a_get('/1.1/direct_messages/show.json').with(:query => {:id => '1825786345'})).to have_been_made
64
- end
65
- it 'returns an array of direct messages' do
66
- direct_messages = @client.direct_messages(1_825_786_345)
67
- expect(direct_messages).to be_an Array
68
- expect(direct_messages.first).to be_a Twitter::DirectMessage
69
- expect(direct_messages.first.sender.id).to eq(14_471_007)
70
- end
71
- end
72
- context 'without ids passed' do
73
- before do
74
- stub_get('/1.1/direct_messages.json').to_return(:body => fixture('direct_messages.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
75
- end
76
- it 'requests the correct resource' do
77
- @client.direct_messages
78
- expect(a_get('/1.1/direct_messages.json')).to have_been_made
79
- end
80
- it 'returns the 20 most recent direct messages sent to the authenticating user' do
81
- direct_messages = @client.direct_messages
82
- expect(direct_messages).to be_an Array
83
- expect(direct_messages.first).to be_a Twitter::DirectMessage
84
- expect(direct_messages.first.sender.id).to eq(7_505_382)
85
- end
86
- end
87
- end
88
-
89
- describe '#destroy_direct_message' do
90
- before do
91
- stub_post('/1.1/direct_messages/destroy.json').with(:body => {:id => '1825785544'}).to_return(:body => fixture('direct_message.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
92
- end
93
- it 'requests the correct resource' do
94
- @client.destroy_direct_message(1_825_785_544)
95
- expect(a_post('/1.1/direct_messages/destroy.json').with(:body => {:id => '1825785544'})).to have_been_made
96
- end
97
- it 'returns an array of deleted messages' do
98
- direct_messages = @client.destroy_direct_message(1_825_785_544)
99
- expect(direct_messages).to be_an Array
100
- expect(direct_messages.first).to be_a Twitter::DirectMessage
101
- expect(direct_messages.first.sender.id).to eq(14_471_007)
102
- end
103
- end
104
-
105
- describe '#create_direct_message' do
106
- before do
107
- stub_post('/1.1/direct_messages/new.json').with(:body => {:screen_name => 'pengwynn', :text => "My #newride from @PUBLICBikes. Don't you want one? https://t.co/7HIwCl68Y8 https://t.co/JSSxDPr4Sf"}).to_return(:body => fixture('direct_message.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
108
- end
109
- it 'requests the correct resource' do
110
- @client.create_direct_message('pengwynn', "My #newride from @PUBLICBikes. Don't you want one? https://t.co/7HIwCl68Y8 https://t.co/JSSxDPr4Sf")
111
- expect(a_post('/1.1/direct_messages/new.json').with(:body => {:screen_name => 'pengwynn', :text => "My #newride from @PUBLICBikes. Don't you want one? https://t.co/7HIwCl68Y8 https://t.co/JSSxDPr4Sf"})).to have_been_made
112
- end
113
- it 'returns the sent message' do
114
- direct_message = @client.create_direct_message('pengwynn', "My #newride from @PUBLICBikes. Don't you want one? https://t.co/7HIwCl68Y8 https://t.co/JSSxDPr4Sf")
115
- expect(direct_message).to be_a Twitter::DirectMessage
116
- expect(direct_message.text).to eq("My #newride from @PUBLICBikes. Don't you want one? https://t.co/7HIwCl68Y8 https://t.co/JSSxDPr4Sf")
117
- end
118
- context 'with a URI object passed' do
119
- it 'requests the correct resource' do
120
- user = URI.parse('https://twitter.com/pengwynn')
121
- @client.create_direct_message(user, "My #newride from @PUBLICBikes. Don't you want one? https://t.co/7HIwCl68Y8 https://t.co/JSSxDPr4Sf")
122
- expect(a_post('/1.1/direct_messages/new.json').with(:body => {:screen_name => 'pengwynn', :text => "My #newride from @PUBLICBikes. Don't you want one? https://t.co/7HIwCl68Y8 https://t.co/JSSxDPr4Sf"})).to have_been_made
123
- end
124
- end
125
- context 'with a URI string passed' do
126
- it 'requests the correct resource' do
127
- @client.create_direct_message('https://twitter.com/pengwynn', "My #newride from @PUBLICBikes. Don't you want one? https://t.co/7HIwCl68Y8 https://t.co/JSSxDPr4Sf")
128
- expect(a_post('/1.1/direct_messages/new.json').with(:body => {:screen_name => 'pengwynn', :text => "My #newride from @PUBLICBikes. Don't you want one? https://t.co/7HIwCl68Y8 https://t.co/JSSxDPr4Sf"})).to have_been_made
129
- end
130
- end
131
- end
132
-
133
- end
@@ -1,188 +0,0 @@
1
- # coding: utf-8
2
- require 'helper'
3
-
4
- describe Twitter::REST::Favorites do
5
-
6
- before do
7
- @client = Twitter::REST::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :access_token => 'AT', :access_token_secret => 'AS')
8
- end
9
-
10
- describe '#favorites' do
11
- context 'with a screen name passed' do
12
- before do
13
- stub_get('/1.1/favorites/list.json').with(:query => {:screen_name => 'sferik'}).to_return(:body => fixture('user_timeline.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
14
- end
15
- it 'requests the correct resource' do
16
- @client.favorites('sferik')
17
- expect(a_get('/1.1/favorites/list.json').with(:query => {:screen_name => 'sferik'})).to have_been_made
18
- end
19
- it 'returns the 20 most recent favorite Tweets for the authenticating user or user specified by the ID parameter' do
20
- favorites = @client.favorites('sferik')
21
- expect(favorites).to be_an Array
22
- expect(favorites.first).to be_a Twitter::Tweet
23
- expect(favorites.first.user.id).to eq(7_505_382)
24
- end
25
- context 'with a URI object passed' do
26
- it 'requests the correct resource' do
27
- user = URI.parse('https://twitter.com/sferik')
28
- @client.favorites(user)
29
- expect(a_get('/1.1/favorites/list.json').with(:query => {:screen_name => 'sferik'})).to have_been_made
30
- end
31
- end
32
- context 'with a URI string passed' do
33
- it 'requests the correct resource' do
34
- @client.favorites('https://twitter.com/sferik')
35
- expect(a_get('/1.1/favorites/list.json').with(:query => {:screen_name => 'sferik'})).to have_been_made
36
- end
37
- end
38
- end
39
- context 'without arguments passed' do
40
- before do
41
- stub_get('/1.1/favorites/list.json').to_return(:body => fixture('user_timeline.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
42
- end
43
- it 'requests the correct resource' do
44
- @client.favorites
45
- expect(a_get('/1.1/favorites/list.json')).to have_been_made
46
- end
47
- it 'returns the 20 most recent favorite Tweets for the authenticating user or user specified by the ID parameter' do
48
- favorites = @client.favorites
49
- expect(favorites).to be_an Array
50
- expect(favorites.first).to be_a Twitter::Tweet
51
- expect(favorites.first.user.id).to eq(7_505_382)
52
- end
53
- end
54
- end
55
-
56
- describe '#unfavorite' do
57
- before do
58
- stub_post('/1.1/favorites/destroy.json').with(:body => {:id => '25938088801'}).to_return(:body => fixture('status.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
59
- end
60
- it 'requests the correct resource' do
61
- @client.unfavorite(25_938_088_801)
62
- expect(a_post('/1.1/favorites/destroy.json').with(:body => {:id => '25938088801'})).to have_been_made
63
- end
64
- it 'returns an array of un-favorited Tweets' do
65
- tweets = @client.unfavorite(25_938_088_801)
66
- expect(tweets).to be_an Array
67
- expect(tweets.first).to be_a Twitter::Tweet
68
- expect(tweets.first.text).to eq("\"I hope you'll keep...building bonds of friendship that will enrich your lives & enrich our world\" —FLOTUS in China, http://t.co/fxmuQN9JL9")
69
- end
70
- context 'with a URI object passed' do
71
- it 'requests the correct resource' do
72
- tweet = URI.parse('https://twitter.com/sferik/status/25938088801')
73
- @client.unfavorite(tweet)
74
- expect(a_post('/1.1/favorites/destroy.json').with(:body => {:id => '25938088801'})).to have_been_made
75
- end
76
- end
77
- context 'with a URI string passed' do
78
- it 'requests the correct resource' do
79
- @client.unfavorite('https://twitter.com/sferik/status/25938088801')
80
- expect(a_post('/1.1/favorites/destroy.json').with(:body => {:id => '25938088801'})).to have_been_made
81
- end
82
- end
83
- context 'with a Tweet passed' do
84
- it 'requests the correct resource' do
85
- tweet = Twitter::Tweet.new(:id => 25_938_088_801)
86
- @client.unfavorite(tweet)
87
- expect(a_post('/1.1/favorites/destroy.json').with(:body => {:id => '25938088801'})).to have_been_made
88
- end
89
- end
90
- end
91
-
92
- describe '#favorite' do
93
- before do
94
- stub_post('/1.1/favorites/create.json').with(:body => {:id => '25938088801'}).to_return(:body => fixture('status.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
95
- end
96
- it 'requests the correct resource' do
97
- @client.favorite(25_938_088_801)
98
- expect(a_post('/1.1/favorites/create.json').with(:body => {:id => '25938088801'})).to have_been_made
99
- end
100
- it 'returns an array of favorited Tweets' do
101
- tweets = @client.favorite(25_938_088_801)
102
- expect(tweets).to be_an Array
103
- expect(tweets.first).to be_a Twitter::Tweet
104
- expect(tweets.first.text).to eq("\"I hope you'll keep...building bonds of friendship that will enrich your lives & enrich our world\" —FLOTUS in China, http://t.co/fxmuQN9JL9")
105
- end
106
- context 'already favorited' do
107
- before do
108
- stub_post('/1.1/favorites/create.json').with(:body => {:id => '25938088801'}).to_return(:status => 403, :body => fixture('already_favorited.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
109
- end
110
- it 'does not raises an error' do
111
- expect { @client.favorite(25_938_088_801) }.not_to raise_error
112
- end
113
- end
114
- context 'with a URI object passed' do
115
- it 'requests the correct resource' do
116
- tweet = URI.parse('https://twitter.com/sferik/status/25938088801')
117
- @client.favorite(tweet)
118
- expect(a_post('/1.1/favorites/create.json').with(:body => {:id => '25938088801'})).to have_been_made
119
- end
120
- end
121
- context 'with a URI string passed' do
122
- it 'requests the correct resource' do
123
- @client.favorite('https://twitter.com/sferik/status/25938088801')
124
- expect(a_post('/1.1/favorites/create.json').with(:body => {:id => '25938088801'})).to have_been_made
125
- end
126
- end
127
- context 'with a Tweet passed' do
128
- it 'requests the correct resource' do
129
- tweet = Twitter::Tweet.new(:id => 25_938_088_801)
130
- @client.favorite(tweet)
131
- expect(a_post('/1.1/favorites/create.json').with(:body => {:id => '25938088801'})).to have_been_made
132
- end
133
- end
134
- end
135
-
136
- describe '#favorite!' do
137
- before do
138
- stub_post('/1.1/favorites/create.json').with(:body => {:id => '25938088801'}).to_return(:body => fixture('status.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
139
- end
140
- it 'requests the correct resource' do
141
- @client.favorite!(25_938_088_801)
142
- expect(a_post('/1.1/favorites/create.json').with(:body => {:id => '25938088801'})).to have_been_made
143
- end
144
- it 'returns an array of favorited Tweets' do
145
- tweets = @client.favorite!(25_938_088_801)
146
- expect(tweets).to be_an Array
147
- expect(tweets.first).to be_a Twitter::Tweet
148
- expect(tweets.first.text).to eq("\"I hope you'll keep...building bonds of friendship that will enrich your lives & enrich our world\" —FLOTUS in China, http://t.co/fxmuQN9JL9")
149
- end
150
- context 'forbidden' do
151
- before do
152
- stub_post('/1.1/favorites/create.json').with(:body => {:id => '25938088801'}).to_return(:status => 403, :headers => {:content_type => 'application/json; charset=utf-8'})
153
- end
154
- it 'raises a Forbidden error' do
155
- expect { @client.favorite!(25_938_088_801) }.to raise_error(Twitter::Error::Forbidden)
156
- end
157
- end
158
- context 'already favorited' do
159
- before do
160
- stub_post('/1.1/favorites/create.json').with(:body => {:id => '25938088801'}).to_return(:status => 403, :body => fixture('already_favorited.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
161
- end
162
- it 'raises an AlreadyFavorited error' do
163
- expect { @client.favorite!(25_938_088_801) }.to raise_error(Twitter::Error::AlreadyFavorited)
164
- end
165
- end
166
- context 'with a URI object passed' do
167
- it 'requests the correct resource' do
168
- tweet = URI.parse('https://twitter.com/sferik/status/25938088801')
169
- @client.favorite!(tweet)
170
- expect(a_post('/1.1/favorites/create.json').with(:body => {:id => '25938088801'})).to have_been_made
171
- end
172
- end
173
- context 'with a URI string passed' do
174
- it 'requests the correct resource' do
175
- @client.favorite!('https://twitter.com/sferik/status/25938088801')
176
- expect(a_post('/1.1/favorites/create.json').with(:body => {:id => '25938088801'})).to have_been_made
177
- end
178
- end
179
- context 'with a Tweet passed' do
180
- it 'requests the correct resource' do
181
- tweet = Twitter::Tweet.new(:id => 25_938_088_801)
182
- @client.favorite!(tweet)
183
- expect(a_post('/1.1/favorites/create.json').with(:body => {:id => '25938088801'})).to have_been_made
184
- end
185
- end
186
- end
187
-
188
- end