twitter 8.2.0 → 8.3.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.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.md +1 -1
  3. data/README.md +172 -10
  4. data/lib/twitter/arguments.rb +14 -1
  5. data/lib/twitter/base.rb +72 -11
  6. data/lib/twitter/basic_user.rb +7 -1
  7. data/lib/twitter/client.rb +94 -3
  8. data/lib/twitter/creatable.rb +11 -2
  9. data/lib/twitter/cursor.rb +58 -11
  10. data/lib/twitter/direct_message.rb +32 -4
  11. data/lib/twitter/direct_message_event.rb +34 -10
  12. data/lib/twitter/direct_messages/welcome_message.rb +22 -1
  13. data/lib/twitter/direct_messages/welcome_message_rule.rb +7 -0
  14. data/lib/twitter/direct_messages/welcome_message_rule_wrapper.rb +26 -3
  15. data/lib/twitter/direct_messages/welcome_message_wrapper.rb +36 -11
  16. data/lib/twitter/entities.rb +84 -8
  17. data/lib/twitter/entity/hashtag.rb +7 -1
  18. data/lib/twitter/entity/symbol.rb +7 -1
  19. data/lib/twitter/entity/uri.rb +2 -1
  20. data/lib/twitter/entity/user_mention.rb +20 -1
  21. data/lib/twitter/entity.rb +7 -1
  22. data/lib/twitter/enumerable.rb +20 -3
  23. data/lib/twitter/error.rb +137 -61
  24. data/lib/twitter/factory.rb +9 -5
  25. data/lib/twitter/geo/point.rb +37 -5
  26. data/lib/twitter/geo/polygon.rb +1 -0
  27. data/lib/twitter/geo.rb +16 -2
  28. data/lib/twitter/geo_factory.rb +7 -3
  29. data/lib/twitter/geo_results.rb +39 -8
  30. data/lib/twitter/headers.rb +44 -7
  31. data/lib/twitter/identity.rb +13 -3
  32. data/lib/twitter/language.rb +21 -1
  33. data/lib/twitter/list.rb +101 -11
  34. data/lib/twitter/media/animated_gif.rb +1 -0
  35. data/lib/twitter/media/photo.rb +19 -3
  36. data/lib/twitter/media/video.rb +21 -3
  37. data/lib/twitter/media/video_info.rb +15 -1
  38. data/lib/twitter/media_factory.rb +7 -3
  39. data/lib/twitter/metadata.rb +14 -1
  40. data/lib/twitter/null_object.rb +16 -14
  41. data/lib/twitter/oembed.rb +56 -2
  42. data/lib/twitter/place.rb +74 -6
  43. data/lib/twitter/premium_search_results.rb +87 -18
  44. data/lib/twitter/profile.rb +100 -44
  45. data/lib/twitter/profile_banner.rb +9 -4
  46. data/lib/twitter/rate_limit.rb +32 -3
  47. data/lib/twitter/relationship.rb +8 -5
  48. data/lib/twitter/rest/account_activity.rb +55 -26
  49. data/lib/twitter/rest/api.rb +2 -0
  50. data/lib/twitter/rest/client.rb +18 -0
  51. data/lib/twitter/rest/direct_messages/welcome_messages.rb +89 -18
  52. data/lib/twitter/rest/direct_messages.rb +158 -94
  53. data/lib/twitter/rest/favorites.rb +57 -21
  54. data/lib/twitter/rest/form_encoder.rb +57 -17
  55. data/lib/twitter/rest/friends_and_followers.rb +101 -35
  56. data/lib/twitter/rest/help.rb +13 -3
  57. data/lib/twitter/rest/lists.rb +133 -45
  58. data/lib/twitter/rest/oauth.rb +23 -17
  59. data/lib/twitter/rest/places_and_geo.rb +44 -28
  60. data/lib/twitter/rest/premium_search.rb +18 -13
  61. data/lib/twitter/rest/request.rb +171 -53
  62. data/lib/twitter/rest/saved_searches.rb +22 -7
  63. data/lib/twitter/rest/search.rb +20 -16
  64. data/lib/twitter/rest/spam_reporting.rb +5 -1
  65. data/lib/twitter/rest/suggested_users.rb +14 -5
  66. data/lib/twitter/rest/timelines.rb +92 -52
  67. data/lib/twitter/rest/trends.rb +31 -12
  68. data/lib/twitter/rest/tweets.rb +145 -88
  69. data/lib/twitter/rest/undocumented.rb +11 -2
  70. data/lib/twitter/rest/upload_utils.rb +42 -26
  71. data/lib/twitter/rest/users.rb +150 -71
  72. data/lib/twitter/rest/utils.rb +135 -39
  73. data/lib/twitter/saved_search.rb +23 -2
  74. data/lib/twitter/search_results.rb +62 -17
  75. data/lib/twitter/settings.rb +37 -11
  76. data/lib/twitter/size.rb +37 -3
  77. data/lib/twitter/source_user.rb +4 -3
  78. data/lib/twitter/streaming/client.rb +60 -8
  79. data/lib/twitter/streaming/connection.rb +55 -8
  80. data/lib/twitter/streaming/deleted_tweet.rb +8 -0
  81. data/lib/twitter/streaming/event.rb +43 -1
  82. data/lib/twitter/streaming/friend_list.rb +1 -0
  83. data/lib/twitter/streaming/message_parser.rb +20 -10
  84. data/lib/twitter/streaming/response.rb +31 -5
  85. data/lib/twitter/streaming/stall_warning.rb +23 -0
  86. data/lib/twitter/suggestion.rb +25 -1
  87. data/lib/twitter/target_user.rb +2 -1
  88. data/lib/twitter/trend.rb +29 -1
  89. data/lib/twitter/trend_results.rb +50 -7
  90. data/lib/twitter/tweet.rb +180 -21
  91. data/lib/twitter/user.rb +289 -53
  92. data/lib/twitter/utils.rb +12 -13
  93. data/lib/twitter/variant.rb +12 -1
  94. data/lib/twitter/version.rb +66 -29
  95. data/lib/twitter.rb +6 -1
  96. metadata +23 -57
  97. data/.yardopts +0 -16
  98. data/CHANGELOG.md +0 -1040
  99. data/CONTRIBUTING.md +0 -49
  100. data/twitter.gemspec +0 -40
@@ -5,17 +5,42 @@ require "twitter/utils"
5
5
  require "uri"
6
6
 
7
7
  module Twitter
8
+ # Represents premium search results from Twitter
8
9
  class PremiumSearchResults
9
- include Twitter::Enumerable
10
- include Twitter::Utils
10
+ include Enumerable
11
+ include Utils
12
+
13
+ # The raw attributes hash
14
+ #
15
+ # @api public
16
+ # @example
17
+ # results.attrs
11
18
  # @return [Hash]
12
19
  attr_reader :attrs
13
- alias to_h attrs
14
- alias to_hash to_h
15
20
 
16
- # Initializes a new SearchResults object
21
+ # @!method to_h
22
+ # Returns the attributes as a hash
23
+ # @api public
24
+ # @example
25
+ # results.to_h
26
+ # @return [Hash]
27
+ alias_method :to_h, :attrs
28
+
29
+ # @!method to_hash
30
+ # Returns the attributes as a hash
31
+ # @api public
32
+ # @example
33
+ # results.to_hash
34
+ # @return [Hash]
35
+ alias_method :to_hash, :to_h
36
+
37
+ # Initializes a new PremiumSearchResults object
17
38
  #
18
- # @param request [Twitter::REST::Request]
39
+ # @api public
40
+ # @example
41
+ # Twitter::PremiumSearchResults.new(request)
42
+ # @param request [Twitter::REST::Request] The request object
43
+ # @param request_config [Hash] Configuration options
19
44
  # @return [Twitter::PremiumSearchResults]
20
45
  def initialize(request, request_config = {})
21
46
  @client = request.client
@@ -27,41 +52,85 @@ module Twitter
27
52
  self.attrs = request.perform
28
53
  end
29
54
 
30
- private
55
+ private
31
56
 
57
+ # Returns true if this is the last page of results
58
+ #
59
+ # @api private
32
60
  # @return [Boolean]
33
61
  def last?
34
62
  !next_page?
35
63
  end
36
64
 
65
+ # Returns true if there is a next page
66
+ #
67
+ # @api private
37
68
  # @return [Boolean]
38
69
  def next_page?
39
- !!@attrs[:next]
70
+ !next_page_token.nil?
40
71
  end
41
72
 
42
- # Returns a Hash of query parameters for the next result in the search
73
+ # Returns query parameters for the next page
43
74
  #
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.
75
+ # @api private
76
+ # @note Returned Hash can be merged into previous search options
77
+ # @return [Hash]
46
78
  def next_page
47
- {next: @attrs[:next]} if next_page?
79
+ return if next_page_token.nil?
80
+
81
+ {next: next_page_token}
48
82
  end
49
83
 
84
+ # Fetches the next page of results
85
+ #
86
+ # @api private
50
87
  # @return [Hash]
51
88
  def fetch_next_page
52
- request = @client.premium_search(@options[:query], (@options.reject { |k| k == :query } || {}).merge(next_page), @request_config)
89
+ request = @client.premium_search(search_query, next_page_options, @request_config) # steep:ignore ArgumentTypeMismatch
53
90
 
54
91
  self.attrs = request.attrs
55
92
  end
56
93
 
57
- # @param attrs [Hash]
94
+ # Sets the attributes and populates the collection
95
+ #
96
+ # @api private
97
+ # @param attrs [Hash] The attributes hash
58
98
  # @return [Hash]
59
99
  def attrs=(attrs)
60
- @attrs = attrs
61
- @attrs.fetch(:results, []).collect do |tweet|
62
- @collection << Tweet.new(tweet)
100
+ attrs.tap do |value|
101
+ @attrs = value
102
+ @collection.concat(value.fetch(:results, []).map { |tweet| Tweet.new(tweet) })
63
103
  end
64
- @attrs
104
+ end
105
+
106
+ # Returns the token used to fetch the next results page
107
+ #
108
+ # @api private
109
+ # @example
110
+ # results.send(:next_page_token)
111
+ # @return [String, nil]
112
+ def next_page_token
113
+ @attrs[:next]
114
+ end
115
+
116
+ # Returns the original search query for this result set
117
+ #
118
+ # @api private
119
+ # @example
120
+ # results.send(:search_query)
121
+ # @return [String, nil]
122
+ def search_query
123
+ @options[:query]
124
+ end
125
+
126
+ # Returns request options for fetching the next page
127
+ #
128
+ # @api private
129
+ # @example
130
+ # results.send(:next_page_options)
131
+ # @return [Hash]
132
+ def next_page_options
133
+ @options.dup.tap { |options| options.delete(:query) }.merge(next_page || {})
65
134
  end
66
135
  end
67
136
  end
@@ -1,65 +1,92 @@
1
- require "addressable/uri"
1
+ require "uri"
2
2
  require "cgi"
3
3
  require "memoizable"
4
4
 
5
5
  module Twitter
6
+ # Provides profile image and banner URL methods
6
7
  module Profile
8
+ # Regular expression for profile image suffix
7
9
  PROFILE_IMAGE_SUFFIX_REGEX = /_normal(\.gif|\.jpe?g|\.png)$/i
8
- PREDICATE_URI_METHOD_REGEX = /_uri\?$/
9
10
  include Memoizable
10
11
 
11
- class << self
12
- private
13
-
14
- def alias_predicate_uri_methods(method)
15
- %w[_url? _uri_https? _url_https?].each do |replacement|
16
- alias_method_sub(method, PREDICATE_URI_METHOD_REGEX, replacement)
17
- end
18
- end
19
-
20
- def alias_method_sub(method, pattern, replacement)
21
- alias_method(method.to_s.sub(pattern, replacement).to_sym, method)
22
- end
23
- end
24
-
25
- # Return the URL to the user's profile banner image
12
+ # Returns the URL to the user's profile banner image
26
13
  #
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
- # @return [Addressable::URI]
14
+ # @api public
15
+ # @example
16
+ # user.profile_banner_uri(:web)
17
+ # @param size [String, Symbol] The size of the image
18
+ # @return [URI::Generic]
29
19
  def profile_banner_uri(size = :web)
30
- parse_uri(insecure_uri([@attrs[:profile_banner_url], size].join("/"))) unless @attrs[:profile_banner_url].nil?
20
+ parse_uri(insecure_uri([@attrs[:profile_banner_url], size].join("/"))) unless @attrs[:profile_banner_url].nil? # steep:ignore FallbackAny
31
21
  end
32
- alias profile_banner_url profile_banner_uri
33
22
 
34
- # Return the secure URL to the user's profile banner image
23
+ # @!method profile_banner_url
24
+ # Returns the URL to the user's profile banner image
25
+ # @api public
26
+ # @example
27
+ # user.profile_banner_url(:web)
28
+ # @return [URI::Generic]
29
+ alias_method :profile_banner_url, :profile_banner_uri
30
+
31
+ # Returns the secure URL to the user's profile banner image
35
32
  #
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
- # @return [Addressable::URI]
33
+ # @api public
34
+ # @example
35
+ # user.profile_banner_uri_https(:web)
36
+ # @param size [String, Symbol] The size of the image
37
+ # @return [URI::Generic]
38
38
  def profile_banner_uri_https(size = :web)
39
- parse_uri([@attrs[:profile_banner_url], size].join("/")) unless @attrs[:profile_banner_url].nil?
39
+ parse_uri([@attrs[:profile_banner_url], size].join("/")) unless @attrs[:profile_banner_url].nil? # steep:ignore FallbackAny
40
40
  end
41
- alias profile_banner_url_https profile_banner_uri_https
42
41
 
42
+ # @!method profile_banner_url_https
43
+ # Returns the secure URL to the user's profile banner image
44
+ # @api public
45
+ # @example
46
+ # user.profile_banner_url_https(:web)
47
+ # @return [URI::Generic]
48
+ alias_method :profile_banner_url_https, :profile_banner_uri_https
49
+
50
+ # Returns true if the user has a profile banner
51
+ #
52
+ # @api public
53
+ # @example
54
+ # user.profile_banner_uri?
43
55
  # @return [Boolean]
44
56
  def profile_banner_uri?
45
- !!@attrs[:profile_banner_url]
57
+ !!@attrs[:profile_banner_url] # steep:ignore FallbackAny
46
58
  end
47
59
  memoize :profile_banner_uri?
48
- alias_predicate_uri_methods :profile_banner_uri?
60
+ alias_method :profile_banner_url?, :profile_banner_uri?
61
+ alias_method :profile_banner_uri_https?, :profile_banner_uri?
62
+ alias_method :profile_banner_url_https?, :profile_banner_uri?
49
63
 
50
- # Return the URL to the user's profile image
64
+ # Returns the URL to the user's profile image
51
65
  #
52
- # @param size [String, Symbol] The size of the image. Must be one of: 'mini', 'normal', 'bigger' or 'original'
53
- # @return [Addressable::URI]
66
+ # @api public
67
+ # @example
68
+ # user.profile_image_uri(:normal)
69
+ # @param size [String, Symbol] The size of the image
70
+ # @return [URI::Generic]
54
71
  def profile_image_uri(size = :normal)
55
- parse_uri(insecure_uri(profile_image_uri_https(size))) unless @attrs[:profile_image_url_https].nil?
72
+ parse_uri(insecure_uri(profile_image_uri_https(size))) unless @attrs[:profile_image_url_https].nil? # steep:ignore FallbackAny
56
73
  end
57
- alias profile_image_url profile_image_uri
58
74
 
59
- # Return the secure URL to the user's profile image
75
+ # @!method profile_image_url
76
+ # Returns the URL to the user's profile image
77
+ # @api public
78
+ # @example
79
+ # user.profile_image_url(:normal)
80
+ # @return [URI::Generic]
81
+ alias_method :profile_image_url, :profile_image_uri
82
+
83
+ # Returns the secure URL to the user's profile image
60
84
  #
61
- # @param size [String, Symbol] The size of the image. Must be one of: 'mini', 'normal', 'bigger' or 'original'
62
- # @return [Addressable::URI]
85
+ # @api public
86
+ # @example
87
+ # user.profile_image_uri_https(:normal)
88
+ # @param size [String, Symbol] The size of the image
89
+ # @return [URI::Generic]
63
90
  def profile_image_uri_https(size = :normal)
64
91
  # The profile image URL comes in looking like like this:
65
92
  # https://a0.twimg.com/profile_images/1759857427/image1326743606_normal.png
@@ -67,29 +94,58 @@ module Twitter
67
94
  # https://a0.twimg.com/profile_images/1759857427/image1326743606.png
68
95
  # https://a0.twimg.com/profile_images/1759857427/image1326743606_mini.png
69
96
  # https://a0.twimg.com/profile_images/1759857427/image1326743606_bigger.png
70
- parse_uri(@attrs[:profile_image_url_https].sub(PROFILE_IMAGE_SUFFIX_REGEX, profile_image_suffix(size))) unless @attrs[:profile_image_url_https].nil?
97
+ parse_uri(@attrs[:profile_image_url_https].sub(PROFILE_IMAGE_SUFFIX_REGEX, profile_image_suffix(size))) unless @attrs[:profile_image_url_https].nil? # steep:ignore FallbackAny
71
98
  end
72
- alias profile_image_url_https profile_image_uri_https
73
99
 
100
+ # @!method profile_image_url_https
101
+ # Returns the secure URL to the user's profile image
102
+ # @api public
103
+ # @example
104
+ # user.profile_image_url_https(:normal)
105
+ # @return [URI::Generic]
106
+ alias_method :profile_image_url_https, :profile_image_uri_https
107
+
108
+ # Returns true if the user has a profile image
109
+ #
110
+ # @api public
111
+ # @example
112
+ # user.profile_image_uri?
74
113
  # @return [Boolean]
75
114
  def profile_image_uri?
76
- !!@attrs[:profile_image_url_https]
115
+ !!@attrs[:profile_image_url_https] # steep:ignore FallbackAny
77
116
  end
78
117
  memoize :profile_image_uri?
79
- alias_predicate_uri_methods :profile_image_uri?
118
+ alias_method :profile_image_url?, :profile_image_uri?
119
+ alias_method :profile_image_uri_https?, :profile_image_uri?
120
+ alias_method :profile_image_url_https?, :profile_image_uri?
80
121
 
81
- private
122
+ private
82
123
 
124
+ # Parses a URI string
125
+ #
126
+ # @api private
127
+ # @param uri [String] The URI string
128
+ # @return [URI::Generic]
83
129
  def parse_uri(uri)
84
- Addressable::URI.parse(uri)
130
+ URI.parse(uri.gsub(/[^\x00-\x7F]/) { |c| c.bytes.map { |b| format("%%%02X", b) }.join })
85
131
  end
86
132
 
133
+ # Converts a URI to insecure (http) version
134
+ #
135
+ # @api private
136
+ # @param uri [Object] The URI to convert
137
+ # @return [String]
87
138
  def insecure_uri(uri)
88
- uri.to_s.sub(/^https/i, "http")
139
+ uri.to_s.sub(/\Ahttps/i, "http")
89
140
  end
90
141
 
142
+ # Returns the suffix for profile image URLs
143
+ #
144
+ # @api private
145
+ # @param size [Symbol] The size
146
+ # @return [String]
91
147
  def profile_image_suffix(size)
92
- size.to_sym == :original ? '\\1' : "_#{size}\\1"
148
+ (size.to_sym == :original) ? '\\1' : "_#{size}\\1"
93
149
  end
94
150
  end
95
151
  end
@@ -2,14 +2,19 @@ require "memoizable"
2
2
  require "twitter/base"
3
3
 
4
4
  module Twitter
5
- class ProfileBanner < Twitter::Base
5
+ # Represents a user's profile banner
6
+ class ProfileBanner < Base
6
7
  include Memoizable
7
8
 
8
- # Returns an array of photo sizes
9
+ # Returns a hash of banner sizes
9
10
  #
10
- # @return [Array<Twitter::Size>]
11
+ # @api public
12
+ # @example
13
+ # profile_banner.sizes
14
+ # @return [Hash{Symbol => Twitter::Size}]
11
15
  def sizes
12
- @attrs.fetch(:sizes, []).each_with_object({}) do |(key, value), object|
16
+ result = {} # : Hash[Symbol, Size]
17
+ @attrs.fetch(:sizes, []).each_with_object(result) do |(key, value), object|
13
18
  object[key] = Size.new(value)
14
19
  end
15
20
  end
@@ -1,9 +1,15 @@
1
1
  require "memoizable"
2
2
 
3
3
  module Twitter
4
- class RateLimit < Twitter::Base
4
+ # Represents rate limit information from Twitter API responses
5
+ class RateLimit < Base
5
6
  include Memoizable
6
7
 
8
+ # Returns the rate limit ceiling for this request
9
+ #
10
+ # @api public
11
+ # @example
12
+ # rate_limit.limit
7
13
  # @return [Integer]
8
14
  def limit
9
15
  limit = @attrs["x-rate-limit-limit"]
@@ -11,6 +17,11 @@ module Twitter
11
17
  end
12
18
  memoize :limit
13
19
 
20
+ # Returns the number of requests remaining
21
+ #
22
+ # @api public
23
+ # @example
24
+ # rate_limit.remaining
14
25
  # @return [Integer]
15
26
  def remaining
16
27
  remaining = @attrs["x-rate-limit-remaining"]
@@ -18,6 +29,11 @@ module Twitter
18
29
  end
19
30
  memoize :remaining
20
31
 
32
+ # Returns the time when the rate limit resets
33
+ #
34
+ # @api public
35
+ # @example
36
+ # rate_limit.reset_at
21
37
  # @return [Time]
22
38
  def reset_at
23
39
  reset = @attrs["x-rate-limit-reset"]
@@ -25,10 +41,23 @@ module Twitter
25
41
  end
26
42
  memoize :reset_at
27
43
 
44
+ # Returns the number of seconds until the rate limit resets
45
+ #
46
+ # @api public
47
+ # @example
48
+ # rate_limit.reset_in
28
49
  # @return [Integer]
29
50
  def reset_in
30
- [(reset_at - Time.now).ceil, 0].max if reset_at
51
+ time = reset_at
52
+ [(time - Time.now).ceil, 0].max if time
31
53
  end
32
- alias retry_after reset_in
54
+
55
+ # @!method retry_after
56
+ # Returns the number of seconds until the rate limit resets
57
+ # @api public
58
+ # @example
59
+ # rate_limit.retry_after
60
+ # @return [Integer]
61
+ alias_method :retry_after, :reset_in
33
62
  end
34
63
  end
@@ -1,17 +1,20 @@
1
1
  require "twitter/base"
2
2
 
3
3
  module Twitter
4
- class Relationship < Twitter::Base
4
+ # Represents a relationship between two Twitter users
5
+ class Relationship < Base
5
6
  object_attr_reader :SourceUser, :source
6
7
  object_attr_reader :TargetUser, :target
7
8
 
8
- # Initializes a new object
9
+ # Initializes a new Relationship object
9
10
  #
10
- # @param attrs [Hash]
11
+ # @api public
12
+ # @example
13
+ # Twitter::Relationship.new(relationship: {source: {}, target: {}})
14
+ # @param attrs [Hash] The attributes hash
11
15
  # @return [Twitter::Relationship]
12
16
  def initialize(attrs = {})
13
- super
14
- @attrs = attrs[:relationship]
17
+ super(attrs[:relationship]) # steep:ignore NoMethod
15
18
  end
16
19
  end
17
20
  end
@@ -4,93 +4,122 @@ require "twitter/utils"
4
4
 
5
5
  module Twitter
6
6
  module REST
7
+ # Methods for interacting with the Account Activity API
7
8
  module AccountActivity
8
9
  include Twitter::REST::Utils
9
10
  include Twitter::Utils
10
11
 
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
+ # Registers a webhook URL for all event types
13
+ #
14
+ # @api public
12
15
  # @see https://developer.twitter.com/en/docs/accounts-and-users/subscribe-account-activity/api-reference
13
16
  # @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
17
  # @note Create a webhook
15
18
  # @rate_limited Yes
16
19
  # @authentication Requires user context - all consumer and access tokens
17
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
20
+ # @example
21
+ # client.create_webhook("production", "https://example.com/webhook")
22
+ # @param env_name [String] Environment Name
23
+ # @param url [String] Encoded URL for the callback endpoint
24
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid
18
25
  # @return [Hash]
19
- # @param env_name [String] Environment Name.
20
- # @param url [String] Encoded URL for the callback endpoint.
21
26
  def create_webhook(env_name, url)
22
27
  perform_request(:json_post, "/1.1/account_activity/all/#{env_name}/webhooks.json?url=#{url}")
23
28
  end
24
29
 
25
- # Returns all environments, webhook URLs and their statuses for the authenticating app. Currently, only one webhook URL can be registered to each environment.
30
+ # Returns all environments and webhook URLs for the app
31
+ #
32
+ # @api public
26
33
  # @see https://developer.twitter.com/en/docs/accounts-and-users/subscribe-account-activity/api-reference/aaa-premium#get-account-activity-all-webhooks
27
34
  # @note List webhooks
28
35
  # @rate_limited Yes
29
36
  # @authentication Requires user context - all consumer and access tokens
30
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
37
+ # @example
38
+ # client.list_webhooks("production")
39
+ # @param env_name [String] Environment Name
40
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid
31
41
  # @return [Hash]
32
- # @param env_name [String] Environment Name.
33
42
  def list_webhooks(env_name)
34
43
  perform_request(:get, "/1.1/account_activity/all/#{env_name}/webhooks.json")
35
44
  end
36
45
 
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.
46
+ # Removes the webhook from the application's configuration
47
+ #
48
+ # @api public
38
49
  # @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
50
  # @note Delete a webhook
40
51
  # @authentication Requires user context - all consumer and access tokens
41
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
52
+ # @example
53
+ # client.delete_webhook("production", "12345")
54
+ # @param env_name [String] Environment Name
55
+ # @param webhook_id [String] Webhook ID
56
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid
42
57
  # @return [nil]
43
- # @param env_name [String] Environment Name.
44
- # @param webhook_id [String] Webhook ID.
45
58
  def delete_webhook(env_name, webhook_id)
46
59
  perform_request(:delete, "/1.1/account_activity/all/#{env_name}/webhooks/#{webhook_id}.json")
47
60
  end
48
61
 
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.
62
+ # Triggers the challenge response check (CRC) for a webhook
63
+ #
64
+ # @api public
50
65
  # @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
66
  # @note Trigger CRC check to a webhook
52
67
  # @rate_limited Yes
53
68
  # @authentication Requires user context - all consumer and access tokens
54
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
69
+ # @example
70
+ # client.trigger_crc_check("production", "12345")
71
+ # @param env_name [String] Environment Name
72
+ # @param webhook_id [String] Webhook ID
73
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid
55
74
  # @return [nil]
56
- # @param env_name [String] Environment Name.
57
- # @param webhook_id [String] Webhook ID.
58
75
  def trigger_crc_check(env_name, webhook_id)
59
76
  perform_request(:json_put, "/1.1/account_activity/all/#{env_name}/webhooks/#{webhook_id}.json")
60
77
  end
61
78
 
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.
79
+ # Subscribes the application to all events for the environment
80
+ #
81
+ # @api public
63
82
  # @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
83
+ # @note Subscribe the user to receive webhook events
65
84
  # @rate_limited Yes
66
85
  # @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]
86
+ # @example
87
+ # client.create_subscription("production")
69
88
  # @param env_name [String] Environment Name
89
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid
90
+ # @return [nil]
70
91
  def create_subscription(env_name)
71
92
  perform_request(:json_post, "/1.1/account_activity/all/#{env_name}/subscriptions.json")
72
93
  end
73
94
 
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.
95
+ # Checks if the user is subscribed to the webhook
96
+ #
97
+ # @api public
75
98
  # @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
99
  # @note Check if the user is subscribed to the given app
77
100
  # @rate_limited Yes
78
101
  # @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]
102
+ # @example
103
+ # client.check_subscription("production")
81
104
  # @param env_name [String] Environment Name
105
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid
106
+ # @return [nil]
82
107
  def check_subscription(env_name)
83
108
  perform_request(:get, "/1.1/account_activity/all/#{env_name}/subscriptions.json")
84
109
  end
85
110
 
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.
111
+ # Deactivates subscription for the user and application
112
+ #
113
+ # @api public
87
114
  # @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
115
+ # @note Deactivate a subscription
89
116
  # @rate_limited Yes
90
117
  # @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]
118
+ # @example
119
+ # client.deactivate_subscription("production")
93
120
  # @param env_name [String] Environment Name
121
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid
122
+ # @return [nil]
94
123
  def deactivate_subscription(env_name)
95
124
  perform_request(:delete, "/1.1/account_activity/all/#{env_name}/subscriptions.json")
96
125
  end
@@ -19,7 +19,9 @@ require "twitter/rest/undocumented"
19
19
  require "twitter/rest/users"
20
20
 
21
21
  module Twitter
22
+ # REST API modules for Twitter
22
23
  module REST
24
+ # Combined Twitter REST API methods
23
25
  # @note All methods have been separated into modules and follow the same grouping used in {http://dev.twitter.com/doc the Twitter API Documentation}.
24
26
  # @see https://dev.twitter.com/overview/general/things-every-developer-should-know
25
27
  module API
@@ -5,15 +5,33 @@ require "twitter/rest/utils"
5
5
 
6
6
  module Twitter
7
7
  module REST
8
+ # REST API client for Twitter
8
9
  class Client < Twitter::Client
9
10
  include Twitter::REST::API
11
+
12
+ # The bearer token for application-only authentication
13
+ #
14
+ # @api public
15
+ # @example
16
+ # client.bearer_token = "AAAA..."
17
+ # @return [String]
10
18
  attr_accessor :bearer_token
11
19
 
20
+ # Returns true if a bearer token is set
21
+ #
22
+ # @api public
23
+ # @example
24
+ # client.bearer_token?
12
25
  # @return [Boolean]
13
26
  def bearer_token?
14
27
  !!bearer_token
15
28
  end
16
29
 
30
+ # Returns true if credentials are configured
31
+ #
32
+ # @api public
33
+ # @example
34
+ # client.credentials?
17
35
  # @return [Boolean]
18
36
  def credentials?
19
37
  super || bearer_token?