twitter 4.8.1 → 5.0.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (197) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG.md +30 -0
  3. data/LICENSE.md +1 -1
  4. data/README.md +386 -266
  5. data/lib/twitter.rb +4 -39
  6. data/lib/twitter/arguments.rb +11 -0
  7. data/lib/twitter/base.rb +89 -68
  8. data/lib/twitter/client.rb +69 -110
  9. data/lib/twitter/configuration.rb +7 -3
  10. data/lib/twitter/creatable.rb +2 -4
  11. data/lib/twitter/cursor.rb +50 -42
  12. data/lib/twitter/direct_message.rb +2 -11
  13. data/lib/twitter/entity/uri.rb +13 -0
  14. data/lib/twitter/enumerable.rb +15 -0
  15. data/lib/twitter/error.rb +55 -7
  16. data/lib/twitter/error/already_favorited.rb +1 -1
  17. data/lib/twitter/error/already_posted.rb +10 -0
  18. data/lib/twitter/error/already_retweeted.rb +1 -1
  19. data/lib/twitter/error/bad_gateway.rb +2 -3
  20. data/lib/twitter/error/bad_request.rb +2 -2
  21. data/lib/twitter/error/forbidden.rb +2 -2
  22. data/lib/twitter/error/gateway_timeout.rb +2 -3
  23. data/lib/twitter/error/internal_server_error.rb +2 -3
  24. data/lib/twitter/error/not_acceptable.rb +2 -2
  25. data/lib/twitter/error/not_found.rb +2 -2
  26. data/lib/twitter/error/service_unavailable.rb +2 -3
  27. data/lib/twitter/error/too_many_requests.rb +2 -2
  28. data/lib/twitter/error/unauthorized.rb +2 -2
  29. data/lib/twitter/error/unprocessable_entity.rb +2 -2
  30. data/lib/twitter/factory.rb +2 -8
  31. data/lib/twitter/geo_factory.rb +2 -2
  32. data/lib/twitter/geo_results.rb +36 -0
  33. data/lib/twitter/identity.rb +0 -22
  34. data/lib/twitter/list.rb +18 -4
  35. data/lib/twitter/media/photo.rb +3 -3
  36. data/lib/twitter/media_factory.rb +2 -2
  37. data/lib/twitter/null_object.rb +24 -0
  38. data/lib/twitter/oembed.rb +3 -2
  39. data/lib/twitter/place.rb +15 -9
  40. data/lib/twitter/profile_banner.rb +5 -3
  41. data/lib/twitter/rate_limit.rb +1 -17
  42. data/lib/twitter/relationship.rb +2 -10
  43. data/lib/twitter/rest/api/direct_messages.rb +135 -0
  44. data/lib/twitter/rest/api/favorites.rb +120 -0
  45. data/lib/twitter/rest/api/friends_and_followers.rb +290 -0
  46. data/lib/twitter/rest/api/help.rb +58 -0
  47. data/lib/twitter/rest/api/lists.rb +491 -0
  48. data/lib/twitter/rest/api/oauth.rb +45 -0
  49. data/lib/twitter/rest/api/places_and_geo.rb +104 -0
  50. data/lib/twitter/rest/api/saved_searches.rb +91 -0
  51. data/lib/twitter/rest/api/search.rb +37 -0
  52. data/lib/twitter/rest/api/spam_reporting.rb +29 -0
  53. data/lib/twitter/rest/api/suggested_users.rb +51 -0
  54. data/lib/twitter/rest/api/timelines.rb +202 -0
  55. data/lib/twitter/rest/api/trends.rb +58 -0
  56. data/lib/twitter/rest/api/tweets.rb +293 -0
  57. data/lib/twitter/rest/api/undocumented.rb +52 -0
  58. data/lib/twitter/rest/api/users.rb +383 -0
  59. data/lib/twitter/rest/api/utils.rb +219 -0
  60. data/lib/twitter/rest/client.rb +193 -0
  61. data/lib/twitter/rest/request/multipart_with_file.rb +36 -0
  62. data/lib/twitter/rest/response/parse_json.rb +27 -0
  63. data/lib/twitter/{response → rest/response}/raise_error.rb +8 -11
  64. data/lib/twitter/search_results.rb +33 -21
  65. data/lib/twitter/settings.rb +1 -6
  66. data/lib/twitter/size.rb +1 -1
  67. data/lib/twitter/streaming/client.rb +77 -0
  68. data/lib/twitter/streaming/connection.rb +22 -0
  69. data/lib/twitter/streaming/response.rb +30 -0
  70. data/lib/twitter/suggestion.rb +4 -2
  71. data/lib/twitter/token.rb +8 -0
  72. data/lib/twitter/trend.rb +2 -1
  73. data/lib/twitter/trend_results.rb +59 -0
  74. data/lib/twitter/tweet.rb +41 -85
  75. data/lib/twitter/user.rb +51 -41
  76. data/lib/twitter/version.rb +4 -4
  77. data/spec/fixtures/already_posted.json +1 -0
  78. data/spec/fixtures/ids_list.json +1 -1
  79. data/spec/fixtures/ids_list2.json +1 -1
  80. data/spec/fixtures/search.json +1 -1
  81. data/spec/fixtures/search_malformed.json +1 -1
  82. data/spec/fixtures/track_streaming.json +3 -0
  83. data/spec/helper.rb +8 -13
  84. data/spec/twitter/base_spec.rb +25 -99
  85. data/spec/twitter/configuration_spec.rb +1 -1
  86. data/spec/twitter/cursor_spec.rb +13 -31
  87. data/spec/twitter/direct_message_spec.rb +41 -8
  88. data/spec/twitter/entity/uri_spec.rb +74 -0
  89. data/spec/twitter/error_spec.rb +59 -11
  90. data/spec/twitter/geo/point_spec.rb +1 -1
  91. data/spec/twitter/geo_factory_spec.rb +3 -3
  92. data/spec/twitter/geo_results_spec.rb +35 -0
  93. data/spec/twitter/identifiable_spec.rb +0 -21
  94. data/spec/twitter/list_spec.rb +51 -8
  95. data/spec/twitter/media/photo_spec.rb +118 -3
  96. data/spec/twitter/media_factory_spec.rb +2 -2
  97. data/spec/twitter/null_object_spec.rb +26 -0
  98. data/spec/twitter/oembed_spec.rb +69 -45
  99. data/spec/twitter/place_spec.rb +68 -12
  100. data/spec/twitter/profile_banner_spec.rb +1 -1
  101. data/spec/twitter/rate_limit_spec.rb +12 -12
  102. data/spec/twitter/relationship_spec.rb +31 -9
  103. data/spec/twitter/{api → rest/api}/direct_messages_spec.rb +22 -9
  104. data/spec/twitter/{api → rest/api}/favorites_spec.rb +80 -7
  105. data/spec/twitter/{api → rest/api}/friends_and_followers_spec.rb +104 -65
  106. data/spec/twitter/{api → rest/api}/geo_spec.rb +10 -10
  107. data/spec/twitter/{api → rest/api}/help_spec.rb +6 -6
  108. data/spec/twitter/{api → rest/api}/lists_spec.rb +77 -56
  109. data/spec/twitter/{api → rest/api}/oauth_spec.rb +6 -6
  110. data/spec/twitter/{api → rest/api}/saved_searches_spec.rb +7 -7
  111. data/spec/twitter/{api → rest/api}/search_spec.rb +8 -9
  112. data/spec/twitter/{api → rest/api}/spam_reporting_spec.rb +3 -3
  113. data/spec/twitter/{api → rest/api}/suggested_users_spec.rb +5 -5
  114. data/spec/twitter/{api → rest/api}/timelines_spec.rb +9 -9
  115. data/spec/twitter/{api → rest/api}/trends_spec.rb +6 -6
  116. data/spec/twitter/rest/api/tweets_spec.rb +503 -0
  117. data/spec/twitter/{api → rest/api}/undocumented_spec.rb +19 -45
  118. data/spec/twitter/{api → rest/api}/users_spec.rb +60 -35
  119. data/spec/twitter/rest/client_spec.rb +193 -0
  120. data/spec/twitter/saved_search_spec.rb +11 -0
  121. data/spec/twitter/search_results_spec.rb +29 -42
  122. data/spec/twitter/settings_spec.rb +17 -6
  123. data/spec/twitter/streaming/client_spec.rb +75 -0
  124. data/spec/twitter/token_spec.rb +16 -0
  125. data/spec/twitter/trend_results_spec.rb +89 -0
  126. data/spec/twitter/trend_spec.rb +23 -0
  127. data/spec/twitter/tweet_spec.rb +122 -115
  128. data/spec/twitter/user_spec.rb +136 -77
  129. data/spec/twitter_spec.rb +0 -119
  130. data/twitter.gemspec +8 -5
  131. metadata +148 -141
  132. metadata.gz.sig +0 -0
  133. data/lib/twitter/action/favorite.rb +0 -19
  134. data/lib/twitter/action/follow.rb +0 -30
  135. data/lib/twitter/action/list_member_added.rb +0 -39
  136. data/lib/twitter/action/mention.rb +0 -46
  137. data/lib/twitter/action/reply.rb +0 -27
  138. data/lib/twitter/action/retweet.rb +0 -27
  139. data/lib/twitter/action/tweet.rb +0 -20
  140. data/lib/twitter/action_factory.rb +0 -22
  141. data/lib/twitter/api/arguments.rb +0 -13
  142. data/lib/twitter/api/direct_messages.rb +0 -148
  143. data/lib/twitter/api/favorites.rb +0 -126
  144. data/lib/twitter/api/friends_and_followers.rb +0 -334
  145. data/lib/twitter/api/help.rb +0 -64
  146. data/lib/twitter/api/lists.rb +0 -618
  147. data/lib/twitter/api/oauth.rb +0 -44
  148. data/lib/twitter/api/places_and_geo.rb +0 -121
  149. data/lib/twitter/api/saved_searches.rb +0 -99
  150. data/lib/twitter/api/search.rb +0 -37
  151. data/lib/twitter/api/spam_reporting.rb +0 -30
  152. data/lib/twitter/api/suggested_users.rb +0 -55
  153. data/lib/twitter/api/timelines.rb +0 -214
  154. data/lib/twitter/api/trends.rb +0 -63
  155. data/lib/twitter/api/tweets.rb +0 -304
  156. data/lib/twitter/api/undocumented.rb +0 -97
  157. data/lib/twitter/api/users.rb +0 -439
  158. data/lib/twitter/api/utils.rb +0 -187
  159. data/lib/twitter/configurable.rb +0 -96
  160. data/lib/twitter/default.rb +0 -102
  161. data/lib/twitter/entity/url.rb +0 -9
  162. data/lib/twitter/error/client_error.rb +0 -35
  163. data/lib/twitter/error/decode_error.rb +0 -9
  164. data/lib/twitter/error/identity_map_key_error.rb +0 -9
  165. data/lib/twitter/error/server_error.rb +0 -28
  166. data/lib/twitter/exceptable.rb +0 -36
  167. data/lib/twitter/identity_map.rb +0 -22
  168. data/lib/twitter/request/multipart_with_file.rb +0 -34
  169. data/lib/twitter/response/parse_json.rb +0 -25
  170. data/spec/fixtures/about_me.json +0 -1
  171. data/spec/fixtures/activity_summary.json +0 -1
  172. data/spec/fixtures/bad_gateway.json +0 -1
  173. data/spec/fixtures/bad_request.json +0 -1
  174. data/spec/fixtures/by_friends.json +0 -1
  175. data/spec/fixtures/end_session.json +0 -1
  176. data/spec/fixtures/forbidden.json +0 -1
  177. data/spec/fixtures/internal_server_error.json +0 -1
  178. data/spec/fixtures/not_acceptable.json +0 -1
  179. data/spec/fixtures/phoenix_search.phoenix +0 -1
  180. data/spec/fixtures/resolve.json +0 -1
  181. data/spec/fixtures/service_unavailable.json +0 -1
  182. data/spec/fixtures/totals.json +0 -1
  183. data/spec/fixtures/trends.json +0 -1
  184. data/spec/fixtures/unauthorized.json +0 -1
  185. data/spec/fixtures/video_facets.json +0 -1
  186. data/spec/twitter/action/favorite_spec.rb +0 -29
  187. data/spec/twitter/action/follow_spec.rb +0 -29
  188. data/spec/twitter/action/list_member_added_spec.rb +0 -41
  189. data/spec/twitter/action/mention_spec.rb +0 -52
  190. data/spec/twitter/action/reply_spec.rb +0 -41
  191. data/spec/twitter/action/retweet_spec.rb +0 -41
  192. data/spec/twitter/action_factory_spec.rb +0 -35
  193. data/spec/twitter/action_spec.rb +0 -16
  194. data/spec/twitter/api/tweets_spec.rb +0 -285
  195. data/spec/twitter/client_spec.rb +0 -223
  196. data/spec/twitter/error/client_error_spec.rb +0 -23
  197. data/spec/twitter/error/server_error_spec.rb +0 -20
@@ -1,3 +1,4 @@
1
+ # -*- coding: UTF-8 -*-
1
2
  require 'helper'
2
3
 
3
4
  describe Twitter::User do
@@ -31,246 +32,304 @@ describe Twitter::User do
31
32
  end
32
33
  end
33
34
 
34
- describe "#description_urls" do
35
- it "returns an Array of Entity::Url" do
35
+ describe "#created?" do
36
+ it "returns true when created_at is set" do
37
+ user = Twitter::User.new(:id => 7505382, :created_at => "Mon Jul 16 12:59:01 +0000 2007")
38
+ expect(user.created?).to be_true
39
+ end
40
+ it "returns false when created_at is not set" do
41
+ user = Twitter::User.new(:id => 7505382)
42
+ expect(user.created?).to be_false
43
+ end
44
+ end
45
+
46
+ describe "#description_uris" do
47
+ it "returns an array of Entity::URIs when entities are set" do
36
48
  urls_array = [
37
49
  {
38
- :url => 'http://example.com/t.co',
39
- :expanded_url => 'http://example.com/expanded',
40
- :display_url => 'example.com/expanded',
50
+ :url => "http://example.com/t.co",
51
+ :expanded_url => "http://example.com/expanded",
52
+ :display_url => "example.com/expanded",
41
53
  :indices => [10, 33],
42
54
  }
43
55
  ]
44
- description_urls = Twitter::User.new(:id => 7505382, :entities => {:description => {:urls => urls_array}}).description_urls
45
- expect(description_urls).to be_an Array
46
- expect(description_urls.first).to be_a Twitter::Entity::Url
47
- expect(description_urls.first.indices).to eq [10, 33]
48
- expect(description_urls.first.display_url).to eq 'example.com/expanded'
56
+ user = Twitter::User.new(:id => 7505382, :entities => {:description => {:urls => urls_array}})
57
+ expect(user.description_uris).to be_an Array
58
+ expect(user.description_uris.first).to be_a Twitter::Entity::URI
59
+ expect(user.description_uris.first.indices).to eq([10, 33])
60
+ expect(user.description_uris.first.display_uri.to_s).to eq("example.com/expanded")
49
61
  end
50
62
  it "is empty when not set" do
51
- description_urls = Twitter::User.new(:id => 7505382, :entities => {:description => {:urls => []}}).description_urls
52
- expect(description_urls).to be_empty
63
+ user = Twitter::User.new(:id => 7505382, :entities => {:description => {:urls => []}})
64
+ expect(user.description_uris).to be_empty
53
65
  end
54
66
  end
55
67
 
56
- describe "#profile_banner_url" do
57
- it "returns a String when profile_banner_url is set" do
68
+ describe "#profile_banner_uri" do
69
+ it "accepts utf8 urls" do
70
+ user = Twitter::User.new(:id => 7505382, :profile_banner_url => "https://si0.twimg.com/profile_banners/7505382/1348266581©_normal.png")
71
+ expect(user.profile_banner_uri).to be_a URI
72
+ end
73
+ it "returns a URI when profile_banner_url is set" do
58
74
  user = Twitter::User.new(:id => 7505382, :profile_banner_url => "https://si0.twimg.com/profile_banners/7505382/1348266581")
59
- expect(user.profile_banner_url).to be_a String
75
+ expect(user.profile_banner_uri).to be_a URI
60
76
  end
61
- it "returns nil when created_at is not set" do
77
+ it "returns nil when profile_banner_uri is not set" do
62
78
  user = Twitter::User.new(:id => 7505382)
63
- expect(user.profile_banner_url).to be_nil
79
+ expect(user.profile_banner_uri).to be_nil
64
80
  end
65
81
  it "returns the web-sized image" do
66
82
  user = Twitter::User.new(:id => 7505382, :profile_banner_url => "https://si0.twimg.com/profile_banners/7505382/1348266581")
67
- expect(user.profile_banner_url).to eq "http://si0.twimg.com/profile_banners/7505382/1348266581/web"
83
+ expect(user.profile_banner_uri.to_s).to eq("http://si0.twimg.com/profile_banners/7505382/1348266581/web")
68
84
  end
69
85
  context "with :web_retina passed" do
70
86
  it "returns the web retina-sized image" do
71
87
  user = Twitter::User.new(:id => 7505382, :profile_banner_url => "https://si0.twimg.com/profile_banners/7505382/1348266581")
72
- expect(user.profile_banner_url(:web_retina)).to eq "http://si0.twimg.com/profile_banners/7505382/1348266581/web_retina"
88
+ expect(user.profile_banner_uri(:web_retina).to_s).to eq("http://si0.twimg.com/profile_banners/7505382/1348266581/web_retina")
73
89
  end
74
90
  end
75
91
  context "with :mobile passed" do
76
92
  it "returns the mobile-sized image" do
77
93
  user = Twitter::User.new(:id => 7505382, :profile_banner_url => "https://si0.twimg.com/profile_banners/7505382/1348266581")
78
- expect(user.profile_banner_url(:mobile)).to eq "http://si0.twimg.com/profile_banners/7505382/1348266581/mobile"
94
+ expect(user.profile_banner_uri(:mobile).to_s).to eq("http://si0.twimg.com/profile_banners/7505382/1348266581/mobile")
79
95
  end
80
96
  end
81
97
  context "with :mobile_retina passed" do
82
98
  it "returns the mobile retina-sized image" do
83
99
  user = Twitter::User.new(:id => 7505382, :profile_banner_url => "https://si0.twimg.com/profile_banners/7505382/1348266581")
84
- expect(user.profile_banner_url(:mobile_retina)).to eq "http://si0.twimg.com/profile_banners/7505382/1348266581/mobile_retina"
100
+ expect(user.profile_banner_uri(:mobile_retina).to_s).to eq("http://si0.twimg.com/profile_banners/7505382/1348266581/mobile_retina")
85
101
  end
86
102
  end
87
103
  context "with :ipad passed" do
88
104
  it "returns the mobile-sized image" do
89
105
  user = Twitter::User.new(:id => 7505382, :profile_banner_url => "https://si0.twimg.com/profile_banners/7505382/1348266581")
90
- expect(user.profile_banner_url(:ipad)).to eq "http://si0.twimg.com/profile_banners/7505382/1348266581/ipad"
106
+ expect(user.profile_banner_uri(:ipad).to_s).to eq("http://si0.twimg.com/profile_banners/7505382/1348266581/ipad")
91
107
  end
92
108
  end
93
109
  context "with :ipad_retina passed" do
94
110
  it "returns the mobile retina-sized image" do
95
111
  user = Twitter::User.new(:id => 7505382, :profile_banner_url => "https://si0.twimg.com/profile_banners/7505382/1348266581")
96
- expect(user.profile_banner_url(:ipad_retina)).to eq "http://si0.twimg.com/profile_banners/7505382/1348266581/ipad_retina"
112
+ expect(user.profile_banner_uri(:ipad_retina).to_s).to eq("http://si0.twimg.com/profile_banners/7505382/1348266581/ipad_retina")
97
113
  end
98
114
  end
99
115
  end
100
116
 
101
- describe "#profile_banner_url_https" do
102
- it "returns a String when profile_banner_url is set" do
117
+ describe "#profile_banner_uri_https" do
118
+ it "accepts utf8 urls" do
119
+ user = Twitter::User.new(:id => 7505382, :profile_banner_url => "https://si0.twimg.com/profile_banners/7505382/1348266581©_normal.png")
120
+ expect(user.profile_banner_uri_https).to be_a URI
121
+ end
122
+ it "returns a URI when profile_banner_url is set" do
103
123
  user = Twitter::User.new(:id => 7505382, :profile_banner_url => "https://si0.twimg.com/profile_banners/7505382/1348266581")
104
- expect(user.profile_banner_url_https).to be_a String
124
+ expect(user.profile_banner_uri_https).to be_a URI
105
125
  end
106
126
  it "returns nil when created_at is not set" do
107
127
  user = Twitter::User.new(:id => 7505382)
108
- expect(user.profile_banner_url_https).to be_nil
128
+ expect(user.profile_banner_uri_https).to be_nil
109
129
  end
110
130
  it "returns the web-sized image" do
111
131
  user = Twitter::User.new(:id => 7505382, :profile_banner_url => "https://si0.twimg.com/profile_banners/7505382/1348266581")
112
- expect(user.profile_banner_url_https).to eq "https://si0.twimg.com/profile_banners/7505382/1348266581/web"
132
+ expect(user.profile_banner_uri_https.to_s).to eq("https://si0.twimg.com/profile_banners/7505382/1348266581/web")
113
133
  end
114
134
  context "with :web_retina passed" do
115
135
  it "returns the web retina-sized image" do
116
136
  user = Twitter::User.new(:id => 7505382, :profile_banner_url => "https://si0.twimg.com/profile_banners/7505382/1348266581")
117
- expect(user.profile_banner_url_https(:web_retina)).to eq "https://si0.twimg.com/profile_banners/7505382/1348266581/web_retina"
137
+ expect(user.profile_banner_uri_https(:web_retina).to_s).to eq("https://si0.twimg.com/profile_banners/7505382/1348266581/web_retina")
118
138
  end
119
139
  end
120
140
  context "with :mobile passed" do
121
141
  it "returns the mobile-sized image" do
122
142
  user = Twitter::User.new(:id => 7505382, :profile_banner_url => "https://si0.twimg.com/profile_banners/7505382/1348266581")
123
- expect(user.profile_banner_url_https(:mobile)).to eq "https://si0.twimg.com/profile_banners/7505382/1348266581/mobile"
143
+ expect(user.profile_banner_uri_https(:mobile).to_s).to eq("https://si0.twimg.com/profile_banners/7505382/1348266581/mobile")
124
144
  end
125
145
  end
126
146
  context "with :mobile_retina passed" do
127
147
  it "returns the mobile retina-sized image" do
128
148
  user = Twitter::User.new(:id => 7505382, :profile_banner_url => "https://si0.twimg.com/profile_banners/7505382/1348266581")
129
- expect(user.profile_banner_url_https(:mobile_retina)).to eq "https://si0.twimg.com/profile_banners/7505382/1348266581/mobile_retina"
149
+ expect(user.profile_banner_uri_https(:mobile_retina).to_s).to eq("https://si0.twimg.com/profile_banners/7505382/1348266581/mobile_retina")
130
150
  end
131
151
  end
132
152
  context "with :ipad passed" do
133
153
  it "returns the mobile-sized image" do
134
154
  user = Twitter::User.new(:id => 7505382, :profile_banner_url => "https://si0.twimg.com/profile_banners/7505382/1348266581")
135
- expect(user.profile_banner_url_https(:ipad)).to eq "https://si0.twimg.com/profile_banners/7505382/1348266581/ipad"
155
+ expect(user.profile_banner_uri_https(:ipad).to_s).to eq("https://si0.twimg.com/profile_banners/7505382/1348266581/ipad")
136
156
  end
137
157
  end
138
158
  context "with :ipad_retina passed" do
139
159
  it "returns the mobile retina-sized image" do
140
160
  user = Twitter::User.new(:id => 7505382, :profile_banner_url => "https://si0.twimg.com/profile_banners/7505382/1348266581")
141
- expect(user.profile_banner_url_https(:ipad_retina)).to eq "https://si0.twimg.com/profile_banners/7505382/1348266581/ipad_retina"
161
+ expect(user.profile_banner_uri_https(:ipad_retina).to_s).to eq("https://si0.twimg.com/profile_banners/7505382/1348266581/ipad_retina")
142
162
  end
143
163
  end
144
164
  end
145
165
 
146
- describe "#profile_banner_url?" do
166
+ describe "#profile_banner_uri?" do
147
167
  it "returns true when profile_banner_url is set" do
148
- profile_banner_url = Twitter::User.new(:id => 7505382, :profile_banner_url => "https://si0.twimg.com/profile_banners/7505382/1348266581").profile_banner_url?
149
- expect(profile_banner_url).to be_true
168
+ user = Twitter::User.new(:id => 7505382, :profile_banner_url => "https://si0.twimg.com/profile_banners/7505382/1348266581")
169
+ expect(user.profile_banner_uri?).to be_true
150
170
  end
151
171
  it "returns false when status is not set" do
152
- profile_banner_url = Twitter::User.new(:id => 7505382).profile_banner_url?
153
- expect(profile_banner_url).to be_false
172
+ user = Twitter::User.new(:id => 7505382)
173
+ expect(user.profile_banner_uri?).to be_false
154
174
  end
155
175
  end
156
176
 
157
- describe "#profile_image_url" do
158
- it "returns a String when profile_image_url_https is set" do
177
+ describe "#profile_image_uri" do
178
+ it "accepts utf8 urls" do
179
+ user = Twitter::User.new(:id => 7505382, :profile_image_url_https => "https://si0.twimg.com/profile_images/7505382/1348266581©_normal.png")
180
+ expect(user.profile_image_uri).to be_a URI
181
+ end
182
+ it "returns a URI when profile_image_url_https is set" do
159
183
  user = Twitter::User.new(:id => 7505382, :profile_image_url_https => "https://a0.twimg.com/profile_images/1759857427/image1326743606_normal.png")
160
- expect(user.profile_image_url).to be_a String
184
+ expect(user.profile_image_uri).to be_a URI
161
185
  end
162
186
  it "returns nil when created_at is not set" do
163
187
  user = Twitter::User.new(:id => 7505382)
164
- expect(user.profile_image_url).to be_nil
188
+ expect(user.profile_image_uri).to be_nil
165
189
  end
166
190
  it "returns the normal-sized image" do
167
191
  user = Twitter::User.new(:id => 7505382, :profile_image_url_https => "https://a0.twimg.com/profile_images/1759857427/image1326743606_normal.png")
168
- expect(user.profile_image_url).to eq "http://a0.twimg.com/profile_images/1759857427/image1326743606_normal.png"
192
+ expect(user.profile_image_uri.to_s).to eq("http://a0.twimg.com/profile_images/1759857427/image1326743606_normal.png")
169
193
  end
170
194
  context "with :original passed" do
171
195
  it "returns the original image" do
172
196
  user = Twitter::User.new(:id => 7505382, :profile_image_url_https => "https://a0.twimg.com/profile_images/1759857427/image1326743606_normal.png")
173
- expect(user.profile_image_url(:original)).to eq "http://a0.twimg.com/profile_images/1759857427/image1326743606.png"
197
+ expect(user.profile_image_uri(:original).to_s).to eq("http://a0.twimg.com/profile_images/1759857427/image1326743606.png")
174
198
  end
175
199
  end
176
200
  context "with :bigger passed" do
177
201
  it "returns the bigger-sized image" do
178
202
  user = Twitter::User.new(:id => 7505382, :profile_image_url_https => "https://a0.twimg.com/profile_images/1759857427/image1326743606_normal.png")
179
- expect(user.profile_image_url(:bigger)).to eq "http://a0.twimg.com/profile_images/1759857427/image1326743606_bigger.png"
203
+ expect(user.profile_image_uri(:bigger).to_s).to eq("http://a0.twimg.com/profile_images/1759857427/image1326743606_bigger.png")
180
204
  end
181
205
  end
182
206
  context "with :mini passed" do
183
207
  it "returns the mini-sized image" do
184
208
  user = Twitter::User.new(:id => 7505382, :profile_image_url_https => "https://a0.twimg.com/profile_images/1759857427/image1326743606_normal.png")
185
- expect(user.profile_image_url(:mini)).to eq "http://a0.twimg.com/profile_images/1759857427/image1326743606_mini.png"
209
+ expect(user.profile_image_uri(:mini).to_s).to eq("http://a0.twimg.com/profile_images/1759857427/image1326743606_mini.png")
186
210
  end
187
211
  end
188
212
  context "with capitalized file extension" do
189
213
  it "returns the correct image" do
190
214
  user = Twitter::User.new(:id => 7505382, :profile_image_url_https => "https://si0.twimg.com/profile_images/67759670/DSCN2136_normal.JPG")
191
- expect(user.profile_image_url(:original)).to eq "http://si0.twimg.com/profile_images/67759670/DSCN2136.JPG"
192
- expect(user.profile_image_url(:bigger)).to eq "http://si0.twimg.com/profile_images/67759670/DSCN2136_bigger.JPG"
193
- expect(user.profile_image_url(:mini)).to eq "http://si0.twimg.com/profile_images/67759670/DSCN2136_mini.JPG"
215
+ expect(user.profile_image_uri(:original).to_s).to eq("http://si0.twimg.com/profile_images/67759670/DSCN2136.JPG")
216
+ expect(user.profile_image_uri(:bigger).to_s).to eq("http://si0.twimg.com/profile_images/67759670/DSCN2136_bigger.JPG")
217
+ expect(user.profile_image_uri(:mini).to_s).to eq("http://si0.twimg.com/profile_images/67759670/DSCN2136_mini.JPG")
194
218
  end
195
219
  end
196
220
  end
197
221
 
198
- describe "#profile_image_url_https" do
199
- it "returns a String when profile_image_url_https is set" do
222
+ describe "#profile_image_uri_https" do
223
+ it "accepts utf8 urls" do
224
+ user = Twitter::User.new(:id => 7505382, :profile_image_url_https => "https://si0.twimg.com/profile_images/7505382/1348266581©_normal.png")
225
+ expect(user.profile_image_uri_https).to be_a URI
226
+ end
227
+ it "returns a URI when profile_image_url_https is set" do
200
228
  user = Twitter::User.new(:id => 7505382, :profile_image_url_https => "https://a0.twimg.com/profile_images/1759857427/image1326743606_normal.png")
201
- expect(user.profile_image_url_https).to be_a String
229
+ expect(user.profile_image_uri_https).to be_a URI
202
230
  end
203
231
  it "returns nil when created_at is not set" do
204
232
  user = Twitter::User.new(:id => 7505382)
205
- expect(user.profile_image_url_https).to be_nil
233
+ expect(user.profile_image_uri_https).to be_nil
206
234
  end
207
235
  it "returns the normal-sized image" do
208
236
  user = Twitter::User.new(:id => 7505382, :profile_image_url_https => "https://a0.twimg.com/profile_images/1759857427/image1326743606_normal.png")
209
- expect(user.profile_image_url_https).to eq "https://a0.twimg.com/profile_images/1759857427/image1326743606_normal.png"
237
+ expect(user.profile_image_uri_https.to_s).to eq("https://a0.twimg.com/profile_images/1759857427/image1326743606_normal.png")
210
238
  end
211
239
  context "with :original passed" do
212
240
  it "returns the original image" do
213
241
  user = Twitter::User.new(:id => 7505382, :profile_image_url_https => "https://a0.twimg.com/profile_images/1759857427/image1326743606_normal.png")
214
- expect(user.profile_image_url_https(:original)).to eq "https://a0.twimg.com/profile_images/1759857427/image1326743606.png"
242
+ expect(user.profile_image_uri_https(:original).to_s).to eq("https://a0.twimg.com/profile_images/1759857427/image1326743606.png")
215
243
  end
216
244
  end
217
245
  context "with :bigger passed" do
218
246
  it "returns the bigger-sized image" do
219
247
  user = Twitter::User.new(:id => 7505382, :profile_image_url_https => "https://a0.twimg.com/profile_images/1759857427/image1326743606_normal.png")
220
- expect(user.profile_image_url_https(:bigger)).to eq "https://a0.twimg.com/profile_images/1759857427/image1326743606_bigger.png"
248
+ expect(user.profile_image_uri_https(:bigger).to_s).to eq("https://a0.twimg.com/profile_images/1759857427/image1326743606_bigger.png")
221
249
  end
222
250
  end
223
251
  context "with :mini passed" do
224
252
  it "returns the mini-sized image" do
225
253
  user = Twitter::User.new(:id => 7505382, :profile_image_url_https => "https://a0.twimg.com/profile_images/1759857427/image1326743606_normal.png")
226
- expect(user.profile_image_url_https(:mini)).to eq "https://a0.twimg.com/profile_images/1759857427/image1326743606_mini.png"
254
+ expect(user.profile_image_uri_https(:mini).to_s).to eq("https://a0.twimg.com/profile_images/1759857427/image1326743606_mini.png")
227
255
  end
228
256
  end
229
257
  context "with capitalized file extension" do
230
258
  it "returns the correct image" do
231
259
  user = Twitter::User.new(:id => 7505382, :profile_image_url_https => "https://si0.twimg.com/profile_images/67759670/DSCN2136_normal.JPG")
232
- expect(user.profile_image_url_https(:original)).to eq "https://si0.twimg.com/profile_images/67759670/DSCN2136.JPG"
233
- expect(user.profile_image_url_https(:bigger)).to eq "https://si0.twimg.com/profile_images/67759670/DSCN2136_bigger.JPG"
234
- expect(user.profile_image_url_https(:mini)).to eq "https://si0.twimg.com/profile_images/67759670/DSCN2136_mini.JPG"
260
+ expect(user.profile_image_uri_https(:original).to_s).to eq("https://si0.twimg.com/profile_images/67759670/DSCN2136.JPG")
261
+ expect(user.profile_image_uri_https(:bigger).to_s).to eq("https://si0.twimg.com/profile_images/67759670/DSCN2136_bigger.JPG")
262
+ expect(user.profile_image_uri_https(:mini).to_s).to eq("https://si0.twimg.com/profile_images/67759670/DSCN2136_mini.JPG")
235
263
  end
236
264
  end
237
265
  end
238
266
 
239
- describe "#profile_image_url?" do
267
+ describe "#profile_image_uri?" do
240
268
  it "returns true when profile_banner_url is set" do
241
- profile_image_url = Twitter::User.new(:id => 7505382, :profile_image_url_https => "https://si0.twimg.com/profile_banners/7505382/1348266581").profile_image_url?
242
- expect(profile_image_url).to be_true
269
+ user = Twitter::User.new(:id => 7505382, :profile_image_url_https => "https://si0.twimg.com/profile_banners/7505382/1348266581")
270
+ expect(user.profile_image_uri?).to be_true
243
271
  end
244
272
  it "returns false when status is not set" do
245
- profile_image_url= Twitter::User.new(:id => 7505382).profile_image_url?
246
- expect(profile_image_url).to be_false
273
+ user = Twitter::User.new(:id => 7505382)
274
+ expect(user.profile_image_uri?).to be_false
247
275
  end
248
276
  end
249
277
 
250
278
  describe "#status" do
251
279
  it "returns a Status when status is set" do
252
- tweet = Twitter::User.new(:id => 7505382, :status => {:id => 25938088801}).status
253
- expect(tweet).to be_a Twitter::Tweet
280
+ user = Twitter::User.new(:id => 7505382, :status => {:id => 25938088801})
281
+ expect(user.status).to be_a Twitter::Tweet
254
282
  end
255
283
  it "returns nil when status is not set" do
256
- tweet = Twitter::User.new(:id => 7505382).status
257
- expect(tweet).to be_nil
284
+ user = Twitter::User.new(:id => 7505382)
285
+ expect(user.status).to be_nil
258
286
  end
259
- it "includes a User when user is set" do
260
- tweet = Twitter::User.new(:id => 7505382, :screen_name => 'sferik', :status => {:id => 25938088801}).status
261
- expect(tweet.user).to be_a Twitter::User
262
- expect(tweet.user.id).to eq 7505382
287
+ it "has a user" do
288
+ user = Twitter::User.new(:id => 7505382, :status => {:id => 25938088801})
289
+ expect(user.status.user).to be_a Twitter::User
290
+ expect(user.status.user.id).to eq(7505382)
263
291
  end
264
292
  end
265
293
 
266
294
  describe "#status?" do
267
295
  it "returns true when status is set" do
268
- tweet = Twitter::User.new(:id => 7505382, :status => {:id => 25938088801}).status?
269
- expect(tweet).to be_true
296
+ user = Twitter::User.new(:id => 7505382, :status => {:id => 25938088801})
297
+ expect(user.status?).to be_true
270
298
  end
271
299
  it "returns false when status is not set" do
272
- tweet = Twitter::User.new(:id => 7505382).status?
273
- expect(tweet).to be_false
300
+ user = Twitter::User.new(:id => 7505382)
301
+ expect(user.status?).to be_false
302
+ end
303
+ end
304
+
305
+ describe "#uri" do
306
+ it "returns the URI to the user" do
307
+ user = Twitter::User.new(:id => 7505382, :screen_name => "sferik")
308
+ expect(user.uri).to be_a URI
309
+ expect(user.uri.to_s).to eq("https://twitter.com/sferik")
310
+ end
311
+ end
312
+
313
+ describe "#website" do
314
+ it "returns a URI when the url is set" do
315
+ user = Twitter::User.new(:id => 7505382, :url => "https://github.com/sferik")
316
+ expect(user.website).to be_a URI
317
+ expect(user.website.to_s).to eq("https://github.com/sferik")
318
+ end
319
+ it "returns nil when the url is not set" do
320
+ user = Twitter::User.new(:id => 7505382)
321
+ expect(user.website).to be_nil
322
+ end
323
+ end
324
+
325
+ describe "#website?" do
326
+ it "returns true when the url is set" do
327
+ user = Twitter::User.new(:id => 7505382, :url => "https://github.com/sferik")
328
+ expect(user.website?).to be_true
329
+ end
330
+ it "returns false when the url is not set" do
331
+ user = Twitter::User.new(:id => 7505382)
332
+ expect(user.website?).to be_false
274
333
  end
275
334
  end
276
335
 
@@ -1,119 +0,0 @@
1
- require 'helper'
2
-
3
- describe Twitter do
4
-
5
- after do
6
- Twitter.reset!
7
- end
8
-
9
- context "when delegating to a client" do
10
-
11
- before do
12
- stub_get("/1.1/statuses/user_timeline.json").with(:query => {:screen_name => "sferik"}).to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
13
- end
14
-
15
- it "requests the correct resource" do
16
- Twitter.user_timeline('sferik')
17
- expect(a_get("/1.1/statuses/user_timeline.json").with(:query => {:screen_name => "sferik"})).to have_been_made
18
- end
19
-
20
- it "returns the same results as a client" do
21
- expect(Twitter.user_timeline('sferik')).to eq Twitter::Client.new.user_timeline('sferik')
22
- end
23
-
24
- end
25
-
26
- describe ".respond_to?" do
27
- it "delegates to Twitter::Client" do
28
- expect(Twitter.respond_to?(:user)).to be_true
29
- end
30
- it "takes an optional argument" do
31
- expect(Twitter.respond_to?(:client, true)).to be_true
32
- end
33
- end
34
-
35
- describe ".client" do
36
- it "returns a Twitter::Client" do
37
- expect(Twitter.client).to be_a Twitter::Client
38
- end
39
-
40
- context "when the options don't change" do
41
- it "caches the client" do
42
- expect(Twitter.client).to eq Twitter.client
43
- end
44
- end
45
- context "when the options change" do
46
- it "busts the cache" do
47
- client1 = Twitter.client
48
- Twitter.configure do |config|
49
- config.consumer_key = 'abc'
50
- config.consumer_secret = '123'
51
- end
52
- client2 = Twitter.client
53
- expect(client1).not_to eq client2
54
- end
55
- end
56
- end
57
-
58
- describe ".configure" do
59
- Twitter::Configurable.keys.each do |key|
60
- it "sets the #{key.to_s.gsub('_', ' ')}" do
61
- Twitter.configure do |config|
62
- config.send("#{key}=", key)
63
- end
64
- expect(Twitter.instance_variable_get(:"@#{key}")).to eq key
65
- end
66
- end
67
-
68
- context "when invalid credentials are provided" do
69
- it "raises a ConfigurationError exception" do
70
- expect {
71
- Twitter.configure do |config|
72
- config.consumer_key = [12345, 54321]
73
- config.consumer_secret = 'valid_data'
74
- end
75
- }.to raise_exception(Twitter::Error::ConfigurationError)
76
- end
77
- end
78
-
79
- context "when no credentials are provided" do
80
- it "does not raise an exception" do
81
- expect {
82
- Twitter.configure do |config|
83
- config.consumer_key = nil
84
- config.consumer_secret = nil
85
- config.oauth_token = nil
86
- config.oauth_token_secret = nil
87
- end
88
- }.to_not raise_exception(Twitter::Error::ConfigurationError)
89
- end
90
- end
91
- end
92
-
93
- describe ".credentials?" do
94
- it "returns true if only bearer_token is supplied" do
95
- Twitter.configure do |config|
96
- config.bearer_token = 'BT'
97
- end
98
- expect(Twitter.credentials?).to be_true
99
- end
100
- it "returns true if all oauth credentials are present" do
101
- Twitter.configure do |config|
102
- config.consumer_key = 'CK'
103
- config.consumer_secret = 'CS'
104
- config.oauth_token = 'OT'
105
- config.oauth_token_secret = 'OS'
106
- end
107
- expect(Twitter.credentials?).to be_true
108
- end
109
- it "returns false if any credentials are missing" do
110
- Twitter.configure do |config|
111
- config.consumer_key = 'CK'
112
- config.consumer_secret = 'CS'
113
- config.oauth_token = 'OT'
114
- end
115
- expect(Twitter.credentials?).to be_false
116
- end
117
- end
118
-
119
- end