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
@@ -4,11 +4,11 @@ describe Twitter::MediaFactory do
4
4
 
5
5
  describe ".new" do
6
6
  it "generates a Photo" do
7
- media = Twitter::MediaFactory.fetch_or_new(:id => 1, :type => 'photo')
7
+ media = Twitter::MediaFactory.new(:id => 1, :type => "photo")
8
8
  expect(media).to be_a Twitter::Media::Photo
9
9
  end
10
10
  it "raises an ArgumentError when type is not specified" do
11
- expect{Twitter::MediaFactory.fetch_or_new}.to raise_error ArgumentError
11
+ expect{Twitter::MediaFactory.new}.to raise_error ArgumentError
12
12
  end
13
13
  end
14
14
 
@@ -0,0 +1,26 @@
1
+ require 'helper'
2
+
3
+ describe Twitter::NullObject do
4
+
5
+ describe "#nil?" do
6
+ it "returns true" do
7
+ null_object = Twitter::NullObject.instance
8
+ expect(null_object.null?).to be_true
9
+ end
10
+ end
11
+
12
+ describe "calling any method" do
13
+ it "returns self" do
14
+ null_object = Twitter::NullObject.instance
15
+ expect(null_object.any).to equal null_object
16
+ end
17
+ end
18
+
19
+ describe "#respond_to?" do
20
+ it "returns true" do
21
+ null_object = Twitter::NullObject.instance
22
+ expect(null_object.respond_to?(:any)).to be_true
23
+ end
24
+ end
25
+
26
+ end
@@ -2,24 +2,34 @@ require 'helper'
2
2
 
3
3
  describe Twitter::OEmbed do
4
4
 
5
- describe "#author_url" do
6
- it "returns the author's url" do
7
- oembed = Twitter::OEmbed.new(:author_url => 'https://twitter.com/sferik')
8
- expect(oembed.author_url).to eq "https://twitter.com/sferik"
5
+ describe "#author_uri" do
6
+ it "returns a URI when the author_url is set" do
7
+ oembed = Twitter::OEmbed.new(:author_url => "https://twitter.com/sferik")
8
+ expect(oembed.author_uri).to be_a URI
9
+ expect(oembed.author_uri.to_s).to eq("https://twitter.com/sferik")
9
10
  end
11
+ it "returns nil when the author_uri is not set" do
12
+ oembed = Twitter::OEmbed.new
13
+ expect(oembed.author_uri).to be_nil
14
+ end
15
+ end
10
16
 
11
- it "returns nil when not set" do
12
- author_url = Twitter::OEmbed.new.author_url
13
- expect(author_url).to be_nil
17
+ describe "#author_uri?" do
18
+ it "returns true when the author_url is set" do
19
+ oembed = Twitter::OEmbed.new(:author_url => "https://twitter.com/sferik")
20
+ expect(oembed.author_uri?).to be_true
21
+ end
22
+ it "returns false when the author_uri is not set" do
23
+ oembed = Twitter::OEmbed.new
24
+ expect(oembed.author_uri?).to be_false
14
25
  end
15
26
  end
16
27
 
17
28
  describe "#author_name" do
18
29
  it "returns the author's name" do
19
- oembed = Twitter::OEmbed.new(:author_name => 'Erik Michaels-Ober')
20
- expect(oembed.author_name).to eq "Erik Michaels-Ober"
30
+ oembed = Twitter::OEmbed.new(:author_name => "Erik Michaels-Ober")
31
+ expect(oembed.author_name).to eq("Erik Michaels-Ober")
21
32
  end
22
-
23
33
  it "returns nil when not set" do
24
34
  author_name = Twitter::OEmbed.new.author_name
25
35
  expect(author_name).to be_nil
@@ -28,10 +38,9 @@ describe Twitter::OEmbed do
28
38
 
29
39
  describe "#cache_age" do
30
40
  it "returns the cache_age" do
31
- oembed = Twitter::OEmbed.new(:cache_age => '31536000000')
32
- expect(oembed.cache_age).to eq "31536000000"
41
+ oembed = Twitter::OEmbed.new(:cache_age => "31536000000")
42
+ expect(oembed.cache_age).to eq("31536000000")
33
43
  end
34
-
35
44
  it "returns nil when not set" do
36
45
  cache_age = Twitter::OEmbed.new.cache_age
37
46
  expect(cache_age).to be_nil
@@ -41,14 +50,12 @@ describe Twitter::OEmbed do
41
50
  describe "#height" do
42
51
  it "returns the height" do
43
52
  oembed = Twitter::OEmbed.new(:height => 200)
44
- expect(oembed.height).to eq 200
53
+ expect(oembed.height).to eq(200)
45
54
  end
46
-
47
55
  it "returns it as an Integer" do
48
56
  oembed = Twitter::OEmbed.new(:height => 200)
49
57
  expect(oembed.height).to be_an Integer
50
58
  end
51
-
52
59
  it "returns nil when not set" do
53
60
  height = Twitter::OEmbed.new.height
54
61
  expect(height).to be_nil
@@ -57,10 +64,9 @@ describe Twitter::OEmbed do
57
64
 
58
65
  describe "#html" do
59
66
  it "returns the html" do
60
- oembed = Twitter::OEmbed.new(:html => '<blockquote>all my <b>witty tweet</b> stuff here</blockquote>')
61
- expect(oembed.html).to eq "<blockquote>all my <b>witty tweet</b> stuff here</blockquote>"
67
+ oembed = Twitter::OEmbed.new(:html => "<blockquote>all my <b>witty tweet</b> stuff here</blockquote>")
68
+ expect(oembed.html).to eq("<blockquote>all my <b>witty tweet</b> stuff here</blockquote>")
62
69
  end
63
-
64
70
  it "returns nil when not set" do
65
71
  html = Twitter::OEmbed.new.html
66
72
  expect(html).to be_nil
@@ -69,34 +75,43 @@ describe Twitter::OEmbed do
69
75
 
70
76
  describe "#provider_name" do
71
77
  it "returns the provider_name" do
72
- oembed = Twitter::OEmbed.new(:provider_name => 'Twitter')
73
- expect(oembed.provider_name).to eq "Twitter"
78
+ oembed = Twitter::OEmbed.new(:provider_name => "Twitter")
79
+ expect(oembed.provider_name).to eq("Twitter")
74
80
  end
75
-
76
81
  it "returns nil when not set" do
77
82
  provider_name = Twitter::OEmbed.new.provider_name
78
83
  expect(provider_name).to be_nil
79
84
  end
80
85
  end
81
86
 
82
- describe "#provider_url" do
83
- it "returns the provider_url" do
84
- oembed = Twitter::OEmbed.new(:provider_url => 'http://twitter.com')
85
- expect(oembed.provider_url).to eq "http://twitter.com"
87
+ describe "#provider_uri" do
88
+ it "returns a URI when the provider_url is set" do
89
+ oembed = Twitter::OEmbed.new(:provider_url => "http://twitter.com")
90
+ expect(oembed.provider_uri).to be_a URI
91
+ expect(oembed.provider_uri.to_s).to eq("http://twitter.com")
92
+ end
93
+ it "returns nil when the provider_uri is not set" do
94
+ oembed = Twitter::OEmbed.new
95
+ expect(oembed.provider_uri).to be_nil
86
96
  end
97
+ end
87
98
 
88
- it "returns nil when not set" do
89
- provider_url = Twitter::OEmbed.new.provider_url
90
- expect(provider_url).to be_nil
99
+ describe "#provider_uri?" do
100
+ it "returns true when the provider_url is set" do
101
+ oembed = Twitter::OEmbed.new(:provider_url => "https://twitter.com/sferik")
102
+ expect(oembed.provider_uri?).to be_true
103
+ end
104
+ it "returns false when the provider_uri is not set" do
105
+ oembed = Twitter::OEmbed.new
106
+ expect(oembed.provider_uri?).to be_false
91
107
  end
92
108
  end
93
109
 
94
110
  describe "#type" do
95
111
  it "returns the type" do
96
- oembed = Twitter::OEmbed.new(:type => 'rich')
97
- expect(oembed.type).to eq "rich"
112
+ oembed = Twitter::OEmbed.new(:type => "rich")
113
+ expect(oembed.type).to eq("rich")
98
114
  end
99
-
100
115
  it "returns nil when not set" do
101
116
  type = Twitter::OEmbed.new.type
102
117
  expect(type).to be_nil
@@ -106,41 +121,50 @@ describe Twitter::OEmbed do
106
121
  describe "#width" do
107
122
  it "returns the width" do
108
123
  oembed = Twitter::OEmbed.new(:width => 550)
109
- expect(oembed.width).to eq 550
124
+ expect(oembed.width).to eq(550)
110
125
  end
111
-
112
126
  it "returns it as an Integer" do
113
127
  oembed = Twitter::OEmbed.new(:width => 550)
114
128
  expect(oembed.width).to be_an Integer
115
129
  end
116
-
117
130
  it "returns nil when not set" do
118
131
  width = Twitter::OEmbed.new.width
119
132
  expect(width).to be_nil
120
133
  end
121
134
  end
122
135
 
123
- describe "#url" do
124
- it "returns the url" do
125
- oembed = Twitter::OEmbed.new(:url => 'https://twitter.com/twitterapi/status/133640144317198338')
126
- expect(oembed.url).to eq "https://twitter.com/twitterapi/status/133640144317198338"
136
+ describe "#uri" do
137
+ it "returns a URI when the url is set" do
138
+ oembed = Twitter::OEmbed.new(:url => "https://twitter.com/twitterapi/status/133640144317198338")
139
+ expect(oembed.uri).to be_a URI
140
+ expect(oembed.uri.to_s).to eq("https://twitter.com/twitterapi/status/133640144317198338")
141
+ end
142
+ it "returns nil when the url is not set" do
143
+ oembed = Twitter::OEmbed.new
144
+ expect(oembed.uri).to be_nil
127
145
  end
146
+ end
128
147
 
129
- it "returns nil when not set" do
130
- url = Twitter::OEmbed.new.url
131
- expect(url).to be_nil
148
+ describe "#uri?" do
149
+ it "returns true when the url is set" do
150
+ oembed = Twitter::OEmbed.new(:url => "https://twitter.com/twitterapi/status/133640144317198338")
151
+ expect(oembed.uri?).to be_true
152
+ end
153
+ it "returns false when the url is not set" do
154
+ oembed = Twitter::OEmbed.new
155
+ expect(oembed.uri?).to be_false
132
156
  end
133
157
  end
134
158
 
135
159
  describe "#version" do
136
160
  it "returns the version" do
137
- oembed = Twitter::OEmbed.new(:version => '1.0')
138
- expect(oembed.version).to eq "1.0"
161
+ oembed = Twitter::OEmbed.new(:version => "1.0")
162
+ expect(oembed.version).to eq("1.0")
139
163
  end
140
-
141
164
  it "returns nil when not set" do
142
165
  version = Twitter::OEmbed.new.version
143
166
  expect(version).to be_nil
144
167
  end
145
168
  end
169
+
146
170
  end
@@ -21,24 +21,57 @@ describe Twitter::Place do
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(:id => "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
28
+ it "returns nil when not bounding_box is not set" do
29
29
  place = Twitter::Place.new(:id => "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(:id => "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(:id => "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(:id => "247f43d441defc03", :contained_within => {:id => "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(:id => "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(:id => "247f43d441defc03", :contained_within => {:id => "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(:id => "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(:id => "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(:id => "247f43d441defc03", :countryCode => "US")
74
+ expect(place.country_code).to eq("US")
42
75
  end
43
76
  it "returns nil when not set" do
44
77
  place = Twitter::Place.new(:id => "247f43d441defc03")
@@ -49,7 +82,7 @@ describe Twitter::Place do
49
82
  describe "#parent_id" do
50
83
  it "returns a parent ID when set with parentid" do
51
84
  place = Twitter::Place.new(:id => "247f43d441defc03", :parentid => 1)
52
- expect(place.parent_id).to eq 1
85
+ expect(place.parent_id).to eq(1)
53
86
  end
54
87
  it "returns nil when not set" do
55
88
  place = Twitter::Place.new(:id => "247f43d441defc03")
@@ -59,12 +92,12 @@ describe Twitter::Place do
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(:id => "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(:id => "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
103
  place = Twitter::Place.new(:id => "247f43d441defc03")
@@ -72,4 +105,27 @@ describe Twitter::Place do
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(:id => "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(:id => "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(:id => "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(:id => "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
@@ -64,12 +64,12 @@ describe Twitter::RateLimit do
64
64
  Timecop.return
65
65
  end
66
66
  it "updates a rate limit" do
67
- rate_limit = Twitter::RateLimit.new('x-rate-limit-reset' => "1339019097")
67
+ rate_limit = Twitter::RateLimit.new("x-rate-limit-reset" => "1339019097")
68
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"})
69
+ expect(rate_limit.reset_in).to eq(15777)
70
+ rate_limit.update({"x-rate-limit-reset" => "1339019098"})
71
71
  expect(rate_limit.reset_in).to be_an Integer
72
- expect(rate_limit.reset_in).to eq 15778
72
+ expect(rate_limit.reset_in).to eq(15778)
73
73
  end
74
74
  end
75
75
 
@@ -4,23 +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
35
+ end
36
+ end
37
+
38
+ describe "#target?" do
39
+ it "returns true when target is set" do
40
+ relationship = Twitter::Relationship.new(:relationship => {:target => {:id => 7505382}})
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
24
46
  end
25
47
  end
26
48
 
@@ -28,7 +50,7 @@ describe Twitter::Relationship do
28
50
  it "updates a relationship" do
29
51
  relationship = Twitter::Relationship.new(:relationship => {:target => {:id => 7505382}})
30
52
  relationship.update(:relationship => {:target => {:id => 14100886}})
31
- expect(relationship.target.id).to eq 14100886
53
+ expect(relationship.target.id).to eq(14100886)
32
54
  end
33
55
  end
34
56