twitter 5.0.0 → 5.4.1
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/.yardopts +4 -0
- data/CHANGELOG.md +47 -0
- data/CONTRIBUTING.md +5 -5
- data/README.md +57 -56
- data/Rakefile +26 -5
- data/lib/twitter/arguments.rb +1 -2
- data/lib/twitter/base.rb +15 -18
- data/lib/twitter/basic_user.rb +3 -3
- data/lib/twitter/client.rb +9 -10
- data/lib/twitter/configuration.rb +5 -5
- data/lib/twitter/creatable.rb +0 -1
- data/lib/twitter/cursor.rb +9 -36
- data/lib/twitter/direct_message.rb +1 -1
- data/lib/twitter/entity/uri.rb +2 -2
- data/lib/twitter/enumerable.rb +10 -1
- data/lib/twitter/error/already_favorited.rb +1 -1
- data/lib/twitter/error/already_posted.rb +1 -1
- data/lib/twitter/error/already_retweeted.rb +1 -1
- data/lib/twitter/error/too_many_requests.rb +2 -2
- data/lib/twitter/error.rb +6 -6
- data/lib/twitter/factory.rb +2 -6
- data/lib/twitter/geo/point.rb +3 -5
- data/lib/twitter/geo.rb +1 -1
- data/lib/twitter/geo_factory.rb +1 -5
- data/lib/twitter/geo_results.rb +5 -8
- data/lib/twitter/identity.rb +1 -2
- data/lib/twitter/list.rb +10 -11
- data/lib/twitter/media/photo.rb +1 -2
- data/lib/twitter/media_factory.rb +1 -5
- data/lib/twitter/null_object.rb +4 -6
- data/lib/twitter/oembed.rb +1 -1
- data/lib/twitter/place.rb +17 -6
- data/lib/twitter/profile_banner.rb +1 -3
- data/lib/twitter/rate_limit.rb +1 -3
- data/lib/twitter/relationship.rb +1 -2
- data/lib/twitter/rest/api/direct_messages.rb +15 -15
- data/lib/twitter/rest/api/favorites.rb +15 -15
- data/lib/twitter/rest/api/friends_and_followers.rb +37 -42
- data/lib/twitter/rest/api/help.rb +8 -9
- data/lib/twitter/rest/api/lists.rb +69 -69
- data/lib/twitter/rest/api/oauth.rb +3 -4
- data/lib/twitter/rest/api/places_and_geo.rb +9 -10
- data/lib/twitter/rest/api/saved_searches.rb +8 -8
- data/lib/twitter/rest/api/search.rb +10 -2
- data/lib/twitter/rest/api/spam_reporting.rb +1 -2
- data/lib/twitter/rest/api/suggested_users.rb +4 -5
- data/lib/twitter/rest/api/timelines.rb +17 -18
- data/lib/twitter/rest/api/trends.rb +10 -11
- data/lib/twitter/rest/api/tweets.rb +31 -20
- data/lib/twitter/rest/api/undocumented.rb +6 -7
- data/lib/twitter/rest/api/users.rb +53 -54
- data/lib/twitter/rest/api/utils.rb +28 -34
- data/lib/twitter/rest/client.rb +8 -9
- data/lib/twitter/rest/request/multipart_with_file.rb +7 -5
- data/lib/twitter/rest/response/parse_error_json.rb +0 -2
- data/lib/twitter/rest/response/parse_json.rb +2 -2
- data/lib/twitter/rest/response/raise_error.rb +1 -3
- data/lib/twitter/search_results.rb +38 -56
- data/lib/twitter/settings.rb +2 -2
- data/lib/twitter/size.rb +2 -2
- data/lib/twitter/source_user.rb +1 -1
- data/lib/twitter/streaming/client.rb +69 -18
- data/lib/twitter/streaming/connection.rb +1 -3
- data/lib/twitter/streaming/deleted_tweet.rb +8 -0
- data/lib/twitter/streaming/event.rb +8 -8
- data/lib/twitter/streaming/friend_list.rb +2 -9
- data/lib/twitter/streaming/message_parser.rb +13 -3
- data/lib/twitter/streaming/response.rb +0 -2
- data/lib/twitter/streaming/stall_warning.rb +7 -0
- data/lib/twitter/suggestion.rb +0 -1
- data/lib/twitter/token.rb +2 -3
- data/lib/twitter/trend_results.rb +5 -8
- data/lib/twitter/tweet.rb +17 -18
- data/lib/twitter/user.rb +33 -35
- data/lib/twitter/utils.rb +14 -0
- data/lib/twitter/version.rb +2 -5
- data/lib/twitter.rb +1 -1
- data/spec/fixtures/forbidden.json +1 -0
- data/spec/fixtures/search.json +1 -1
- data/spec/fixtures/search2.json +1 -0
- data/spec/fixtures/track_streaming_user.json +2 -1
- data/spec/helper.rb +6 -2
- data/spec/twitter/base_spec.rb +9 -9
- data/spec/twitter/basic_user_spec.rb +6 -6
- data/spec/twitter/configuration_spec.rb +4 -4
- data/spec/twitter/cursor_spec.rb +13 -51
- data/spec/twitter/direct_message_spec.rb +36 -36
- data/spec/twitter/entity/uri_spec.rb +29 -29
- data/spec/twitter/error_spec.rb +21 -21
- data/spec/twitter/geo/point_spec.rb +9 -9
- data/spec/twitter/geo/polygon_spec.rb +5 -5
- data/spec/twitter/geo_factory_spec.rb +7 -7
- data/spec/twitter/geo_results_spec.rb +11 -11
- data/spec/twitter/geo_spec.rb +5 -5
- data/spec/twitter/identifiable_spec.rb +9 -9
- data/spec/twitter/list_spec.rb +38 -38
- data/spec/twitter/media/photo_spec.rb +58 -58
- data/spec/twitter/media_factory_spec.rb +5 -5
- data/spec/twitter/null_object_spec.rb +6 -6
- data/spec/twitter/oembed_spec.rb +68 -68
- data/spec/twitter/place_spec.rb +91 -62
- data/spec/twitter/profile_banner_spec.rb +3 -3
- data/spec/twitter/rate_limit_spec.rb +18 -18
- data/spec/twitter/relationship_spec.rb +16 -16
- data/spec/twitter/rest/api/direct_messages_spec.rb +61 -61
- data/spec/twitter/rest/api/favorites_spec.rb +93 -93
- data/spec/twitter/rest/api/friends_and_followers_spec.rb +357 -349
- data/spec/twitter/rest/api/geo_spec.rb +33 -33
- data/spec/twitter/rest/api/help_spec.rb +24 -24
- data/spec/twitter/rest/api/lists_spec.rb +487 -487
- data/spec/twitter/rest/api/oauth_spec.rb +30 -30
- data/spec/twitter/rest/api/saved_searches_spec.rb +50 -40
- data/spec/twitter/rest/api/search_spec.rb +27 -26
- data/spec/twitter/rest/api/spam_reporting_spec.rb +9 -9
- data/spec/twitter/rest/api/suggested_users_spec.rb +23 -23
- data/spec/twitter/rest/api/timelines_spec.rb +58 -58
- data/spec/twitter/rest/api/trends_spec.rb +26 -26
- data/spec/twitter/rest/api/tweets_spec.rb +304 -266
- data/spec/twitter/rest/api/undocumented_spec.rb +51 -51
- data/spec/twitter/rest/api/users_spec.rb +360 -360
- data/spec/twitter/rest/client_spec.rb +99 -103
- data/spec/twitter/saved_search_spec.rb +16 -16
- data/spec/twitter/search_results_spec.rb +14 -110
- data/spec/twitter/settings_spec.rb +8 -8
- data/spec/twitter/size_spec.rb +5 -5
- data/spec/twitter/source_user_spec.rb +6 -6
- data/spec/twitter/streaming/client_spec.rb +85 -54
- data/spec/twitter/streaming/deleted_tweet_spec.rb +23 -0
- data/spec/twitter/streaming/event_spec.rb +20 -22
- data/spec/twitter/streaming/friend_list_spec.rb +11 -0
- data/spec/twitter/streaming/message_parser_spec.rb +54 -0
- data/spec/twitter/suggestion_spec.rb +11 -11
- data/spec/twitter/target_user_spec.rb +6 -6
- data/spec/twitter/token_spec.rb +4 -4
- data/spec/twitter/trend_results_spec.rb +30 -30
- data/spec/twitter/trend_spec.rb +21 -21
- data/spec/twitter/tweet_spec.rb +178 -164
- data/spec/twitter/user_spec.rb +190 -190
- data/twitter.gemspec +6 -6
- data.tar.gz.sig +0 -0
- metadata +44 -16
- metadata.gz.sig +0 -0
- data/lib/twitter/core_ext/enumerable.rb +0 -10
- data/lib/twitter/core_ext/kernel.rb +0 -10
- data/spec/twitter_spec.rb +0 -0
data/lib/twitter/cursor.rb
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
require 'twitter/
|
|
1
|
+
require 'twitter/enumerable'
|
|
2
2
|
|
|
3
3
|
module Twitter
|
|
4
4
|
class Cursor
|
|
5
|
-
include Enumerable
|
|
5
|
+
include Twitter::Enumerable
|
|
6
6
|
attr_reader :attrs
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
alias_method :to_h, :attrs
|
|
8
|
+
alias_method :to_hash, :attrs
|
|
9
|
+
alias_method :to_hsh, :attrs
|
|
10
10
|
|
|
11
11
|
class << self
|
|
12
|
-
|
|
13
12
|
# Construct a new Cursor object from a response hash
|
|
14
13
|
#
|
|
15
14
|
# @param response [Hash]
|
|
@@ -20,10 +19,9 @@ module Twitter
|
|
|
20
19
|
# @param path [String]
|
|
21
20
|
# @param options [Hash]
|
|
22
21
|
# @return [Twitter::Cursor]
|
|
23
|
-
def from_response(response, key, klass, client, request_method, path, options)
|
|
22
|
+
def from_response(response, key, klass, client, request_method, path, options) # rubocop:disable ParameterLists
|
|
24
23
|
new(response[:body], key, klass, client, request_method, path, options)
|
|
25
24
|
end
|
|
26
|
-
|
|
27
25
|
end
|
|
28
26
|
|
|
29
27
|
# Initializes a new Cursor
|
|
@@ -36,7 +34,7 @@ module Twitter
|
|
|
36
34
|
# @param path [String]
|
|
37
35
|
# @param options [Hash]
|
|
38
36
|
# @return [Twitter::Cursor]
|
|
39
|
-
def initialize(attrs, key, klass, client, request_method, path, options)
|
|
37
|
+
def initialize(attrs, key, klass, client, request_method, path, options = {}) # rubocop:disable ParameterLists
|
|
40
38
|
@key = key.to_sym
|
|
41
39
|
@klass = klass
|
|
42
40
|
@client = client
|
|
@@ -47,42 +45,18 @@ module Twitter
|
|
|
47
45
|
set_attrs(attrs)
|
|
48
46
|
end
|
|
49
47
|
|
|
50
|
-
|
|
51
|
-
def each(start = 0, &block)
|
|
52
|
-
return to_enum(:each) unless block_given?
|
|
53
|
-
Array(@collection[start..-1]).each do |element|
|
|
54
|
-
yield element
|
|
55
|
-
end
|
|
56
|
-
unless last?
|
|
57
|
-
start = [@collection.size, start].max
|
|
58
|
-
fetch_next_page
|
|
59
|
-
each(start, &block)
|
|
60
|
-
end
|
|
61
|
-
self
|
|
62
|
-
end
|
|
48
|
+
private
|
|
63
49
|
|
|
64
50
|
def next_cursor
|
|
65
51
|
@attrs[:next_cursor] || -1
|
|
66
52
|
end
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
def previous_cursor
|
|
70
|
-
@attrs[:previous_cursor]
|
|
71
|
-
end
|
|
72
|
-
alias previous previous_cursor
|
|
73
|
-
|
|
74
|
-
# @return [Boolean]
|
|
75
|
-
def first?
|
|
76
|
-
previous_cursor.zero?
|
|
77
|
-
end
|
|
53
|
+
alias_method :next, :next_cursor
|
|
78
54
|
|
|
79
55
|
# @return [Boolean]
|
|
80
56
|
def last?
|
|
81
57
|
next_cursor.zero?
|
|
82
58
|
end
|
|
83
59
|
|
|
84
|
-
private
|
|
85
|
-
|
|
86
60
|
def fetch_next_page
|
|
87
61
|
response = @client.send(@request_method, @path, @options.merge(:cursor => next_cursor))
|
|
88
62
|
set_attrs(response[:body])
|
|
@@ -94,6 +68,5 @@ module Twitter
|
|
|
94
68
|
@collection << (@klass ? @klass.new(element) : element)
|
|
95
69
|
end
|
|
96
70
|
end
|
|
97
|
-
|
|
98
71
|
end
|
|
99
72
|
end
|
data/lib/twitter/entity/uri.rb
CHANGED
data/lib/twitter/enumerable.rb
CHANGED
|
@@ -3,13 +3,22 @@ module Twitter
|
|
|
3
3
|
include ::Enumerable
|
|
4
4
|
|
|
5
5
|
# @return [Enumerator]
|
|
6
|
-
def each(start=0, &block)
|
|
6
|
+
def each(start = 0, &block)
|
|
7
7
|
return to_enum(:each) unless block_given?
|
|
8
8
|
Array(@collection[start..-1]).each do |element|
|
|
9
9
|
yield element
|
|
10
10
|
end
|
|
11
|
+
unless last?
|
|
12
|
+
start = [@collection.size, start].max
|
|
13
|
+
fetch_next_page
|
|
14
|
+
each(start, &block)
|
|
15
|
+
end
|
|
11
16
|
self
|
|
12
17
|
end
|
|
13
18
|
|
|
19
|
+
# @return [Boolean]
|
|
20
|
+
def last?
|
|
21
|
+
true
|
|
22
|
+
end
|
|
14
23
|
end
|
|
15
24
|
end
|
|
@@ -4,7 +4,7 @@ module Twitter
|
|
|
4
4
|
class Error
|
|
5
5
|
# Raised when a Tweet has already been retweeted
|
|
6
6
|
class AlreadyRetweeted < Twitter::Error::Forbidden
|
|
7
|
-
MESSAGE =
|
|
7
|
+
MESSAGE = 'sharing is not permissible for this status (Share validations failed)'
|
|
8
8
|
end
|
|
9
9
|
end
|
|
10
10
|
end
|
|
@@ -6,7 +6,7 @@ module Twitter
|
|
|
6
6
|
class TooManyRequests < Twitter::Error
|
|
7
7
|
HTTP_STATUS_CODE = 429
|
|
8
8
|
end
|
|
9
|
-
EnhanceYourCalm = TooManyRequests
|
|
10
|
-
RateLimited = TooManyRequests
|
|
9
|
+
EnhanceYourCalm = TooManyRequests # rubocop:disable ConstantName
|
|
10
|
+
RateLimited = TooManyRequests # rubocop:disable ConstantName
|
|
11
11
|
end
|
|
12
12
|
end
|
data/lib/twitter/error.rb
CHANGED
|
@@ -15,11 +15,14 @@ module Twitter
|
|
|
15
15
|
DEPRECATED_CALL = 68
|
|
16
16
|
RATE_LIMIT_EXCEEDED = 88
|
|
17
17
|
INVALID_OR_EXPIRED_TOKEN = 89
|
|
18
|
+
UNABLE_TO_VERIFY_CREDENTIALS = 99
|
|
18
19
|
OVER_CAPACITY = 130
|
|
19
20
|
INTERNAL_ERROR = 131
|
|
20
21
|
OAUTH_TIMESTAMP_OUT_OF_RANGE = 135
|
|
22
|
+
FOLLOW_ALREADY_REQUESTED = 160
|
|
21
23
|
FOLLOW_LIMIT_EXCEEDED = 161
|
|
22
24
|
PROTECTED_STATUS = 179
|
|
25
|
+
OVER_UPDATE_LIMIT = 185
|
|
23
26
|
DUPLICATE_STATUS = 187
|
|
24
27
|
BAD_AUTHENTICATION_DATA = 215
|
|
25
28
|
LOGIN_VERIFICATION_NEEDED = 231
|
|
@@ -27,19 +30,18 @@ module Twitter
|
|
|
27
30
|
end
|
|
28
31
|
|
|
29
32
|
class << self
|
|
30
|
-
|
|
31
33
|
# Create a new error from an HTTP response
|
|
32
34
|
#
|
|
33
35
|
# @param response [Hash]
|
|
34
36
|
# @return [Twitter::Error]
|
|
35
|
-
def from_response(response={})
|
|
37
|
+
def from_response(response = {})
|
|
36
38
|
error, code = parse_error(response[:body])
|
|
37
39
|
new(error, response[:response_headers], code)
|
|
38
40
|
end
|
|
39
41
|
|
|
40
42
|
# @return [Hash]
|
|
41
43
|
def errors
|
|
42
|
-
@errors ||= descendants.
|
|
44
|
+
@errors ||= descendants.reduce({}) do |hash, klass|
|
|
43
45
|
hash[klass::HTTP_STATUS_CODE] = klass
|
|
44
46
|
hash
|
|
45
47
|
end
|
|
@@ -65,7 +67,6 @@ module Twitter
|
|
|
65
67
|
[first.chomp, nil]
|
|
66
68
|
end
|
|
67
69
|
end
|
|
68
|
-
|
|
69
70
|
end
|
|
70
71
|
|
|
71
72
|
# Initializes a new Error object
|
|
@@ -74,12 +75,11 @@ module Twitter
|
|
|
74
75
|
# @param response_headers [Hash]
|
|
75
76
|
# @param code [Integer]
|
|
76
77
|
# @return [Twitter::Error]
|
|
77
|
-
def initialize(exception
|
|
78
|
+
def initialize(exception = $ERROR_INFO, response_headers = {}, code = nil) # rubocop:disable MethodLength
|
|
78
79
|
@rate_limit = RateLimit.new(response_headers)
|
|
79
80
|
@wrapped_exception = exception
|
|
80
81
|
@code = code
|
|
81
82
|
exception.respond_to?(:message) ? super(exception.message) : super(exception.to_s)
|
|
82
83
|
end
|
|
83
|
-
|
|
84
84
|
end
|
|
85
85
|
end
|
data/lib/twitter/factory.rb
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
module Twitter
|
|
2
2
|
class Factory
|
|
3
|
-
|
|
4
3
|
class << self
|
|
5
|
-
|
|
6
4
|
# Construct a new object
|
|
7
5
|
#
|
|
8
6
|
# @param method [Symbol]
|
|
@@ -10,13 +8,11 @@ module Twitter
|
|
|
10
8
|
# @param attrs [Hash]
|
|
11
9
|
# @raise [IndexError] Error raised when supplied argument is missing a key.
|
|
12
10
|
# @return [Twitter::Base]
|
|
13
|
-
def new(method, klass, attrs={})
|
|
11
|
+
def new(method, klass, attrs = {})
|
|
14
12
|
type = attrs.fetch(method.to_sym)
|
|
15
|
-
const_name = type.gsub(/\/(.?)/){"::#{
|
|
13
|
+
const_name = type.gsub(/\/(.?)/) { "::#{Regexp.last_match[1].upcase}" }.gsub(/(?:^|_)(.)/) { Regexp.last_match[1].upcase }
|
|
16
14
|
klass.const_get(const_name.to_sym).new(attrs)
|
|
17
15
|
end
|
|
18
|
-
|
|
19
16
|
end
|
|
20
|
-
|
|
21
17
|
end
|
|
22
18
|
end
|
data/lib/twitter/geo/point.rb
CHANGED
|
@@ -3,20 +3,18 @@ require 'twitter/geo'
|
|
|
3
3
|
module Twitter
|
|
4
4
|
class Geo
|
|
5
5
|
class Point < Twitter::Geo
|
|
6
|
-
|
|
7
6
|
# @return [Integer]
|
|
8
7
|
def latitude
|
|
9
8
|
coordinates[0]
|
|
10
9
|
end
|
|
11
|
-
|
|
10
|
+
alias_method :lat, :latitude
|
|
12
11
|
|
|
13
12
|
# @return [Integer]
|
|
14
13
|
def longitude
|
|
15
14
|
coordinates[1]
|
|
16
15
|
end
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
alias_method :long, :longitude
|
|
17
|
+
alias_method :lng, :longitude
|
|
20
18
|
end
|
|
21
19
|
end
|
|
22
20
|
end
|
data/lib/twitter/geo.rb
CHANGED
data/lib/twitter/geo_factory.rb
CHANGED
|
@@ -4,19 +4,15 @@ require 'twitter/geo/polygon'
|
|
|
4
4
|
|
|
5
5
|
module Twitter
|
|
6
6
|
class GeoFactory < Twitter::Factory
|
|
7
|
-
|
|
8
7
|
class << self
|
|
9
|
-
|
|
10
8
|
# Construct a new geo object
|
|
11
9
|
#
|
|
12
10
|
# @param attrs [Hash]
|
|
13
11
|
# @raise [IndexError] Error raised when supplied argument is missing a :type key.
|
|
14
12
|
# @return [Twitter::Geo]
|
|
15
|
-
def new(attrs={})
|
|
13
|
+
def new(attrs = {})
|
|
16
14
|
super(:type, Geo, attrs)
|
|
17
15
|
end
|
|
18
|
-
|
|
19
16
|
end
|
|
20
|
-
|
|
21
17
|
end
|
|
22
18
|
end
|
data/lib/twitter/geo_results.rb
CHANGED
|
@@ -4,27 +4,25 @@ module Twitter
|
|
|
4
4
|
class GeoResults
|
|
5
5
|
include Twitter::Enumerable
|
|
6
6
|
attr_reader :attrs
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
alias_method :to_h, :attrs
|
|
8
|
+
alias_method :to_hash, :attrs
|
|
9
|
+
alias_method :to_hsh, :attrs
|
|
10
10
|
|
|
11
11
|
class << self
|
|
12
|
-
|
|
13
12
|
# Construct a new GeoResults object from a response hash
|
|
14
13
|
#
|
|
15
14
|
# @param response [Hash]
|
|
16
15
|
# @return [Twitter::Base]
|
|
17
|
-
def from_response(response={})
|
|
16
|
+
def from_response(response = {})
|
|
18
17
|
new(response[:body])
|
|
19
18
|
end
|
|
20
|
-
|
|
21
19
|
end
|
|
22
20
|
|
|
23
21
|
# Initializes a new GeoResults object
|
|
24
22
|
#
|
|
25
23
|
# @param attrs [Hash]
|
|
26
24
|
# @return [Twitter::GeoResults]
|
|
27
|
-
def initialize(attrs={})
|
|
25
|
+
def initialize(attrs = {})
|
|
28
26
|
@attrs = attrs
|
|
29
27
|
@collection = Array(@attrs[:result][:places]).map do |place|
|
|
30
28
|
Place.new(place)
|
|
@@ -35,6 +33,5 @@ module Twitter
|
|
|
35
33
|
def token
|
|
36
34
|
@attrs[:token]
|
|
37
35
|
end
|
|
38
|
-
|
|
39
36
|
end
|
|
40
37
|
end
|
data/lib/twitter/identity.rb
CHANGED
|
@@ -11,10 +11,9 @@ module Twitter
|
|
|
11
11
|
# @param attrs [Hash]
|
|
12
12
|
# @raise [ArgumentError] Error raised when supplied argument is missing an :id key.
|
|
13
13
|
# @return [Twitter::Identity]
|
|
14
|
-
def initialize(attrs={})
|
|
14
|
+
def initialize(attrs = {})
|
|
15
15
|
attrs.fetch(:id)
|
|
16
16
|
super
|
|
17
17
|
end
|
|
18
|
-
|
|
19
18
|
end
|
|
20
19
|
end
|
data/lib/twitter/list.rb
CHANGED
|
@@ -5,29 +5,28 @@ module Twitter
|
|
|
5
5
|
class List < Twitter::Identity
|
|
6
6
|
include Twitter::Creatable
|
|
7
7
|
attr_reader :description, :following, :full_name, :member_count,
|
|
8
|
-
|
|
8
|
+
:mode, :name, :slug, :subscriber_count
|
|
9
9
|
object_attr_reader :User, :user
|
|
10
10
|
|
|
11
|
-
# @return [URI] The URI to the list members.
|
|
11
|
+
# @return [Addressable::URI] The URI to the list members.
|
|
12
12
|
def members_uri
|
|
13
|
-
URI.parse("https://twitter.com/#{user.screen_name}/#{slug}/members")
|
|
13
|
+
Addressable::URI.parse("https://twitter.com/#{user.screen_name}/#{slug}/members")
|
|
14
14
|
end
|
|
15
15
|
memoize :members_uri
|
|
16
|
-
|
|
16
|
+
alias_method :members_url, :members_uri
|
|
17
17
|
|
|
18
|
-
# @return [URI] The URI to the list subscribers.
|
|
18
|
+
# @return [Addressable::URI] The URI to the list subscribers.
|
|
19
19
|
def subscribers_uri
|
|
20
|
-
URI.parse("https://twitter.com/#{user.screen_name}/#{slug}/subscribers")
|
|
20
|
+
Addressable::URI.parse("https://twitter.com/#{user.screen_name}/#{slug}/subscribers")
|
|
21
21
|
end
|
|
22
22
|
memoize :subscribers_uri
|
|
23
|
-
|
|
23
|
+
alias_method :subscribers_url, :subscribers_uri
|
|
24
24
|
|
|
25
|
-
# @return [URI] The URI to the list.
|
|
25
|
+
# @return [Addressable::URI] The URI to the list.
|
|
26
26
|
def uri
|
|
27
|
-
URI.parse("https://twitter.com/#{user.screen_name}/#{slug}")
|
|
27
|
+
Addressable::URI.parse("https://twitter.com/#{user.screen_name}/#{slug}")
|
|
28
28
|
end
|
|
29
29
|
memoize :uri
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
alias_method :url, :uri
|
|
32
31
|
end
|
|
33
32
|
end
|
data/lib/twitter/media/photo.rb
CHANGED
|
@@ -11,13 +11,12 @@ module Twitter
|
|
|
11
11
|
#
|
|
12
12
|
# @return [Array<Twitter::Size>]
|
|
13
13
|
def sizes
|
|
14
|
-
Array(@attrs[:sizes]).
|
|
14
|
+
Array(@attrs[:sizes]).reduce({}) do |object, (key, value)|
|
|
15
15
|
object[key] = Size.new(value)
|
|
16
16
|
object
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
memoize :sizes
|
|
20
|
-
|
|
21
20
|
end
|
|
22
21
|
end
|
|
23
22
|
end
|
|
@@ -3,19 +3,15 @@ require 'twitter/media/photo'
|
|
|
3
3
|
|
|
4
4
|
module Twitter
|
|
5
5
|
class MediaFactory < Twitter::Factory
|
|
6
|
-
|
|
7
6
|
class << self
|
|
8
|
-
|
|
9
7
|
# Construct a new media object
|
|
10
8
|
#
|
|
11
9
|
# @param attrs [Hash]
|
|
12
10
|
# @raise [IndexError] Error raised when supplied argument is missing a :type key.
|
|
13
11
|
# @return [Twitter::Media]
|
|
14
|
-
def new(attrs={})
|
|
12
|
+
def new(attrs = {})
|
|
15
13
|
super(:type, Media, attrs)
|
|
16
14
|
end
|
|
17
|
-
|
|
18
15
|
end
|
|
19
|
-
|
|
20
16
|
end
|
|
21
17
|
end
|
data/lib/twitter/null_object.rb
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
module Twitter
|
|
2
2
|
class NullObject
|
|
3
|
-
|
|
4
3
|
# @return [TrueClass] This method always returns true.
|
|
5
4
|
def nil?
|
|
6
5
|
true
|
|
@@ -12,14 +11,13 @@ module Twitter
|
|
|
12
11
|
end
|
|
13
12
|
|
|
14
13
|
# @return [TrueClass] This method always returns true.
|
|
15
|
-
def respond_to?(method_name, include_private=false)
|
|
14
|
+
def respond_to?(method_name, include_private = false)
|
|
16
15
|
true
|
|
17
|
-
end if RUBY_VERSION <
|
|
16
|
+
end if RUBY_VERSION < '1.9'
|
|
18
17
|
|
|
19
18
|
# @return [TrueClass] This method always returns true.
|
|
20
|
-
def respond_to_missing?(method_name, include_private=false)
|
|
19
|
+
def respond_to_missing?(method_name, include_private = false)
|
|
21
20
|
true
|
|
22
|
-
end if RUBY_VERSION >=
|
|
23
|
-
|
|
21
|
+
end if RUBY_VERSION >= '1.9'
|
|
24
22
|
end
|
|
25
23
|
end
|
data/lib/twitter/oembed.rb
CHANGED
data/lib/twitter/place.rb
CHANGED
|
@@ -3,17 +3,29 @@ require 'twitter/base'
|
|
|
3
3
|
|
|
4
4
|
module Twitter
|
|
5
5
|
class Place < Twitter::Base
|
|
6
|
-
include Equalizer.new(:woeid)
|
|
7
6
|
attr_reader :attributes, :country, :full_name, :name, :woeid
|
|
8
|
-
|
|
7
|
+
alias_method :woe_id, :woeid
|
|
9
8
|
object_attr_reader :GeoFactory, :bounding_box
|
|
10
9
|
object_attr_reader :Place, :contained_within
|
|
11
|
-
|
|
10
|
+
alias_method :contained?, :contained_within?
|
|
12
11
|
uri_attr_reader :uri
|
|
13
12
|
|
|
13
|
+
# @param other [Twitter::Place]
|
|
14
|
+
# @return [Boolean]
|
|
15
|
+
def eql?(other)
|
|
16
|
+
super || instance_of?(other.class) && !woeid.nil? && other.respond_to?(:woeid) && woeid.eql?(other.woeid)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# @param other [Twitter::Place]
|
|
20
|
+
# @return [Boolean]
|
|
21
|
+
def ==(other)
|
|
22
|
+
other = coerce(other) if respond_to?(:coerce, true)
|
|
23
|
+
super || kind_of?(self.class) && !woeid.nil? && other.respond_to?(:woeid) && woeid == other.woeid
|
|
24
|
+
end
|
|
25
|
+
|
|
14
26
|
# @return [String]
|
|
15
27
|
def country_code
|
|
16
|
-
@attrs[:country_code] || @attrs[:countryCode]
|
|
28
|
+
@attrs[:country_code] || @attrs[:countryCode] # rubocop:disable SymbolName
|
|
17
29
|
end
|
|
18
30
|
memoize :country_code
|
|
19
31
|
|
|
@@ -25,9 +37,8 @@ module Twitter
|
|
|
25
37
|
|
|
26
38
|
# @return [String]
|
|
27
39
|
def place_type
|
|
28
|
-
@attrs[:place_type] || @attrs[:placeType] && @attrs[:placeType][:name]
|
|
40
|
+
@attrs[:place_type] || @attrs[:placeType] && @attrs[:placeType][:name] # rubocop:disable SymbolName
|
|
29
41
|
end
|
|
30
42
|
memoize :place_type
|
|
31
|
-
|
|
32
43
|
end
|
|
33
44
|
end
|
|
@@ -2,17 +2,15 @@ require 'twitter/base'
|
|
|
2
2
|
|
|
3
3
|
module Twitter
|
|
4
4
|
class ProfileBanner < Twitter::Base
|
|
5
|
-
|
|
6
5
|
# Returns an array of photo sizes
|
|
7
6
|
#
|
|
8
7
|
# @return [Array<Twitter::Size>]
|
|
9
8
|
def sizes
|
|
10
|
-
Array(@attrs[:sizes]).
|
|
9
|
+
Array(@attrs[:sizes]).reduce({}) do |object, (key, value)|
|
|
11
10
|
object[key] = Size.new(value)
|
|
12
11
|
object
|
|
13
12
|
end
|
|
14
13
|
end
|
|
15
14
|
memoize :sizes
|
|
16
|
-
|
|
17
15
|
end
|
|
18
16
|
end
|
data/lib/twitter/rate_limit.rb
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
module Twitter
|
|
2
2
|
class RateLimit < Twitter::Base
|
|
3
|
-
|
|
4
3
|
# @return [Integer]
|
|
5
4
|
def limit
|
|
6
5
|
limit = @attrs['x-rate-limit-limit']
|
|
@@ -26,7 +25,6 @@ module Twitter
|
|
|
26
25
|
def reset_in
|
|
27
26
|
[(reset_at - Time.now).ceil, 0].max if reset_at
|
|
28
27
|
end
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
alias_method :retry_after, :reset_in
|
|
31
29
|
end
|
|
32
30
|
end
|
data/lib/twitter/relationship.rb
CHANGED
|
@@ -2,6 +2,7 @@ require 'twitter/arguments'
|
|
|
2
2
|
require 'twitter/direct_message'
|
|
3
3
|
require 'twitter/rest/api/utils'
|
|
4
4
|
require 'twitter/user'
|
|
5
|
+
require 'twitter/utils'
|
|
5
6
|
|
|
6
7
|
module Twitter
|
|
7
8
|
module REST
|
|
@@ -22,8 +23,8 @@ module Twitter
|
|
|
22
23
|
# @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
|
|
23
24
|
# @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
|
|
24
25
|
# @option options [Integer] :page Specifies the page of results to retrieve.
|
|
25
|
-
def direct_messages_received(options={})
|
|
26
|
-
objects_from_response(Twitter::DirectMessage, :get,
|
|
26
|
+
def direct_messages_received(options = {})
|
|
27
|
+
objects_from_response(Twitter::DirectMessage, :get, '/1.1/direct_messages.json', options)
|
|
27
28
|
end
|
|
28
29
|
|
|
29
30
|
# Returns the 20 most recent direct messages sent by the authenticating user
|
|
@@ -39,8 +40,8 @@ module Twitter
|
|
|
39
40
|
# @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
|
|
40
41
|
# @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
|
|
41
42
|
# @option options [Integer] :page Specifies the page of results to retrieve.
|
|
42
|
-
def direct_messages_sent(options={})
|
|
43
|
-
objects_from_response(Twitter::DirectMessage, :get,
|
|
43
|
+
def direct_messages_sent(options = {})
|
|
44
|
+
objects_from_response(Twitter::DirectMessage, :get, '/1.1/direct_messages/sent.json', options)
|
|
44
45
|
end
|
|
45
46
|
|
|
46
47
|
# Returns a direct message
|
|
@@ -53,9 +54,9 @@ module Twitter
|
|
|
53
54
|
# @return [Twitter::DirectMessage] The requested messages.
|
|
54
55
|
# @param id [Integer] A direct message ID.
|
|
55
56
|
# @param options [Hash] A customizable set of options.
|
|
56
|
-
def direct_message(id, options={})
|
|
57
|
+
def direct_message(id, options = {})
|
|
57
58
|
options[:id] = id
|
|
58
|
-
object_from_response(Twitter::DirectMessage, :get,
|
|
59
|
+
object_from_response(Twitter::DirectMessage, :get, '/1.1/direct_messages/show.json', options)
|
|
59
60
|
end
|
|
60
61
|
|
|
61
62
|
# @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
|
|
@@ -63,7 +64,7 @@ module Twitter
|
|
|
63
64
|
# @authentication Requires user context
|
|
64
65
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
65
66
|
# @return [Array<Twitter::DirectMessage>] The requested messages.
|
|
66
|
-
# @overload direct_messages(options={})
|
|
67
|
+
# @overload direct_messages(options = {})
|
|
67
68
|
# Returns the 20 most recent direct messages sent to the authenticating user
|
|
68
69
|
#
|
|
69
70
|
# @see https://dev.twitter.com/docs/api/1.1/get/direct_messages
|
|
@@ -88,7 +89,7 @@ module Twitter
|
|
|
88
89
|
if arguments.empty?
|
|
89
90
|
direct_messages_received(arguments.options)
|
|
90
91
|
else
|
|
91
|
-
arguments
|
|
92
|
+
Twitter::Utils.parallel_map(arguments) do |id|
|
|
92
93
|
direct_message(id, arguments.options)
|
|
93
94
|
end
|
|
94
95
|
end
|
|
@@ -108,7 +109,7 @@ module Twitter
|
|
|
108
109
|
# @param ids [Enumerable<Integer>] A collection of direct message IDs.
|
|
109
110
|
# @param options [Hash] A customizable set of options.
|
|
110
111
|
def destroy_direct_message(*args)
|
|
111
|
-
threaded_objects_from_response(Twitter::DirectMessage, :post,
|
|
112
|
+
threaded_objects_from_response(Twitter::DirectMessage, :post, '/1.1/direct_messages/destroy.json', args)
|
|
112
113
|
end
|
|
113
114
|
deprecate_alias :direct_message_destroy, :destroy_direct_message
|
|
114
115
|
|
|
@@ -122,16 +123,15 @@ module Twitter
|
|
|
122
123
|
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
|
|
123
124
|
# @param text [String] The text of your direct message, up to 140 characters.
|
|
124
125
|
# @param options [Hash] A customizable set of options.
|
|
125
|
-
def create_direct_message(user, text, options={})
|
|
126
|
+
def create_direct_message(user, text, options = {})
|
|
126
127
|
merge_user!(options, user)
|
|
127
128
|
options[:text] = text
|
|
128
|
-
object_from_response(Twitter::DirectMessage, :post,
|
|
129
|
+
object_from_response(Twitter::DirectMessage, :post, '/1.1/direct_messages/new.json', options)
|
|
129
130
|
end
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
131
|
+
alias_method :d, :create_direct_message
|
|
132
|
+
alias_method :m, :create_direct_message
|
|
133
|
+
alias_method :dm, :create_direct_message
|
|
133
134
|
deprecate_alias :direct_message_create, :create_direct_message
|
|
134
|
-
|
|
135
135
|
end
|
|
136
136
|
end
|
|
137
137
|
end
|