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,28 @@
|
|
1
|
+
require 'twitter/error'
|
2
|
+
|
3
|
+
module Twitter
|
4
|
+
class Error
|
5
|
+
# Raised when Twitter returns a 5xx HTTP status code
|
6
|
+
class ServerError < Twitter::Error
|
7
|
+
MESSAGE = "Server Error"
|
8
|
+
|
9
|
+
# Create a new error from an HTTP environment
|
10
|
+
#
|
11
|
+
# @param response [Hash]
|
12
|
+
# @return [Twitter::Error]
|
13
|
+
def self.from_response(response={})
|
14
|
+
new(nil, response[:response_headers])
|
15
|
+
end
|
16
|
+
|
17
|
+
# Initializes a new ServerError object
|
18
|
+
#
|
19
|
+
# @param message [String]
|
20
|
+
# @param response_headers [Hash]
|
21
|
+
# @return [Twitter::Error::ServerError]
|
22
|
+
def initialize(message=nil, response_headers={})
|
23
|
+
super((message || self.class.const_get(:MESSAGE)), response_headers)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'twitter/error/server_error'
|
2
|
+
|
3
|
+
module Twitter
|
4
|
+
class Error
|
5
|
+
# Raised when Twitter returns the HTTP status code 503
|
6
|
+
class ServiceUnavailable < Twitter::Error::ServerError
|
7
|
+
HTTP_STATUS_CODE = 503
|
8
|
+
MESSAGE = "(__-){ Twitter is over capacity."
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'twitter/core_ext/string'
|
2
|
+
|
3
|
+
module Twitter
|
4
|
+
class Factory
|
5
|
+
|
6
|
+
# Instantiates a new action object
|
7
|
+
#
|
8
|
+
# @param attrs [Hash]
|
9
|
+
# @raise [ArgumentError] Error raised when supplied argument is missing an :action key.
|
10
|
+
# @return [Twitter::Action::Favorite, Twitter::Action::Follow, Twitter::Action::ListMemberAdded, Twitter::Action::Mention, Twitter::Action::Reply, Twitter::Action::Retweet]
|
11
|
+
def self.fetch_or_new(method, klass, attrs={})
|
12
|
+
return unless attrs
|
13
|
+
if type = attrs.delete(method.to_sym)
|
14
|
+
klass.const_get(type.camelize.to_sym).fetch_or_new(attrs)
|
15
|
+
else
|
16
|
+
raise ArgumentError, "argument must have :#{method} key"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
data/lib/twitter/geo.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'twitter/base'
|
2
|
+
|
3
|
+
module Twitter
|
4
|
+
class Geo < Twitter::Base
|
5
|
+
attr_reader :coordinates
|
6
|
+
alias coords coordinates
|
7
|
+
|
8
|
+
# @param other [Twitter::Geo]
|
9
|
+
# @return [Boolean]
|
10
|
+
def ==(other)
|
11
|
+
super || attr_equal(:coordinates, other) || attrs_equal(other)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'twitter/geo'
|
2
|
+
|
3
|
+
module Twitter
|
4
|
+
class Geo
|
5
|
+
class Point < Twitter::Geo
|
6
|
+
|
7
|
+
# @return [Integer]
|
8
|
+
def latitude
|
9
|
+
self.coordinates[0]
|
10
|
+
end
|
11
|
+
alias lat latitude
|
12
|
+
|
13
|
+
# @return [Integer]
|
14
|
+
def longitude
|
15
|
+
self.coordinates[1]
|
16
|
+
end
|
17
|
+
alias long longitude
|
18
|
+
alias lng longitude
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'twitter/factory'
|
2
|
+
require 'twitter/geo/point'
|
3
|
+
require 'twitter/geo/polygon'
|
4
|
+
|
5
|
+
module Twitter
|
6
|
+
class GeoFactory < Twitter::Factory
|
7
|
+
|
8
|
+
# Instantiates a new geo object
|
9
|
+
#
|
10
|
+
# @param attrs [Hash]
|
11
|
+
# @raise [ArgumentError] Error raised when supplied argument is missing a :type key.
|
12
|
+
# @return [Twitter::Geo]
|
13
|
+
def self.fetch_or_new(attrs={})
|
14
|
+
super(:type, Twitter::Geo, attrs)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'twitter/base'
|
2
|
+
require 'twitter/error/identity_map_key_error'
|
3
|
+
|
4
|
+
module Twitter
|
5
|
+
class Identity < Twitter::Base
|
6
|
+
|
7
|
+
def self.fetch(attrs)
|
8
|
+
return unless identity_map
|
9
|
+
|
10
|
+
id = attrs[:id]
|
11
|
+
if id && object = identity_map.fetch(id)
|
12
|
+
return object.update(attrs)
|
13
|
+
end
|
14
|
+
|
15
|
+
return yield if block_given?
|
16
|
+
raise Twitter::Error::IdentityMapKeyError, "key not found"
|
17
|
+
end
|
18
|
+
|
19
|
+
# Stores an object in the identity map.
|
20
|
+
#
|
21
|
+
# @param object [Object]
|
22
|
+
# @return [Twitter::Identity]
|
23
|
+
def self.store(object)
|
24
|
+
return object unless identity_map
|
25
|
+
identity_map.store(object.id, object)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Initializes a new object
|
29
|
+
#
|
30
|
+
# @param attrs [Hash]
|
31
|
+
# @raise [ArgumentError] Error raised when supplied argument is missing an :id key.
|
32
|
+
# @return [Twitter::Identity]
|
33
|
+
def initialize(attrs={})
|
34
|
+
super
|
35
|
+
raise ArgumentError, "argument must have an :id key" unless id
|
36
|
+
end
|
37
|
+
|
38
|
+
# @param other [Twitter::Identity]
|
39
|
+
# @return [Boolean]
|
40
|
+
def ==(other)
|
41
|
+
super || attr_equal(:id, other) || attrs_equal(other)
|
42
|
+
end
|
43
|
+
|
44
|
+
# @return [Integer]
|
45
|
+
def id
|
46
|
+
@attrs[:id]
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Twitter
|
2
|
+
|
3
|
+
# Tracks objects to help ensure that each object gets loaded only once.
|
4
|
+
# See: http://www.martinfowler.com/eaaCatalog/identityMap.html
|
5
|
+
class IdentityMap < Hash
|
6
|
+
|
7
|
+
# @param id
|
8
|
+
# @return [Object]
|
9
|
+
def fetch(id)
|
10
|
+
self[id]
|
11
|
+
end
|
12
|
+
|
13
|
+
# @param id
|
14
|
+
# @param object
|
15
|
+
# @return [Object]
|
16
|
+
def store(id, object)
|
17
|
+
self[id] = object
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/lib/twitter/list.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'twitter/creatable'
|
2
|
+
require 'twitter/identity'
|
3
|
+
require 'twitter/user'
|
4
|
+
|
5
|
+
module Twitter
|
6
|
+
class List < Twitter::Identity
|
7
|
+
include Twitter::Creatable
|
8
|
+
attr_reader :description, :following, :full_name, :member_count,
|
9
|
+
:mode, :name, :slug, :subscriber_count, :uri
|
10
|
+
alias following? following
|
11
|
+
|
12
|
+
# @return [Twitter::User]
|
13
|
+
def user
|
14
|
+
@user ||= Twitter::User.fetch_or_new(@attrs[:user])
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'twitter/identity'
|
2
|
+
require 'twitter/size'
|
3
|
+
|
4
|
+
module Twitter
|
5
|
+
module Media
|
6
|
+
class Photo < Twitter::Identity
|
7
|
+
attr_reader :display_url, :expanded_url, :indices, :media_url,
|
8
|
+
:media_url_https, :url
|
9
|
+
|
10
|
+
# Returns an array of photo sizes
|
11
|
+
#
|
12
|
+
# @return [Array<Twitter::Size>]
|
13
|
+
def sizes
|
14
|
+
@sizes ||= Array(@attrs[:sizes]).inject({}) do |object, (key, value)|
|
15
|
+
object[key] = Twitter::Size.fetch_or_new(value)
|
16
|
+
object
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'twitter/factory'
|
2
|
+
require 'twitter/media/photo'
|
3
|
+
|
4
|
+
module Twitter
|
5
|
+
class MediaFactory < Twitter::Factory
|
6
|
+
|
7
|
+
# Instantiates a new media object
|
8
|
+
#
|
9
|
+
# @param attrs [Hash]
|
10
|
+
# @raise [ArgumentError] Error raised when supplied argument is missing a :type key.
|
11
|
+
# @return [Twitter::Media]
|
12
|
+
def self.fetch_or_new(attrs={})
|
13
|
+
super(:type, Twitter::Media, attrs)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'twitter/geo_factory'
|
2
|
+
require 'twitter/identity'
|
3
|
+
|
4
|
+
module Twitter
|
5
|
+
class Place < Twitter::Identity
|
6
|
+
attr_reader :attributes, :country, :full_name, :name, :url, :woeid
|
7
|
+
alias woe_id woeid
|
8
|
+
|
9
|
+
# @return [Twitter::Geo]
|
10
|
+
def bounding_box
|
11
|
+
@bounding_box ||= Twitter::GeoFactory.fetch_or_new(@attrs[:bounding_box])
|
12
|
+
end
|
13
|
+
|
14
|
+
# @return [String]
|
15
|
+
def country_code
|
16
|
+
@country_code ||= @attrs[:country_code] || @attrs[:countryCode]
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [Integer]
|
20
|
+
def parent_id
|
21
|
+
@parent_id ||= @attrs[:parentid]
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [String]
|
25
|
+
def place_type
|
26
|
+
@place_type ||= @attrs[:place_type] || @attrs[:placeType] && @attrs[:placeType][:name]
|
27
|
+
end
|
28
|
+
|
29
|
+
def id
|
30
|
+
@attrs[:id] || @attrs[:woeid]
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Twitter
|
2
|
+
class RateLimit
|
3
|
+
attr_reader :attrs
|
4
|
+
alias to_hash attrs
|
5
|
+
|
6
|
+
# @return [Twitter::RateLimit]
|
7
|
+
def initialize(attrs={})
|
8
|
+
@attrs = attrs
|
9
|
+
end
|
10
|
+
|
11
|
+
# @return [Integer]
|
12
|
+
def limit
|
13
|
+
limit = @attrs['x-rate-limit-limit']
|
14
|
+
limit.to_i if limit
|
15
|
+
end
|
16
|
+
|
17
|
+
# @return [Integer]
|
18
|
+
def remaining
|
19
|
+
remaining = @attrs['x-rate-limit-remaining']
|
20
|
+
remaining.to_i if remaining
|
21
|
+
end
|
22
|
+
|
23
|
+
# @return [Time]
|
24
|
+
def reset_at
|
25
|
+
reset = @attrs['x-rate-limit-reset']
|
26
|
+
Time.at(reset.to_i) if reset
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [Integer]
|
30
|
+
def reset_in
|
31
|
+
[(reset_at - Time.now).ceil, 0].max if reset_at
|
32
|
+
end
|
33
|
+
alias retry_after reset_in
|
34
|
+
|
35
|
+
# Update the attributes of a RateLimit
|
36
|
+
#
|
37
|
+
# @param attrs [Hash]
|
38
|
+
# @return [Twitter::RateLimit]
|
39
|
+
def update(attrs)
|
40
|
+
@attrs.update(attrs)
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'twitter/base'
|
2
|
+
require 'twitter/source_user'
|
3
|
+
require 'twitter/target_user'
|
4
|
+
|
5
|
+
module Twitter
|
6
|
+
class Relationship < Twitter::Base
|
7
|
+
|
8
|
+
# Initializes a new object
|
9
|
+
#
|
10
|
+
# @param attrs [Hash]
|
11
|
+
# @return [Twitter::Relationship]
|
12
|
+
def initialize(attrs={})
|
13
|
+
@attrs = attrs[:relationship]
|
14
|
+
end
|
15
|
+
|
16
|
+
# @return [Twitter::SourceUser]
|
17
|
+
def source
|
18
|
+
@source ||= Twitter::SourceUser.fetch_or_new(@attrs[:source])
|
19
|
+
end
|
20
|
+
|
21
|
+
# @return [Twitter::TargetUser]
|
22
|
+
def target
|
23
|
+
@target ||= Twitter::TargetUser.fetch_or_new(@attrs[:target])
|
24
|
+
end
|
25
|
+
|
26
|
+
# Update the attributes of a Relationship
|
27
|
+
#
|
28
|
+
# @param attrs [Hash]
|
29
|
+
# @return [Twitter::Relationship]
|
30
|
+
def update(attrs)
|
31
|
+
@attrs.update(attrs[:relationship]) unless attrs[:relationship].nil?
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|