twitter 5.1.1 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data.tar.gz.sig +0 -0
- data/.yardopts +2 -0
- data/CHANGELOG.md +10 -1
- data/CONTRIBUTING.md +2 -2
- data/README.md +30 -20
- data/Rakefile +26 -5
- data/lib/twitter/arguments.rb +0 -1
- data/lib/twitter/base.rb +13 -16
- data/lib/twitter/basic_user.rb +3 -3
- data/lib/twitter/client.rb +7 -8
- data/lib/twitter/configuration.rb +5 -5
- data/lib/twitter/core_ext/enumerable.rb +0 -2
- data/lib/twitter/core_ext/kernel.rb +0 -2
- data/lib/twitter/creatable.rb +0 -1
- data/lib/twitter/cursor.rb +7 -10
- data/lib/twitter/direct_message.rb +1 -1
- data/lib/twitter/entity/uri.rb +2 -2
- data/lib/twitter/enumerable.rb +1 -2
- data/lib/twitter/error.rb +4 -6
- 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/factory.rb +2 -6
- data/lib/twitter/geo.rb +1 -1
- data/lib/twitter/geo/point.rb +3 -5
- 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 +4 -5
- 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 +4 -5
- 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 +13 -14
- data/lib/twitter/rest/api/favorites.rb +10 -11
- data/lib/twitter/rest/api/friends_and_followers.rb +36 -36
- data/lib/twitter/rest/api/help.rb +8 -9
- data/lib/twitter/rest/api/lists.rb +62 -63
- 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 +5 -6
- data/lib/twitter/rest/api/search.rb +2 -3
- 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 +15 -16
- data/lib/twitter/rest/api/undocumented.rb +6 -7
- data/lib/twitter/rest/api/users.rb +51 -52
- data/lib/twitter/rest/api/utils.rb +23 -30
- data/lib/twitter/rest/client.rb +8 -9
- data/lib/twitter/rest/request/multipart_with_file.rb +0 -1
- data/lib/twitter/rest/response/parse_error_json.rb +0 -2
- data/lib/twitter/rest/response/parse_json.rb +0 -2
- data/lib/twitter/rest/response/raise_error.rb +1 -3
- data/lib/twitter/search_results.rb +12 -15
- 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 +71 -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 -7
- 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 +16 -24
- data/lib/twitter/user.rb +30 -32
- data/lib/twitter/version.rb +2 -5
- 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 +27 -27
- data/spec/twitter/direct_message_spec.rb +36 -36
- data/spec/twitter/entity/uri_spec.rb +27 -27
- 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 +54 -54
- data/spec/twitter/media_factory_spec.rb +5 -5
- data/spec/twitter/null_object_spec.rb +6 -6
- data/spec/twitter/oembed_spec.rb +65 -65
- data/spec/twitter/place_spec.rb +89 -60
- 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 +349 -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 +40 -40
- data/spec/twitter/rest/api/search_spec.rb +16 -16
- 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 +284 -284
- 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 +44 -44
- 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 +53 -49
- 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 +20 -20
- data/spec/twitter/tweet_spec.rb +170 -173
- data/spec/twitter/user_spec.rb +179 -179
- data/twitter.gemspec +2 -2
- metadata +21 -4
- metadata.gz.sig +2 -1
data/lib/twitter/rest/client.rb
CHANGED
|
@@ -88,23 +88,23 @@ module Twitter
|
|
|
88
88
|
end
|
|
89
89
|
|
|
90
90
|
# Perform an HTTP DELETE request
|
|
91
|
-
def delete(path, params={})
|
|
91
|
+
def delete(path, params = {})
|
|
92
92
|
request(:delete, path, params)
|
|
93
93
|
end
|
|
94
94
|
|
|
95
95
|
# Perform an HTTP GET request
|
|
96
|
-
def get(path, params={})
|
|
96
|
+
def get(path, params = {})
|
|
97
97
|
request(:get, path, params)
|
|
98
98
|
end
|
|
99
99
|
|
|
100
100
|
# Perform an HTTP POST request
|
|
101
|
-
def post(path, params={})
|
|
102
|
-
signature_params = params.values.any?{|value| value.respond_to?(:to_io)} ? {} : params
|
|
101
|
+
def post(path, params = {})
|
|
102
|
+
signature_params = params.values.any? { |value| value.respond_to?(:to_io) } ? {} : params
|
|
103
103
|
request(:post, path, params, signature_params)
|
|
104
104
|
end
|
|
105
105
|
|
|
106
106
|
# Perform an HTTP PUT request
|
|
107
|
-
def put(path, params={})
|
|
107
|
+
def put(path, params = {})
|
|
108
108
|
request(:put, path, params)
|
|
109
109
|
end
|
|
110
110
|
|
|
@@ -127,7 +127,7 @@ module Twitter
|
|
|
127
127
|
@connection ||= Faraday.new(ENDPOINT, connection_options)
|
|
128
128
|
end
|
|
129
129
|
|
|
130
|
-
def request(method, path, params={}, signature_params=params)
|
|
130
|
+
def request(method, path, params = {}, signature_params = params) # rubocop:disable ParameterLists
|
|
131
131
|
response = connection.send(method.to_sym, path, params) do |request|
|
|
132
132
|
bearer_token_request = params.delete(:bearer_token_request)
|
|
133
133
|
if bearer_token_request
|
|
@@ -143,7 +143,7 @@ module Twitter
|
|
|
143
143
|
raise Twitter::Error
|
|
144
144
|
end
|
|
145
145
|
|
|
146
|
-
def auth_token(method, path, params={}, signature_params=params)
|
|
146
|
+
def auth_token(method, path, params = {}, signature_params = params) # rubocop:disable ParameterLists
|
|
147
147
|
if !user_token?
|
|
148
148
|
@bearer_token = token unless bearer_token?
|
|
149
149
|
bearer_auth_header
|
|
@@ -167,9 +167,8 @@ module Twitter
|
|
|
167
167
|
|
|
168
168
|
# Base64.strict_encode64 is not available on Ruby 1.8.7
|
|
169
169
|
def strict_encode64(str)
|
|
170
|
-
Base64.encode64(str).gsub("\n",
|
|
170
|
+
Base64.encode64(str).gsub("\n", '')
|
|
171
171
|
end
|
|
172
|
-
|
|
173
172
|
end
|
|
174
173
|
end
|
|
175
174
|
end
|
|
@@ -5,7 +5,6 @@ module Twitter
|
|
|
5
5
|
module REST
|
|
6
6
|
module Response
|
|
7
7
|
class ParseJson < Faraday::Response::Middleware
|
|
8
|
-
|
|
9
8
|
def parse(body)
|
|
10
9
|
case body
|
|
11
10
|
when /\A^\s*$\z/, nil
|
|
@@ -24,7 +23,6 @@ module Twitter
|
|
|
24
23
|
def unparsable_status_codes
|
|
25
24
|
[204, 301, 302, 304]
|
|
26
25
|
end
|
|
27
|
-
|
|
28
26
|
end
|
|
29
27
|
end
|
|
30
28
|
end
|
|
@@ -15,13 +15,11 @@ module Twitter
|
|
|
15
15
|
module REST
|
|
16
16
|
module Response
|
|
17
17
|
class RaiseError < Faraday::Response::Middleware
|
|
18
|
-
|
|
19
18
|
def on_complete(env)
|
|
20
19
|
status_code = env[:status].to_i
|
|
21
20
|
error_class = Twitter::Error.errors[status_code]
|
|
22
|
-
|
|
21
|
+
fail error_class.from_response(env) if error_class
|
|
23
22
|
end
|
|
24
|
-
|
|
25
23
|
end
|
|
26
24
|
end
|
|
27
25
|
end
|
|
@@ -4,27 +4,25 @@ module Twitter
|
|
|
4
4
|
class SearchResults
|
|
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 SearchResults 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 SearchResults object
|
|
24
22
|
#
|
|
25
23
|
# @param attrs [Hash]
|
|
26
24
|
# @return [Twitter::SearchResults]
|
|
27
|
-
def initialize(attrs={})
|
|
25
|
+
def initialize(attrs = {})
|
|
28
26
|
@attrs = attrs
|
|
29
27
|
@collection = Array(@attrs[:statuses]).map do |tweet|
|
|
30
28
|
Tweet.new(tweet)
|
|
@@ -55,8 +53,8 @@ module Twitter
|
|
|
55
53
|
def results_per_page
|
|
56
54
|
@attrs[:search_metadata][:count] if @attrs[:search_metadata]
|
|
57
55
|
end
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
alias_method :rpp, :results_per_page
|
|
57
|
+
alias_method :count, :results_per_page
|
|
60
58
|
|
|
61
59
|
# @return [Integer]
|
|
62
60
|
def since_id
|
|
@@ -67,7 +65,7 @@ module Twitter
|
|
|
67
65
|
def next_results?
|
|
68
66
|
!!(@attrs[:search_metadata] && @attrs[:search_metadata][:next_results])
|
|
69
67
|
end
|
|
70
|
-
|
|
68
|
+
alias_method :next_page?, :next_results?
|
|
71
69
|
|
|
72
70
|
# Returns a Hash of query parameters for the next result in the search
|
|
73
71
|
#
|
|
@@ -79,7 +77,7 @@ module Twitter
|
|
|
79
77
|
query_string_to_hash(query_string)
|
|
80
78
|
end
|
|
81
79
|
end
|
|
82
|
-
|
|
80
|
+
alias_method :next_page, :next_results
|
|
83
81
|
|
|
84
82
|
# Returns a Hash of query parameters for the refresh URL in the search
|
|
85
83
|
#
|
|
@@ -89,7 +87,7 @@ module Twitter
|
|
|
89
87
|
query_string = strip_first_character(@attrs[:search_metadata][:refresh_url])
|
|
90
88
|
query_string_to_hash(query_string)
|
|
91
89
|
end
|
|
92
|
-
|
|
90
|
+
alias_method :refresh_page, :refresh_results
|
|
93
91
|
|
|
94
92
|
private
|
|
95
93
|
|
|
@@ -110,7 +108,7 @@ module Twitter
|
|
|
110
108
|
# @example Remove the first character from a query string
|
|
111
109
|
# strip_first_character!("?foo=bar&baz=qux") #=> "foo=bar&baz=qux"
|
|
112
110
|
def strip_first_character!(string)
|
|
113
|
-
string[0] =
|
|
111
|
+
string[0] = ''
|
|
114
112
|
string
|
|
115
113
|
end
|
|
116
114
|
|
|
@@ -132,8 +130,7 @@ module Twitter
|
|
|
132
130
|
# @example Convert hash's keys to symbols
|
|
133
131
|
# symbolize_keys({"foo"=>"bar", "baz"=>"qux"}) #=> {:foo=>"bar", :baz=>"qux"}
|
|
134
132
|
def symbolize_keys(hash)
|
|
135
|
-
Hash[hash.map{|key, value| [key.to_sym, value]}]
|
|
133
|
+
Hash[hash.map { |key, value| [key.to_sym, value] }]
|
|
136
134
|
end
|
|
137
|
-
|
|
138
135
|
end
|
|
139
136
|
end
|
data/lib/twitter/settings.rb
CHANGED
|
@@ -3,8 +3,8 @@ require 'twitter/base'
|
|
|
3
3
|
module Twitter
|
|
4
4
|
class Settings < Twitter::Base
|
|
5
5
|
attr_reader :always_use_https, :discoverable_by_email, :geo_enabled,
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
:language, :protected, :screen_name, :show_all_inline_media,
|
|
7
|
+
:sleep_time, :time_zone
|
|
8
8
|
object_attr_reader :Place, :trend_location
|
|
9
9
|
end
|
|
10
10
|
end
|
data/lib/twitter/size.rb
CHANGED
data/lib/twitter/source_user.rb
CHANGED
|
@@ -4,8 +4,6 @@ require 'twitter/client'
|
|
|
4
4
|
require 'twitter/streaming/connection'
|
|
5
5
|
require 'twitter/streaming/response'
|
|
6
6
|
require 'twitter/streaming/message_parser'
|
|
7
|
-
require 'twitter/streaming/event'
|
|
8
|
-
require 'twitter/streaming/friend_list'
|
|
9
7
|
|
|
10
8
|
module Twitter
|
|
11
9
|
module Streaming
|
|
@@ -15,34 +13,74 @@ module Twitter
|
|
|
15
13
|
# Initializes a new Client object
|
|
16
14
|
#
|
|
17
15
|
# @return [Twitter::Streaming::Client]
|
|
18
|
-
def initialize(options={}, &block)
|
|
16
|
+
def initialize(options = {}, &block)
|
|
19
17
|
super
|
|
20
18
|
@connection = Streaming::Connection.new
|
|
21
19
|
end
|
|
22
20
|
|
|
23
|
-
#
|
|
24
|
-
|
|
21
|
+
# Returns public statuses that match one or more filter predicates
|
|
22
|
+
#
|
|
23
|
+
# @see https://dev.twitter.com/docs/api/1.1/post/statuses/filter
|
|
24
|
+
# @see https://dev.twitter.com/docs/streaming-apis/parameters
|
|
25
|
+
# @note At least one predicate parameter (follow, locations, or track) must be specified.
|
|
26
|
+
# @param options [Hash] A customizable set of options.
|
|
27
|
+
# @option options [String] :follow A comma separated list of user IDs, indicating the users to return statuses for in the stream.
|
|
28
|
+
# @option options [String] :track Includes additional Tweets matching the specified keywords. Phrases of keywords are specified by a comma-separated list.
|
|
29
|
+
# @option options [String] :locations Includes additional Tweets falling within the specified bounding boxes.
|
|
30
|
+
# @yield [Twitter::Tweet, Twitter::Streaming::Event, Twitter::DirectMessage, Twitter::Streaming::FriendList, Twitter::Streaming::DeletedTweet, Twitter::Streaming::StallWarning] A stream of Twitter objects.
|
|
31
|
+
def filter(options = {}, &block)
|
|
25
32
|
request(:post, 'https://stream.twitter.com:443/1.1/statuses/filter.json', options, &block)
|
|
26
33
|
end
|
|
27
34
|
|
|
28
|
-
#
|
|
29
|
-
|
|
35
|
+
# Returns all public statuses
|
|
36
|
+
#
|
|
37
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/statuses/firehose
|
|
38
|
+
# @see https://dev.twitter.com/docs/streaming-apis/parameters
|
|
39
|
+
# @note This endpoint requires special permission to access.
|
|
40
|
+
# @param options [Hash] A customizable set of options.
|
|
41
|
+
# @option options [Integer] :count The number of messages to backfill.
|
|
42
|
+
# @yield [Twitter::Tweet, Twitter::Streaming::Event, Twitter::DirectMessage, Twitter::Streaming::FriendList, Twitter::Streaming::DeletedTweet, Twitter::Streaming::StallWarning] A stream of Twitter objects.
|
|
43
|
+
def firehose(options = {}, &block)
|
|
30
44
|
request(:get, 'https://stream.twitter.com:443/1.1/statuses/firehose.json', options, &block)
|
|
31
45
|
end
|
|
32
46
|
|
|
33
|
-
#
|
|
34
|
-
|
|
47
|
+
# Returns a small random sample of all public statuses
|
|
48
|
+
#
|
|
49
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/statuses/sample
|
|
50
|
+
# @see https://dev.twitter.com/docs/streaming-apis/parameters
|
|
51
|
+
# @yield [Twitter::Tweet, Twitter::Streaming::Event, Twitter::DirectMessage, Twitter::Streaming::FriendList, Twitter::Streaming::DeletedTweet, Twitter::Streaming::StallWarning] A stream of Twitter objects.
|
|
52
|
+
def sample(options = {}, &block)
|
|
35
53
|
request(:get, 'https://stream.twitter.com:443/1.1/statuses/sample.json', options, &block)
|
|
36
54
|
end
|
|
37
55
|
|
|
38
|
-
#
|
|
56
|
+
# Streams messages for a set of user
|
|
57
|
+
#
|
|
58
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/site
|
|
59
|
+
# @see https://dev.twitter.com/docs/streaming-apis/streams/site
|
|
60
|
+
# @see https://dev.twitter.com/docs/streaming-apis/parameters
|
|
61
|
+
# @param follow [Enumerable<Integer, String, Twitter::User>] A list of user IDs, indicating the users to return statuses for in the stream.
|
|
62
|
+
# @param options [Hash] A customizable set of options.
|
|
63
|
+
# @option options [String] :with Specifies whether to return information for just the users specified in the follow parameter, or include messages from accounts they follow.
|
|
64
|
+
# @option options [String] :replies Specifies whether stall warnings should be delivered.
|
|
65
|
+
# @yield [Twitter::Tweet, Twitter::Streaming::Event, Twitter::DirectMessage, Twitter::Streaming::FriendList, Twitter::Streaming::DeletedTweet, Twitter::Streaming::StallWarning] A stream of Twitter objects.
|
|
39
66
|
def site(*args, &block)
|
|
40
67
|
arguments = Arguments.new(args)
|
|
41
|
-
|
|
68
|
+
user_ids = collect_user_ids(arguments)
|
|
69
|
+
request(:get, 'https://sitestream.twitter.com:443/1.1/site.json', arguments.options.merge(:follow => user_ids.join(',')), &block)
|
|
42
70
|
end
|
|
43
71
|
|
|
44
|
-
#
|
|
45
|
-
|
|
72
|
+
# Streams messages for a single user
|
|
73
|
+
#
|
|
74
|
+
# @see https://dev.twitter.com/docs/api/1.1/get/user
|
|
75
|
+
# @see https://dev.twitter.com/docs/streaming-apis/streams/user
|
|
76
|
+
# @see https://dev.twitter.com/docs/streaming-apis/parameters
|
|
77
|
+
# @param options [Hash] A customizable set of options.
|
|
78
|
+
# @option options [String] :with Specifies whether to return information for just the users specified in the follow parameter, or include messages from accounts they follow.
|
|
79
|
+
# @option options [String] :replies Specifies whether stall warnings should be delivered.
|
|
80
|
+
# @option options [String] :track Includes additional Tweets matching the specified keywords. Phrases of keywords are specified by a comma-separated list.
|
|
81
|
+
# @option options [String] :locations Includes additional Tweets falling within the specified bounding boxes.
|
|
82
|
+
# @yield [Twitter::Tweet, Twitter::Streaming::Event, Twitter::DirectMessage, Twitter::Streaming::FriendList, Twitter::Streaming::DeletedTweet, Twitter::Streaming::StallWarning] A stream of Twitter objects.
|
|
83
|
+
def user(options = {}, &block)
|
|
46
84
|
request(:get, 'https://userstream.twitter.com:443/1.1/user.json', options, &block)
|
|
47
85
|
end
|
|
48
86
|
|
|
@@ -54,19 +92,19 @@ module Twitter
|
|
|
54
92
|
elsif instance_variable_defined?(:@before_request)
|
|
55
93
|
@before_request
|
|
56
94
|
else
|
|
57
|
-
|
|
95
|
+
proc {}
|
|
58
96
|
end
|
|
59
97
|
end
|
|
60
98
|
|
|
61
99
|
private
|
|
62
100
|
|
|
63
|
-
def request(method, uri, params, &block)
|
|
101
|
+
def request(method, uri, params, &block) # rubocop:disable ParameterLists
|
|
64
102
|
before_request.call
|
|
65
103
|
headers = default_headers.merge(:authorization => oauth_auth_header(method, uri, params).to_s)
|
|
66
104
|
request = HTTP::Request.new(method, uri + '?' + to_url_params(params), headers)
|
|
67
105
|
response = Streaming::Response.new do |data|
|
|
68
|
-
if item = Streaming::MessageParser.parse(data)
|
|
69
|
-
|
|
106
|
+
if item = Streaming::MessageParser.parse(data) # rubocop:disable AssignmentInCondition, IfUnlessModifier
|
|
107
|
+
block.call(item)
|
|
70
108
|
end
|
|
71
109
|
end
|
|
72
110
|
@connection.stream(request, response)
|
|
@@ -74,7 +112,7 @@ module Twitter
|
|
|
74
112
|
|
|
75
113
|
def to_url_params(params)
|
|
76
114
|
params.map do |param, value|
|
|
77
|
-
[param, URI.encode(value)].join(
|
|
115
|
+
[param, URI.encode(value)].join('=')
|
|
78
116
|
end.sort.join('&')
|
|
79
117
|
end
|
|
80
118
|
|
|
@@ -84,6 +122,21 @@ module Twitter
|
|
|
84
122
|
:user_agent => user_agent,
|
|
85
123
|
}
|
|
86
124
|
end
|
|
125
|
+
|
|
126
|
+
def collect_user_ids(users)
|
|
127
|
+
user_ids = []
|
|
128
|
+
users.flatten.each do |user|
|
|
129
|
+
case user
|
|
130
|
+
when Integer
|
|
131
|
+
user_ids << user
|
|
132
|
+
when String
|
|
133
|
+
user_ids << user.to_i
|
|
134
|
+
when Twitter::User
|
|
135
|
+
user_ids << user.id
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
user_ids
|
|
139
|
+
end
|
|
87
140
|
end
|
|
88
141
|
end
|
|
89
142
|
end
|
|
@@ -5,18 +5,16 @@ require 'resolv'
|
|
|
5
5
|
module Twitter
|
|
6
6
|
module Streaming
|
|
7
7
|
class Connection
|
|
8
|
-
|
|
9
8
|
def stream(request, response)
|
|
10
9
|
client_context = OpenSSL::SSL::SSLContext.new
|
|
11
10
|
client = TCPSocket.new(Resolv.getaddress(request.uri.host), request.uri.port)
|
|
12
11
|
ssl_client = OpenSSL::SSL::SSLSocket.new(client, client_context)
|
|
13
12
|
ssl_client.connect
|
|
14
13
|
request.stream(ssl_client)
|
|
15
|
-
while body = ssl_client.readpartial(1024)
|
|
14
|
+
while body = ssl_client.readpartial(1024) # rubocop:disable AssignmentInCondition, WhileUntilModifier
|
|
16
15
|
response << body
|
|
17
16
|
end
|
|
18
17
|
end
|
|
19
|
-
|
|
20
18
|
end
|
|
21
19
|
end
|
|
22
20
|
end
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
module Twitter
|
|
2
2
|
module Streaming
|
|
3
3
|
class Event
|
|
4
|
-
|
|
5
4
|
LIST_EVENTS = [
|
|
6
|
-
:list_created, :list_destroyed, :list_updated, :list_member_added,
|
|
7
|
-
:list_member_added, :list_member_removed, :list_user_subscribed,
|
|
8
|
-
:list_user_subscribed, :list_user_unsubscribed, :list_user_unsubscribed
|
|
5
|
+
:list_created, :list_destroyed, :list_updated, :list_member_added,
|
|
6
|
+
:list_member_added, :list_member_removed, :list_user_subscribed,
|
|
7
|
+
:list_user_subscribed, :list_user_unsubscribed, :list_user_unsubscribed,
|
|
9
8
|
]
|
|
10
9
|
|
|
11
10
|
TWEET_EVENTS = [
|
|
12
|
-
:favorite, :unfavorite
|
|
11
|
+
:favorite, :unfavorite,
|
|
13
12
|
]
|
|
14
|
-
|
|
13
|
+
|
|
15
14
|
attr_reader :name, :source, :target, :target_object
|
|
16
15
|
|
|
17
16
|
# @param data [Hash]
|
|
18
17
|
def initialize(data)
|
|
19
|
-
@name = data[:event].
|
|
18
|
+
@name = data[:event].to_sym
|
|
20
19
|
@source = Twitter::User.new(data[:source])
|
|
21
20
|
@target = Twitter::User.new(data[:target])
|
|
22
21
|
@target_object = target_object_factory(@name, data[:target_object])
|
|
23
22
|
end
|
|
24
23
|
|
|
25
24
|
private
|
|
25
|
+
|
|
26
26
|
def target_object_factory(event_name, data)
|
|
27
27
|
if LIST_EVENTS.include?(event_name)
|
|
28
28
|
Twitter::List.new(data)
|
|
@@ -32,4 +32,4 @@ module Twitter
|
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
34
|
end
|
|
35
|
-
end
|
|
35
|
+
end
|