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,40 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Twitter::Error::ClientError do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@client = Twitter::Client.new
|
7
|
+
end
|
8
|
+
|
9
|
+
Twitter::Error::ClientError.errors.each do |status, exception|
|
10
|
+
[nil, "error", "errors"].each do |body|
|
11
|
+
context "when HTTP status is #{status} and body is #{body.inspect}" do
|
12
|
+
before do
|
13
|
+
body_message = '{"' + body + '":"Client Error"}' unless body.nil?
|
14
|
+
stub_get("/1.1/statuses/user_timeline.json").
|
15
|
+
with(:query => {:screen_name => 'sferik'}).
|
16
|
+
to_return(:status => status, :body => body_message)
|
17
|
+
end
|
18
|
+
it "raises #{exception.name}" do
|
19
|
+
lambda do
|
20
|
+
@client.user_timeline('sferik')
|
21
|
+
end.should raise_error(exception)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "when response status is 404 from lookup" do
|
28
|
+
before do
|
29
|
+
stub_post("/1.1/users/lookup.json").
|
30
|
+
with(:body => {:screen_name => "not_on_twitter"}).
|
31
|
+
to_return(:status => 404, :body => fixture('no_user_matches.json'))
|
32
|
+
end
|
33
|
+
it "raises Twitter::Error::NotFound" do
|
34
|
+
lambda do
|
35
|
+
@client.users('not_on_twitter')
|
36
|
+
end.should raise_error(Twitter::Error::NotFound)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Twitter::Error::ServerError do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@client = Twitter::Client.new
|
7
|
+
end
|
8
|
+
|
9
|
+
Twitter::Error::ServerError.errors.each do |status, exception|
|
10
|
+
context "when HTTP status is #{status}" do
|
11
|
+
before do
|
12
|
+
stub_get("/1.1/statuses/user_timeline.json").
|
13
|
+
with(:query => {:screen_name => 'sferik'}).
|
14
|
+
to_return(:status => status)
|
15
|
+
end
|
16
|
+
it "raises #{exception.name}" do
|
17
|
+
lambda do
|
18
|
+
@client.user_timeline('sferik')
|
19
|
+
end.should raise_error(exception)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Twitter::Error do
|
4
|
+
|
5
|
+
describe "#initialize" do
|
6
|
+
it "wraps another error class" do
|
7
|
+
begin
|
8
|
+
raise Faraday::Error::ClientError.new("Oups")
|
9
|
+
rescue Faraday::Error::ClientError
|
10
|
+
begin
|
11
|
+
raise Twitter::Error
|
12
|
+
rescue Twitter::Error => error
|
13
|
+
error.message.should eq "Oups"
|
14
|
+
error.wrapped_exception.class.should eq Faraday::Error::ClientError
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Twitter::Geo::Point do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@point = Twitter::Geo::Point.new(:coordinates => [-122.399983, 37.788299])
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#==" do
|
10
|
+
it "returns false for empty objects" do
|
11
|
+
point = Twitter::Geo::Point.new
|
12
|
+
other = Twitter::Geo::Point.new
|
13
|
+
(point == other).should be_false
|
14
|
+
end
|
15
|
+
it "returns true when objects coordinates are the same" do
|
16
|
+
other = Twitter::Geo::Point.new(:coordinates => [-122.399983, 37.788299])
|
17
|
+
(@point == other).should be_true
|
18
|
+
end
|
19
|
+
it "returns false when objects coordinates are different" do
|
20
|
+
other = Twitter::Geo::Point.new(:coordinates => [37.788299, -122.399983])
|
21
|
+
(@point == other).should be_false
|
22
|
+
end
|
23
|
+
it "returns false when classes are different" do
|
24
|
+
other = Twitter::Geo.new(:coordinates => [-122.399983, 37.788299])
|
25
|
+
(@point == other).should be_false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#latitude" do
|
30
|
+
it "returns the latitude" do
|
31
|
+
@point.latitude.should eq(-122.399983)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#longitude" do
|
36
|
+
it "returns the longitude" do
|
37
|
+
@point.longitude.should eq 37.788299
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Twitter::Geo::Polygon do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@polygon = Twitter::Geo::Polygon.new(:coordinates => [[[-122.40348192, 37.77752898], [-122.387436, 37.77752898], [-122.387436, 37.79448597], [-122.40348192, 37.79448597]]])
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#==" do
|
10
|
+
it "returns false for empty objects" do
|
11
|
+
polygon = Twitter::Geo::Polygon.new
|
12
|
+
other = Twitter::Geo::Polygon.new
|
13
|
+
(polygon == other).should be_false
|
14
|
+
end
|
15
|
+
it "returns true when objects coordinates are the same" do
|
16
|
+
other = Twitter::Geo::Polygon.new(:coordinates => [[[-122.40348192, 37.77752898], [-122.387436, 37.77752898], [-122.387436, 37.79448597], [-122.40348192, 37.79448597]]])
|
17
|
+
(@polygon == other).should be_true
|
18
|
+
end
|
19
|
+
it "returns false when objects coordinates are different" do
|
20
|
+
other = Twitter::Geo::Polygon.new(:coordinates => [[[37.77752898, -122.40348192], [37.77752898, -122.387436], [37.79448597, -122.387436], [37.79448597, -122.40348192]]])
|
21
|
+
(@polygon == other).should be_false
|
22
|
+
end
|
23
|
+
it "returns false when classes are different" do
|
24
|
+
other = Twitter::Geo.new(:coordinates => [[[-122.40348192, 37.77752898], [-122.387436, 37.77752898], [-122.387436, 37.79448597], [-122.40348192, 37.79448597]]])
|
25
|
+
(@polygon == other).should be_false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Twitter::GeoFactory do
|
4
|
+
|
5
|
+
describe ".new" do
|
6
|
+
it "generates a Point" do
|
7
|
+
geo = Twitter::GeoFactory.fetch_or_new(:type => 'Point')
|
8
|
+
geo.should be_a Twitter::Geo::Point
|
9
|
+
end
|
10
|
+
it "generates a Polygon" do
|
11
|
+
geo = Twitter::GeoFactory.fetch_or_new(:type => 'Polygon')
|
12
|
+
geo.should be_a Twitter::Geo::Polygon
|
13
|
+
end
|
14
|
+
it "raises an ArgumentError when type is not specified" do
|
15
|
+
lambda do
|
16
|
+
Twitter::GeoFactory.fetch_or_new
|
17
|
+
end.should raise_error(ArgumentError, "argument must have :type key")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Twitter::Geo do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@geo = Twitter::Geo.new(:coordinates => [[[-122.40348192, 37.77752898], [-122.387436, 37.77752898], [-122.387436, 37.79448597], [-122.40348192, 37.79448597]]])
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#==" do
|
10
|
+
it "returns false for empty objects" do
|
11
|
+
geo = Twitter::Geo.new
|
12
|
+
other = Twitter::Geo.new
|
13
|
+
(geo == other).should be_false
|
14
|
+
end
|
15
|
+
it "returns true when objects coordinates are the same" do
|
16
|
+
other = Twitter::Geo.new(:coordinates => [[[-122.40348192, 37.77752898], [-122.387436, 37.77752898], [-122.387436, 37.79448597], [-122.40348192, 37.79448597]]])
|
17
|
+
(@geo == other).should be_true
|
18
|
+
end
|
19
|
+
it "returns false when objects coordinates are different" do
|
20
|
+
other = Twitter::Geo.new(:coordinates => [[[37.77752898, -122.40348192], [37.77752898, -122.387436], [37.79448597, -122.387436], [37.79448597, -122.40348192]]])
|
21
|
+
(@geo == other).should be_false
|
22
|
+
end
|
23
|
+
it "returns false when classes are different" do
|
24
|
+
other = Twitter::Geo::Polygon.new(:coordinates => [[[-122.40348192, 37.77752898], [-122.387436, 37.77752898], [-122.387436, 37.79448597], [-122.40348192, 37.79448597]]])
|
25
|
+
(@geo == other).should be_false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Twitter::Identity do
|
4
|
+
|
5
|
+
describe "#initialize" do
|
6
|
+
it "raises an ArgumentError when type is not specified" do
|
7
|
+
lambda do
|
8
|
+
Twitter::Identity.new
|
9
|
+
end.should raise_error(ArgumentError, "argument must have an :id key")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'identity map enabled' do
|
14
|
+
before do
|
15
|
+
Twitter.identity_map = Twitter::IdentityMap
|
16
|
+
end
|
17
|
+
|
18
|
+
after do
|
19
|
+
Twitter.identity_map = false
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '.fetch' do
|
23
|
+
it 'returns existing objects' do
|
24
|
+
Twitter::Identity.store(Twitter::Identity.new(:id => 1))
|
25
|
+
Twitter::Identity.fetch(:id => 1).should be
|
26
|
+
end
|
27
|
+
|
28
|
+
it "raises an error on objects that don't exist" do
|
29
|
+
lambda {
|
30
|
+
Twitter::Identity.fetch(:id => 6)
|
31
|
+
}.should raise_error(Twitter::Error::IdentityMapKeyError)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#==" do
|
37
|
+
it "returns true when objects IDs are the same" do
|
38
|
+
one = Twitter::Identity.new(:id => 1, :screen_name => "sferik")
|
39
|
+
two = Twitter::Identity.new(:id => 1, :screen_name => "garybernhardt")
|
40
|
+
(one == two).should be_true
|
41
|
+
end
|
42
|
+
it "returns false when objects IDs are different" do
|
43
|
+
one = Twitter::Identity.new(:id => 1)
|
44
|
+
two = Twitter::Identity.new(:id => 2)
|
45
|
+
(one == two).should be_false
|
46
|
+
end
|
47
|
+
it "returns false when classes are different" do
|
48
|
+
one = Twitter::Identity.new(:id => 1)
|
49
|
+
two = Twitter::Base.new(:id => 1)
|
50
|
+
(one == two).should be_false
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Twitter::List do
|
4
|
+
|
5
|
+
describe "#==" do
|
6
|
+
it "returns true when objects IDs are the same" do
|
7
|
+
list = Twitter::List.new(:id => 1, :slug => "foo")
|
8
|
+
other = Twitter::List.new(:id => 1, :slug => "bar")
|
9
|
+
(list == other).should be_true
|
10
|
+
end
|
11
|
+
it "returns false when objects IDs are different" do
|
12
|
+
list = Twitter::List.new(:id => 1)
|
13
|
+
other = Twitter::List.new(:id => 2)
|
14
|
+
(list == other).should be_false
|
15
|
+
end
|
16
|
+
it "returns false when classes are different" do
|
17
|
+
list = Twitter::List.new(:id => 1)
|
18
|
+
other = Twitter::Identity.new(:id => 1)
|
19
|
+
(list == 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::List.new(:id => 8863586, :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::List.new(:id => 8863586)
|
30
|
+
user.created_at.should be_nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#user" do
|
35
|
+
it "returns a User when user is set" do
|
36
|
+
user = Twitter::List.new(:id => 8863586, :user => {:id => 7505382}).user
|
37
|
+
user.should be_a Twitter::User
|
38
|
+
end
|
39
|
+
it "returns nil when status is not set" do
|
40
|
+
user = Twitter::List.new(:id => 8863586).user
|
41
|
+
user.should be_nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Twitter::Media::Photo do
|
4
|
+
|
5
|
+
describe "#==" do
|
6
|
+
it "returns true when objects IDs are the same" do
|
7
|
+
photo = Twitter::Media::Photo.new(:id => 1, :url => "foo")
|
8
|
+
other = Twitter::Media::Photo.new(:id => 1, :url => "bar")
|
9
|
+
(photo == other).should be_true
|
10
|
+
end
|
11
|
+
it "returns false when objects IDs are different" do
|
12
|
+
photo = Twitter::Media::Photo.new(:id => 1)
|
13
|
+
other = Twitter::Media::Photo.new(:id => 2)
|
14
|
+
(photo == other).should be_false
|
15
|
+
end
|
16
|
+
it "returns false when classes are different" do
|
17
|
+
photo = Twitter::Media::Photo.new(:id => 1)
|
18
|
+
other = Twitter::Identity.new(:id => 1)
|
19
|
+
(photo == other).should be_false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#sizes" do
|
24
|
+
it "returns a hash of Sizes when sizes is set" do
|
25
|
+
sizes = Twitter::Media::Photo.new(:id => 110102452988157952, :sizes => {:small => {:h => 226, :w => 340, :resize => 'fit'}, :large => {:h => 466, :w => 700, :resize => 'fit'}, :medium => {:h => 399, :w => 600, :resize => 'fit'}, :thumb => {:h => 150, :w => 150, :resize => 'crop'}}).sizes
|
26
|
+
sizes.should be_a Hash
|
27
|
+
sizes[:small].should be_a Twitter::Size
|
28
|
+
end
|
29
|
+
it "is empty when sizes is not set" do
|
30
|
+
sizes = Twitter::Media::Photo.new(:id => 110102452988157952).sizes
|
31
|
+
sizes.should be_empty
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Twitter::MediaFactory do
|
4
|
+
|
5
|
+
describe ".new" do
|
6
|
+
it "generates a Photo" do
|
7
|
+
media = Twitter::MediaFactory.fetch_or_new(:id => 1, :type => 'photo')
|
8
|
+
media.should be_a Twitter::Media::Photo
|
9
|
+
end
|
10
|
+
it "raises an ArgumentError when type is not specified" do
|
11
|
+
lambda do
|
12
|
+
Twitter::MediaFactory.fetch_or_new
|
13
|
+
end.should raise_error(ArgumentError, "argument must have :type key")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Twitter::OEmbed do
|
4
|
+
|
5
|
+
describe "#author_url" do
|
6
|
+
it "returns the author's url" do
|
7
|
+
oembed = Twitter::OEmbed.new(:author_url => 'https://twitter.com/sferik')
|
8
|
+
oembed.author_url.should eq "https://twitter.com/sferik"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns nil when not set" do
|
12
|
+
author_url = Twitter::OEmbed.new.author_url
|
13
|
+
author_url.should be_nil
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#author_name" do
|
18
|
+
it "returns the author's name" do
|
19
|
+
oembed = Twitter::OEmbed.new(:author_name => 'Erik Michaels-Ober')
|
20
|
+
oembed.author_name.should eq "Erik Michaels-Ober"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns nil when not set" do
|
24
|
+
author_name = Twitter::OEmbed.new.author_name
|
25
|
+
author_name.should be_nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#cache_age" do
|
30
|
+
it "returns the cache_age" do
|
31
|
+
oembed = Twitter::OEmbed.new(:cache_age => '31536000000')
|
32
|
+
oembed.cache_age.should eq "31536000000"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns nil when not set" do
|
36
|
+
cache_age = Twitter::OEmbed.new.cache_age
|
37
|
+
cache_age.should be_nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#height" do
|
42
|
+
it "returns the height" do
|
43
|
+
oembed = Twitter::OEmbed.new(:height => 200)
|
44
|
+
oembed.height.should eq 200
|
45
|
+
end
|
46
|
+
|
47
|
+
it "returns it as an Integer" do
|
48
|
+
oembed = Twitter::OEmbed.new(:height => 200)
|
49
|
+
oembed.height.should be_an Integer
|
50
|
+
end
|
51
|
+
|
52
|
+
it "returns nil when not set" do
|
53
|
+
height = Twitter::OEmbed.new.height
|
54
|
+
height.should be_nil
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#html" do
|
59
|
+
it "returns the html" do
|
60
|
+
oembed = Twitter::OEmbed.new(:html => '<blockquote>all my <b>witty tweet</b> stuff here</blockquote>')
|
61
|
+
oembed.html.should eq "<blockquote>all my <b>witty tweet</b> stuff here</blockquote>"
|
62
|
+
end
|
63
|
+
|
64
|
+
it "returns nil when not set" do
|
65
|
+
html = Twitter::OEmbed.new.html
|
66
|
+
html.should be_nil
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "#provider_name" do
|
71
|
+
it "returns the provider_name" do
|
72
|
+
oembed = Twitter::OEmbed.new(:provider_name => 'Twitter')
|
73
|
+
oembed.provider_name.should eq "Twitter"
|
74
|
+
end
|
75
|
+
|
76
|
+
it "returns nil when not set" do
|
77
|
+
provider_name = Twitter::OEmbed.new.provider_name
|
78
|
+
provider_name.should be_nil
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "#provider_url" do
|
83
|
+
it "returns the provider_url" do
|
84
|
+
oembed = Twitter::OEmbed.new(:provider_url => 'http://twitter.com')
|
85
|
+
oembed.provider_url.should eq "http://twitter.com"
|
86
|
+
end
|
87
|
+
|
88
|
+
it "returns nil when not set" do
|
89
|
+
provider_url = Twitter::OEmbed.new.provider_url
|
90
|
+
provider_url.should be_nil
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "#type" do
|
95
|
+
it "returns the type" do
|
96
|
+
oembed = Twitter::OEmbed.new(:type => 'rich')
|
97
|
+
oembed.type.should eq "rich"
|
98
|
+
end
|
99
|
+
|
100
|
+
it "returns nil when not set" do
|
101
|
+
type = Twitter::OEmbed.new.type
|
102
|
+
type.should be_nil
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "#width" do
|
107
|
+
it "returns the width" do
|
108
|
+
oembed = Twitter::OEmbed.new(:width => 550)
|
109
|
+
oembed.width.should eq 550
|
110
|
+
end
|
111
|
+
|
112
|
+
it "returns it as an Integer" do
|
113
|
+
oembed = Twitter::OEmbed.new(:width => 550)
|
114
|
+
oembed.width.should be_an Integer
|
115
|
+
end
|
116
|
+
|
117
|
+
it "returns nil when not set" do
|
118
|
+
width = Twitter::OEmbed.new.width
|
119
|
+
width.should be_nil
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "#url" do
|
124
|
+
it "returns the url" do
|
125
|
+
oembed = Twitter::OEmbed.new(:url => 'https://twitter.com/twitterapi/status/133640144317198338')
|
126
|
+
oembed.url.should eq "https://twitter.com/twitterapi/status/133640144317198338"
|
127
|
+
end
|
128
|
+
|
129
|
+
it "returns nil when not set" do
|
130
|
+
url = Twitter::OEmbed.new.url
|
131
|
+
url.should be_nil
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
describe "#version" do
|
136
|
+
it "returns the version" do
|
137
|
+
oembed = Twitter::OEmbed.new(:version => '1.0')
|
138
|
+
oembed.version.should eq "1.0"
|
139
|
+
end
|
140
|
+
|
141
|
+
it "returns nil when not set" do
|
142
|
+
version = Twitter::OEmbed.new.version
|
143
|
+
version.should be_nil
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|