twitter 4.8.1 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. data/CHANGELOG.md +36 -0
  2. data/CONTRIBUTING.md +13 -15
  3. data/LICENSE.md +1 -1
  4. data/README.md +401 -261
  5. data/Rakefile +6 -0
  6. data/lib/twitter/arguments.rb +14 -0
  7. data/lib/twitter/base.rb +109 -89
  8. data/lib/twitter/client.rb +38 -115
  9. data/lib/twitter/configuration.rb +5 -2
  10. data/lib/twitter/core_ext/kernel.rb +5 -1
  11. data/lib/twitter/creatable.rb +7 -4
  12. data/lib/twitter/cursor.rb +57 -45
  13. data/lib/twitter/direct_message.rb +2 -11
  14. data/lib/twitter/entity/uri.rb +14 -0
  15. data/lib/twitter/enumerable.rb +15 -0
  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/error.rb +65 -14
  31. data/lib/twitter/factory.rb +13 -12
  32. data/lib/twitter/geo.rb +2 -7
  33. data/lib/twitter/geo_factory.rb +11 -7
  34. data/lib/twitter/geo_results.rb +40 -0
  35. data/lib/twitter/identity.rb +4 -34
  36. data/lib/twitter/list.rb +21 -4
  37. data/lib/twitter/media/photo.rb +6 -4
  38. data/lib/twitter/media_factory.rb +11 -7
  39. data/lib/twitter/null_object.rb +25 -0
  40. data/lib/twitter/oembed.rb +3 -2
  41. data/lib/twitter/place.rb +15 -15
  42. data/lib/twitter/profile_banner.rb +3 -2
  43. data/lib/twitter/rate_limit.rb +4 -17
  44. data/lib/twitter/relationship.rb +2 -19
  45. data/lib/twitter/rest/api/direct_messages.rb +138 -0
  46. data/lib/twitter/rest/api/favorites.rb +115 -0
  47. data/lib/twitter/rest/api/friends_and_followers.rb +287 -0
  48. data/lib/twitter/rest/api/help.rb +58 -0
  49. data/lib/twitter/rest/api/lists.rb +498 -0
  50. data/lib/twitter/rest/api/oauth.rb +62 -0
  51. data/lib/twitter/rest/api/places_and_geo.rb +86 -0
  52. data/lib/twitter/rest/api/saved_searches.rb +93 -0
  53. data/lib/twitter/rest/api/search.rb +37 -0
  54. data/lib/twitter/rest/api/spam_reporting.rb +29 -0
  55. data/lib/twitter/rest/api/suggested_users.rb +51 -0
  56. data/lib/twitter/rest/api/timelines.rb +202 -0
  57. data/lib/twitter/rest/api/trends.rb +58 -0
  58. data/lib/twitter/rest/api/tweets.rb +291 -0
  59. data/lib/twitter/rest/api/undocumented.rb +52 -0
  60. data/lib/twitter/rest/api/users.rb +383 -0
  61. data/lib/twitter/rest/api/utils.rb +246 -0
  62. data/lib/twitter/rest/client.rb +175 -0
  63. data/lib/twitter/rest/request/multipart_with_file.rb +36 -0
  64. data/lib/twitter/rest/response/parse_error_json.rb +15 -0
  65. data/lib/twitter/rest/response/parse_json.rb +31 -0
  66. data/lib/twitter/{response → rest/response}/raise_error.rb +8 -11
  67. data/lib/twitter/search_results.rb +37 -21
  68. data/lib/twitter/settings.rb +1 -6
  69. data/lib/twitter/size.rb +2 -15
  70. data/lib/twitter/streaming/client.rb +89 -0
  71. data/lib/twitter/streaming/connection.rb +22 -0
  72. data/lib/twitter/streaming/event.rb +35 -0
  73. data/lib/twitter/streaming/friend_list.rb +13 -0
  74. data/lib/twitter/streaming/message_parser.rb +18 -0
  75. data/lib/twitter/streaming/response.rb +34 -0
  76. data/lib/twitter/suggestion.rb +5 -8
  77. data/lib/twitter/token.rb +11 -1
  78. data/lib/twitter/trend.rb +4 -8
  79. data/lib/twitter/trend_results.rb +65 -0
  80. data/lib/twitter/tweet.rb +43 -92
  81. data/lib/twitter/user.rb +72 -47
  82. data/lib/twitter/version.rb +4 -4
  83. data/lib/twitter.rb +4 -39
  84. data/spec/fixtures/already_posted.json +1 -0
  85. data/spec/fixtures/ids_list.json +1 -1
  86. data/spec/fixtures/ids_list2.json +1 -1
  87. data/spec/fixtures/request_token.txt +6 -0
  88. data/spec/fixtures/search.json +1 -1
  89. data/spec/fixtures/search_malformed.json +1 -1
  90. data/spec/fixtures/track_streaming.json +3 -0
  91. data/spec/fixtures/track_streaming_user.json +5 -0
  92. data/spec/helper.rb +8 -13
  93. data/spec/twitter/base_spec.rb +13 -103
  94. data/spec/twitter/basic_user_spec.rb +3 -3
  95. data/spec/twitter/configuration_spec.rb +1 -1
  96. data/spec/twitter/cursor_spec.rb +17 -35
  97. data/spec/twitter/direct_message_spec.rb +44 -11
  98. data/spec/twitter/entity/uri_spec.rb +75 -0
  99. data/spec/twitter/error_spec.rb +59 -11
  100. data/spec/twitter/geo/point_spec.rb +6 -6
  101. data/spec/twitter/geo/polygon_spec.rb +5 -5
  102. data/spec/twitter/geo_factory_spec.rb +4 -4
  103. data/spec/twitter/geo_results_spec.rb +35 -0
  104. data/spec/twitter/geo_spec.rb +6 -6
  105. data/spec/twitter/identifiable_spec.rb +5 -26
  106. data/spec/twitter/list_spec.rb +54 -11
  107. data/spec/twitter/media/photo_spec.rb +122 -6
  108. data/spec/twitter/media_factory_spec.rb +3 -3
  109. data/spec/twitter/null_object_spec.rb +27 -0
  110. data/spec/twitter/oembed_spec.rb +69 -45
  111. data/spec/twitter/place_spec.rb +84 -28
  112. data/spec/twitter/profile_banner_spec.rb +1 -1
  113. data/spec/twitter/rate_limit_spec.rb +8 -25
  114. data/spec/twitter/relationship_spec.rb +26 -12
  115. data/spec/twitter/{api → rest/api}/direct_messages_spec.rb +28 -15
  116. data/spec/twitter/{api → rest/api}/favorites_spec.rb +80 -7
  117. data/spec/twitter/{api → rest/api}/friends_and_followers_spec.rb +121 -152
  118. data/spec/twitter/{api → rest/api}/geo_spec.rb +9 -23
  119. data/spec/twitter/{api → rest/api}/help_spec.rb +6 -6
  120. data/spec/twitter/{api → rest/api}/lists_spec.rb +116 -95
  121. data/spec/twitter/{api → rest/api}/oauth_spec.rb +21 -10
  122. data/spec/twitter/{api → rest/api}/saved_searches_spec.rb +13 -13
  123. data/spec/twitter/{api → rest/api}/search_spec.rb +8 -9
  124. data/spec/twitter/{api → rest/api}/spam_reporting_spec.rb +3 -3
  125. data/spec/twitter/{api → rest/api}/suggested_users_spec.rb +5 -5
  126. data/spec/twitter/{api → rest/api}/timelines_spec.rb +9 -9
  127. data/spec/twitter/{api → rest/api}/trends_spec.rb +6 -6
  128. data/spec/twitter/rest/api/tweets_spec.rb +503 -0
  129. data/spec/twitter/{api → rest/api}/undocumented_spec.rb +19 -45
  130. data/spec/twitter/{api → rest/api}/users_spec.rb +64 -39
  131. data/spec/twitter/rest/client_spec.rb +193 -0
  132. data/spec/twitter/saved_search_spec.rb +14 -3
  133. data/spec/twitter/search_results_spec.rb +32 -45
  134. data/spec/twitter/settings_spec.rb +17 -6
  135. data/spec/twitter/size_spec.rb +5 -15
  136. data/spec/twitter/source_user_spec.rb +3 -3
  137. data/spec/twitter/streaming/client_spec.rb +92 -0
  138. data/spec/twitter/streaming/event_spec.rb +45 -0
  139. data/spec/twitter/suggestion_spec.rb +5 -15
  140. data/spec/twitter/target_user_spec.rb +3 -3
  141. data/spec/twitter/token_spec.rb +16 -0
  142. data/spec/twitter/trend_results_spec.rb +89 -0
  143. data/spec/twitter/trend_spec.rb +26 -13
  144. data/spec/twitter/tweet_spec.rb +137 -124
  145. data/spec/twitter/user_spec.rb +139 -80
  146. data/spec/twitter_spec.rb +0 -119
  147. data/twitter.gemspec +12 -6
  148. data.tar.gz.sig +0 -0
  149. metadata +197 -138
  150. metadata.gz.sig +0 -0
  151. data/lib/twitter/action/favorite.rb +0 -19
  152. data/lib/twitter/action/follow.rb +0 -30
  153. data/lib/twitter/action/list_member_added.rb +0 -39
  154. data/lib/twitter/action/mention.rb +0 -46
  155. data/lib/twitter/action/reply.rb +0 -27
  156. data/lib/twitter/action/retweet.rb +0 -27
  157. data/lib/twitter/action/tweet.rb +0 -20
  158. data/lib/twitter/action_factory.rb +0 -22
  159. data/lib/twitter/api/arguments.rb +0 -13
  160. data/lib/twitter/api/direct_messages.rb +0 -148
  161. data/lib/twitter/api/favorites.rb +0 -126
  162. data/lib/twitter/api/friends_and_followers.rb +0 -334
  163. data/lib/twitter/api/help.rb +0 -64
  164. data/lib/twitter/api/lists.rb +0 -618
  165. data/lib/twitter/api/oauth.rb +0 -44
  166. data/lib/twitter/api/places_and_geo.rb +0 -121
  167. data/lib/twitter/api/saved_searches.rb +0 -99
  168. data/lib/twitter/api/search.rb +0 -37
  169. data/lib/twitter/api/spam_reporting.rb +0 -30
  170. data/lib/twitter/api/suggested_users.rb +0 -55
  171. data/lib/twitter/api/timelines.rb +0 -214
  172. data/lib/twitter/api/trends.rb +0 -63
  173. data/lib/twitter/api/tweets.rb +0 -304
  174. data/lib/twitter/api/undocumented.rb +0 -97
  175. data/lib/twitter/api/users.rb +0 -439
  176. data/lib/twitter/api/utils.rb +0 -187
  177. data/lib/twitter/configurable.rb +0 -96
  178. data/lib/twitter/default.rb +0 -102
  179. data/lib/twitter/entity/url.rb +0 -9
  180. data/lib/twitter/error/client_error.rb +0 -35
  181. data/lib/twitter/error/decode_error.rb +0 -9
  182. data/lib/twitter/error/identity_map_key_error.rb +0 -9
  183. data/lib/twitter/error/server_error.rb +0 -28
  184. data/lib/twitter/exceptable.rb +0 -36
  185. data/lib/twitter/identity_map.rb +0 -22
  186. data/lib/twitter/request/multipart_with_file.rb +0 -34
  187. data/lib/twitter/response/parse_json.rb +0 -25
  188. data/spec/fixtures/about_me.json +0 -1
  189. data/spec/fixtures/activity_summary.json +0 -1
  190. data/spec/fixtures/bad_gateway.json +0 -1
  191. data/spec/fixtures/bad_request.json +0 -1
  192. data/spec/fixtures/by_friends.json +0 -1
  193. data/spec/fixtures/end_session.json +0 -1
  194. data/spec/fixtures/forbidden.json +0 -1
  195. data/spec/fixtures/internal_server_error.json +0 -1
  196. data/spec/fixtures/not_acceptable.json +0 -1
  197. data/spec/fixtures/phoenix_search.phoenix +0 -1
  198. data/spec/fixtures/resolve.json +0 -1
  199. data/spec/fixtures/service_unavailable.json +0 -1
  200. data/spec/fixtures/totals.json +0 -1
  201. data/spec/fixtures/trends.json +0 -1
  202. data/spec/fixtures/unauthorized.json +0 -1
  203. data/spec/fixtures/video_facets.json +0 -1
  204. data/spec/twitter/action/favorite_spec.rb +0 -29
  205. data/spec/twitter/action/follow_spec.rb +0 -29
  206. data/spec/twitter/action/list_member_added_spec.rb +0 -41
  207. data/spec/twitter/action/mention_spec.rb +0 -52
  208. data/spec/twitter/action/reply_spec.rb +0 -41
  209. data/spec/twitter/action/retweet_spec.rb +0 -41
  210. data/spec/twitter/action_factory_spec.rb +0 -35
  211. data/spec/twitter/action_spec.rb +0 -16
  212. data/spec/twitter/api/tweets_spec.rb +0 -285
  213. data/spec/twitter/client_spec.rb +0 -223
  214. data/spec/twitter/error/client_error_spec.rb +0 -23
  215. data/spec/twitter/error/server_error_spec.rb +0 -20
@@ -3,73 +3,129 @@ require 'helper'
3
3
  describe Twitter::Place do
4
4
 
5
5
  describe "#==" do
6
- it "returns true when objects IDs are the same" do
7
- place = Twitter::Place.new(:id => 1, :name => "foo")
8
- other = Twitter::Place.new(:id => 1, :name => "bar")
9
- expect(place == other).to be_true
6
+ it "returns true when objects WOE IDs are the same" do
7
+ place = Twitter::Place.new(:woeid => 1, :name => "foo")
8
+ other = Twitter::Place.new(:woeid => 1, :name => "bar")
9
+ expect(place == other).to be true
10
10
  end
11
- it "returns false when objects IDs are different" do
12
- place = Twitter::Place.new(:id => 1)
13
- other = Twitter::Place.new(:id => 2)
14
- expect(place == other).to be_false
11
+ it "returns false when objects WOE IDs are different" do
12
+ place = Twitter::Place.new(:woeid => 1)
13
+ other = Twitter::Place.new(:woeid => 2)
14
+ expect(place == other).to be false
15
15
  end
16
16
  it "returns false when classes are different" do
17
- place = Twitter::Place.new(:id => 1)
18
- other = Twitter::Identity.new(:id => 1)
19
- expect(place == other).to be_false
17
+ place = Twitter::Place.new(:woeid => 1)
18
+ other = Twitter::Base.new(:woeid => 1)
19
+ expect(place == other).to be false
20
20
  end
21
21
  end
22
22
 
23
23
  describe "#bounding_box" do
24
- it "returns a Twitter::Place when set" do
25
- place = Twitter::Place.new(:id => "247f43d441defc03", :bounding_box => {:type => 'Polygon', :coordinates => [[[-122.40348192, 37.77752898], [-122.387436, 37.77752898], [-122.387436, 37.79448597], [-122.40348192, 37.79448597]]]})
24
+ it "returns a Twitter::Geo when bounding_box is set" do
25
+ place = Twitter::Place.new(:woeid => "247f43d441defc03", :bounding_box => {:type => "Polygon", :coordinates => [[[-122.40348192, 37.77752898], [-122.387436, 37.77752898], [-122.387436, 37.79448597], [-122.40348192, 37.79448597]]]})
26
26
  expect(place.bounding_box).to be_a Twitter::Geo::Polygon
27
27
  end
28
- it "returns nil when not set" do
29
- place = Twitter::Place.new(:id => "247f43d441defc03")
28
+ it "returns nil when not bounding_box is not set" do
29
+ place = Twitter::Place.new(:woeid => "247f43d441defc03")
30
30
  expect(place.bounding_box).to be_nil
31
31
  end
32
32
  end
33
33
 
34
+ describe "#bounding_box?" do
35
+ it "returns true when bounding_box is set" do
36
+ place = Twitter::Place.new(:woeid => "247f43d441defc03", :bounding_box => {:type => "Polygon", :coordinates => [[[-122.40348192, 37.77752898], [-122.387436, 37.77752898], [-122.387436, 37.79448597], [-122.40348192, 37.79448597]]]})
37
+ expect(place.bounding_box?).to be true
38
+ end
39
+ it "returns false when bounding_box is not set" do
40
+ place = Twitter::Place.new(:woeid => "247f43d441defc03")
41
+ expect(place.bounding_box?).to be false
42
+ end
43
+ end
44
+
45
+ describe "#contained_within" do
46
+ it "returns a Twitter::Place when contained_within is set" do
47
+ place = Twitter::Place.new(:woeid => "247f43d441defc03", :contained_within => {:woeid => "247f43d441defc04"})
48
+ expect(place.contained_within).to be_a Twitter::Place
49
+ end
50
+ it "returns nil when not contained_within is not set" do
51
+ place = Twitter::Place.new(:woeid => "247f43d441defc03")
52
+ expect(place.contained_within).to be_nil
53
+ end
54
+ end
55
+
56
+ describe "#contained_within?" do
57
+ it "returns true when contained_within is set" do
58
+ place = Twitter::Place.new(:woeid => "247f43d441defc03", :contained_within => {:woeid => "247f43d441defc04"})
59
+ expect(place.contained?).to be true
60
+ end
61
+ it "returns false when contained_within is not set" do
62
+ place = Twitter::Place.new(:woeid => "247f43d441defc03")
63
+ expect(place.contained?).to be false
64
+ end
65
+ end
66
+
34
67
  describe "#country_code" do
35
68
  it "returns a country code when set with country_code" do
36
- place = Twitter::Place.new(:id => "247f43d441defc03", :country_code => 'US')
37
- expect(place.country_code).to eq 'US'
69
+ place = Twitter::Place.new(:woeid => "247f43d441defc03", :country_code => "US")
70
+ expect(place.country_code).to eq("US")
38
71
  end
39
72
  it "returns a country code when set with countryCode" do
40
- place = Twitter::Place.new(:id => "247f43d441defc03", :countryCode => 'US')
41
- expect(place.country_code).to eq 'US'
73
+ place = Twitter::Place.new(:woeid => "247f43d441defc03", :countryCode => "US")
74
+ expect(place.country_code).to eq("US")
42
75
  end
43
76
  it "returns nil when not set" do
44
- place = Twitter::Place.new(:id => "247f43d441defc03")
77
+ place = Twitter::Place.new(:woeid => "247f43d441defc03")
45
78
  expect(place.country_code).to be_nil
46
79
  end
47
80
  end
48
81
 
49
82
  describe "#parent_id" do
50
83
  it "returns a parent ID when set with parentid" do
51
- place = Twitter::Place.new(:id => "247f43d441defc03", :parentid => 1)
52
- expect(place.parent_id).to eq 1
84
+ place = Twitter::Place.new(:woeid => "247f43d441defc03", :parentid => 1)
85
+ expect(place.parent_id).to eq(1)
53
86
  end
54
87
  it "returns nil when not set" do
55
- place = Twitter::Place.new(:id => "247f43d441defc03")
88
+ place = Twitter::Place.new(:woeid => "247f43d441defc03")
56
89
  expect(place.parent_id).to be_nil
57
90
  end
58
91
  end
59
92
 
60
93
  describe "#place_type" do
61
94
  it "returns a place type when set with place_type" do
62
- place = Twitter::Place.new(:id => "247f43d441defc03", :place_type => 'city')
63
- expect(place.place_type).to eq 'city'
95
+ place = Twitter::Place.new(:woeid => "247f43d441defc03", :place_type => "city")
96
+ expect(place.place_type).to eq("city")
64
97
  end
65
98
  it "returns a place type when set with placeType[name]" do
66
- place = Twitter::Place.new(:id => "247f43d441defc03", :placeType => {:name => 'Town'})
67
- expect(place.place_type).to eq 'Town'
99
+ place = Twitter::Place.new(:woeid => "247f43d441defc03", :placeType => {:name => "Town"})
100
+ expect(place.place_type).to eq("Town")
68
101
  end
69
102
  it "returns nil when not set" do
70
- place = Twitter::Place.new(:id => "247f43d441defc03")
103
+ place = Twitter::Place.new(:woeid => "247f43d441defc03")
71
104
  expect(place.place_type).to be_nil
72
105
  end
73
106
  end
74
107
 
108
+ describe "#uri" do
109
+ it "returns a URI when the url is set" do
110
+ place = Twitter::Place.new(:woeid => "247f43d441defc03", :url => "https://api.twitter.com/1.1/geo/id/247f43d441defc03.json")
111
+ expect(place.uri).to be_a URI
112
+ expect(place.uri.to_s).to eq("https://api.twitter.com/1.1/geo/id/247f43d441defc03.json")
113
+ end
114
+ it "returns nil when the url is not set" do
115
+ place = Twitter::Place.new(:woeid => "247f43d441defc03")
116
+ expect(place.uri).to be_nil
117
+ end
118
+ end
119
+
120
+ describe "#uri?" do
121
+ it "returns true when the url is set" do
122
+ place = Twitter::Place.new(:woeid => "247f43d441defc03", :url => "https://api.twitter.com/1.1/geo/id/247f43d441defc03.json")
123
+ expect(place.uri?).to be true
124
+ end
125
+ it "returns false when the url is not set" do
126
+ place = Twitter::Place.new(:woeid => "247f43d441defc03")
127
+ expect(place.uri?).to be false
128
+ end
129
+ end
130
+
75
131
  end
@@ -4,7 +4,7 @@ describe Twitter::ProfileBanner do
4
4
 
5
5
  describe "#sizes" do
6
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
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
8
  expect(sizes).to be_a Hash
9
9
  expect(sizes[:small]).to be_a Twitter::Size
10
10
  end
@@ -4,9 +4,9 @@ describe Twitter::RateLimit do
4
4
 
5
5
  describe "#limit" do
6
6
  it "returns an Integer when x-rate-limit-limit header is set" do
7
- rate_limit = Twitter::RateLimit.new('x-rate-limit-limit' => "150")
7
+ rate_limit = Twitter::RateLimit.new("x-rate-limit-limit" => "150")
8
8
  expect(rate_limit.limit).to be_an Integer
9
- expect(rate_limit.limit).to eq 150
9
+ expect(rate_limit.limit).to eq(150)
10
10
  end
11
11
  it "returns nil when x-rate-limit-limit header is not set" do
12
12
  rate_limit = Twitter::RateLimit.new
@@ -16,9 +16,9 @@ describe Twitter::RateLimit do
16
16
 
17
17
  describe "#remaining" do
18
18
  it "returns an Integer when x-rate-limit-remaining header is set" do
19
- rate_limit = Twitter::RateLimit.new('x-rate-limit-remaining' => "149")
19
+ rate_limit = Twitter::RateLimit.new("x-rate-limit-remaining" => "149")
20
20
  expect(rate_limit.remaining).to be_an Integer
21
- expect(rate_limit.remaining).to eq 149
21
+ expect(rate_limit.remaining).to eq(149)
22
22
  end
23
23
  it "returns nil when x-rate-limit-remaining header is not set" do
24
24
  rate_limit = Twitter::RateLimit.new
@@ -28,9 +28,9 @@ describe Twitter::RateLimit do
28
28
 
29
29
  describe "#reset_at" do
30
30
  it "returns a Time when x-rate-limit-reset header is set" do
31
- rate_limit = Twitter::RateLimit.new('x-rate-limit-reset' => "1339019097")
31
+ rate_limit = Twitter::RateLimit.new("x-rate-limit-reset" => "1339019097")
32
32
  expect(rate_limit.reset_at).to be_a Time
33
- expect(rate_limit.reset_at).to eq Time.at(1339019097)
33
+ expect(rate_limit.reset_at).to eq(Time.at(1339019097))
34
34
  end
35
35
  it "returns nil when x-rate-limit-reset header is not set" do
36
36
  rate_limit = Twitter::RateLimit.new
@@ -46,9 +46,9 @@ describe Twitter::RateLimit do
46
46
  Timecop.return
47
47
  end
48
48
  it "returns an Integer when x-rate-limit-reset header is set" do
49
- rate_limit = Twitter::RateLimit.new('x-rate-limit-reset' => "1339019097")
49
+ rate_limit = Twitter::RateLimit.new("x-rate-limit-reset" => "1339019097")
50
50
  expect(rate_limit.reset_in).to be_an Integer
51
- expect(rate_limit.reset_in).to eq 15777
51
+ expect(rate_limit.reset_in).to eq(15777)
52
52
  end
53
53
  it "returns nil when x-rate-limit-reset header is not set" do
54
54
  rate_limit = Twitter::RateLimit.new
@@ -56,21 +56,4 @@ describe Twitter::RateLimit do
56
56
  end
57
57
  end
58
58
 
59
- describe "#update" do
60
- before do
61
- Timecop.freeze(Time.utc(2012, 6, 6, 17, 22, 0))
62
- end
63
- after do
64
- Timecop.return
65
- end
66
- it "updates a rate limit" do
67
- rate_limit = Twitter::RateLimit.new('x-rate-limit-reset' => "1339019097")
68
- expect(rate_limit.reset_in).to be_an Integer
69
- expect(rate_limit.reset_in).to eq 15777
70
- rate_limit.update({'x-rate-limit-reset' => "1339019098"})
71
- expect(rate_limit.reset_in).to be_an Integer
72
- expect(rate_limit.reset_in).to eq 15778
73
- end
74
- end
75
-
76
59
  end
@@ -4,31 +4,45 @@ describe Twitter::Relationship do
4
4
 
5
5
  describe "#source" do
6
6
  it "returns a User when source is set" do
7
- source = Twitter::Relationship.new(:relationship => {:source => {:id => 7505382}}).source
8
- expect(source).to be_a Twitter::SourceUser
7
+ relationship = Twitter::Relationship.new(:relationship => {:source => {:id => 7505382}})
8
+ expect(relationship.source).to be_a Twitter::SourceUser
9
9
  end
10
10
  it "returns nil when source is not set" do
11
- source = Twitter::Relationship.new(:relationship => {}).source
12
- expect(source).to be_nil
11
+ relationship = Twitter::Relationship.new(:relationship => {})
12
+ expect(relationship.source).to be_nil
13
+ end
14
+ end
15
+
16
+ describe "#source?" do
17
+ it "returns true when source is set" do
18
+ relationship = Twitter::Relationship.new(:relationship => {:source => {:id => 7505382}})
19
+ expect(relationship.source?).to be true
20
+ end
21
+ it "returns false when source is not set" do
22
+ relationship = Twitter::Relationship.new(:relationship => {})
23
+ expect(relationship.source?).to be false
13
24
  end
14
25
  end
15
26
 
16
27
  describe "#target" do
17
28
  it "returns a User when target is set" do
18
- target = Twitter::Relationship.new(:relationship => {:target => {:id => 7505382}}).target
19
- expect(target).to be_a Twitter::TargetUser
29
+ relationship = Twitter::Relationship.new(:relationship => {:target => {:id => 7505382}})
30
+ expect(relationship.target).to be_a Twitter::TargetUser
20
31
  end
21
32
  it "returns nil when target is not set" do
22
- target = Twitter::Relationship.new(:relationship => {}).target
23
- expect(target).to be_nil
33
+ relationship = Twitter::Relationship.new(:relationship => {})
34
+ expect(relationship.target).to be_nil
24
35
  end
25
36
  end
26
37
 
27
- describe "#update" do
28
- it "updates a relationship" do
38
+ describe "#target?" do
39
+ it "returns true when target is set" do
29
40
  relationship = Twitter::Relationship.new(:relationship => {:target => {:id => 7505382}})
30
- relationship.update(:relationship => {:target => {:id => 14100886}})
31
- expect(relationship.target.id).to eq 14100886
41
+ expect(relationship.target?).to be true
42
+ end
43
+ it "returns false when target is not set" do
44
+ relationship = Twitter::Relationship.new(:relationship => {})
45
+ expect(relationship.target?).to be false
32
46
  end
33
47
  end
34
48
 
@@ -1,9 +1,9 @@
1
1
  require 'helper'
2
2
 
3
- describe Twitter::API::DirectMessages do
3
+ describe Twitter::REST::API::DirectMessages do
4
4
 
5
5
  before do
6
- @client = Twitter::Client.new
6
+ @client = Twitter::REST::Client.new(:consumer_key => "CK", :consumer_secret => "CS", :access_token => "AT", :access_token_secret => "AS")
7
7
  end
8
8
 
9
9
  describe "#direct_messages_received" do
@@ -18,7 +18,7 @@ describe Twitter::API::DirectMessages do
18
18
  direct_messages = @client.direct_messages_received
19
19
  expect(direct_messages).to be_an Array
20
20
  expect(direct_messages.first).to be_a Twitter::DirectMessage
21
- expect(direct_messages.first.sender.id).to eq 7505382
21
+ expect(direct_messages.first.sender.id).to eq(7505382)
22
22
  end
23
23
  end
24
24
 
@@ -34,7 +34,7 @@ describe Twitter::API::DirectMessages do
34
34
  direct_messages = @client.direct_messages_sent
35
35
  expect(direct_messages).to be_an Array
36
36
  expect(direct_messages.first).to be_a Twitter::DirectMessage
37
- expect(direct_messages.first.sender.id).to eq 7505382
37
+ expect(direct_messages.first.sender.id).to eq(7505382)
38
38
  end
39
39
  end
40
40
 
@@ -49,7 +49,7 @@ describe Twitter::API::DirectMessages do
49
49
  it "returns the specified direct message" do
50
50
  direct_message = @client.direct_message(1825786345)
51
51
  expect(direct_message).to be_a Twitter::DirectMessage
52
- expect(direct_message.sender.id).to eq 7505382
52
+ expect(direct_message.sender.id).to eq(7505382)
53
53
  end
54
54
  end
55
55
 
@@ -66,7 +66,7 @@ describe Twitter::API::DirectMessages do
66
66
  direct_messages = @client.direct_messages(1825786345)
67
67
  expect(direct_messages).to be_an Array
68
68
  expect(direct_messages.first).to be_a Twitter::DirectMessage
69
- expect(direct_messages.first.sender.id).to eq 7505382
69
+ expect(direct_messages.first.sender.id).to eq(7505382)
70
70
  end
71
71
  end
72
72
  context "without ids passed" do
@@ -81,39 +81,52 @@ describe Twitter::API::DirectMessages do
81
81
  direct_messages = @client.direct_messages
82
82
  expect(direct_messages).to be_an Array
83
83
  expect(direct_messages.first).to be_a Twitter::DirectMessage
84
- expect(direct_messages.first.sender.id).to eq 7505382
84
+ expect(direct_messages.first.sender.id).to eq(7505382)
85
85
  end
86
86
  end
87
87
  end
88
88
 
89
- describe "#direct_message_destroy" do
89
+ describe "#destroy_direct_message" do
90
90
  before do
91
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
92
  end
93
93
  it "requests the correct resource" do
94
- @client.direct_message_destroy(1825785544)
94
+ @client.destroy_direct_message(1825785544)
95
95
  expect(a_post("/1.1/direct_messages/destroy.json").with(:body => {:id => "1825785544"})).to have_been_made
96
96
  end
97
97
  it "returns an array of deleted messages" do
98
- direct_messages = @client.direct_message_destroy(1825785544)
98
+ direct_messages = @client.destroy_direct_message(1825785544)
99
99
  expect(direct_messages).to be_an Array
100
100
  expect(direct_messages.first).to be_a Twitter::DirectMessage
101
- expect(direct_messages.first.sender.id).to eq 7505382
101
+ expect(direct_messages.first.sender.id).to eq(7505382)
102
102
  end
103
103
  end
104
104
 
105
- describe "#direct_message_create" do
105
+ describe "#create_direct_message" do
106
106
  before do
107
107
  stub_post("/1.1/direct_messages/new.json").with(:body => {:screen_name => "pengwynn", :text => "Creating a fixture for the Twitter gem"}).to_return(:body => fixture("direct_message.json"), :headers => {:content_type => "application/json; charset=utf-8"})
108
108
  end
109
109
  it "requests the correct resource" do
110
- @client.direct_message_create("pengwynn", "Creating a fixture for the Twitter gem")
110
+ @client.create_direct_message("pengwynn", "Creating a fixture for the Twitter gem")
111
111
  expect(a_post("/1.1/direct_messages/new.json").with(:body => {:screen_name => "pengwynn", :text => "Creating a fixture for the Twitter gem"})).to have_been_made
112
112
  end
113
113
  it "returns the sent message" do
114
- direct_message = @client.direct_message_create("pengwynn", "Creating a fixture for the Twitter gem")
114
+ direct_message = @client.create_direct_message("pengwynn", "Creating a fixture for the Twitter gem")
115
115
  expect(direct_message).to be_a Twitter::DirectMessage
116
- expect(direct_message.text).to eq "Creating a fixture for the Twitter gem"
116
+ expect(direct_message.text).to eq("Creating a fixture for the Twitter gem")
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, "Creating a fixture for the Twitter gem")
122
+ expect(a_post("/1.1/direct_messages/new.json").with(:body => {:screen_name => "pengwynn", :text => "Creating a fixture for the Twitter gem"})).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", "Creating a fixture for the Twitter gem")
128
+ expect(a_post("/1.1/direct_messages/new.json").with(:body => {:screen_name => "pengwynn", :text => "Creating a fixture for the Twitter gem"})).to have_been_made
129
+ end
117
130
  end
118
131
  end
119
132
 
@@ -1,9 +1,9 @@
1
1
  require 'helper'
2
2
 
3
- describe Twitter::API::Favorites do
3
+ describe Twitter::REST::API::Favorites do
4
4
 
5
5
  before do
6
- @client = Twitter::Client.new
6
+ @client = Twitter::REST::Client.new(:consumer_key => "CK", :consumer_secret => "CS", :access_token => "AT", :access_token_secret => "AS")
7
7
  end
8
8
 
9
9
  describe "#favorites" do
@@ -19,7 +19,20 @@ describe Twitter::API::Favorites do
19
19
  favorites = @client.favorites("sferik")
20
20
  expect(favorites).to be_an Array
21
21
  expect(favorites.first).to be_a Twitter::Tweet
22
- expect(favorites.first.user.id).to eq 7505382
22
+ expect(favorites.first.user.id).to eq(7505382)
23
+ end
24
+ context "with a URI object passed" do
25
+ it "requests the correct resource" do
26
+ user = URI.parse("https://twitter.com/sferik")
27
+ @client.favorites(user)
28
+ expect(a_get("/1.1/favorites/list.json").with(:query => {:screen_name => "sferik"})).to have_been_made
29
+ end
30
+ end
31
+ context "with a URI string passed" do
32
+ it "requests the correct resource" do
33
+ @client.favorites("https://twitter.com/sferik")
34
+ expect(a_get("/1.1/favorites/list.json").with(:query => {:screen_name => "sferik"})).to have_been_made
35
+ end
23
36
  end
24
37
  end
25
38
  context "without arguments passed" do
@@ -34,7 +47,7 @@ describe Twitter::API::Favorites do
34
47
  favorites = @client.favorites
35
48
  expect(favorites).to be_an Array
36
49
  expect(favorites.first).to be_a Twitter::Tweet
37
- expect(favorites.first.user.id).to eq 7505382
50
+ expect(favorites.first.user.id).to eq(7505382)
38
51
  end
39
52
  end
40
53
  end
@@ -51,7 +64,27 @@ describe Twitter::API::Favorites do
51
64
  tweets = @client.unfavorite(25938088801)
52
65
  expect(tweets).to be_an Array
53
66
  expect(tweets.first).to be_a Twitter::Tweet
54
- expect(tweets.first.text).to eq "The problem with your code is that it's doing exactly what you told it to do."
67
+ expect(tweets.first.text).to eq("The problem with your code is that it's doing exactly what you told it to do.")
68
+ end
69
+ context "with a URI object passed" do
70
+ it "requests the correct resource" do
71
+ tweet = URI.parse("https://twitter.com/sferik/status/25938088801")
72
+ @client.unfavorite(tweet)
73
+ expect(a_post("/1.1/favorites/destroy.json").with(:body => {:id => "25938088801"})).to have_been_made
74
+ end
75
+ end
76
+ context "with a URI string passed" do
77
+ it "requests the correct resource" do
78
+ @client.unfavorite("https://twitter.com/sferik/status/25938088801")
79
+ expect(a_post("/1.1/favorites/destroy.json").with(:body => {:id => "25938088801"})).to have_been_made
80
+ end
81
+ end
82
+ context "with a Tweet passed" do
83
+ it "requests the correct resource" do
84
+ tweet = Twitter::Tweet.new(:id => 25938088801)
85
+ @client.unfavorite(tweet)
86
+ expect(a_post("/1.1/favorites/destroy.json").with(:body => {:id => "25938088801"})).to have_been_made
87
+ end
55
88
  end
56
89
  end
57
90
 
@@ -67,7 +100,7 @@ describe Twitter::API::Favorites do
67
100
  tweets = @client.favorite(25938088801)
68
101
  expect(tweets).to be_an Array
69
102
  expect(tweets.first).to be_a Twitter::Tweet
70
- expect(tweets.first.text).to eq "The problem with your code is that it's doing exactly what you told it to do."
103
+ expect(tweets.first.text).to eq("The problem with your code is that it's doing exactly what you told it to do.")
71
104
  end
72
105
  context "already favorited" do
73
106
  before do
@@ -77,6 +110,26 @@ describe Twitter::API::Favorites do
77
110
  expect{@client.favorite(25938088801)}.not_to raise_error
78
111
  end
79
112
  end
113
+ context "with a URI object passed" do
114
+ it "requests the correct resource" do
115
+ tweet = URI.parse("https://twitter.com/sferik/status/25938088801")
116
+ @client.favorite(tweet)
117
+ expect(a_post("/1.1/favorites/create.json").with(:body => {:id => "25938088801"})).to have_been_made
118
+ end
119
+ end
120
+ context "with a URI string passed" do
121
+ it "requests the correct resource" do
122
+ @client.favorite("https://twitter.com/sferik/status/25938088801")
123
+ expect(a_post("/1.1/favorites/create.json").with(:body => {:id => "25938088801"})).to have_been_made
124
+ end
125
+ end
126
+ context "with a Tweet passed" do
127
+ it "requests the correct resource" do
128
+ tweet = Twitter::Tweet.new(:id => 25938088801)
129
+ @client.favorite(tweet)
130
+ expect(a_post("/1.1/favorites/create.json").with(:body => {:id => "25938088801"})).to have_been_made
131
+ end
132
+ end
80
133
  end
81
134
 
82
135
  describe "#favorite!" do
@@ -91,7 +144,7 @@ describe Twitter::API::Favorites do
91
144
  tweets = @client.favorite!(25938088801)
92
145
  expect(tweets).to be_an Array
93
146
  expect(tweets.first).to be_a Twitter::Tweet
94
- expect(tweets.first.text).to eq "The problem with your code is that it's doing exactly what you told it to do."
147
+ expect(tweets.first.text).to eq("The problem with your code is that it's doing exactly what you told it to do.")
95
148
  end
96
149
  context "forbidden" do
97
150
  before do
@@ -109,6 +162,26 @@ describe Twitter::API::Favorites do
109
162
  expect{@client.favorite!(25938088801)}.to raise_error Twitter::Error::AlreadyFavorited
110
163
  end
111
164
  end
165
+ context "with a URI object passed" do
166
+ it "requests the correct resource" do
167
+ tweet = URI.parse("https://twitter.com/sferik/status/25938088801")
168
+ @client.favorite!(tweet)
169
+ expect(a_post("/1.1/favorites/create.json").with(:body => {:id => "25938088801"})).to have_been_made
170
+ end
171
+ end
172
+ context "with a URI string passed" do
173
+ it "requests the correct resource" do
174
+ @client.favorite!("https://twitter.com/sferik/status/25938088801")
175
+ expect(a_post("/1.1/favorites/create.json").with(:body => {:id => "25938088801"})).to have_been_made
176
+ end
177
+ end
178
+ context "with a Tweet passed" do
179
+ it "requests the correct resource" do
180
+ tweet = Twitter::Tweet.new(:id => 25938088801)
181
+ @client.favorite!(tweet)
182
+ expect(a_post("/1.1/favorites/create.json").with(:body => {:id => "25938088801"})).to have_been_made
183
+ end
184
+ end
112
185
  end
113
186
 
114
187
  end