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.
- data.tar.gz.sig +0 -0
- data/CHANGELOG.md +30 -0
- data/LICENSE.md +1 -1
- data/README.md +386 -266
- data/lib/twitter.rb +4 -39
- data/lib/twitter/arguments.rb +11 -0
- data/lib/twitter/base.rb +89 -68
- data/lib/twitter/client.rb +69 -110
- data/lib/twitter/configuration.rb +7 -3
- data/lib/twitter/creatable.rb +2 -4
- data/lib/twitter/cursor.rb +50 -42
- data/lib/twitter/direct_message.rb +2 -11
- data/lib/twitter/entity/uri.rb +13 -0
- data/lib/twitter/enumerable.rb +15 -0
- data/lib/twitter/error.rb +55 -7
- data/lib/twitter/error/already_favorited.rb +1 -1
- data/lib/twitter/error/already_posted.rb +10 -0
- data/lib/twitter/error/already_retweeted.rb +1 -1
- data/lib/twitter/error/bad_gateway.rb +2 -3
- data/lib/twitter/error/bad_request.rb +2 -2
- data/lib/twitter/error/forbidden.rb +2 -2
- data/lib/twitter/error/gateway_timeout.rb +2 -3
- data/lib/twitter/error/internal_server_error.rb +2 -3
- data/lib/twitter/error/not_acceptable.rb +2 -2
- data/lib/twitter/error/not_found.rb +2 -2
- data/lib/twitter/error/service_unavailable.rb +2 -3
- data/lib/twitter/error/too_many_requests.rb +2 -2
- data/lib/twitter/error/unauthorized.rb +2 -2
- data/lib/twitter/error/unprocessable_entity.rb +2 -2
- data/lib/twitter/factory.rb +2 -8
- data/lib/twitter/geo_factory.rb +2 -2
- data/lib/twitter/geo_results.rb +36 -0
- data/lib/twitter/identity.rb +0 -22
- data/lib/twitter/list.rb +18 -4
- data/lib/twitter/media/photo.rb +3 -3
- data/lib/twitter/media_factory.rb +2 -2
- data/lib/twitter/null_object.rb +24 -0
- data/lib/twitter/oembed.rb +3 -2
- data/lib/twitter/place.rb +15 -9
- data/lib/twitter/profile_banner.rb +5 -3
- data/lib/twitter/rate_limit.rb +1 -17
- data/lib/twitter/relationship.rb +2 -10
- data/lib/twitter/rest/api/direct_messages.rb +135 -0
- data/lib/twitter/rest/api/favorites.rb +120 -0
- data/lib/twitter/rest/api/friends_and_followers.rb +290 -0
- data/lib/twitter/rest/api/help.rb +58 -0
- data/lib/twitter/rest/api/lists.rb +491 -0
- data/lib/twitter/rest/api/oauth.rb +45 -0
- data/lib/twitter/rest/api/places_and_geo.rb +104 -0
- data/lib/twitter/rest/api/saved_searches.rb +91 -0
- data/lib/twitter/rest/api/search.rb +37 -0
- data/lib/twitter/rest/api/spam_reporting.rb +29 -0
- data/lib/twitter/rest/api/suggested_users.rb +51 -0
- data/lib/twitter/rest/api/timelines.rb +202 -0
- data/lib/twitter/rest/api/trends.rb +58 -0
- data/lib/twitter/rest/api/tweets.rb +293 -0
- data/lib/twitter/rest/api/undocumented.rb +52 -0
- data/lib/twitter/rest/api/users.rb +383 -0
- data/lib/twitter/rest/api/utils.rb +219 -0
- data/lib/twitter/rest/client.rb +193 -0
- data/lib/twitter/rest/request/multipart_with_file.rb +36 -0
- data/lib/twitter/rest/response/parse_json.rb +27 -0
- data/lib/twitter/{response → rest/response}/raise_error.rb +8 -11
- data/lib/twitter/search_results.rb +33 -21
- data/lib/twitter/settings.rb +1 -6
- data/lib/twitter/size.rb +1 -1
- data/lib/twitter/streaming/client.rb +77 -0
- data/lib/twitter/streaming/connection.rb +22 -0
- data/lib/twitter/streaming/response.rb +30 -0
- data/lib/twitter/suggestion.rb +4 -2
- data/lib/twitter/token.rb +8 -0
- data/lib/twitter/trend.rb +2 -1
- data/lib/twitter/trend_results.rb +59 -0
- data/lib/twitter/tweet.rb +41 -85
- data/lib/twitter/user.rb +51 -41
- data/lib/twitter/version.rb +4 -4
- data/spec/fixtures/already_posted.json +1 -0
- data/spec/fixtures/ids_list.json +1 -1
- data/spec/fixtures/ids_list2.json +1 -1
- data/spec/fixtures/search.json +1 -1
- data/spec/fixtures/search_malformed.json +1 -1
- data/spec/fixtures/track_streaming.json +3 -0
- data/spec/helper.rb +8 -13
- data/spec/twitter/base_spec.rb +25 -99
- data/spec/twitter/configuration_spec.rb +1 -1
- data/spec/twitter/cursor_spec.rb +13 -31
- data/spec/twitter/direct_message_spec.rb +41 -8
- data/spec/twitter/entity/uri_spec.rb +74 -0
- data/spec/twitter/error_spec.rb +59 -11
- data/spec/twitter/geo/point_spec.rb +1 -1
- data/spec/twitter/geo_factory_spec.rb +3 -3
- data/spec/twitter/geo_results_spec.rb +35 -0
- data/spec/twitter/identifiable_spec.rb +0 -21
- data/spec/twitter/list_spec.rb +51 -8
- data/spec/twitter/media/photo_spec.rb +118 -3
- data/spec/twitter/media_factory_spec.rb +2 -2
- data/spec/twitter/null_object_spec.rb +26 -0
- data/spec/twitter/oembed_spec.rb +69 -45
- data/spec/twitter/place_spec.rb +68 -12
- data/spec/twitter/profile_banner_spec.rb +1 -1
- data/spec/twitter/rate_limit_spec.rb +12 -12
- data/spec/twitter/relationship_spec.rb +31 -9
- data/spec/twitter/{api → rest/api}/direct_messages_spec.rb +22 -9
- data/spec/twitter/{api → rest/api}/favorites_spec.rb +80 -7
- data/spec/twitter/{api → rest/api}/friends_and_followers_spec.rb +104 -65
- data/spec/twitter/{api → rest/api}/geo_spec.rb +10 -10
- data/spec/twitter/{api → rest/api}/help_spec.rb +6 -6
- data/spec/twitter/{api → rest/api}/lists_spec.rb +77 -56
- data/spec/twitter/{api → rest/api}/oauth_spec.rb +6 -6
- data/spec/twitter/{api → rest/api}/saved_searches_spec.rb +7 -7
- data/spec/twitter/{api → rest/api}/search_spec.rb +8 -9
- data/spec/twitter/{api → rest/api}/spam_reporting_spec.rb +3 -3
- data/spec/twitter/{api → rest/api}/suggested_users_spec.rb +5 -5
- data/spec/twitter/{api → rest/api}/timelines_spec.rb +9 -9
- data/spec/twitter/{api → rest/api}/trends_spec.rb +6 -6
- data/spec/twitter/rest/api/tweets_spec.rb +503 -0
- data/spec/twitter/{api → rest/api}/undocumented_spec.rb +19 -45
- data/spec/twitter/{api → rest/api}/users_spec.rb +60 -35
- data/spec/twitter/rest/client_spec.rb +193 -0
- data/spec/twitter/saved_search_spec.rb +11 -0
- data/spec/twitter/search_results_spec.rb +29 -42
- data/spec/twitter/settings_spec.rb +17 -6
- data/spec/twitter/streaming/client_spec.rb +75 -0
- data/spec/twitter/token_spec.rb +16 -0
- data/spec/twitter/trend_results_spec.rb +89 -0
- data/spec/twitter/trend_spec.rb +23 -0
- data/spec/twitter/tweet_spec.rb +122 -115
- data/spec/twitter/user_spec.rb +136 -77
- data/spec/twitter_spec.rb +0 -119
- data/twitter.gemspec +8 -5
- metadata +148 -141
- metadata.gz.sig +0 -0
- data/lib/twitter/action/favorite.rb +0 -19
- data/lib/twitter/action/follow.rb +0 -30
- data/lib/twitter/action/list_member_added.rb +0 -39
- data/lib/twitter/action/mention.rb +0 -46
- data/lib/twitter/action/reply.rb +0 -27
- data/lib/twitter/action/retweet.rb +0 -27
- data/lib/twitter/action/tweet.rb +0 -20
- data/lib/twitter/action_factory.rb +0 -22
- data/lib/twitter/api/arguments.rb +0 -13
- data/lib/twitter/api/direct_messages.rb +0 -148
- data/lib/twitter/api/favorites.rb +0 -126
- data/lib/twitter/api/friends_and_followers.rb +0 -334
- data/lib/twitter/api/help.rb +0 -64
- data/lib/twitter/api/lists.rb +0 -618
- data/lib/twitter/api/oauth.rb +0 -44
- data/lib/twitter/api/places_and_geo.rb +0 -121
- data/lib/twitter/api/saved_searches.rb +0 -99
- data/lib/twitter/api/search.rb +0 -37
- data/lib/twitter/api/spam_reporting.rb +0 -30
- data/lib/twitter/api/suggested_users.rb +0 -55
- data/lib/twitter/api/timelines.rb +0 -214
- data/lib/twitter/api/trends.rb +0 -63
- data/lib/twitter/api/tweets.rb +0 -304
- data/lib/twitter/api/undocumented.rb +0 -97
- data/lib/twitter/api/users.rb +0 -439
- data/lib/twitter/api/utils.rb +0 -187
- data/lib/twitter/configurable.rb +0 -96
- data/lib/twitter/default.rb +0 -102
- data/lib/twitter/entity/url.rb +0 -9
- data/lib/twitter/error/client_error.rb +0 -35
- data/lib/twitter/error/decode_error.rb +0 -9
- data/lib/twitter/error/identity_map_key_error.rb +0 -9
- data/lib/twitter/error/server_error.rb +0 -28
- data/lib/twitter/exceptable.rb +0 -36
- data/lib/twitter/identity_map.rb +0 -22
- data/lib/twitter/request/multipart_with_file.rb +0 -34
- data/lib/twitter/response/parse_json.rb +0 -25
- data/spec/fixtures/about_me.json +0 -1
- data/spec/fixtures/activity_summary.json +0 -1
- data/spec/fixtures/bad_gateway.json +0 -1
- data/spec/fixtures/bad_request.json +0 -1
- data/spec/fixtures/by_friends.json +0 -1
- data/spec/fixtures/end_session.json +0 -1
- data/spec/fixtures/forbidden.json +0 -1
- data/spec/fixtures/internal_server_error.json +0 -1
- data/spec/fixtures/not_acceptable.json +0 -1
- data/spec/fixtures/phoenix_search.phoenix +0 -1
- data/spec/fixtures/resolve.json +0 -1
- data/spec/fixtures/service_unavailable.json +0 -1
- data/spec/fixtures/totals.json +0 -1
- data/spec/fixtures/trends.json +0 -1
- data/spec/fixtures/unauthorized.json +0 -1
- data/spec/fixtures/video_facets.json +0 -1
- data/spec/twitter/action/favorite_spec.rb +0 -29
- data/spec/twitter/action/follow_spec.rb +0 -29
- data/spec/twitter/action/list_member_added_spec.rb +0 -41
- data/spec/twitter/action/mention_spec.rb +0 -52
- data/spec/twitter/action/reply_spec.rb +0 -41
- data/spec/twitter/action/retweet_spec.rb +0 -41
- data/spec/twitter/action_factory_spec.rb +0 -35
- data/spec/twitter/action_spec.rb +0 -16
- data/spec/twitter/api/tweets_spec.rb +0 -285
- data/spec/twitter/client_spec.rb +0 -223
- data/spec/twitter/error/client_error_spec.rb +0 -23
- data/spec/twitter/error/server_error_spec.rb +0 -20
data/spec/twitter/user_spec.rb
CHANGED
@@ -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 "#
|
35
|
-
it "returns
|
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 =>
|
39
|
-
:expanded_url =>
|
40
|
-
:display_url =>
|
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
|
-
|
45
|
-
expect(
|
46
|
-
expect(
|
47
|
-
expect(
|
48
|
-
expect(
|
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
|
-
|
52
|
-
expect(
|
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 "#
|
57
|
-
it "
|
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.
|
75
|
+
expect(user.profile_banner_uri).to be_a URI
|
60
76
|
end
|
61
|
-
it "returns nil when
|
77
|
+
it "returns nil when profile_banner_uri is not set" do
|
62
78
|
user = Twitter::User.new(:id => 7505382)
|
63
|
-
expect(user.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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 "#
|
102
|
-
it "
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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 "#
|
166
|
+
describe "#profile_banner_uri?" do
|
147
167
|
it "returns true when profile_banner_url is set" do
|
148
|
-
|
149
|
-
expect(
|
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
|
-
|
153
|
-
expect(
|
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 "#
|
158
|
-
it "
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
192
|
-
expect(user.
|
193
|
-
expect(user.
|
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 "#
|
199
|
-
it "
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
233
|
-
expect(user.
|
234
|
-
expect(user.
|
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 "#
|
267
|
+
describe "#profile_image_uri?" do
|
240
268
|
it "returns true when profile_banner_url is set" do
|
241
|
-
|
242
|
-
expect(
|
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
|
-
|
246
|
-
expect(
|
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
|
-
|
253
|
-
expect(
|
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
|
-
|
257
|
-
expect(
|
284
|
+
user = Twitter::User.new(:id => 7505382)
|
285
|
+
expect(user.status).to be_nil
|
258
286
|
end
|
259
|
-
it "
|
260
|
-
|
261
|
-
expect(
|
262
|
-
expect(
|
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
|
-
|
269
|
-
expect(
|
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
|
-
|
273
|
-
expect(
|
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
|
|
data/spec/twitter_spec.rb
CHANGED
@@ -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
|