twitter 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +673 -0
- data/LICENSE.md +20 -0
- data/README.md +415 -0
- data/Rakefile +11 -0
- data/lib/twitter.rb +29 -0
- data/lib/twitter/action/favorite.rb +19 -0
- data/lib/twitter/action/follow.rb +31 -0
- data/lib/twitter/action/list_member_added.rb +41 -0
- data/lib/twitter/action/mention.rb +48 -0
- data/lib/twitter/action/reply.rb +27 -0
- data/lib/twitter/action/retweet.rb +27 -0
- data/lib/twitter/action/tweet.rb +22 -0
- data/lib/twitter/action_factory.rb +22 -0
- data/lib/twitter/api.rb +2442 -0
- data/lib/twitter/base.rb +119 -0
- data/lib/twitter/basic_user.rb +8 -0
- data/lib/twitter/client.rb +96 -0
- data/lib/twitter/configurable.rb +67 -0
- data/lib/twitter/configuration.rb +20 -0
- data/lib/twitter/core_ext/array.rb +7 -0
- data/lib/twitter/core_ext/enumerable.rb +11 -0
- data/lib/twitter/core_ext/hash.rb +100 -0
- data/lib/twitter/core_ext/kernel.rb +15 -0
- data/lib/twitter/core_ext/string.rb +10 -0
- data/lib/twitter/creatable.rb +20 -0
- data/lib/twitter/cursor.rb +87 -0
- data/lib/twitter/default.rb +101 -0
- data/lib/twitter/direct_message.rb +21 -0
- data/lib/twitter/entity.rb +7 -0
- data/lib/twitter/entity/hashtag.rb +9 -0
- data/lib/twitter/entity/url.rb +9 -0
- data/lib/twitter/entity/user_mention.rb +9 -0
- data/lib/twitter/error.rb +34 -0
- data/lib/twitter/error/bad_gateway.rb +11 -0
- data/lib/twitter/error/bad_request.rb +10 -0
- data/lib/twitter/error/client_error.rb +35 -0
- data/lib/twitter/error/decode_error.rb +9 -0
- data/lib/twitter/error/forbidden.rb +10 -0
- data/lib/twitter/error/gateway_timeout.rb +11 -0
- data/lib/twitter/error/identity_map_key_error.rb +9 -0
- data/lib/twitter/error/internal_server_error.rb +11 -0
- data/lib/twitter/error/not_acceptable.rb +10 -0
- data/lib/twitter/error/not_found.rb +10 -0
- data/lib/twitter/error/rate_limited.rb +11 -0
- data/lib/twitter/error/server_error.rb +28 -0
- data/lib/twitter/error/service_unavailable.rb +11 -0
- data/lib/twitter/error/unauthorized.rb +10 -0
- data/lib/twitter/factory.rb +21 -0
- data/lib/twitter/geo.rb +15 -0
- data/lib/twitter/geo/point.rb +22 -0
- data/lib/twitter/geo/polygon.rb +8 -0
- data/lib/twitter/geo_factory.rb +18 -0
- data/lib/twitter/identity.rb +50 -0
- data/lib/twitter/identity_map.rb +22 -0
- data/lib/twitter/language.rb +7 -0
- data/lib/twitter/list.rb +18 -0
- data/lib/twitter/media/photo.rb +22 -0
- data/lib/twitter/media_factory.rb +17 -0
- data/lib/twitter/metadata.rb +7 -0
- data/lib/twitter/oembed.rb +8 -0
- data/lib/twitter/place.rb +34 -0
- data/lib/twitter/rate_limit.rb +45 -0
- data/lib/twitter/relationship.rb +36 -0
- data/lib/twitter/request/multipart_with_file.rb +41 -0
- data/lib/twitter/response/parse_json.rb +25 -0
- data/lib/twitter/response/raise_error.rb +30 -0
- data/lib/twitter/saved_search.rb +9 -0
- data/lib/twitter/search_results.rb +48 -0
- data/lib/twitter/settings.rb +17 -0
- data/lib/twitter/size.rb +24 -0
- data/lib/twitter/source_user.rb +15 -0
- data/lib/twitter/suggestion.rb +22 -0
- data/lib/twitter/target_user.rb +8 -0
- data/lib/twitter/trend.rb +14 -0
- data/lib/twitter/tweet.rb +145 -0
- data/lib/twitter/user.rb +97 -0
- data/lib/twitter/version.rb +18 -0
- data/spec/fixtures/about_me.json +1 -0
- data/spec/fixtures/activity_summary.json +1 -0
- data/spec/fixtures/all.json +1 -0
- data/spec/fixtures/bad_gateway.json +1 -0
- data/spec/fixtures/bad_request.json +1 -0
- data/spec/fixtures/by_friends.json +1 -0
- data/spec/fixtures/category.json +1 -0
- data/spec/fixtures/configuration.json +1 -0
- data/spec/fixtures/contributees.json +1 -0
- data/spec/fixtures/contributors.json +1 -0
- data/spec/fixtures/direct_message.json +1 -0
- data/spec/fixtures/direct_messages.json +1 -0
- data/spec/fixtures/end_session.json +1 -0
- data/spec/fixtures/enhance_your_calm.text +11 -0
- data/spec/fixtures/favorites.json +1 -0
- data/spec/fixtures/following.json +1 -0
- data/spec/fixtures/forbidden.json +1 -0
- data/spec/fixtures/friendships.json +1 -0
- data/spec/fixtures/ids.json +1 -0
- data/spec/fixtures/ids_list.json +1 -0
- data/spec/fixtures/ids_list2.json +1 -0
- data/spec/fixtures/image_facets.json +1 -0
- data/spec/fixtures/internal_server_error.json +1 -0
- data/spec/fixtures/languages.json +1 -0
- data/spec/fixtures/list.json +1 -0
- data/spec/fixtures/lists.json +1 -0
- data/spec/fixtures/locations.json +1 -0
- data/spec/fixtures/matching_trends.json +1 -0
- data/spec/fixtures/me.jpeg +0 -0
- data/spec/fixtures/media_timeline.json +1 -0
- data/spec/fixtures/members.json +1 -0
- data/spec/fixtures/no_user_matches.json +1 -0
- data/spec/fixtures/not_acceptable.json +1 -0
- data/spec/fixtures/not_following.json +1 -0
- data/spec/fixtures/not_found.json +1 -0
- data/spec/fixtures/oembed.json +1 -0
- data/spec/fixtures/pbjt.gif +0 -0
- data/spec/fixtures/pengwynn.json +1 -0
- data/spec/fixtures/phoenix_search.phoenix +1 -0
- data/spec/fixtures/place.json +1 -0
- data/spec/fixtures/places.json +1 -0
- data/spec/fixtures/privacy.json +1 -0
- data/spec/fixtures/profile_image.text +24 -0
- data/spec/fixtures/rate_limit_status.json +1 -0
- data/spec/fixtures/recommendations.json +1 -0
- data/spec/fixtures/related_results.json +1 -0
- data/spec/fixtures/resolve.json +1 -0
- data/spec/fixtures/retweet.json +1 -0
- data/spec/fixtures/retweeted_status.json +1 -0
- data/spec/fixtures/retweeters_of.json +1 -0
- data/spec/fixtures/retweets.json +1 -0
- data/spec/fixtures/saved_search.json +1 -0
- data/spec/fixtures/saved_searches.json +1 -0
- data/spec/fixtures/search.json +1 -0
- data/spec/fixtures/search_malformed.json +1 -0
- data/spec/fixtures/service_unavailable.json +1 -0
- data/spec/fixtures/settings.json +1 -0
- data/spec/fixtures/sferik.json +1 -0
- data/spec/fixtures/status.json +1 -0
- data/spec/fixtures/status_with_media.json +104 -0
- data/spec/fixtures/statuses.json +1 -0
- data/spec/fixtures/suggestions.json +1 -0
- data/spec/fixtures/tos.json +1 -0
- data/spec/fixtures/totals.json +1 -0
- data/spec/fixtures/trends.json +1 -0
- data/spec/fixtures/trends_current.json +1 -0
- data/spec/fixtures/trends_daily.json +1 -0
- data/spec/fixtures/trends_weekly.json +1 -0
- data/spec/fixtures/unauthorized.json +1 -0
- data/spec/fixtures/user_search.json +1 -0
- data/spec/fixtures/user_timeline.json +1 -0
- data/spec/fixtures/users.json +1 -0
- data/spec/fixtures/users_list.json +1 -0
- data/spec/fixtures/video_facets.json +1 -0
- data/spec/fixtures/we_concept_bg2.png +0 -0
- data/spec/fixtures/wildcomet2.jpe +0 -0
- data/spec/helper.rb +53 -0
- data/spec/twitter/action/favorite_spec.rb +29 -0
- data/spec/twitter/action/follow_spec.rb +29 -0
- data/spec/twitter/action/list_member_added_spec.rb +41 -0
- data/spec/twitter/action/mention_spec.rb +52 -0
- data/spec/twitter/action/reply_spec.rb +41 -0
- data/spec/twitter/action/retweet_spec.rb +41 -0
- data/spec/twitter/action_factory_spec.rb +37 -0
- data/spec/twitter/action_spec.rb +16 -0
- data/spec/twitter/api/account_spec.rb +148 -0
- data/spec/twitter/api/activity_spec.rb +41 -0
- data/spec/twitter/api/blocks_spec.rb +167 -0
- data/spec/twitter/api/direct_messages_spec.rb +142 -0
- data/spec/twitter/api/friendships_spec.rb +567 -0
- data/spec/twitter/api/geo_spec.rb +100 -0
- data/spec/twitter/api/help_spec.rb +76 -0
- data/spec/twitter/api/lists_spec.rb +900 -0
- data/spec/twitter/api/report_spam_spec.rb +29 -0
- data/spec/twitter/api/saved_searches_spec.rb +100 -0
- data/spec/twitter/api/search_spec.rb +68 -0
- data/spec/twitter/api/statuses_spec.rb +559 -0
- data/spec/twitter/api/trends_spec.rb +80 -0
- data/spec/twitter/api/users_spec.rb +419 -0
- data/spec/twitter/base_spec.rb +113 -0
- data/spec/twitter/basic_user_spec.rb +23 -0
- data/spec/twitter/client_spec.rb +175 -0
- data/spec/twitter/configuration_spec.rb +17 -0
- data/spec/twitter/cursor_spec.rb +102 -0
- data/spec/twitter/direct_message_spec.rb +56 -0
- data/spec/twitter/error/client_error_spec.rb +40 -0
- data/spec/twitter/error/server_error_spec.rb +24 -0
- data/spec/twitter/error_spec.rb +20 -0
- data/spec/twitter/geo/point_spec.rb +41 -0
- data/spec/twitter/geo/polygon_spec.rb +29 -0
- data/spec/twitter/geo_factory_spec.rb +21 -0
- data/spec/twitter/geo_spec.rb +29 -0
- data/spec/twitter/identifiable_spec.rb +54 -0
- data/spec/twitter/list_spec.rb +45 -0
- data/spec/twitter/media/photo_spec.rb +35 -0
- data/spec/twitter/media_factory_spec.rb +17 -0
- data/spec/twitter/oembed_spec.rb +146 -0
- data/spec/twitter/place_spec.rb +75 -0
- data/spec/twitter/rate_limit_spec.rb +76 -0
- data/spec/twitter/relationship_spec.rb +35 -0
- data/spec/twitter/saved_search_spec.rb +34 -0
- data/spec/twitter/search_results_spec.rb +89 -0
- data/spec/twitter/settings_spec.rb +16 -0
- data/spec/twitter/size_spec.rb +38 -0
- data/spec/twitter/source_user_spec.rb +23 -0
- data/spec/twitter/suggestion_spec.rb +50 -0
- data/spec/twitter/target_user_spec.rb +23 -0
- data/spec/twitter/trend_spec.rb +38 -0
- data/spec/twitter/tweet_spec.rb +307 -0
- data/spec/twitter/user_spec.rb +127 -0
- data/spec/twitter_spec.rb +93 -0
- data/twitter.gemspec +30 -0
- metadata +584 -0
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Twitter::TargetUser do
|
4
|
+
|
5
|
+
describe "#==" do
|
6
|
+
it "returns true when objects IDs are the same" do
|
7
|
+
saved_search = Twitter::TargetUser.new(:id => 1, :name => "foo")
|
8
|
+
other = Twitter::TargetUser.new(:id => 1, :name => "bar")
|
9
|
+
(saved_search == other).should be_true
|
10
|
+
end
|
11
|
+
it "returns false when objects IDs are different" do
|
12
|
+
saved_search = Twitter::TargetUser.new(:id => 1)
|
13
|
+
other = Twitter::TargetUser.new(:id => 2)
|
14
|
+
(saved_search == other).should be_false
|
15
|
+
end
|
16
|
+
it "returns false when classes are different" do
|
17
|
+
saved_search = Twitter::TargetUser.new(:id => 1)
|
18
|
+
other = Twitter::Identity.new(:id => 1)
|
19
|
+
(saved_search == other).should be_false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Twitter::Trend do
|
4
|
+
|
5
|
+
describe "#==" do
|
6
|
+
it "returns false for empty objects" do
|
7
|
+
trend = Twitter::Trend.new
|
8
|
+
other = Twitter::Trend.new
|
9
|
+
(trend == other).should be_false
|
10
|
+
end
|
11
|
+
it "returns true when objects names are the same" do
|
12
|
+
trend = Twitter::Trend.new(:name => "#sevenwordsaftersex", :query => "foo")
|
13
|
+
other = Twitter::Trend.new(:name => "#sevenwordsaftersex", :query => "bar")
|
14
|
+
(trend == other).should be_true
|
15
|
+
end
|
16
|
+
it "returns false when objects names are different" do
|
17
|
+
trend = Twitter::Trend.new(:name => "#sevenwordsaftersex")
|
18
|
+
other = Twitter::Trend.new(:name => "#sixwordsaftersex")
|
19
|
+
(trend == other).should be_false
|
20
|
+
end
|
21
|
+
it "returns false when classes are different" do
|
22
|
+
trend = Twitter::Trend.new(:name => "#sevenwordsaftersex")
|
23
|
+
other = Twitter::Base.new(:name => "#sevenwordsaftersex")
|
24
|
+
(trend == other).should be_false
|
25
|
+
end
|
26
|
+
it "returns true when objects non-name attributes are the same" do
|
27
|
+
trend = Twitter::Trend.new(:query => "foo")
|
28
|
+
other = Twitter::Trend.new(:query => "foo")
|
29
|
+
(trend == other).should be_true
|
30
|
+
end
|
31
|
+
it "returns false when objects non-name attributes are different" do
|
32
|
+
trend = Twitter::Trend.new(:query => "foo")
|
33
|
+
other = Twitter::Trend.new(:query => "bar")
|
34
|
+
(trend == other).should be_false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,307 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Twitter::Tweet do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@old_stderr = $stderr
|
7
|
+
$stderr = StringIO.new
|
8
|
+
end
|
9
|
+
|
10
|
+
after do
|
11
|
+
$stderr = @old_stderr
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#==" do
|
15
|
+
it "returns true when objects IDs are the same" do
|
16
|
+
tweet = Twitter::Tweet.new(:id => 1, :text => "foo")
|
17
|
+
other = Twitter::Tweet.new(:id => 1, :text => "bar")
|
18
|
+
(tweet == other).should be_true
|
19
|
+
end
|
20
|
+
it "returns false when objects IDs are different" do
|
21
|
+
tweet = Twitter::Tweet.new(:id => 1)
|
22
|
+
other = Twitter::Tweet.new(:id => 2)
|
23
|
+
(tweet == other).should be_false
|
24
|
+
end
|
25
|
+
it "returns false when classes are different" do
|
26
|
+
tweet = Twitter::Tweet.new(:id => 1)
|
27
|
+
other = Twitter::Identity.new(:id => 1)
|
28
|
+
(tweet == other).should be_false
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#created_at" do
|
33
|
+
it "returns a Time when set" do
|
34
|
+
tweet = Twitter::Tweet.new(:id => 28669546014, :created_at => "Mon Jul 16 12:59:01 +0000 2007")
|
35
|
+
tweet.created_at.should be_a Time
|
36
|
+
end
|
37
|
+
it "returns nil when not set" do
|
38
|
+
tweet = Twitter::Tweet.new(:id => 28669546014)
|
39
|
+
tweet.created_at.should be_nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#favoriters_count" do
|
44
|
+
it "returns the count of favoriters when favoriters_count is set" do
|
45
|
+
tweet = Twitter::Tweet.new(:id => 28669546014, :favoriters_count => '1')
|
46
|
+
tweet.favoriters_count.should be_an Integer
|
47
|
+
tweet.favoriters_count.should eq 1
|
48
|
+
end
|
49
|
+
it "returns nil when not set" do
|
50
|
+
tweet = Twitter::Tweet.new(:id => 28669546014)
|
51
|
+
tweet.favoriters_count.should be_nil
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#from_user" do
|
56
|
+
it "returns a screen name when from_user is set" do
|
57
|
+
tweet = Twitter::Tweet.new(:id => 28669546014, :from_user => 'sferik')
|
58
|
+
tweet.from_user.should be_a String
|
59
|
+
tweet.from_user.should eq "sferik"
|
60
|
+
end
|
61
|
+
it "returns a screen name when screen_name is set" do
|
62
|
+
tweet = Twitter::Tweet.new(:id => 28669546014, :user => {:id => 7505382, :screen_name => 'sferik'})
|
63
|
+
tweet.from_user.should be_a String
|
64
|
+
tweet.from_user.should eq "sferik"
|
65
|
+
end
|
66
|
+
it "returns nil when not set" do
|
67
|
+
tweet = Twitter::Tweet.new(:id => 28669546014)
|
68
|
+
tweet.from_user.should be_nil
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "#full_text" do
|
73
|
+
it "returns the text of a Tweet" do
|
74
|
+
tweet = Twitter::Tweet.new(:id => 28669546014, :text => 'BOOSH')
|
75
|
+
tweet.full_text.should be_a String
|
76
|
+
tweet.full_text.should eq "BOOSH"
|
77
|
+
end
|
78
|
+
it "returns the text of a Tweet without a user" do
|
79
|
+
tweet = Twitter::Tweet.new(:id => 28669546014, :text => 'BOOSH', :retweeted_status => {:id => 28561922517, :text => 'BOOSH'})
|
80
|
+
tweet.full_text.should be_a String
|
81
|
+
tweet.full_text.should eq "BOOSH"
|
82
|
+
end
|
83
|
+
it "returns the full text of a retweeted Tweet" do
|
84
|
+
tweet = Twitter::Tweet.new(:id => 28669546014, :retweeted_status => {:id => 28561922516, :text => 'BOOSH', :user => {:id => 7505382, :screen_name => 'sferik'}})
|
85
|
+
tweet.full_text.should be_a String
|
86
|
+
tweet.full_text.should eq "RT @sferik: BOOSH"
|
87
|
+
end
|
88
|
+
it "returns nil when retweeted_status is not set" do
|
89
|
+
tweet = Twitter::Tweet.new(:id => 28669546014)
|
90
|
+
tweet.full_text.should be_nil
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "#geo" do
|
95
|
+
it "returns a Twitter::Geo::Point when set" do
|
96
|
+
tweet = Twitter::Tweet.new(:id => 28669546014, :geo => {:id => 1, :type => 'Point'})
|
97
|
+
tweet.geo.should be_a Twitter::Geo::Point
|
98
|
+
end
|
99
|
+
it "returns nil when not set" do
|
100
|
+
tweet = Twitter::Tweet.new(:id => 28669546014)
|
101
|
+
tweet.geo.should be_nil
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "#hashtags" do
|
106
|
+
it "returns an Array of Entity::Hashtag when entities are set" do
|
107
|
+
hashtags_hash = [
|
108
|
+
{
|
109
|
+
:text => 'twitter',
|
110
|
+
:indices => [10, 33],
|
111
|
+
}
|
112
|
+
]
|
113
|
+
hashtags = Twitter::Tweet.new(:id => 28669546014, :entities => {:hashtags => hashtags_hash}).hashtags
|
114
|
+
hashtags.should be_an Array
|
115
|
+
hashtags.first.should be_a Twitter::Entity::Hashtag
|
116
|
+
hashtags.first.indices.should eq [10, 33]
|
117
|
+
hashtags.first.text.should eq 'twitter'
|
118
|
+
end
|
119
|
+
it "is empty when not set" do
|
120
|
+
hashtags = Twitter::Tweet.new(:id => 28669546014).hashtags
|
121
|
+
hashtags.should be_empty
|
122
|
+
end
|
123
|
+
it "warns when not set" do
|
124
|
+
Twitter::Tweet.new(:id => 28669546014).hashtags
|
125
|
+
$stderr.string.should =~ /To get hashtags, you must pass `:include_entities => true` when requesting the Twitter::Tweet\./
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe "#media" do
|
130
|
+
it "returns media" do
|
131
|
+
media = Twitter::Tweet.new(:id => 28669546014, :entities => {:media => [{:id => 1, :type => 'photo'}]}).media
|
132
|
+
media.should be_an Array
|
133
|
+
media.first.should be_a Twitter::Media::Photo
|
134
|
+
end
|
135
|
+
it "is empty when not set" do
|
136
|
+
media = Twitter::Tweet.new(:id => 28669546014).media
|
137
|
+
media.should be_empty
|
138
|
+
end
|
139
|
+
it "warns when not set" do
|
140
|
+
Twitter::Tweet.new(:id => 28669546014).media
|
141
|
+
$stderr.string.should =~ /To get media, you must pass `:include_entities => true` when requesting the Twitter::Tweet\./
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe "#metadata" do
|
146
|
+
it "returns a User when user is set" do
|
147
|
+
metadata = Twitter::Tweet.new(:id => 28669546014, :metadata => {}).metadata
|
148
|
+
metadata.should be_a Twitter::Metadata
|
149
|
+
end
|
150
|
+
it "returns nil when user is not set" do
|
151
|
+
metadata = Twitter::Tweet.new(:id => 28669546014).metadata
|
152
|
+
metadata.should be_nil
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
describe "#place" do
|
157
|
+
it "returns a Twitter::Place when set" do
|
158
|
+
tweet = Twitter::Tweet.new(:id => 28669546014, :place => {:id => "247f43d441defc03"})
|
159
|
+
tweet.place.should be_a Twitter::Place
|
160
|
+
end
|
161
|
+
it "returns nil when not set" do
|
162
|
+
tweet = Twitter::Tweet.new(:id => 28669546014)
|
163
|
+
tweet.place.should be_nil
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
describe "#repliers_count" do
|
168
|
+
it "returns the count of favoriters when repliers_count is set" do
|
169
|
+
tweet = Twitter::Tweet.new(:id => 28669546014, :repliers_count => '1')
|
170
|
+
tweet.repliers_count.should be_an Integer
|
171
|
+
tweet.repliers_count.should eq 1
|
172
|
+
end
|
173
|
+
it "returns nil when not set" do
|
174
|
+
tweet = Twitter::Tweet.new(:id => 28669546014)
|
175
|
+
tweet.repliers_count.should be_nil
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
describe "#retweet?" do
|
180
|
+
it "returns true when there is a retweeted status" do
|
181
|
+
tweet = Twitter::Tweet.new(:id => 28669546014, :retweeted_status => {:id => 28561922516, :text => 'BOOSH'})
|
182
|
+
tweet.retweet?.should be_true
|
183
|
+
end
|
184
|
+
it "returns false when retweeted_status is not set" do
|
185
|
+
tweet = Twitter::Tweet.new(:id => 28669546014)
|
186
|
+
tweet.retweet?.should be_false
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
describe "#retweeted_status" do
|
191
|
+
it "has text when retweeted_status is set" do
|
192
|
+
tweet = Twitter::Tweet.new(:id => 28669546014, :retweeted_status => {:id => 28561922516, :text => 'BOOSH'})
|
193
|
+
tweet.retweeted_tweet.should be_a Twitter::Tweet
|
194
|
+
tweet.retweeted_tweet.text.should eq 'BOOSH'
|
195
|
+
end
|
196
|
+
it "returns nil when retweeted_status is not set" do
|
197
|
+
tweet = Twitter::Tweet.new(:id => 28669546014)
|
198
|
+
tweet.retweeted_tweet.should be_nil
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
describe "#retweeters_count" do
|
203
|
+
it "returns the count of favoriters when retweet_count is set" do
|
204
|
+
tweet = Twitter::Tweet.new(:id => 28669546014, :retweet_count => '1')
|
205
|
+
tweet.retweeters_count.should be_an Integer
|
206
|
+
tweet.retweeters_count.should eq 1
|
207
|
+
end
|
208
|
+
it "returns the count of favoriters when retweeters_count is set" do
|
209
|
+
tweet = Twitter::Tweet.new(:id => 28669546014, :retweeters_count => '1')
|
210
|
+
tweet.retweeters_count.should be_an Integer
|
211
|
+
tweet.retweeters_count.should eq 1
|
212
|
+
end
|
213
|
+
it "returns nil when not set" do
|
214
|
+
tweet = Twitter::Tweet.new(:id => 28669546014)
|
215
|
+
tweet.retweeters_count.should be_nil
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
describe "#entities?" do
|
220
|
+
it "returns false if there are no entities set" do
|
221
|
+
tweet = Twitter::Tweet.new(:id => 28669546014)
|
222
|
+
tweet.entities?.should be_false
|
223
|
+
end
|
224
|
+
|
225
|
+
it "returns true if there are entities set" do
|
226
|
+
urls_hash = [
|
227
|
+
{
|
228
|
+
:url => 'http://example.com/t.co',
|
229
|
+
:expanded_url => 'http://example.com/expanded',
|
230
|
+
:display_url => 'example.com/expanded',
|
231
|
+
:indices => [10, 33],
|
232
|
+
}
|
233
|
+
]
|
234
|
+
tweet = Twitter::Tweet.new(:id => 28669546014, :entities => {:urls => urls_hash})
|
235
|
+
tweet.entities?.should be_true
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
describe "#urls" do
|
240
|
+
it "returns an Array of Entity::Url when entities are set" do
|
241
|
+
urls_hash = [
|
242
|
+
{
|
243
|
+
:url => 'http://example.com/t.co',
|
244
|
+
:expanded_url => 'http://example.com/expanded',
|
245
|
+
:display_url => 'example.com/expanded',
|
246
|
+
:indices => [10, 33],
|
247
|
+
}
|
248
|
+
]
|
249
|
+
urls = Twitter::Tweet.new(:id => 28669546014, :entities => {:urls => urls_hash}).urls
|
250
|
+
urls.should be_an Array
|
251
|
+
urls.first.should be_a Twitter::Entity::Url
|
252
|
+
urls.first.indices.should eq [10, 33]
|
253
|
+
urls.first.display_url.should eq 'example.com/expanded'
|
254
|
+
end
|
255
|
+
it "is empty when not set" do
|
256
|
+
urls = Twitter::Tweet.new(:id => 28669546014).urls
|
257
|
+
urls.should be_empty
|
258
|
+
end
|
259
|
+
it "warns when not set" do
|
260
|
+
Twitter::Tweet.new(:id => 28669546014).urls
|
261
|
+
$stderr.string.should =~ /To get urls, you must pass `:include_entities => true` when requesting the Twitter::Tweet\./
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
describe "#user" do
|
266
|
+
it "returns a User when user is set" do
|
267
|
+
user = Twitter::Tweet.new(:id => 28669546014, :user => {:id => 7505382}).user
|
268
|
+
user.should be_a Twitter::User
|
269
|
+
end
|
270
|
+
it "returns nil when user is not set" do
|
271
|
+
user = Twitter::Tweet.new(:id => 28669546014).user
|
272
|
+
user.should be_nil
|
273
|
+
end
|
274
|
+
it "has a status when status is set" do
|
275
|
+
user = Twitter::Tweet.new(:id => 28669546014, :text => 'Tweet text.', :user => {:id => 7505382}).user
|
276
|
+
user.status.should be_a Twitter::Tweet
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
describe "#user_mentions" do
|
281
|
+
it "returns an Array of Entity::UserMention when entities are set" do
|
282
|
+
user_mentions_hash = [
|
283
|
+
{
|
284
|
+
:screen_name => 'sferik',
|
285
|
+
:name => 'Erik Michaels-Ober',
|
286
|
+
:id_str => '7505382',
|
287
|
+
:indices => [0, 6],
|
288
|
+
:id => 7505382,
|
289
|
+
}
|
290
|
+
]
|
291
|
+
user_mentions = Twitter::Tweet.new(:id => 28669546014, :entities => {:user_mentions => user_mentions_hash}).user_mentions
|
292
|
+
user_mentions.should be_an Array
|
293
|
+
user_mentions.first.should be_a Twitter::Entity::UserMention
|
294
|
+
user_mentions.first.indices.should eq [0, 6]
|
295
|
+
user_mentions.first.id.should eq 7505382
|
296
|
+
end
|
297
|
+
it "is empty when not set" do
|
298
|
+
user_mentions = Twitter::Tweet.new(:id => 28669546014).user_mentions
|
299
|
+
user_mentions.should be_empty
|
300
|
+
end
|
301
|
+
it "warns when not set" do
|
302
|
+
Twitter::Tweet.new(:id => 28669546014).user_mentions
|
303
|
+
$stderr.string.should =~ /To get user mentions, you must pass `:include_entities => true` when requesting the Twitter::Tweet\./
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Twitter::User do
|
4
|
+
|
5
|
+
describe "#==" do
|
6
|
+
it "returns true when objects IDs are the same" do
|
7
|
+
user = Twitter::User.new(:id => 1, :screen_name => "foo")
|
8
|
+
other = Twitter::User.new(:id => 1, :screen_name => "bar")
|
9
|
+
(user == other).should be_true
|
10
|
+
end
|
11
|
+
it "returns false when objects IDs are different" do
|
12
|
+
user = Twitter::User.new(:id => 1)
|
13
|
+
other = Twitter::User.new(:id => 2)
|
14
|
+
(user == other).should be_false
|
15
|
+
end
|
16
|
+
it "returns false when classes are different" do
|
17
|
+
user = Twitter::User.new(:id => 1)
|
18
|
+
other = Twitter::Identity.new(:id => 1)
|
19
|
+
(user == other).should be_false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#created_at" do
|
24
|
+
it "returns a Time when created_at is set" do
|
25
|
+
user = Twitter::User.new(:id => 7505382, :created_at => "Mon Jul 16 12:59:01 +0000 2007")
|
26
|
+
user.created_at.should be_a Time
|
27
|
+
end
|
28
|
+
it "returns nil when created_at is not set" do
|
29
|
+
user = Twitter::User.new(:id => 7505382)
|
30
|
+
user.created_at.should be_nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#profile_image_url" do
|
35
|
+
it "returns a String when profile_image_url is set" do
|
36
|
+
user = Twitter::User.new(:id => 7505382, :profile_image_url => "http://a0.twimg.com/profile_images/1759857427/image1326743606_normal.png")
|
37
|
+
user.profile_image_url.should be_a String
|
38
|
+
end
|
39
|
+
it "returns nil when created_at is not set" do
|
40
|
+
user = Twitter::User.new(:id => 7505382)
|
41
|
+
user.profile_image_url.should be_nil
|
42
|
+
end
|
43
|
+
it "returns the normal-sized image" do
|
44
|
+
user = Twitter::User.new(:id => 7505382, :profile_image_url => "http://a0.twimg.com/profile_images/1759857427/image1326743606_normal.png")
|
45
|
+
user.profile_image_url.should eq "http://a0.twimg.com/profile_images/1759857427/image1326743606_normal.png"
|
46
|
+
end
|
47
|
+
context "with :original passed" do
|
48
|
+
it "returns the original image" do
|
49
|
+
user = Twitter::User.new(:id => 7505382, :profile_image_url => "http://a0.twimg.com/profile_images/1759857427/image1326743606_normal.png")
|
50
|
+
user.profile_image_url(:original).should eq "http://a0.twimg.com/profile_images/1759857427/image1326743606.png"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
context "with :bigger passed" do
|
54
|
+
it "returns the bigger-sized image" do
|
55
|
+
user = Twitter::User.new(:id => 7505382, :profile_image_url => "http://a0.twimg.com/profile_images/1759857427/image1326743606_normal.png")
|
56
|
+
user.profile_image_url(:bigger).should eq "http://a0.twimg.com/profile_images/1759857427/image1326743606_bigger.png"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
context "with :mini passed" do
|
60
|
+
it "returns the mini-sized image" do
|
61
|
+
user = Twitter::User.new(:id => 7505382, :profile_image_url => "http://a0.twimg.com/profile_images/1759857427/image1326743606_normal.png")
|
62
|
+
user.profile_image_url(:mini).should eq "http://a0.twimg.com/profile_images/1759857427/image1326743606_mini.png"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "#profile_image_url_https" do
|
68
|
+
it "returns a String when profile_image_url_https is set" do
|
69
|
+
user = Twitter::User.new(:id => 7505382, :profile_image_url_https => "https://a0.twimg.com/profile_images/1759857427/image1326743606_normal.png")
|
70
|
+
user.profile_image_url_https.should be_a String
|
71
|
+
end
|
72
|
+
it "returns nil when created_at is not set" do
|
73
|
+
user = Twitter::User.new(:id => 7505382)
|
74
|
+
user.profile_image_url_https.should be_nil
|
75
|
+
end
|
76
|
+
it "returns the normal-sized image" do
|
77
|
+
user = Twitter::User.new(:id => 7505382, :profile_image_url_https => "https://a0.twimg.com/profile_images/1759857427/image1326743606_normal.png")
|
78
|
+
user.profile_image_url_https.should eq "https://a0.twimg.com/profile_images/1759857427/image1326743606_normal.png"
|
79
|
+
end
|
80
|
+
context "with :original passed" do
|
81
|
+
it "returns the original image" do
|
82
|
+
user = Twitter::User.new(:id => 7505382, :profile_image_url_https => "https://a0.twimg.com/profile_images/1759857427/image1326743606_normal.png")
|
83
|
+
user.profile_image_url_https(:original).should eq "https://a0.twimg.com/profile_images/1759857427/image1326743606.png"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
context "with :bigger passed" do
|
87
|
+
it "returns the bigger-sized image" do
|
88
|
+
user = Twitter::User.new(:id => 7505382, :profile_image_url_https => "https://a0.twimg.com/profile_images/1759857427/image1326743606_normal.png")
|
89
|
+
user.profile_image_url_https(:bigger).should eq "https://a0.twimg.com/profile_images/1759857427/image1326743606_bigger.png"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
context "with :mini passed" do
|
93
|
+
it "returns the mini-sized image" do
|
94
|
+
user = Twitter::User.new(:id => 7505382, :profile_image_url_https => "https://a0.twimg.com/profile_images/1759857427/image1326743606_normal.png")
|
95
|
+
user.profile_image_url_https(:mini).should eq "https://a0.twimg.com/profile_images/1759857427/image1326743606_mini.png"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "#status" do
|
101
|
+
it "returns a Status when status is set" do
|
102
|
+
tweet = Twitter::User.new(:id => 7505382, :status => {:id => 25938088801}).status
|
103
|
+
tweet.should be_a Twitter::Tweet
|
104
|
+
end
|
105
|
+
it "returns nil when status is not set" do
|
106
|
+
tweet = Twitter::User.new(:id => 7505382).status
|
107
|
+
tweet.should be_nil
|
108
|
+
end
|
109
|
+
it "includes a User when user is set" do
|
110
|
+
tweet = Twitter::User.new(:id => 7505382, :screen_name => 'sferik', :status => {:id => 25938088801}).status
|
111
|
+
tweet.user.should be_a Twitter::User
|
112
|
+
tweet.user.id.should eq 7505382
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe "#status?" do
|
117
|
+
it "returns true when status is set" do
|
118
|
+
tweet = Twitter::User.new(:id => 7505382, :status => {:id => 25938088801}).status?
|
119
|
+
tweet.should be_true
|
120
|
+
end
|
121
|
+
it "returns false when status is not set" do
|
122
|
+
tweet = Twitter::User.new(:id => 7505382).status?
|
123
|
+
tweet.should be_false
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|