twitter 8.2.0 → 8.3.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.
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 +160 -96
  53. data/lib/twitter/rest/favorites.rb +58 -22
  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 +136 -47
  58. data/lib/twitter/rest/oauth.rb +21 -15
  59. data/lib/twitter/rest/places_and_geo.rb +44 -28
  60. data/lib/twitter/rest/premium_search.rb +17 -12
  61. data/lib/twitter/rest/request.rb +173 -55
  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 +15 -6
  66. data/lib/twitter/rest/timelines.rb +92 -52
  67. data/lib/twitter/rest/trends.rb +32 -13
  68. data/lib/twitter/rest/tweets.rb +147 -89
  69. data/lib/twitter/rest/undocumented.rb +10 -1
  70. data/lib/twitter/rest/upload_utils.rb +45 -29
  71. data/lib/twitter/rest/users.rb +151 -72
  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 +66 -18
  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 +61 -9
  79. data/lib/twitter/streaming/connection.rb +54 -6
  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
@@ -6,43 +6,75 @@ require "twitter/utils"
6
6
  module Twitter
7
7
  module REST
8
8
  module DirectMessages
9
+ # Methods for managing welcome messages in direct messages
9
10
  module WelcomeMessages
10
11
  include Twitter::REST::UploadUtils
11
12
  include Twitter::REST::Utils
12
13
  include Twitter::Utils
13
14
 
14
- # Welcome Message
15
-
15
+ # Creates a new welcome message
16
+ #
17
+ # @api public
18
+ # @example
19
+ # client.create_welcome_message("Welcome!", "default")
20
+ # @param text [String] The text of the welcome message
21
+ # @param name [String] Optional name for the welcome message
22
+ # @param options [Hash] A customizable set of options
23
+ # @return [Twitter::DirectMessages::WelcomeMessage]
16
24
  def create_welcome_message(text, name = nil, options = {})
17
25
  json_options = {
18
26
  welcome_message: {
19
27
  message_data: {
20
- text:,
21
- },
22
- },
28
+ text:
29
+ }
30
+ }
23
31
  }
24
- json_options[:welcome_message][:name] = name if name
25
- welcome_message_wrapper = perform_request_with_object(:json_post, "/1.1/direct_messages/welcome_messages/new.json", json_options.merge!(options), Twitter::DirectMessages::WelcomeMessageWrapper)
32
+ json_options.fetch(:welcome_message)[:name] = name if name # steep:ignore ArgumentTypeMismatch
33
+ welcome_message_wrapper = perform_request_with_object(:json_post, "/1.1/direct_messages/welcome_messages/new.json", options.merge(json_options), Twitter::DirectMessages::WelcomeMessageWrapper)
26
34
  welcome_message_wrapper.welcome_message
27
35
  end
28
36
 
37
+ # Destroys welcome messages
38
+ #
39
+ # @api public
40
+ # @example
41
+ # client.destroy_welcome_message(123456789)
42
+ # @param ids [Array<Integer>] IDs of welcome messages to destroy
43
+ # @return [nil]
29
44
  def destroy_welcome_message(*ids)
30
45
  perform_requests(:delete, "/1.1/direct_messages/welcome_messages/destroy.json", ids)
31
46
  end
32
47
 
48
+ # Updates a welcome message
49
+ #
50
+ # @api public
51
+ # @example
52
+ # client.update_welcome_message(123456789, "New text")
53
+ # @param welcome_message_id [Integer] The ID of the welcome message
54
+ # @param text [String] The new text for the welcome message
55
+ # @param options [Hash] A customizable set of options
56
+ # @return [Twitter::DirectMessages::WelcomeMessage]
33
57
  def update_welcome_message(welcome_message_id, text, options = {})
34
58
  params = {
35
- id: welcome_message_id,
59
+ id: welcome_message_id
36
60
  }
37
61
  json_options = {
38
62
  message_data: {
39
- text:,
40
- },
63
+ text:
64
+ }
41
65
  }
42
- welcome_message_wrapper = perform_request_with_object(:json_put, "/1.1/direct_messages/welcome_messages/update.json", json_options.merge!(options), Twitter::DirectMessages::WelcomeMessageWrapper, params)
66
+ welcome_message_wrapper = perform_request_with_object(:json_put, "/1.1/direct_messages/welcome_messages/update.json", options.merge(json_options), Twitter::DirectMessages::WelcomeMessageWrapper, params)
43
67
  welcome_message_wrapper.welcome_message
44
68
  end
45
69
 
70
+ # Returns a welcome message
71
+ #
72
+ # @api public
73
+ # @example
74
+ # client.welcome_message(123456789)
75
+ # @param id [Integer] The ID of the welcome message
76
+ # @param options [Hash] A customizable set of options
77
+ # @return [Twitter::DirectMessages::WelcomeMessage]
46
78
  def welcome_message(id, options = {})
47
79
  options = options.dup
48
80
  options[:id] = id
@@ -50,28 +82,58 @@ module Twitter
50
82
  welcome_message_wrapper.welcome_message
51
83
  end
52
84
 
85
+ # Returns a list of welcome messages
86
+ #
87
+ # @api public
88
+ # @example
89
+ # client.welcome_message_list
90
+ # @param options [Hash] A customizable set of options
91
+ # @option options [Integer] :count Number of records to retrieve
92
+ # @return [Array<Twitter::DirectMessages::WelcomeMessage>]
53
93
  def welcome_message_list(options = {})
54
94
  limit = options.fetch(:count, 20)
55
- welcome_message_wrappers = perform_get_with_cursor("/1.1/direct_messages/welcome_messages/list.json", options.merge!(no_default_cursor: true, count: 50, limit:), :welcome_messages, Twitter::DirectMessages::WelcomeMessageWrapper)
95
+ request_options = options.merge(no_default_cursor: true, count: 50, limit:)
96
+ welcome_message_wrappers = perform_get_with_cursor("/1.1/direct_messages/welcome_messages/list.json", request_options, :welcome_messages, Twitter::DirectMessages::WelcomeMessageWrapper)
56
97
  welcome_message_wrappers.collect(&:welcome_message)
57
98
  end
58
99
 
59
- # Welcome Message Rule
60
-
100
+ # Creates a new welcome message rule
101
+ #
102
+ # @api public
103
+ # @example
104
+ # client.create_welcome_message_rule(123456789)
105
+ # @param welcome_message_id [Integer] The ID of the welcome message
106
+ # @param options [Hash] A customizable set of options
107
+ # @return [Twitter::DirectMessages::WelcomeMessageRule]
61
108
  def create_welcome_message_rule(welcome_message_id, options = {})
62
109
  json_options = {
63
110
  welcome_message_rule: {
64
- welcome_message_id:,
65
- },
111
+ welcome_message_id:
112
+ }
66
113
  }
67
- rule_wrapper = perform_request_with_object(:json_post, "/1.1/direct_messages/welcome_messages/rules/new.json", json_options.merge!(options), Twitter::DirectMessages::WelcomeMessageRuleWrapper)
114
+ rule_wrapper = perform_request_with_object(:json_post, "/1.1/direct_messages/welcome_messages/rules/new.json", options.merge(json_options), Twitter::DirectMessages::WelcomeMessageRuleWrapper)
68
115
  rule_wrapper.welcome_message_rule
69
116
  end
70
117
 
118
+ # Destroys welcome message rules
119
+ #
120
+ # @api public
121
+ # @example
122
+ # client.destroy_welcome_message_rule(123456789)
123
+ # @param ids [Array<Integer>] IDs of welcome message rules to destroy
124
+ # @return [nil]
71
125
  def destroy_welcome_message_rule(*ids)
72
126
  perform_requests(:delete, "/1.1/direct_messages/welcome_messages/rules/destroy.json", ids)
73
127
  end
74
128
 
129
+ # Returns a welcome message rule
130
+ #
131
+ # @api public
132
+ # @example
133
+ # client.welcome_message_rule(123456789)
134
+ # @param id [Integer] The ID of the welcome message rule
135
+ # @param options [Hash] A customizable set of options
136
+ # @return [Twitter::DirectMessages::WelcomeMessageRule]
75
137
  def welcome_message_rule(id, options = {})
76
138
  options = options.dup
77
139
  options[:id] = id
@@ -79,9 +141,18 @@ module Twitter
79
141
  rule_wrapper.welcome_message_rule
80
142
  end
81
143
 
144
+ # Returns a list of welcome message rules
145
+ #
146
+ # @api public
147
+ # @example
148
+ # client.welcome_message_rule_list
149
+ # @param options [Hash] A customizable set of options
150
+ # @option options [Integer] :count Number of records to retrieve
151
+ # @return [Array<Twitter::DirectMessages::WelcomeMessageRule>]
82
152
  def welcome_message_rule_list(options = {})
83
153
  limit = options.fetch(:count, 20)
84
- rule_wrappers = perform_get_with_cursor("/1.1/direct_messages/welcome_messages/rules/list.json", options.merge!(no_default_cursor: true, count: 50, limit:), :welcome_message_rules, Twitter::DirectMessages::WelcomeMessageRuleWrapper)
154
+ request_options = options.merge(no_default_cursor: true, count: 50, limit:)
155
+ rule_wrappers = perform_get_with_cursor("/1.1/direct_messages/welcome_messages/rules/list.json", request_options, :welcome_message_rules, Twitter::DirectMessages::WelcomeMessageRuleWrapper)
85
156
  rule_wrappers.collect(&:welcome_message_rule)
86
157
  end
87
158
  end
@@ -8,126 +8,150 @@ require "twitter/utils"
8
8
 
9
9
  module Twitter
10
10
  module REST
11
+ # Methods for interacting with direct messages
11
12
  module DirectMessages
12
13
  include Twitter::REST::UploadUtils
13
14
  include Twitter::REST::Utils
14
15
  include Twitter::Utils
15
16
 
16
- # Returns all Direct Message events for the authenticated user (both sent and received) within the last 30 days. Sorted in reverse-chronological order.
17
+ # Returns all Direct Message events for the authenticated user
18
+ #
19
+ # @api public
17
20
  # @see https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/list-events
18
- # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
21
+ # @note This method requires an access token with RWD permissions
19
22
  # @rate_limited Yes
20
23
  # @authentication Requires user context
21
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
22
- # @return [Array<Twitter::DirectMessageEvent>] Direct message events sent by and received by the authenticating user.
23
- # @param options [Hash] A customizable set of options.
24
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 50. Default is 20
25
- # @option options [String] :cursor Specifies the cursor position of results to retrieve.
24
+ # @example
25
+ # client.direct_messages_events
26
+ # @param options [Hash] A customizable set of options
27
+ # @option options [Integer] :count Number of records to retrieve (max 50)
28
+ # @option options [String] :cursor Cursor position of results
29
+ # @raise [Twitter::Error::Unauthorized] Error raised when credentials are not valid
30
+ # @return [Array<Twitter::DirectMessageEvent>] Direct message events
26
31
  def direct_messages_events(options = {})
27
32
  limit = options.fetch(:count, 20)
28
- perform_get_with_cursor("/1.1/direct_messages/events/list.json", options.merge!(no_default_cursor: true, count: 50, limit:), :events, Twitter::DirectMessageEvent)
33
+ request_options = options.merge(no_default_cursor: true, count: 50, limit:)
34
+ perform_get_with_cursor("/1.1/direct_messages/events/list.json", request_options, :events, DirectMessageEvent)
29
35
  end
30
36
 
31
- # Returns all Direct Messages for the authenticated user (both sent and received) within the last 30 days. Sorted in reverse-chronological order.
37
+ # Returns all Direct Messages for the authenticated user
38
+ #
39
+ # @api public
32
40
  # @see https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/list-events
33
- # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
41
+ # @note This method requires an access token with RWD permissions
34
42
  # @rate_limited Yes
35
43
  # @authentication Requires user context
36
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
37
- # @return [Array<Twitter::DirectMessage>] Direct messages sent by and received by the authenticating user.
38
- # @param options [Hash] A customizable set of options.
39
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 50. Default is 20
40
- # @option options [String] :cursor Specifies the cursor position of results to retrieve.
44
+ # @example
45
+ # client.direct_messages_list
46
+ # @param options [Hash] A customizable set of options
47
+ # @option options [Integer] :count Number of records to retrieve (max 50)
48
+ # @option options [String] :cursor Cursor position of results
49
+ # @raise [Twitter::Error::Unauthorized] Error raised when credentials are not valid
50
+ # @return [Array<Twitter::DirectMessage>] Direct messages
41
51
  def direct_messages_list(options = {})
42
52
  direct_messages_events(options).collect(&:direct_message)
43
53
  end
44
54
 
45
- # Returns Direct Messages received by the authenticated user within the last 30 days. Sorted in reverse-chronological order.
55
+ # Returns Direct Messages received by the authenticated user
56
+ #
57
+ # @api public
46
58
  # @see https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/list-events
47
- # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
59
+ # @note This method requires an access token with RWD permissions
48
60
  # @rate_limited Yes
49
61
  # @authentication Requires user context
50
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
51
- # @return [Array<Twitter::DirectMessage>] Direct messages received by the authenticating user.
52
- # @param options [Hash] A customizable set of options.
53
- # @option options [Integer] :count Specifies the number of records (sent and received dms) to retrieve. Must be less than or equal to 50. Default is 20
54
- # @option options [String] :cursor Specifies the cursor position of results to retrieve.
62
+ # @example
63
+ # client.direct_messages_received
64
+ # @param options [Hash] A customizable set of options
65
+ # @option options [Integer] :count Number of records to retrieve (max 50)
66
+ # @option options [String] :cursor Cursor position of results
67
+ # @raise [Twitter::Error::Unauthorized] Error raised when credentials are not valid
68
+ # @return [Array<Twitter::DirectMessage>] Direct messages received
55
69
  def direct_messages_received(options = {})
56
70
  limit = options.fetch(:count, 20)
57
- direct_messages_list(options).select { |dm| dm.recipient_id == user_id }.first(limit)
71
+ direct_messages_list(options).select { |dm| dm.recipient_id.eql?(user_id) }.first(limit)
58
72
  end
59
73
 
60
- # Returns Direct Messages sent by the authenticated user within the last 30 days. Sorted in reverse-chronological order.
74
+ # Returns Direct Messages sent by the authenticated user
75
+ #
76
+ # @api public
61
77
  # @see https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/list-events
62
- # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
78
+ # @note This method requires an access token with RWD permissions
63
79
  # @rate_limited Yes
64
80
  # @authentication Requires user context
65
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
66
- # @return [Array<Twitter::DirectMessage>] Direct messages sent by the authenticating user.
67
- # @param options [Hash] A customizable set of options.
68
- # @option options [Integer] :count Specifies the number of records (sent and received dms) to retrieve. Must be less than or equal to 50. Default is 20
69
- # @option options [String] :cursor Specifies the cursor position of results to retrieve.
81
+ # @example
82
+ # client.direct_messages_sent
83
+ # @param options [Hash] A customizable set of options
84
+ # @option options [Integer] :count Number of records to retrieve (max 50)
85
+ # @option options [String] :cursor Cursor position of results
86
+ # @raise [Twitter::Error::Unauthorized] Error raised when credentials are not valid
87
+ # @return [Array<Twitter::DirectMessage>] Direct messages sent
70
88
  def direct_messages_sent(options = {})
71
89
  limit = options.fetch(:count, 20)
72
- direct_messages_list(options).select { |dm| dm.sender_id == user_id }.first(limit)
90
+ direct_messages_list(options).select { |dm| dm.sender_id.eql?(user_id) }.first(limit)
73
91
  end
74
92
 
75
93
  # Returns a direct message
76
94
  #
95
+ # @api public
77
96
  # @see https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/get-event
78
- # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
97
+ # @note This method requires an access token with RWD permissions
79
98
  # @rate_limited Yes
80
99
  # @authentication Requires user context
81
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
82
- # @return [Twitter::DirectMessage] The requested message.
83
- # @param id [Integer] A direct message ID.
84
- # @param options [Hash] A customizable set of options.
100
+ # @example
101
+ # client.direct_message(123456789)
102
+ # @param id [Integer] A direct message ID
103
+ # @param options [Hash] A customizable set of options
104
+ # @raise [Twitter::Error::Unauthorized] Error raised when credentials are not valid
105
+ # @return [Twitter::DirectMessage] The requested message
85
106
  def direct_message(id, options = {})
86
107
  direct_message_event(id, options).direct_message
87
108
  end
88
109
 
89
110
  # Returns a direct message event
90
111
  #
112
+ # @api public
91
113
  # @see https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/get-event
92
- # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
114
+ # @note This method requires an access token with RWD permissions
93
115
  # @rate_limited Yes
94
116
  # @authentication Requires user context
95
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
96
- # @return [Twitter::DirectMessageEvent] The requested message.
97
- # @param id [Integer] A direct message ID.
98
- # @param options [Hash] A customizable set of options.
117
+ # @example
118
+ # client.direct_message_event(123456789)
119
+ # @param id [Integer] A direct message ID
120
+ # @param options [Hash] A customizable set of options
121
+ # @raise [Twitter::Error::Unauthorized] Error raised when credentials are not valid
122
+ # @return [Twitter::DirectMessageEvent] The requested message event
99
123
  def direct_message_event(id, options = {})
100
- options = options.dup
101
124
  options[:id] = id
102
- perform_get_with_object("/1.1/direct_messages/events/show.json", options, Twitter::DirectMessageEvent)
125
+ perform_get_with_object("/1.1/direct_messages/events/show.json", options, DirectMessageEvent)
103
126
  end
104
127
 
105
- # Returns direct messages specified in arguments, or, if no arguments are given, returns direct messages received by authenticating user
106
- # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
128
+ # Returns direct messages
129
+ #
130
+ # @api public
131
+ # @note This method requires an access token with RWD permissions
107
132
  # @rate_limited Yes
108
133
  # @authentication Requires user context
109
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
110
- # @return [Array<Twitter::DirectMessage>] The requested messages.
134
+ # @example
135
+ # client.direct_messages
111
136
  # @overload direct_messages(options = {})
112
137
  # Returns the 20 most recent direct messages sent to the authenticating user
113
-
114
138
  # @see https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/list-events
115
- # @param options [Hash] A customizable set of options.
116
- # @option options [Integer] :count Specifies the number of records (sent and received dms) to retrieve. Must be less than or equal to 50. Default is 20
117
- # @option options [String] :cursor Specifies the cursor position of results to retrieve.
139
+ # @param options [Hash] A customizable set of options
140
+ # @option options [Integer] :count Number of records to retrieve (max 50)
141
+ # @option options [String] :cursor Cursor position of results
118
142
  # @overload direct_messages(*ids)
119
143
  # Returns direct messages
120
- #
121
144
  # @see https://dev.twitter.com/rest/reference/get/direct_messages/show
122
- # @param ids [Enumerable<Integer>] A collection of direct message IDs.
145
+ # @param ids [Enumerable<Integer>] A collection of direct message IDs
123
146
  # @overload direct_messages(*ids, options)
124
147
  # Returns direct messages
125
- #
126
148
  # @see https://dev.twitter.com/rest/reference/get/direct_messages/show
127
- # @param ids [Enumerable<Integer>] A collection of direct message IDs.
128
- # @param options [Hash] A customizable set of options.
149
+ # @param ids [Enumerable<Integer>] A collection of direct message IDs
150
+ # @param options [Hash] A customizable set of options
151
+ # @raise [Twitter::Error::Unauthorized] Error raised when credentials are not valid
152
+ # @return [Array<Twitter::DirectMessage>] The requested messages
129
153
  def direct_messages(*args)
130
- arguments = Twitter::Arguments.new(args)
154
+ arguments = Arguments.new(args)
131
155
  if arguments.empty?
132
156
  direct_messages_received(arguments.options)
133
157
  else
@@ -139,81 +163,121 @@ module Twitter
139
163
 
140
164
  # Destroys direct messages
141
165
  #
166
+ # @api public
142
167
  # @see https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/delete-message-event
143
- # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
168
+ # @note This method requires an access token with RWD permissions
144
169
  # @rate_limited Yes
145
170
  # @authentication Requires user context
146
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
147
- # @return [nil] Response body from Twitter is nil if successful
171
+ # @example
172
+ # client.destroy_direct_message(123456789)
148
173
  # @overload destroy_direct_message(*ids)
149
- # @param ids [Enumerable<Integer>] A collection of direct message IDs.
174
+ # @param ids [Enumerable<Integer>] A collection of direct message IDs
175
+ # @raise [Twitter::Error::Unauthorized] Error raised when credentials are not valid
176
+ # @return [nil] Response body from Twitter is nil if successful
150
177
  def destroy_direct_message(*ids)
151
178
  pmap(ids) do |id|
152
- perform_requests(:delete, "/1.1/direct_messages/events/destroy.json", id:)
179
+ perform_requests(:delete, "/1.1/direct_messages/events/destroy.json", id:) # steep:ignore ArgumentTypeMismatch
153
180
  end
154
181
  nil
155
182
  end
156
183
 
157
- # Sends a new direct message to the specified user from the authenticating user
184
+ # Sends a new direct message to the specified user
158
185
  #
186
+ # @api public
159
187
  # @see https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/new-event
160
188
  # @rate_limited Yes
161
189
  # @authentication Requires user context
162
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
163
- # @return [Twitter::DirectMessage] The sent message.
190
+ # @example
191
+ # client.create_direct_message(123456789, "Hello!")
164
192
  # @param user_id [Integer] A Twitter user ID
165
- # @param text [String] The text of your direct message, up to 10,000 characters.
166
- # @param options [Hash] A customizable set of options.
193
+ # @param text [String] The text of the message (up to 10,000 characters)
194
+ # @param options [Hash] A customizable set of options
195
+ # @raise [Twitter::Error::Unauthorized] Error raised when credentials are not valid
196
+ # @return [Twitter::DirectMessage] The sent message
167
197
  def create_direct_message(user_id, text, options = {})
168
- event = perform_request_with_object(:json_post, "/1.1/direct_messages/events/new.json", format_json_options(user_id, text, options), Twitter::DirectMessageEvent)
198
+ event = perform_request_with_object(:json_post, "/1.1/direct_messages/events/new.json", format_json_options(user_id, text, options), DirectMessageEvent)
169
199
  event.direct_message
170
200
  end
171
- alias d create_direct_message
172
- alias m create_direct_message
173
- alias dm create_direct_message
174
201
 
175
- # Create a new direct message event to the specified user from the authenticating user
202
+ # @!method d
203
+ # @see #create_direct_message
204
+ # @api public
205
+ # @example
206
+ # client.d(123456789, "Hello!")
207
+ # @return [Twitter::DirectMessage]
208
+ alias_method :d, :create_direct_message
209
+
210
+ # @!method m
211
+ # @see #create_direct_message
212
+ # @api public
213
+ # @example
214
+ # client.m(123456789, "Hello!")
215
+ # @return [Twitter::DirectMessage]
216
+ alias_method :m, :create_direct_message
217
+
218
+ # @!method dm
219
+ # @see #create_direct_message
220
+ # @api public
221
+ # @example
222
+ # client.dm(123456789, "Hello!")
223
+ # @return [Twitter::DirectMessage]
224
+ alias_method :dm, :create_direct_message
225
+
226
+ # Creates a new direct message event to the specified user
176
227
  #
228
+ # @api public
177
229
  # @see https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/new-event
178
- # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
230
+ # @note This method requires an access token with RWD permissions
179
231
  # @rate_limited Yes
180
232
  # @authentication Requires user context
181
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
182
- # @return [Twitter::DirectMessageEvent] The created direct message event.
183
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
184
- # @param text [String] The text of your direct message, up to 10,000 characters.
185
- # @param options [Hash] A customizable set of options.
233
+ # @example
234
+ # client.create_direct_message_event(123456789, "Hello!")
235
+ # @overload create_direct_message_event(user, text, options = {})
236
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
237
+ # @param text [String] The text of the message (up to 10,000 characters).
238
+ # @param options [Hash] A customizable set of options.
239
+ # @raise [Twitter::Error::Unauthorized] Error raised when credentials are not valid
240
+ # @return [Twitter::DirectMessageEvent] The created direct message event
186
241
  def create_direct_message_event(*args)
187
- arguments = Twitter::Arguments.new(args)
188
- options = arguments.options.dup
189
- options[:event] = {type: "message_create", message_create: {target: {recipient_id: extract_id(arguments[0])}, message_data: {text: arguments[1]}}} if arguments.length >= 2
190
- response = Twitter::REST::Request.new(self, :json_post, "/1.1/direct_messages/events/new.json", options).perform
191
- Twitter::DirectMessageEvent.new(response[:event])
242
+ arguments = Arguments.new(args)
243
+ options = arguments.options
244
+ options[:event] = {type: "message_create", message_create: {target: {recipient_id: extract_id(arguments.fetch(0))}, message_data: {text: arguments.fetch(1)}}} if arguments.length.eql?(2)
245
+ response = Request.new(self, :json_post, "/1.1/direct_messages/events/new.json", options).perform
246
+ DirectMessageEvent.new(response)
192
247
  end
193
248
 
194
- # Create a new direct message event to the specified user from the authenticating user with media
249
+ # Creates a direct message event with media attachment
195
250
  #
251
+ # @api public
196
252
  # @see https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/new-event
197
253
  # @see https://developer.twitter.com/en/docs/direct-messages/message-attachments/guides/attaching-media
198
- # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
254
+ # @note This method requires an access token with RWD permissions
199
255
  # @rate_limited Yes
200
256
  # @authentication Requires user context
201
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
202
- # @return [Twitter::DirectMessageEvent] The created direct message event.
203
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
204
- # @param text [String] The text of your direct message, up to 10,000 characters.
205
- # @param media [File] A media file (PNG, JPEG, GIF or MP4).
206
- # @param options [Hash] A customizable set of options.
257
+ # @example
258
+ # client.create_direct_message_event_with_media(123, "Hi!", File.new("image.png"))
259
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object
260
+ # @param text [String] The text of the message (up to 10,000 characters)
261
+ # @param media [File] A media file (PNG, JPEG, GIF or MP4)
262
+ # @param options [Hash] A customizable set of options
263
+ # @raise [Twitter::Error::Unauthorized] Error raised when credentials are not valid
264
+ # @return [Twitter::DirectMessageEvent] The created direct message event
207
265
  def create_direct_message_event_with_media(user, text, media, options = {})
208
- media_id = upload(media, media_category_prefix: "dm")[:media_id]
209
- options = options.dup
266
+ media_id = upload(media, media_category_prefix: "dm").fetch(:media_id) # steep:ignore NoMethod
210
267
  options[:event] = {type: "message_create", message_create: {target: {recipient_id: extract_id(user)}, message_data: {text:, attachment: {type: "media", media: {id: media_id}}}}}
211
- response = Twitter::REST::Request.new(self, :json_post, "/1.1/direct_messages/events/new.json", options).perform
212
- Twitter::DirectMessageEvent.new(response[:event])
268
+ response = Request.new(self, :json_post, "/1.1/direct_messages/events/new.json", options).perform
269
+ DirectMessageEvent.new(response)
213
270
  end
214
271
 
215
- private
272
+ private
216
273
 
274
+ # Formats options for JSON direct message requests
275
+ #
276
+ # @api private
277
+ # @param user_id [Integer] The recipient user ID
278
+ # @param text [String] The message text
279
+ # @param options [Hash] Additional options
280
+ # @return [Hash]
217
281
  def format_json_options(user_id, text, options)
218
282
  {event: {type: "message_create", message_create: {target: {recipient_id: user_id}, message_data: {text:}.merge(options)}}}
219
283
  end