twitter 6.2.0 → 8.0.0.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +32 -10
- data/LICENSE.md +1 -1
- data/README.md +9 -14
- data/lib/twitter/base.rb +11 -11
- data/lib/twitter/basic_user.rb +3 -2
- data/lib/twitter/client.rb +8 -8
- data/lib/twitter/creatable.rb +7 -3
- data/lib/twitter/cursor.rb +15 -5
- data/lib/twitter/direct_message.rb +4 -3
- data/lib/twitter/direct_message_event.rb +44 -0
- data/lib/twitter/direct_messages/welcome_message.rb +17 -0
- data/lib/twitter/direct_messages/welcome_message_rule.rb +12 -0
- data/lib/twitter/direct_messages/welcome_message_rule_wrapper.rb +36 -0
- data/lib/twitter/direct_messages/welcome_message_wrapper.rb +42 -0
- data/lib/twitter/entities.rb +6 -6
- data/lib/twitter/entity/hashtag.rb +1 -1
- data/lib/twitter/entity/symbol.rb +1 -1
- data/lib/twitter/entity/uri.rb +1 -1
- data/lib/twitter/entity/user_mention.rb +1 -1
- data/lib/twitter/entity.rb +1 -1
- data/lib/twitter/enumerable.rb +15 -6
- data/lib/twitter/error.rb +52 -9
- data/lib/twitter/factory.rb +1 -1
- data/lib/twitter/geo/point.rb +1 -1
- data/lib/twitter/geo/polygon.rb +1 -1
- data/lib/twitter/geo.rb +2 -2
- data/lib/twitter/geo_factory.rb +3 -3
- data/lib/twitter/geo_results.rb +2 -2
- data/lib/twitter/headers.rb +4 -4
- data/lib/twitter/identity.rb +2 -2
- data/lib/twitter/language.rb +1 -1
- data/lib/twitter/list.rb +3 -2
- data/lib/twitter/media/animated_gif.rb +1 -1
- data/lib/twitter/media/photo.rb +2 -2
- data/lib/twitter/media/video.rb +3 -3
- data/lib/twitter/media/video_info.rb +2 -2
- data/lib/twitter/media_factory.rb +4 -4
- data/lib/twitter/metadata.rb +1 -1
- data/lib/twitter/null_object.rb +19 -5
- data/lib/twitter/oembed.rb +2 -1
- data/lib/twitter/place.rb +3 -3
- data/lib/twitter/premium_search_results.rb +67 -0
- data/lib/twitter/profile.rb +6 -6
- data/lib/twitter/profile_banner.rb +2 -2
- data/lib/twitter/rate_limit.rb +6 -6
- data/lib/twitter/relationship.rb +2 -1
- data/lib/twitter/rest/account_activity.rb +99 -0
- data/lib/twitter/rest/api.rb +22 -16
- data/lib/twitter/rest/client.rb +4 -4
- data/lib/twitter/rest/direct_messages/welcome_messages.rb +90 -0
- data/lib/twitter/rest/direct_messages.rb +136 -47
- data/lib/twitter/rest/favorites.rb +17 -21
- data/lib/twitter/rest/form_encoder.rb +27 -0
- data/lib/twitter/rest/friends_and_followers.rb +21 -21
- data/lib/twitter/rest/help.rb +6 -18
- data/lib/twitter/rest/lists.rb +33 -32
- data/lib/twitter/rest/oauth.rb +8 -8
- data/lib/twitter/rest/places_and_geo.rb +6 -6
- data/lib/twitter/rest/premium_search.rb +34 -0
- data/lib/twitter/rest/request.rb +64 -31
- data/lib/twitter/rest/saved_searches.rb +6 -6
- data/lib/twitter/rest/search.rb +6 -5
- data/lib/twitter/rest/spam_reporting.rb +3 -3
- data/lib/twitter/rest/suggested_users.rb +5 -5
- data/lib/twitter/rest/timelines.rb +8 -7
- data/lib/twitter/rest/trends.rb +7 -7
- data/lib/twitter/rest/tweets.rb +20 -53
- data/lib/twitter/rest/undocumented.rb +7 -7
- data/lib/twitter/rest/upload_utils.rb +68 -0
- data/lib/twitter/rest/users.rb +32 -32
- data/lib/twitter/rest/utils.rb +41 -24
- data/lib/twitter/saved_search.rb +2 -2
- data/lib/twitter/search_results.rb +10 -9
- data/lib/twitter/settings.rb +2 -1
- data/lib/twitter/size.rb +2 -2
- data/lib/twitter/source_user.rb +1 -1
- data/lib/twitter/streaming/client.rb +19 -15
- data/lib/twitter/streaming/connection.rb +19 -7
- data/lib/twitter/streaming/message_parser.rb +7 -7
- data/lib/twitter/streaming/response.rb +12 -10
- data/lib/twitter/suggestion.rb +3 -3
- data/lib/twitter/target_user.rb +1 -1
- data/lib/twitter/trend.rb +3 -2
- data/lib/twitter/trend_results.rb +5 -5
- data/lib/twitter/tweet.rb +13 -4
- data/lib/twitter/user.rb +9 -9
- data/lib/twitter/utils.rb +6 -4
- data/lib/twitter/variant.rb +2 -1
- data/lib/twitter/version.rb +4 -4
- data/lib/twitter.rb +36 -31
- data/twitter.gemspec +19 -19
- metadata +33 -37
- data/lib/twitter/configuration.rb +0 -27
data/lib/twitter/error.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "twitter/rate_limit"
|
2
2
|
|
3
3
|
module Twitter
|
4
4
|
# Custom error class for rescuing from all Twitter errors
|
@@ -59,6 +59,21 @@ module Twitter
|
|
59
59
|
# Raised when Twitter returns the HTTP status code 504
|
60
60
|
GatewayTimeout = Class.new(ServerError)
|
61
61
|
|
62
|
+
# Raised when Twitter returns a media related error
|
63
|
+
MediaError = Class.new(self)
|
64
|
+
|
65
|
+
# Raised when Twitter returns an InvalidMedia error
|
66
|
+
InvalidMedia = Class.new(MediaError)
|
67
|
+
|
68
|
+
# Raised when Twitter returns a media InternalError error
|
69
|
+
MediaInternalError = Class.new(MediaError)
|
70
|
+
|
71
|
+
# Raised when Twitter returns an UnsupportedMedia error
|
72
|
+
UnsupportedMedia = Class.new(MediaError)
|
73
|
+
|
74
|
+
# Raised when an operation subject to timeout takes too long
|
75
|
+
TimeoutError = Class.new(self)
|
76
|
+
|
62
77
|
ERRORS = {
|
63
78
|
400 => Twitter::Error::BadRequest,
|
64
79
|
401 => Twitter::Error::Unauthorized,
|
@@ -66,6 +81,7 @@ module Twitter
|
|
66
81
|
404 => Twitter::Error::NotFound,
|
67
82
|
406 => Twitter::Error::NotAcceptable,
|
68
83
|
413 => Twitter::Error::RequestEntityTooLarge,
|
84
|
+
420 => Twitter::Error::TooManyRequests,
|
69
85
|
422 => Twitter::Error::UnprocessableEntity,
|
70
86
|
429 => Twitter::Error::TooManyRequests,
|
71
87
|
500 => Twitter::Error::InternalServerError,
|
@@ -74,14 +90,29 @@ module Twitter
|
|
74
90
|
504 => Twitter::Error::GatewayTimeout,
|
75
91
|
}.freeze
|
76
92
|
|
77
|
-
FORBIDDEN_MESSAGES =
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
93
|
+
FORBIDDEN_MESSAGES = proc do |message|
|
94
|
+
case message
|
95
|
+
when /(?=.*status).*duplicate/i
|
96
|
+
# - "Status is a duplicate."
|
97
|
+
Twitter::Error::DuplicateStatus
|
98
|
+
when /already favorited/i
|
99
|
+
# - "You have already favorited this status."
|
100
|
+
Twitter::Error::AlreadyFavorited
|
101
|
+
when /already retweeted|Share validations failed/i
|
102
|
+
# - "You have already retweeted this Tweet." (Nov 2017-)
|
103
|
+
# - "You have already retweeted this tweet." (?-Nov 2017)
|
104
|
+
# - "sharing is not permissible for this status (Share validations failed)" (-? 2017)
|
105
|
+
Twitter::Error::AlreadyRetweeted
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
MEDIA_ERRORS = {
|
110
|
+
"InternalError" => Twitter::Error::MediaInternalError,
|
111
|
+
"InvalidMedia" => Twitter::Error::InvalidMedia,
|
112
|
+
"UnsupportedMedia" => Twitter::Error::UnsupportedMedia,
|
82
113
|
}.freeze
|
83
114
|
|
84
|
-
# If error code is missing see https://
|
115
|
+
# If error code is missing see https://developer.twitter.com/en/docs/basics/response-codes
|
85
116
|
module Code
|
86
117
|
AUTHENTICATION_PROBLEM = 32
|
87
118
|
RESOURCE_NOT_FOUND = 34
|
@@ -122,11 +153,23 @@ module Twitter
|
|
122
153
|
new(message, headers, code)
|
123
154
|
end
|
124
155
|
|
156
|
+
# Create a new error from a media error hash
|
157
|
+
#
|
158
|
+
# @param error [Hash]
|
159
|
+
# @param headers [Hash]
|
160
|
+
# @return [Twitter::MediaError]
|
161
|
+
def from_processing_response(error, headers)
|
162
|
+
klass = MEDIA_ERRORS[error[:name]] || self
|
163
|
+
message = error[:message]
|
164
|
+
code = error[:code]
|
165
|
+
klass.new(message, headers, code)
|
166
|
+
end
|
167
|
+
|
125
168
|
private
|
126
169
|
|
127
170
|
def parse_error(body)
|
128
171
|
if body.nil? || body.empty?
|
129
|
-
[
|
172
|
+
["", nil]
|
130
173
|
elsif body[:error]
|
131
174
|
[body[:error], nil]
|
132
175
|
elsif body[:errors]
|
@@ -150,7 +193,7 @@ module Twitter
|
|
150
193
|
# @param rate_limit [Hash]
|
151
194
|
# @param code [Integer]
|
152
195
|
# @return [Twitter::Error]
|
153
|
-
def initialize(message =
|
196
|
+
def initialize(message = "", rate_limit = {}, code = nil)
|
154
197
|
super(message)
|
155
198
|
@rate_limit = Twitter::RateLimit.new(rate_limit)
|
156
199
|
@code = code
|
data/lib/twitter/factory.rb
CHANGED
@@ -10,7 +10,7 @@ module Twitter
|
|
10
10
|
# @return [Twitter::Base]
|
11
11
|
def new(method, klass, attrs = {})
|
12
12
|
type = attrs.fetch(method.to_sym)
|
13
|
-
const_name = type.split(
|
13
|
+
const_name = type.split("_").collect(&:capitalize).join
|
14
14
|
klass.const_get(const_name.to_sym).new(attrs)
|
15
15
|
end
|
16
16
|
end
|
data/lib/twitter/geo/point.rb
CHANGED
data/lib/twitter/geo/polygon.rb
CHANGED
data/lib/twitter/geo.rb
CHANGED
data/lib/twitter/geo_factory.rb
CHANGED
data/lib/twitter/geo_results.rb
CHANGED
data/lib/twitter/headers.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "addressable/uri"
|
2
|
+
require "base64"
|
3
|
+
require "simple_oauth"
|
4
4
|
|
5
5
|
module Twitter
|
6
6
|
class Headers
|
@@ -24,7 +24,7 @@ module Twitter
|
|
24
24
|
headers = {}
|
25
25
|
headers[:user_agent] = @client.user_agent
|
26
26
|
if bearer_token_request?
|
27
|
-
headers[:accept] =
|
27
|
+
headers[:accept] = "*/*"
|
28
28
|
headers[:authorization] = bearer_token_credentials_auth_header
|
29
29
|
else
|
30
30
|
headers[:authorization] = auth_header
|
data/lib/twitter/identity.rb
CHANGED
data/lib/twitter/language.rb
CHANGED
data/lib/twitter/list.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "twitter/creatable"
|
2
|
+
require "twitter/identity"
|
3
3
|
|
4
4
|
module Twitter
|
5
5
|
class List < Twitter::Identity
|
@@ -8,6 +8,7 @@ module Twitter
|
|
8
8
|
attr_reader :member_count, :subscriber_count
|
9
9
|
# @return [String]
|
10
10
|
attr_reader :description, :full_name, :mode, :name, :slug
|
11
|
+
|
11
12
|
object_attr_reader :User, :user
|
12
13
|
predicate_attr_reader :following
|
13
14
|
|
data/lib/twitter/media/photo.rb
CHANGED
data/lib/twitter/media/video.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "twitter/factory"
|
2
|
+
require "twitter/media/animated_gif"
|
3
|
+
require "twitter/media/photo"
|
4
|
+
require "twitter/media/video"
|
5
5
|
|
6
6
|
module Twitter
|
7
7
|
class MediaFactory < Twitter::Factory
|
data/lib/twitter/metadata.rb
CHANGED
data/lib/twitter/null_object.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require "naught"
|
2
2
|
|
3
3
|
module Twitter
|
4
|
-
NullObject = Naught.build do |config|
|
4
|
+
NullObject = Naught.build do |config| # rubocop:disable Metrics/BlockLength
|
5
5
|
include Comparable
|
6
6
|
|
7
7
|
config.black_hole
|
@@ -18,12 +18,14 @@ module Twitter
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def instance_of?(klass)
|
21
|
-
raise(TypeError,
|
21
|
+
raise(TypeError, "class or module required") unless klass.is_a?(Class)
|
22
|
+
|
22
23
|
self.class == klass
|
23
24
|
end
|
24
25
|
|
25
26
|
def kind_of?(mod)
|
26
|
-
raise(TypeError,
|
27
|
+
raise(TypeError, "class or module required") unless mod.is_a?(Module)
|
28
|
+
|
27
29
|
self.class.ancestors.include?(mod)
|
28
30
|
end
|
29
31
|
|
@@ -42,11 +44,23 @@ module Twitter
|
|
42
44
|
end
|
43
45
|
|
44
46
|
def as_json(*)
|
45
|
-
|
47
|
+
"null"
|
46
48
|
end
|
47
49
|
|
48
50
|
def to_json(*args)
|
49
51
|
nil.to_json(*args)
|
50
52
|
end
|
53
|
+
|
54
|
+
def presence
|
55
|
+
nil
|
56
|
+
end
|
57
|
+
|
58
|
+
def blank?
|
59
|
+
true
|
60
|
+
end
|
61
|
+
|
62
|
+
def present?
|
63
|
+
false
|
64
|
+
end
|
51
65
|
end
|
52
66
|
end
|
data/lib/twitter/oembed.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "twitter/base"
|
2
2
|
|
3
3
|
module Twitter
|
4
4
|
class OEmbed < Twitter::Base
|
@@ -7,6 +7,7 @@ module Twitter
|
|
7
7
|
# @return [String]
|
8
8
|
attr_reader :author_name, :cache_age, :html, :provider_name, :type,
|
9
9
|
:version
|
10
|
+
|
10
11
|
uri_attr_reader :author_uri, :provider_uri, :uri
|
11
12
|
end
|
12
13
|
end
|
data/lib/twitter/place.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "memoizable"
|
2
|
+
require "twitter/identity"
|
3
3
|
|
4
4
|
module Twitter
|
5
5
|
class Place < Twitter::Identity
|
@@ -40,7 +40,7 @@ module Twitter
|
|
40
40
|
|
41
41
|
# @return [String]
|
42
42
|
def place_type
|
43
|
-
@attrs[:place_type] || @attrs[:placeType] && @attrs[:placeType][:name]
|
43
|
+
@attrs[:place_type] || (@attrs[:placeType] && @attrs[:placeType][:name])
|
44
44
|
end
|
45
45
|
memoize :place_type
|
46
46
|
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require "cgi"
|
2
|
+
require "twitter/enumerable"
|
3
|
+
require "twitter/rest/request"
|
4
|
+
require "twitter/utils"
|
5
|
+
require "uri"
|
6
|
+
|
7
|
+
module Twitter
|
8
|
+
class PremiumSearchResults
|
9
|
+
include Twitter::Enumerable
|
10
|
+
include Twitter::Utils
|
11
|
+
# @return [Hash]
|
12
|
+
attr_reader :attrs
|
13
|
+
alias to_h attrs
|
14
|
+
alias to_hash to_h
|
15
|
+
|
16
|
+
# Initializes a new SearchResults object
|
17
|
+
#
|
18
|
+
# @param request [Twitter::REST::Request]
|
19
|
+
# @return [Twitter::PremiumSearchResults]
|
20
|
+
def initialize(request, request_config = {})
|
21
|
+
@client = request.client
|
22
|
+
@request_method = request.verb
|
23
|
+
@path = request.path
|
24
|
+
@options = request.options
|
25
|
+
@request_config = request_config
|
26
|
+
@collection = []
|
27
|
+
self.attrs = request.perform
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
# @return [Boolean]
|
33
|
+
def last?
|
34
|
+
!next_page?
|
35
|
+
end
|
36
|
+
|
37
|
+
# @return [Boolean]
|
38
|
+
def next_page?
|
39
|
+
!!@attrs[:next]
|
40
|
+
end
|
41
|
+
|
42
|
+
# Returns a Hash of query parameters for the next result in the search
|
43
|
+
#
|
44
|
+
# @note Returned Hash can be merged into the previous search options list to easily access the next page.
|
45
|
+
# @return [Hash] The parameters needed to fetch the next page.
|
46
|
+
def next_page
|
47
|
+
{next: @attrs[:next]} if next_page?
|
48
|
+
end
|
49
|
+
|
50
|
+
# @return [Hash]
|
51
|
+
def fetch_next_page
|
52
|
+
request = @client.premium_search(@options[:query], (@options.reject { |k| k == :query } || {}).merge(next_page), @request_config)
|
53
|
+
|
54
|
+
self.attrs = request.attrs
|
55
|
+
end
|
56
|
+
|
57
|
+
# @param attrs [Hash]
|
58
|
+
# @return [Hash]
|
59
|
+
def attrs=(attrs)
|
60
|
+
@attrs = attrs
|
61
|
+
@attrs.fetch(:results, []).collect do |tweet|
|
62
|
+
@collection << Tweet.new(tweet)
|
63
|
+
end
|
64
|
+
@attrs
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/twitter/profile.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "addressable/uri"
|
2
|
+
require "cgi"
|
3
|
+
require "memoizable"
|
4
4
|
|
5
5
|
module Twitter
|
6
6
|
module Profile
|
@@ -27,7 +27,7 @@ module Twitter
|
|
27
27
|
# @param size [String, Symbol] The size of the image. Must be one of: 'mobile', 'mobile_retina', 'web', 'web_retina', 'ipad', or 'ipad_retina'
|
28
28
|
# @return [Addressable::URI]
|
29
29
|
def profile_banner_uri(size = :web)
|
30
|
-
parse_uri(insecure_uri([@attrs[:profile_banner_url], size].join(
|
30
|
+
parse_uri(insecure_uri([@attrs[:profile_banner_url], size].join("/"))) unless @attrs[:profile_banner_url].nil?
|
31
31
|
end
|
32
32
|
alias profile_banner_url profile_banner_uri
|
33
33
|
|
@@ -36,7 +36,7 @@ module Twitter
|
|
36
36
|
# @param size [String, Symbol] The size of the image. Must be one of: 'mobile', 'mobile_retina', 'web', 'web_retina', 'ipad', or 'ipad_retina'
|
37
37
|
# @return [Addressable::URI]
|
38
38
|
def profile_banner_uri_https(size = :web)
|
39
|
-
parse_uri([@attrs[:profile_banner_url], size].join(
|
39
|
+
parse_uri([@attrs[:profile_banner_url], size].join("/")) unless @attrs[:profile_banner_url].nil?
|
40
40
|
end
|
41
41
|
alias profile_banner_url_https profile_banner_uri_https
|
42
42
|
|
@@ -85,7 +85,7 @@ module Twitter
|
|
85
85
|
end
|
86
86
|
|
87
87
|
def insecure_uri(uri)
|
88
|
-
uri.to_s.sub(/^https/i,
|
88
|
+
uri.to_s.sub(/^https/i, "http")
|
89
89
|
end
|
90
90
|
|
91
91
|
def profile_image_suffix(size)
|
data/lib/twitter/rate_limit.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "memoizable"
|
2
2
|
|
3
3
|
module Twitter
|
4
4
|
class RateLimit < Twitter::Base
|
@@ -6,21 +6,21 @@ module Twitter
|
|
6
6
|
|
7
7
|
# @return [Integer]
|
8
8
|
def limit
|
9
|
-
limit = @attrs[
|
10
|
-
limit
|
9
|
+
limit = @attrs["x-rate-limit-limit"]
|
10
|
+
limit&.to_i
|
11
11
|
end
|
12
12
|
memoize :limit
|
13
13
|
|
14
14
|
# @return [Integer]
|
15
15
|
def remaining
|
16
|
-
remaining = @attrs[
|
17
|
-
remaining
|
16
|
+
remaining = @attrs["x-rate-limit-remaining"]
|
17
|
+
remaining&.to_i
|
18
18
|
end
|
19
19
|
memoize :remaining
|
20
20
|
|
21
21
|
# @return [Time]
|
22
22
|
def reset_at
|
23
|
-
reset = @attrs[
|
23
|
+
reset = @attrs["x-rate-limit-reset"]
|
24
24
|
Time.at(reset.to_i).utc if reset
|
25
25
|
end
|
26
26
|
memoize :reset_at
|
data/lib/twitter/relationship.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "twitter/base"
|
2
2
|
|
3
3
|
module Twitter
|
4
4
|
class Relationship < Twitter::Base
|
@@ -10,6 +10,7 @@ module Twitter
|
|
10
10
|
# @param attrs [Hash]
|
11
11
|
# @return [Twitter::Relationship]
|
12
12
|
def initialize(attrs = {})
|
13
|
+
super
|
13
14
|
@attrs = attrs[:relationship]
|
14
15
|
end
|
15
16
|
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require "twitter/rest/request"
|
2
|
+
require "twitter/rest/utils"
|
3
|
+
require "twitter/utils"
|
4
|
+
|
5
|
+
module Twitter
|
6
|
+
module REST
|
7
|
+
module AccountActivity
|
8
|
+
include Twitter::REST::Utils
|
9
|
+
include Twitter::Utils
|
10
|
+
|
11
|
+
# Registers a webhook URL for all event types. The URL will be validated via CRC request before saving. In case the validation failed, returns comprehensive error message to the requester.
|
12
|
+
# @see https://developer.twitter.com/en/docs/accounts-and-users/subscribe-account-activity/api-reference
|
13
|
+
# @see https://developer.twitter.com/en/docs/accounts-and-users/subscribe-account-activity/api-reference/aaa-premium#post-account-activity-all-env-name-webhooks
|
14
|
+
# @note Create a webhook
|
15
|
+
# @rate_limited Yes
|
16
|
+
# @authentication Requires user context - all consumer and access tokens
|
17
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
18
|
+
# @return [Hash]
|
19
|
+
# @param env_name [String] Environment Name.
|
20
|
+
# @param url [String] Encoded URL for the callback endpoint.
|
21
|
+
def create_webhook(env_name, url)
|
22
|
+
perform_request(:json_post, "/1.1/account_activity/all/#{env_name}/webhooks.json?url=#{url}")
|
23
|
+
end
|
24
|
+
|
25
|
+
# Returns all environments, webhook URLs and their statuses for the authenticating app. Currently, only one webhook URL can be registered to each environment.
|
26
|
+
# @see https://developer.twitter.com/en/docs/accounts-and-users/subscribe-account-activity/api-reference/aaa-premium#get-account-activity-all-webhooks
|
27
|
+
# @note List webhooks
|
28
|
+
# @rate_limited Yes
|
29
|
+
# @authentication Requires user context - all consumer and access tokens
|
30
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
31
|
+
# @return [Hash]
|
32
|
+
# @param env_name [String] Environment Name.
|
33
|
+
def list_webhooks(env_name)
|
34
|
+
perform_request(:get, "/1.1/account_activity/all/#{env_name}/webhooks.json")
|
35
|
+
end
|
36
|
+
|
37
|
+
# Removes the webhook from the provided application's all activities configuration. The webhook ID can be accessed by making a call to GET /1.1/account_activity/all/webhooks.
|
38
|
+
# @see https://developer.twitter.com/en/docs/accounts-and-users/subscribe-account-activity/api-reference/aaa-premium#delete-account-activity-all-env-name-webhooks-webhook-id
|
39
|
+
# @note Delete a webhook
|
40
|
+
# @authentication Requires user context - all consumer and access tokens
|
41
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
42
|
+
# @return [nil]
|
43
|
+
# @param env_name [String] Environment Name.
|
44
|
+
# @param webhook_id [String] Webhook ID.
|
45
|
+
def delete_webhook(env_name, webhook_id)
|
46
|
+
perform_request(:delete, "/1.1/account_activity/all/#{env_name}/webhooks/#{webhook_id}.json")
|
47
|
+
end
|
48
|
+
|
49
|
+
# Triggers the challenge response check (CRC) for the given enviroments webhook for all activites. If the check is successful, returns 204 and reenables the webhook by setting its status to valid.
|
50
|
+
# @see https://developer.twitter.com/en/docs/accounts-and-users/subscribe-account-activity/api-reference/aaa-premium#put-account-activity-all-env-name-webhooks-webhook-id
|
51
|
+
# @note Trigger CRC check to a webhook
|
52
|
+
# @rate_limited Yes
|
53
|
+
# @authentication Requires user context - all consumer and access tokens
|
54
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
55
|
+
# @return [nil]
|
56
|
+
# @param env_name [String] Environment Name.
|
57
|
+
# @param webhook_id [String] Webhook ID.
|
58
|
+
def trigger_crc_check(env_name, webhook_id)
|
59
|
+
perform_request(:json_put, "/1.1/account_activity/all/#{env_name}/webhooks/#{webhook_id}.json")
|
60
|
+
end
|
61
|
+
|
62
|
+
# Subscribes the provided application to all events for the provided environment for all message types. After activation, all events for the requesting user will be sent to the application's webhook via POST request.
|
63
|
+
# @see https://developer.twitter.com/en/docs/accounts-and-users/subscribe-account-activity/api-reference/aaa-premium#post-account-activity-all-env-name-subscriptions
|
64
|
+
# @note Subscribe the user(whose credentials are provided) to the app so that the webhook can receive all types of events from user
|
65
|
+
# @rate_limited Yes
|
66
|
+
# @authentication Requires user context - all consumer and access tokens
|
67
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
68
|
+
# @return [nil]
|
69
|
+
# @param env_name [String] Environment Name
|
70
|
+
def create_subscription(env_name)
|
71
|
+
perform_request(:json_post, "/1.1/account_activity/all/#{env_name}/subscriptions.json")
|
72
|
+
end
|
73
|
+
|
74
|
+
# Provides a way to determine if a webhook configuration is subscribed to the provided user's events. If the provided user context has an active subscription with provided application, returns 204 OK.
|
75
|
+
# @see https://developer.twitter.com/en/docs/accounts-and-users/subscribe-account-activity/api-reference/aaa-premium#get-account-activity-all-env-name-subscriptions
|
76
|
+
# @note Check if the user is subscribed to the given app
|
77
|
+
# @rate_limited Yes
|
78
|
+
# @authentication Requires user context - all consumer and access tokens
|
79
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
80
|
+
# @return [nil]
|
81
|
+
# @param env_name [String] Environment Name
|
82
|
+
def check_subscription(env_name)
|
83
|
+
perform_request(:get, "/1.1/account_activity/all/#{env_name}/subscriptions.json")
|
84
|
+
end
|
85
|
+
|
86
|
+
# Deactivates subscription(s) for the provided user context and application for all activities. After deactivation, all events for the requesting user will no longer be sent to the webhook URL.
|
87
|
+
# @see https://developer.twitter.com/en/docs/accounts-and-users/subscribe-account-activity/api-reference/aaa-premium#delete-account-activity-all-env-name-subscriptions
|
88
|
+
# @note Deactivate a subscription, Users events will not be sent to the app
|
89
|
+
# @rate_limited Yes
|
90
|
+
# @authentication Requires user context - all consumer and access tokens
|
91
|
+
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
92
|
+
# @return [nil]
|
93
|
+
# @param env_name [String] Environment Name
|
94
|
+
def deactivate_subscription(env_name)
|
95
|
+
perform_request(:delete, "/1.1/account_activity/all/#{env_name}/subscriptions.json")
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|