twitter 5.0.0.rc.1 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data.tar.gz.sig +0 -0
- data/CHANGELOG.md +7 -1
- data/CONTRIBUTING.md +13 -15
- data/README.md +53 -33
- data/Rakefile +6 -0
- data/lib/twitter/arguments.rb +3 -0
- data/lib/twitter/base.rb +88 -89
- data/lib/twitter/client.rb +5 -41
- data/lib/twitter/configuration.rb +4 -5
- data/lib/twitter/core_ext/kernel.rb +5 -1
- data/lib/twitter/creatable.rb +6 -1
- data/lib/twitter/cursor.rb +16 -12
- data/lib/twitter/entity/uri.rb +2 -1
- data/lib/twitter/enumerable.rb +1 -1
- data/lib/twitter/error.rb +42 -39
- data/lib/twitter/factory.rb +12 -5
- data/lib/twitter/geo.rb +2 -7
- data/lib/twitter/geo_factory.rb +11 -7
- data/lib/twitter/geo_results.rb +12 -8
- data/lib/twitter/identity.rb +4 -12
- data/lib/twitter/list.rb +6 -3
- data/lib/twitter/media/photo.rb +5 -3
- data/lib/twitter/media_factory.rb +11 -7
- data/lib/twitter/null_object.rb +4 -3
- data/lib/twitter/place.rb +10 -16
- data/lib/twitter/profile_banner.rb +4 -5
- data/lib/twitter/rate_limit.rb +3 -0
- data/lib/twitter/relationship.rb +0 -9
- data/lib/twitter/rest/api/direct_messages.rb +9 -6
- data/lib/twitter/rest/api/favorites.rb +6 -11
- data/lib/twitter/rest/api/friends_and_followers.rb +6 -9
- data/lib/twitter/rest/api/lists.rb +27 -20
- data/lib/twitter/rest/api/oauth.rb +17 -0
- data/lib/twitter/rest/api/places_and_geo.rb +0 -18
- data/lib/twitter/rest/api/saved_searches.rb +6 -4
- data/lib/twitter/rest/api/suggested_users.rb +2 -2
- data/lib/twitter/rest/api/tweets.rb +7 -9
- data/lib/twitter/rest/api/users.rb +6 -6
- data/lib/twitter/rest/api/utils.rb +44 -17
- data/lib/twitter/rest/client.rb +25 -43
- data/lib/twitter/rest/response/parse_error_json.rb +15 -0
- data/lib/twitter/rest/response/parse_json.rb +5 -1
- data/lib/twitter/search_results.rb +12 -8
- data/lib/twitter/size.rb +2 -15
- data/lib/twitter/streaming/client.rb +23 -11
- data/lib/twitter/streaming/event.rb +35 -0
- data/lib/twitter/streaming/friend_list.rb +13 -0
- data/lib/twitter/streaming/message_parser.rb +18 -0
- data/lib/twitter/streaming/response.rb +4 -0
- data/lib/twitter/suggestion.rb +5 -10
- data/lib/twitter/token.rb +3 -1
- data/lib/twitter/trend.rb +2 -7
- data/lib/twitter/trend_results.rb +20 -14
- data/lib/twitter/tweet.rb +18 -23
- data/lib/twitter/user.rb +34 -19
- data/lib/twitter/version.rb +1 -1
- data/spec/fixtures/request_token.txt +6 -0
- data/spec/fixtures/track_streaming_user.json +5 -0
- data/spec/twitter/base_spec.rb +0 -16
- data/spec/twitter/basic_user_spec.rb +3 -3
- data/spec/twitter/cursor_spec.rb +4 -4
- data/spec/twitter/direct_message_spec.rb +9 -9
- data/spec/twitter/entity/uri_spec.rb +12 -11
- data/spec/twitter/geo/point_spec.rb +5 -5
- data/spec/twitter/geo/polygon_spec.rb +5 -5
- data/spec/twitter/geo_factory_spec.rb +2 -2
- data/spec/twitter/geo_spec.rb +6 -6
- data/spec/twitter/identifiable_spec.rb +5 -5
- data/spec/twitter/list_spec.rb +7 -7
- data/spec/twitter/media/photo_spec.rb +19 -18
- data/spec/twitter/media_factory_spec.rb +2 -2
- data/spec/twitter/null_object_spec.rb +7 -6
- data/spec/twitter/oembed_spec.rb +6 -6
- data/spec/twitter/place_spec.rb +37 -37
- data/spec/twitter/rate_limit_spec.rb +0 -17
- data/spec/twitter/relationship_spec.rb +4 -12
- data/spec/twitter/rest/api/direct_messages_spec.rb +8 -8
- data/spec/twitter/rest/api/friends_and_followers_spec.rb +50 -120
- data/spec/twitter/rest/api/geo_spec.rb +0 -14
- data/spec/twitter/rest/api/lists_spec.rb +39 -39
- data/spec/twitter/rest/api/oauth_spec.rb +15 -4
- data/spec/twitter/rest/api/saved_searches_spec.rb +6 -6
- data/spec/twitter/rest/api/tweets_spec.rb +6 -6
- data/spec/twitter/rest/api/users_spec.rb +4 -4
- data/spec/twitter/rest/client_spec.rb +9 -9
- data/spec/twitter/saved_search_spec.rb +5 -5
- data/spec/twitter/search_results_spec.rb +3 -3
- data/spec/twitter/settings_spec.rb +2 -2
- data/spec/twitter/size_spec.rb +5 -15
- data/spec/twitter/source_user_spec.rb +3 -3
- data/spec/twitter/streaming/client_spec.rb +33 -16
- data/spec/twitter/streaming/event_spec.rb +45 -0
- data/spec/twitter/suggestion_spec.rb +5 -15
- data/spec/twitter/target_user_spec.rb +3 -3
- data/spec/twitter/token_spec.rb +2 -2
- data/spec/twitter/trend_results_spec.rb +6 -6
- data/spec/twitter/trend_spec.rb +7 -17
- data/spec/twitter/tweet_spec.rb +31 -25
- data/spec/twitter/user_spec.rb +16 -16
- data/twitter.gemspec +5 -2
- metadata +67 -15
- metadata.gz.sig +0 -0
@@ -18,10 +18,7 @@ describe Twitter::REST::API::OAuth do
|
|
18
18
|
end
|
19
19
|
it "requests with the correct headers" do
|
20
20
|
@client.token
|
21
|
-
expect(a_request(:post, @oauth2_token_url).with(:headers => {
|
22
|
-
:content_type => "application/x-www-form-urlencoded; charset=UTF-8",
|
23
|
-
:accept => "*/*"
|
24
|
-
})).to have_been_made
|
21
|
+
expect(a_request(:post, @oauth2_token_url).with(:headers => {:content_type => "application/x-www-form-urlencoded; charset=UTF-8", :accept => "*/*"})).to have_been_made
|
25
22
|
end
|
26
23
|
it "returns the bearer token" do
|
27
24
|
bearer_token = @client.token
|
@@ -53,4 +50,18 @@ describe Twitter::REST::API::OAuth do
|
|
53
50
|
end
|
54
51
|
end
|
55
52
|
|
53
|
+
describe "#reverse_token" do
|
54
|
+
before do
|
55
|
+
# WebMock treats Basic Auth differently so we have to chack against the full URL with credentials.
|
56
|
+
@oauth_request_token_url = "https://api.twitter.com/oauth/request_token?x_auth_mode=reverse_auth"
|
57
|
+
stub_request(:post, @oauth_request_token_url).to_return(:body => fixture('request_token.txt'), :headers => {:content_type => "text/html; charset=utf-8"})
|
58
|
+
end
|
59
|
+
it "requests the correct resource" do
|
60
|
+
@client.reverse_token
|
61
|
+
expect(a_request(:post, @oauth_request_token_url).with(:params => {:x_auth_mode => "reverse_auth"})).to have_been_made
|
62
|
+
end
|
63
|
+
it "requests the correct resource" do
|
64
|
+
expect(@client.reverse_token).to eql fixture('request_token.txt').read
|
65
|
+
end
|
66
|
+
end
|
56
67
|
end
|
@@ -54,31 +54,31 @@ describe Twitter::REST::API::SavedSearches do
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
describe "#
|
57
|
+
describe "#create_saved_search" do
|
58
58
|
before do
|
59
59
|
stub_post("/1.1/saved_searches/create.json").with(:body => {:query => "twitter"}).to_return(:body => fixture("saved_search.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
60
60
|
end
|
61
61
|
it "requests the correct resource" do
|
62
|
-
@client.
|
62
|
+
@client.create_saved_search("twitter")
|
63
63
|
expect(a_post("/1.1/saved_searches/create.json").with(:body => {:query => "twitter"})).to have_been_made
|
64
64
|
end
|
65
65
|
it "returns the created saved search" do
|
66
|
-
saved_search = @client.
|
66
|
+
saved_search = @client.create_saved_search("twitter")
|
67
67
|
expect(saved_search).to be_a Twitter::SavedSearch
|
68
68
|
expect(saved_search.name).to eq("twitter")
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
-
describe "#
|
72
|
+
describe "#destroy_saved_search" do
|
73
73
|
before do
|
74
74
|
stub_post("/1.1/saved_searches/destroy/16129012.json").to_return(:body => fixture("saved_search.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
75
75
|
end
|
76
76
|
it "requests the correct resource" do
|
77
|
-
@client.
|
77
|
+
@client.destroy_saved_search(16129012)
|
78
78
|
expect(a_post("/1.1/saved_searches/destroy/16129012.json")).to have_been_made
|
79
79
|
end
|
80
80
|
it "returns an array of deleted saved searches" do
|
81
|
-
saved_searches = @client.
|
81
|
+
saved_searches = @client.destroy_saved_search(16129012)
|
82
82
|
expect(saved_searches).to be_an Array
|
83
83
|
expect(saved_searches.first).to be_a Twitter::SavedSearch
|
84
84
|
expect(saved_searches.first.name).to eq("twitter")
|
@@ -169,16 +169,16 @@ describe Twitter::REST::API::Tweets do
|
|
169
169
|
end
|
170
170
|
end
|
171
171
|
|
172
|
-
describe "#
|
172
|
+
describe "#destroy_status" do
|
173
173
|
before do
|
174
174
|
stub_post("/1.1/statuses/destroy/25938088801.json").to_return(:body => fixture("status.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
175
175
|
end
|
176
176
|
it "requests the correct resource" do
|
177
|
-
@client.
|
177
|
+
@client.destroy_status(25938088801)
|
178
178
|
expect(a_post("/1.1/statuses/destroy/25938088801.json")).to have_been_made
|
179
179
|
end
|
180
180
|
it "returns an array of Tweets" do
|
181
|
-
tweets = @client.
|
181
|
+
tweets = @client.destroy_status(25938088801)
|
182
182
|
expect(tweets).to be_an Array
|
183
183
|
expect(tweets.first).to be_a Twitter::Tweet
|
184
184
|
expect(tweets.first.text).to eq("The problem with your code is that it's doing exactly what you told it to do.")
|
@@ -186,20 +186,20 @@ describe Twitter::REST::API::Tweets do
|
|
186
186
|
context "with a URI object passed" do
|
187
187
|
it "requests the correct resource" do
|
188
188
|
tweet = URI.parse("https://twitter.com/sferik/status/25938088801")
|
189
|
-
@client.
|
189
|
+
@client.destroy_status(tweet)
|
190
190
|
expect(a_post("/1.1/statuses/destroy/25938088801.json")).to have_been_made
|
191
191
|
end
|
192
192
|
end
|
193
193
|
context "with a URI string passed" do
|
194
194
|
it "requests the correct resource" do
|
195
|
-
@client.
|
195
|
+
@client.destroy_status("https://twitter.com/sferik/status/25938088801")
|
196
196
|
expect(a_post("/1.1/statuses/destroy/25938088801.json")).to have_been_made
|
197
197
|
end
|
198
198
|
end
|
199
199
|
context "with a Tweet passed" do
|
200
200
|
it "requests the correct resource" do
|
201
201
|
tweet = Twitter::Tweet.new(:id => 25938088801)
|
202
|
-
@client.
|
202
|
+
@client.destroy_status(tweet)
|
203
203
|
expect(a_post("/1.1/statuses/destroy/25938088801.json")).to have_been_made
|
204
204
|
end
|
205
205
|
end
|
@@ -238,11 +238,11 @@ describe Twitter::REST::API::Users do
|
|
238
238
|
end
|
239
239
|
it "returns true if block exists" do
|
240
240
|
block = @client.block?("pengwynn")
|
241
|
-
expect(block).to
|
241
|
+
expect(block).to be true
|
242
242
|
end
|
243
243
|
it "returns false if block does not exist" do
|
244
244
|
block = @client.block?("sferik")
|
245
|
-
expect(block).to
|
245
|
+
expect(block).to be false
|
246
246
|
end
|
247
247
|
end
|
248
248
|
context "with a user ID passed" do
|
@@ -528,11 +528,11 @@ describe Twitter::REST::API::Users do
|
|
528
528
|
end
|
529
529
|
it "returns true if user exists" do
|
530
530
|
user = @client.user?("sferik")
|
531
|
-
expect(user).to
|
531
|
+
expect(user).to be true
|
532
532
|
end
|
533
533
|
it "returns false if user does not exist" do
|
534
534
|
user = @client.user?("pengwynn")
|
535
|
-
expect(user).to
|
535
|
+
expect(user).to be false
|
536
536
|
end
|
537
537
|
end
|
538
538
|
|
@@ -27,15 +27,15 @@ describe Twitter::REST::Client do
|
|
27
27
|
describe ".credentials?" do
|
28
28
|
it "returns true if only bearer_token is supplied" do
|
29
29
|
client = Twitter::REST::Client.new(:bearer_token => "BT")
|
30
|
-
expect(client.credentials?).to
|
30
|
+
expect(client.credentials?).to be true
|
31
31
|
end
|
32
32
|
it "returns true if all OAuth credentials are present" do
|
33
33
|
client = Twitter::REST::Client.new(:consumer_key => "CK", :consumer_secret => "CS", :access_token => "AT", :access_token_secret => "AS")
|
34
|
-
expect(client.credentials?).to
|
34
|
+
expect(client.credentials?).to be true
|
35
35
|
end
|
36
36
|
it "returns false if any credentials are missing" do
|
37
37
|
client = Twitter::REST::Client.new(:consumer_key => "CK", :consumer_secret => "CS", :access_token => "AT")
|
38
|
-
expect(client.credentials?).to
|
38
|
+
expect(client.credentials?).to be false
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -70,33 +70,33 @@ describe Twitter::REST::Client do
|
|
70
70
|
describe "#user_token?" do
|
71
71
|
it "returns true if the user token/secret are present" do
|
72
72
|
client = Twitter::REST::Client.new(:consumer_key => "CK", :consumer_secret => "CS", :access_token => "AT", :access_token_secret => "AS")
|
73
|
-
expect(client.user_token?).to
|
73
|
+
expect(client.user_token?).to be true
|
74
74
|
end
|
75
75
|
it "returns false if the user token/secret are not completely present" do
|
76
76
|
client = Twitter::REST::Client.new(:consumer_key => "CK", :consumer_secret => "CS", :access_token => "AT")
|
77
|
-
expect(client.user_token?).to
|
77
|
+
expect(client.user_token?).to be false
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
81
|
describe "#bearer_token?" do
|
82
82
|
it "returns true if the app token is present" do
|
83
83
|
client = Twitter::REST::Client.new(:consumer_key => "CK", :consumer_secret => "CS", :bearer_token => "BT")
|
84
|
-
expect(client.bearer_token?).to
|
84
|
+
expect(client.bearer_token?).to be true
|
85
85
|
end
|
86
86
|
it "returns false if the bearer_token is not present" do
|
87
87
|
client = Twitter::REST::Client.new(:consumer_key => "CK", :consumer_secret => "CS")
|
88
|
-
expect(client.bearer_token?).to
|
88
|
+
expect(client.bearer_token?).to be false
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
92
|
describe "#credentials?" do
|
93
93
|
it "returns true if all credentials are present" do
|
94
94
|
client = Twitter::REST::Client.new(:consumer_key => "CK", :consumer_secret => "CS", :access_token => "AT", :access_token_secret => "AS")
|
95
|
-
expect(client.credentials?).to
|
95
|
+
expect(client.credentials?).to be true
|
96
96
|
end
|
97
97
|
it "returns false if any credentials are missing" do
|
98
98
|
client = Twitter::REST::Client.new(:consumer_key => "CK", :consumer_secret => "CS", :access_token => "AT")
|
99
|
-
expect(client.credentials?).to
|
99
|
+
expect(client.credentials?).to be false
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
@@ -6,17 +6,17 @@ describe Twitter::SavedSearch do
|
|
6
6
|
it "returns true when objects IDs are the same" do
|
7
7
|
saved_search = Twitter::SavedSearch.new(:id => 1, :name => "foo")
|
8
8
|
other = Twitter::SavedSearch.new(:id => 1, :name => "bar")
|
9
|
-
expect(saved_search == other).to
|
9
|
+
expect(saved_search == other).to be true
|
10
10
|
end
|
11
11
|
it "returns false when objects IDs are different" do
|
12
12
|
saved_search = Twitter::SavedSearch.new(:id => 1)
|
13
13
|
other = Twitter::SavedSearch.new(:id => 2)
|
14
|
-
expect(saved_search == other).to
|
14
|
+
expect(saved_search == other).to be false
|
15
15
|
end
|
16
16
|
it "returns false when classes are different" do
|
17
17
|
saved_search = Twitter::SavedSearch.new(:id => 1)
|
18
18
|
other = Twitter::Identity.new(:id => 1)
|
19
|
-
expect(saved_search == other).to
|
19
|
+
expect(saved_search == other).to be false
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -34,11 +34,11 @@ describe Twitter::SavedSearch do
|
|
34
34
|
describe "#created?" do
|
35
35
|
it "returns true when created_at is set" do
|
36
36
|
saved_search = Twitter::SavedSearch.new(:id => 16129012, :created_at => "Mon Jul 16 12:59:01 +0000 2007")
|
37
|
-
expect(saved_search.created?).to
|
37
|
+
expect(saved_search.created?).to be true
|
38
38
|
end
|
39
39
|
it "returns false when created_at is not set" do
|
40
40
|
saved_search = Twitter::SavedSearch.new(:id => 16129012)
|
41
|
-
expect(saved_search.created?).to
|
41
|
+
expect(saved_search.created?).to be false
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -95,15 +95,15 @@ describe Twitter::SearchResults do
|
|
95
95
|
describe "#next_results?" do
|
96
96
|
it "returns true when next_results is set" do
|
97
97
|
next_results = Twitter::SearchResults.new(:search_metadata => {:next_results => "?"}).next_results?
|
98
|
-
expect(next_results).to
|
98
|
+
expect(next_results).to be true
|
99
99
|
end
|
100
100
|
it "returns false when next_results is not set" do
|
101
101
|
next_results = Twitter::SearchResults.new(:search_metadata => {}).next_results?
|
102
|
-
expect(next_results).to
|
102
|
+
expect(next_results).to be false
|
103
103
|
end
|
104
104
|
it "returns false is search_metadata is not set" do
|
105
105
|
next_results = Twitter::SearchResults.new().next_results?
|
106
|
-
expect(next_results).to
|
106
|
+
expect(next_results).to be false
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
@@ -16,11 +16,11 @@ describe Twitter::Settings do
|
|
16
16
|
describe "#trend_location?" do
|
17
17
|
it "returns true when trend_location is set" do
|
18
18
|
settings = Twitter::Settings.new(:trend_location => {:countryCode => "US", :name => "San Francisco", :country => "United States", :placeType => {:name => "Town", :code => 7}, :woeid => 2487956, :parentid => 23424977, :url => "http://where.yahooapis.com/v1/place/2487956"})
|
19
|
-
expect(settings.trend_location?).to
|
19
|
+
expect(settings.trend_location?).to be true
|
20
20
|
end
|
21
21
|
it "returns false when trend_location is not set" do
|
22
22
|
settings = Twitter::Settings.new
|
23
|
-
expect(settings.trend_location?).to
|
23
|
+
expect(settings.trend_location?).to be false
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
data/spec/twitter/size_spec.rb
CHANGED
@@ -3,35 +3,25 @@ require 'helper'
|
|
3
3
|
describe Twitter::Size do
|
4
4
|
|
5
5
|
describe "#==" do
|
6
|
-
it "returns
|
6
|
+
it "returns true for empty objects" do
|
7
7
|
size = Twitter::Size.new
|
8
8
|
other = Twitter::Size.new
|
9
|
-
expect(size == other).to
|
9
|
+
expect(size == other).to be true
|
10
10
|
end
|
11
11
|
it "returns true when objects height and width are the same" do
|
12
12
|
size = Twitter::Size.new(:h => 1, :w => 1, :resize => true)
|
13
13
|
other = Twitter::Size.new(:h => 1, :w => 1, :resize => false)
|
14
|
-
expect(size == other).to
|
14
|
+
expect(size == other).to be true
|
15
15
|
end
|
16
16
|
it "returns false when objects height or width are different" do
|
17
17
|
size = Twitter::Size.new(:h => 1, :w => 1)
|
18
18
|
other = Twitter::Size.new(:h => 1, :w => 2)
|
19
|
-
expect(size == other).to
|
19
|
+
expect(size == other).to be false
|
20
20
|
end
|
21
21
|
it "returns false when classes are different" do
|
22
22
|
size = Twitter::Size.new(:h => 1, :w => 1)
|
23
23
|
other = Twitter::Base.new(:h => 1, :w => 1)
|
24
|
-
expect(size == other).to
|
25
|
-
end
|
26
|
-
it "returns true when objects non-height and width attributes are the same" do
|
27
|
-
size = Twitter::Size.new(:resize => true)
|
28
|
-
other = Twitter::Size.new(:resize => true)
|
29
|
-
expect(size == other).to be_true
|
30
|
-
end
|
31
|
-
it "returns false when objects non-height and width attributes are different" do
|
32
|
-
size = Twitter::Size.new(:resize => true)
|
33
|
-
other = Twitter::Size.new(:resize => false)
|
34
|
-
expect(size == other).to be_false
|
24
|
+
expect(size == other).to be false
|
35
25
|
end
|
36
26
|
end
|
37
27
|
|
@@ -6,17 +6,17 @@ describe Twitter::SourceUser do
|
|
6
6
|
it "returns true when objects IDs are the same" do
|
7
7
|
saved_search = Twitter::SourceUser.new(:id => 1, :name => "foo")
|
8
8
|
other = Twitter::SourceUser.new(:id => 1, :name => "bar")
|
9
|
-
expect(saved_search == other).to
|
9
|
+
expect(saved_search == other).to be true
|
10
10
|
end
|
11
11
|
it "returns false when objects IDs are different" do
|
12
12
|
saved_search = Twitter::SourceUser.new(:id => 1)
|
13
13
|
other = Twitter::SourceUser.new(:id => 2)
|
14
|
-
expect(saved_search == other).to
|
14
|
+
expect(saved_search == other).to be false
|
15
15
|
end
|
16
16
|
it "returns false when classes are different" do
|
17
17
|
saved_search = Twitter::SourceUser.new(:id => 1)
|
18
18
|
other = Twitter::Identity.new(:id => 1)
|
19
|
-
expect(saved_search == other).to
|
19
|
+
expect(saved_search == other).to be false
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -17,59 +17,76 @@ describe Twitter::Streaming::Client do
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
it "
|
20
|
+
it "#before_request" do
|
21
|
+
@client.connection = FakeConnection.new(fixture("track_streaming.json"))
|
22
|
+
var = false
|
23
|
+
@client.before_request do
|
24
|
+
var = true
|
25
|
+
end
|
26
|
+
expect(var).to be false
|
27
|
+
@client.user{}
|
28
|
+
expect(var).to be true
|
29
|
+
end
|
30
|
+
|
31
|
+
it "#filter" do
|
21
32
|
@client.connection = FakeConnection.new(fixture("track_streaming.json"))
|
22
33
|
tweets = []
|
23
34
|
@client.filter(:track => "india") do |tweet|
|
24
35
|
tweets << tweet
|
25
36
|
end
|
26
|
-
expect(tweets).to
|
37
|
+
expect(tweets.size).to eq(2)
|
27
38
|
expect(tweets.first).to be_a Twitter::Tweet
|
28
39
|
expect(tweets.first.text).to eq "The problem with your code is that it's doing exactly what you told it to do."
|
29
40
|
end
|
30
41
|
|
31
|
-
it "
|
42
|
+
it "#firehose" do
|
32
43
|
@client.connection = FakeConnection.new(fixture("track_streaming.json"))
|
33
44
|
tweets = []
|
34
45
|
@client.firehose do |tweet|
|
35
46
|
tweets << tweet
|
36
47
|
end
|
37
|
-
expect(tweets).to
|
48
|
+
expect(tweets.size).to eq(2)
|
38
49
|
expect(tweets.first).to be_a Twitter::Tweet
|
39
50
|
expect(tweets.first.text).to eq "The problem with your code is that it's doing exactly what you told it to do."
|
40
51
|
end
|
41
52
|
|
42
|
-
it "
|
53
|
+
it "#sample" do
|
43
54
|
@client.connection = FakeConnection.new(fixture("track_streaming.json"))
|
44
55
|
tweets = []
|
45
56
|
@client.sample do |tweet|
|
46
57
|
tweets << tweet
|
47
58
|
end
|
48
|
-
expect(tweets).to
|
59
|
+
expect(tweets.size).to eq(2)
|
49
60
|
expect(tweets.first).to be_a Twitter::Tweet
|
50
61
|
expect(tweets.first.text).to eq "The problem with your code is that it's doing exactly what you told it to do."
|
51
62
|
end
|
52
63
|
|
53
|
-
it "
|
64
|
+
it "#site" do
|
54
65
|
@client.connection = FakeConnection.new(fixture("track_streaming.json"))
|
55
66
|
tweets = []
|
56
67
|
@client.site(7505382) do |tweet|
|
57
68
|
tweets << tweet
|
58
69
|
end
|
59
|
-
expect(tweets).to
|
70
|
+
expect(tweets.size).to eq(2)
|
60
71
|
expect(tweets.first).to be_a Twitter::Tweet
|
61
72
|
expect(tweets.first.text).to eq "The problem with your code is that it's doing exactly what you told it to do."
|
62
73
|
end
|
63
74
|
|
64
|
-
it "
|
65
|
-
@client.connection = FakeConnection.new(fixture("
|
66
|
-
|
67
|
-
@client.user do |
|
68
|
-
|
75
|
+
it "#user" do
|
76
|
+
@client.connection = FakeConnection.new(fixture("track_streaming_user.json"))
|
77
|
+
items = []
|
78
|
+
@client.user do |item|
|
79
|
+
items << item
|
69
80
|
end
|
70
|
-
expect(
|
71
|
-
expect(
|
72
|
-
expect(
|
81
|
+
expect(items.size).to eq(5)
|
82
|
+
expect(items[0]).to be_a Twitter::Streaming::FriendList
|
83
|
+
expect(items[0].friend_ids).to eq([488736931,311444249])
|
84
|
+
expect(items[1]).to be_a Twitter::Tweet
|
85
|
+
expect(items[1].text).to eq "The problem with your code is that it's doing exactly what you told it to do."
|
86
|
+
expect(items[3]).to be_a Twitter::DirectMessage
|
87
|
+
expect(items[3].text).to eq "hello bot"
|
88
|
+
expect(items[4]).to be_a Twitter::Streaming::Event
|
89
|
+
expect(items[4].name).to be(:follow)
|
73
90
|
end
|
74
91
|
|
75
92
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Twitter::Streaming::Event do
|
4
|
+
describe "#initialize" do
|
5
|
+
before(:each) do
|
6
|
+
@data = {:event=>"follow", :source=>{:id=>10083602, :id_str=>"10083602", :name=>"Adam Bird", :screen_name=>"adambird", :location=>"Nottingham, UK", :url=>"http://t.co/M1eaIKDQyz", :description=>"CEO @onediaryapp, ex @esendex CTO and co-founder, still cycling", :protected=>false, :followers_count=>1295, :friends_count=>850, :listed_count=>53, :created_at=>"Fri Nov 09 00:35:12 +0000 2007", :favourites_count=>93, :utc_offset=>0, :time_zone=>"London", :geo_enabled=>true, :verified=>false, :statuses_count=>13507, :lang=>"en", :contributors_enabled=>false, :is_translator=>false, :profile_background_color=>"C0DEED", :profile_background_image_url=>"http://abs.twimg.com/images/themes/theme1/bg.png", :profile_background_image_url_https=>"https://abs.twimg.com/images/themes/theme1/bg.png", :profile_background_tile=>false, :profile_image_url=>"http://pbs.twimg.com/profile_images/378800000477232297/23d85bb78f71534eea1e1133fb771f86_normal.jpeg", :profile_image_url_https=>"https://pbs.twimg.com/profile_images/378800000477232297/23d85bb78f71534eea1e1133fb771f86_normal.jpeg", :profile_link_color=>"0084B4", :profile_sidebar_border_color=>"C0DEED", :profile_sidebar_fill_color=>"DDEEF6", :profile_text_color=>"333333", :profile_use_background_image=>true, :default_profile=>true, :default_profile_image=>false, :following=>false, :follow_request_sent=>false, :notifications=>false}, :target=>{:id=>1292911088, :id_str=>"1292911088", :name=>"One Diary Bot", :screen_name=>"onediarybot", :location=>nil, :url=>"http://t.co/etHGc0xHX4", :description=>"I'm the One Diary bot, here to help you with your life including personal cycling weather forecasts.", :protected=>false, :followers_count=>123, :friends_count=>157, :listed_count=>1, :created_at=>"Sat Mar 23 23:52:18 +0000 2013", :favourites_count=>0, :utc_offset=>nil, :time_zone=>nil, :geo_enabled=>false, :verified=>false, :statuses_count=>9637, :lang=>"en", :contributors_enabled=>false, :is_translator=>false, :profile_background_color=>"C0DEED", :profile_background_image_url=>"http://abs.twimg.com/images/themes/theme1/bg.png", :profile_background_image_url_https=>"https://abs.twimg.com/images/themes/theme1/bg.png", :profile_background_tile=>false, :profile_image_url=>"http://pbs.twimg.com/profile_images/3651575369/090551d8dd92080198f707769239ff43_normal.jpeg", :profile_image_url_https=>"https://pbs.twimg.com/profile_images/3651575369/090551d8dd92080198f707769239ff43_normal.jpeg", :profile_link_color=>"0084B4", :profile_sidebar_border_color=>"C0DEED", :profile_sidebar_fill_color=>"DDEEF6", :profile_text_color=>"333333", :profile_use_background_image=>true, :default_profile=>true, :default_profile_image=>false, :following=>false, :follow_request_sent=>false, :notifications=>false}, :created_at=>"Sun Oct 27 20:44:19 +0000 2013"}
|
7
|
+
end
|
8
|
+
|
9
|
+
subject { Twitter::Streaming::Event.new(@data) }
|
10
|
+
|
11
|
+
it "should set the name to be a symbolised version of string string" do
|
12
|
+
expect(subject.name).to eq(:follow)
|
13
|
+
end
|
14
|
+
it "should set the source to be the User" do
|
15
|
+
expect(subject.source).to be_a(Twitter::User)
|
16
|
+
expect(subject.source.id).to eq(10083602)
|
17
|
+
end
|
18
|
+
it "should set the target to be the User" do
|
19
|
+
expect(subject.target).to be_a(Twitter::User)
|
20
|
+
expect(subject.target.id).to eq(1292911088)
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when target object is a list" do
|
24
|
+
before(:each) do
|
25
|
+
@data = {:event=>"list_member_added", :target_object=>{:full_name=>"@adambird/lists/dev", :user=>{:default_profile_image=>false, :profile_text_color=>"333333", :created_at=>"Fri Nov 09 00:35:12 +0000 2007", :is_translator=>false, :name=>"Adam Bird", :screen_name=>"adambird", :geo_enabled=>true, :follow_request_sent=>false, :profile_sidebar_border_color=>"C0DEED", :default_profile=>true, :id=>10083602, :contributors_enabled=>false, :followers_count=>1295, :lang=>"en", :profile_background_tile=>false, :url=>"http://about.me/adambird", :profile_sidebar_fill_color=>"DDEEF6", :listed_count=>53, :utc_offset=>0, :location=>"Nottingham, UK", :time_zone=>"London", :profile_background_color=>"C0DEED", :following=>false, :protected=>false, :description=>"CEO @onediaryapp, ex @esendex CTO and co-founder, still cycling", :profile_image_url_https=>"https://pbs.twimg.com/profile_images/378800000477232297/23d85bb78f71534eea1e1133fb771f86_normal.jpeg", :profile_background_image_url=>"http://abs.twimg.com/images/themes/theme1/bg.png", :profile_link_color=>"0084B4", :notifications=>false, :profile_background_image_url_https=>"https://abs.twimg.com/images/themes/theme1/bg.png", :favourites_count=>93, :id_str=>"10083602", :statuses_count=>13507, :verified=>false, :profile_image_url=>"http://pbs.twimg.com/profile_images/378800000477232297/23d85bb78f71534eea1e1133fb771f86_normal.jpeg", :profile_use_background_image=>true, :friends_count=>851}, :uri=>"/adambird/lists/dev", :subscriber_count=>0, :id_str=>"60314359", :created_at=>"Sun Dec 04 19:54:20 +0000 2011", :id=>60314359, :following=>false, :mode=>"public", :member_count=>13, :description=>"", :slug=>"dev", :name=>"dev"}, :source=>{:default_profile_image=>false, :profile_text_color=>"333333", :created_at=>"Fri Nov 09 00:35:12 +0000 2007", :is_translator=>false, :name=>"Adam Bird", :screen_name=>"adambird", :geo_enabled=>true, :follow_request_sent=>false, :profile_sidebar_border_color=>"C0DEED", :default_profile=>true, :id=>10083602, :contributors_enabled=>false, :followers_count=>1295, :lang=>"en", :profile_background_tile=>false, :url=>"http://about.me/adambird", :profile_sidebar_fill_color=>"DDEEF6", :listed_count=>53, :utc_offset=>0, :location=>"Nottingham, UK", :time_zone=>"London", :profile_background_color=>"C0DEED", :following=>false, :protected=>false, :description=>"CEO @onediaryapp, ex @esendex CTO and co-founder, still cycling", :profile_image_url_https=>"https://pbs.twimg.com/profile_images/378800000477232297/23d85bb78f71534eea1e1133fb771f86_normal.jpeg", :profile_background_image_url=>"http://abs.twimg.com/images/themes/theme1/bg.png", :profile_link_color=>"0084B4", :notifications=>false, :profile_background_image_url_https=>"https://abs.twimg.com/images/themes/theme1/bg.png", :favourites_count=>93, :id_str=>"10083602", :statuses_count=>13507, :verified=>false, :profile_image_url=>"http://pbs.twimg.com/profile_images/378800000477232297/23d85bb78f71534eea1e1133fb771f86_normal.jpeg", :profile_use_background_image=>true, :friends_count=>851}, :created_at=>"Sun Oct 27 20:54:51 +0000 2013", :target=>{:default_profile_image=>false, :profile_text_color=>"333333", :created_at=>"Sat Mar 23 23:52:18 +0000 2013", :is_translator=>false, :name=>"One Diary Bot", :screen_name=>"onediarybot", :geo_enabled=>false, :follow_request_sent=>false, :profile_sidebar_border_color=>"C0DEED", :default_profile=>true, :id=>1292911088, :contributors_enabled=>false, :followers_count=>124, :lang=>"en", :profile_background_tile=>false, :url=>"http://www.onediary.com", :profile_sidebar_fill_color=>"DDEEF6", :listed_count=>2, :utc_offset=>nil, :location=>nil, :time_zone=>nil, :profile_background_color=>"C0DEED", :following=>true, :protected=>false, :description=>"I'm the One Diary bot, here to help you with your life including personal cycling weather forecasts.", :profile_image_url_https=>"https://pbs.twimg.com/profile_images/3651575369/090551d8dd92080198f707769239ff43_normal.jpeg", :profile_background_image_url=>"http://abs.twimg.com/images/themes/theme1/bg.png", :profile_link_color=>"0084B4", :notifications=>false, :profile_background_image_url_https=>"https://abs.twimg.com/images/themes/theme1/bg.png", :favourites_count=>0, :id_str=>"1292911088", :statuses_count=>9637, :verified=>false, :profile_image_url=>"http://pbs.twimg.com/profile_images/3651575369/090551d8dd92080198f707769239ff43_normal.jpeg", :profile_use_background_image=>true, :friends_count=>157}}
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should have the list object as the target object" do
|
29
|
+
expect(subject.target_object).to be_a(Twitter::List)
|
30
|
+
expect(subject.target_object.full_name).to eq("@adambird/lists/dev")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "when target object is a tweet" do
|
35
|
+
before(:each) do
|
36
|
+
@data = {:event=>"favorite", :target_object=>{:in_reply_to_status_id=>394341960603172864, :favorited=>true, :entities=>{:hashtags=>[], :urls=>[], :user_mentions=>[{:screen_name=>"darrenliddell", :id_str=>"18845675", :id=>18845675, :indices=>[0, 14], :name=>"Darren Liddell"}]}, :user=>{:default_profile_image=>false, :profile_text_color=>"333333", :created_at=>"Sat Mar 23 23:52:18 +0000 2013", :is_translator=>false, :name=>"One Diary Bot", :screen_name=>"onediarybot", :geo_enabled=>false, :follow_request_sent=>false, :profile_sidebar_border_color=>"C0DEED", :default_profile=>true, :id=>1292911088, :contributors_enabled=>false, :followers_count=>124, :lang=>"en", :profile_background_tile=>false, :url=>"http://www.onediary.com", :profile_sidebar_fill_color=>"DDEEF6", :listed_count=>1, :utc_offset=>nil, :location=>nil, :time_zone=>nil, :profile_background_color=>"C0DEED", :following=>true, :protected=>false, :description=>"I'm the One Diary bot, here to help you with your life including personal cycling weather forecasts.", :profile_background_image_url=>"http://abs.twimg.com/images/themes/theme1/bg.png", :profile_link_color=>"0084B4", :notifications=>false, :profile_background_image_url_https=>"https://abs.twimg.com/images/themes/theme1/bg.png", :favourites_count=>0, :id_str=>"1292911088", :statuses_count=>9637, :verified=>false, :profile_image_url=>"http://pbs.twimg.com/profile_images/3651575369/090551d8dd92080198f707769239ff43_normal.jpeg", :profile_use_background_image=>true, :profile_image_url_https=>"https://pbs.twimg.com/profile_images/3651575369/090551d8dd92080198f707769239ff43_normal.jpeg", :friends_count=>157}, :in_reply_to_screen_name=>"darrenliddell", :place=>nil, :coordinates=>nil, :id_str=>"394454214132256768", :source=>"web", :retweet_count=>0, :id=>394454214132256768, :created_at=>"Sun Oct 27 13:23:07 +0000 2013", :in_reply_to_status_id_str=>"394341960603172864", :retweeted=>false, :in_reply_to_user_id=>18845675, :truncated=>false, :contributors=>nil, :geo=>nil, :in_reply_to_user_id_str=>"18845675", :text=>"@darrenliddell my programmers thought that they had that one covered. I have admonished them."}, :source=>{:default_profile_image=>false, :profile_text_color=>"333333", :created_at=>"Fri Nov 09 00:35:12 +0000 2007", :is_translator=>false, :name=>"Adam Bird", :screen_name=>"adambird", :geo_enabled=>true, :follow_request_sent=>false, :profile_sidebar_border_color=>"C0DEED", :default_profile=>true, :id=>10083602, :contributors_enabled=>false, :followers_count=>1295, :lang=>"en", :profile_background_tile=>false, :url=>"http://about.me/adambird", :profile_sidebar_fill_color=>"DDEEF6", :listed_count=>53, :utc_offset=>0, :location=>"Nottingham, UK", :time_zone=>"London", :profile_background_color=>"C0DEED", :following=>false, :protected=>false, :description=>"CEO @onediaryapp, ex @esendex CTO and co-founder, still cycling", :profile_background_image_url=>"http://abs.twimg.com/images/themes/theme1/bg.png", :profile_link_color=>"0084B4", :notifications=>false, :profile_background_image_url_https=>"https://abs.twimg.com/images/themes/theme1/bg.png", :favourites_count=>93, :id_str=>"10083602", :statuses_count=>13507, :verified=>false, :profile_image_url=>"http://pbs.twimg.com/profile_images/378800000477232297/23d85bb78f71534eea1e1133fb771f86_normal.jpeg", :profile_use_background_image=>true, :profile_image_url_https=>"https://pbs.twimg.com/profile_images/378800000477232297/23d85bb78f71534eea1e1133fb771f86_normal.jpeg", :friends_count=>851}, :created_at=>"Sun Oct 27 21:05:35 +0000 2013", :target=>{:default_profile_image=>false, :profile_text_color=>"333333", :created_at=>"Sat Mar 23 23:52:18 +0000 2013", :is_translator=>false, :name=>"One Diary Bot", :screen_name=>"onediarybot", :geo_enabled=>false, :follow_request_sent=>false, :profile_sidebar_border_color=>"C0DEED", :default_profile=>true, :id=>1292911088, :contributors_enabled=>false, :followers_count=>124, :lang=>"en", :profile_background_tile=>false, :url=>"http://www.onediary.com", :profile_sidebar_fill_color=>"DDEEF6", :listed_count=>1, :utc_offset=>nil, :location=>nil, :time_zone=>nil, :profile_background_color=>"C0DEED", :following=>true, :protected=>false, :description=>"I'm the One Diary bot, here to help you with your life including personal cycling weather forecasts.", :profile_background_image_url=>"http://abs.twimg.com/images/themes/theme1/bg.png", :profile_link_color=>"0084B4", :notifications=>false, :profile_background_image_url_https=>"https://abs.twimg.com/images/themes/theme1/bg.png", :favourites_count=>0, :id_str=>"1292911088", :statuses_count=>9637, :verified=>false, :profile_image_url=>"http://pbs.twimg.com/profile_images/3651575369/090551d8dd92080198f707769239ff43_normal.jpeg", :profile_use_background_image=>true, :profile_image_url_https=>"https://pbs.twimg.com/profile_images/3651575369/090551d8dd92080198f707769239ff43_normal.jpeg", :friends_count=>157}}
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should have the tweet as the target object" do
|
40
|
+
expect(subject.target_object).to be_a(Twitter::Tweet)
|
41
|
+
expect(subject.target_object.id).to eq(394454214132256768)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|