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.
- checksums.yaml +4 -4
- data/LICENSE.md +1 -1
- data/README.md +172 -10
- data/lib/twitter/arguments.rb +14 -1
- data/lib/twitter/base.rb +72 -11
- data/lib/twitter/basic_user.rb +7 -1
- data/lib/twitter/client.rb +94 -3
- data/lib/twitter/creatable.rb +11 -2
- data/lib/twitter/cursor.rb +58 -11
- data/lib/twitter/direct_message.rb +32 -4
- data/lib/twitter/direct_message_event.rb +34 -10
- data/lib/twitter/direct_messages/welcome_message.rb +22 -1
- data/lib/twitter/direct_messages/welcome_message_rule.rb +7 -0
- data/lib/twitter/direct_messages/welcome_message_rule_wrapper.rb +26 -3
- data/lib/twitter/direct_messages/welcome_message_wrapper.rb +36 -11
- data/lib/twitter/entities.rb +84 -8
- data/lib/twitter/entity/hashtag.rb +7 -1
- data/lib/twitter/entity/symbol.rb +7 -1
- data/lib/twitter/entity/uri.rb +2 -1
- data/lib/twitter/entity/user_mention.rb +20 -1
- data/lib/twitter/entity.rb +7 -1
- data/lib/twitter/enumerable.rb +20 -3
- data/lib/twitter/error.rb +137 -61
- data/lib/twitter/factory.rb +9 -5
- data/lib/twitter/geo/point.rb +37 -5
- data/lib/twitter/geo/polygon.rb +1 -0
- data/lib/twitter/geo.rb +16 -2
- data/lib/twitter/geo_factory.rb +7 -3
- data/lib/twitter/geo_results.rb +39 -8
- data/lib/twitter/headers.rb +44 -7
- data/lib/twitter/identity.rb +13 -3
- data/lib/twitter/language.rb +21 -1
- data/lib/twitter/list.rb +101 -11
- data/lib/twitter/media/animated_gif.rb +1 -0
- data/lib/twitter/media/photo.rb +19 -3
- data/lib/twitter/media/video.rb +21 -3
- data/lib/twitter/media/video_info.rb +15 -1
- data/lib/twitter/media_factory.rb +7 -3
- data/lib/twitter/metadata.rb +14 -1
- data/lib/twitter/null_object.rb +16 -14
- data/lib/twitter/oembed.rb +56 -2
- data/lib/twitter/place.rb +74 -6
- data/lib/twitter/premium_search_results.rb +87 -18
- data/lib/twitter/profile.rb +100 -44
- data/lib/twitter/profile_banner.rb +9 -4
- data/lib/twitter/rate_limit.rb +32 -3
- data/lib/twitter/relationship.rb +8 -5
- data/lib/twitter/rest/account_activity.rb +55 -26
- data/lib/twitter/rest/api.rb +2 -0
- data/lib/twitter/rest/client.rb +18 -0
- data/lib/twitter/rest/direct_messages/welcome_messages.rb +89 -18
- data/lib/twitter/rest/direct_messages.rb +160 -96
- data/lib/twitter/rest/favorites.rb +58 -22
- data/lib/twitter/rest/form_encoder.rb +57 -17
- data/lib/twitter/rest/friends_and_followers.rb +101 -35
- data/lib/twitter/rest/help.rb +13 -3
- data/lib/twitter/rest/lists.rb +136 -47
- data/lib/twitter/rest/oauth.rb +21 -15
- data/lib/twitter/rest/places_and_geo.rb +44 -28
- data/lib/twitter/rest/premium_search.rb +17 -12
- data/lib/twitter/rest/request.rb +173 -55
- data/lib/twitter/rest/saved_searches.rb +22 -7
- data/lib/twitter/rest/search.rb +20 -16
- data/lib/twitter/rest/spam_reporting.rb +5 -1
- data/lib/twitter/rest/suggested_users.rb +15 -6
- data/lib/twitter/rest/timelines.rb +92 -52
- data/lib/twitter/rest/trends.rb +32 -13
- data/lib/twitter/rest/tweets.rb +147 -89
- data/lib/twitter/rest/undocumented.rb +10 -1
- data/lib/twitter/rest/upload_utils.rb +45 -29
- data/lib/twitter/rest/users.rb +151 -72
- data/lib/twitter/rest/utils.rb +135 -39
- data/lib/twitter/saved_search.rb +23 -2
- data/lib/twitter/search_results.rb +66 -18
- data/lib/twitter/settings.rb +37 -11
- data/lib/twitter/size.rb +37 -3
- data/lib/twitter/source_user.rb +4 -3
- data/lib/twitter/streaming/client.rb +61 -9
- data/lib/twitter/streaming/connection.rb +54 -6
- data/lib/twitter/streaming/deleted_tweet.rb +8 -0
- data/lib/twitter/streaming/event.rb +43 -1
- data/lib/twitter/streaming/friend_list.rb +1 -0
- data/lib/twitter/streaming/message_parser.rb +20 -10
- data/lib/twitter/streaming/response.rb +31 -5
- data/lib/twitter/streaming/stall_warning.rb +23 -0
- data/lib/twitter/suggestion.rb +25 -1
- data/lib/twitter/target_user.rb +2 -1
- data/lib/twitter/trend.rb +29 -1
- data/lib/twitter/trend_results.rb +50 -7
- data/lib/twitter/tweet.rb +180 -21
- data/lib/twitter/user.rb +289 -53
- data/lib/twitter/utils.rb +12 -13
- data/lib/twitter/variant.rb +12 -1
- data/lib/twitter/version.rb +66 -29
- data/lib/twitter.rb +6 -1
- metadata +23 -57
- data/.yardopts +0 -16
- data/CHANGELOG.md +0 -1040
- data/CONTRIBUTING.md +0 -49
- 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
|
-
#
|
|
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
|
|
25
|
-
welcome_message_wrapper = perform_request_with_object(:json_post, "/1.1/direct_messages/welcome_messages/new.json",
|
|
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",
|
|
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
|
-
|
|
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
|
-
#
|
|
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",
|
|
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
|
-
|
|
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
|
|
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
|
|
21
|
+
# @note This method requires an access token with RWD permissions
|
|
19
22
|
# @rate_limited Yes
|
|
20
23
|
# @authentication Requires user context
|
|
21
|
-
# @
|
|
22
|
-
#
|
|
23
|
-
# @param options [Hash] A customizable set of options
|
|
24
|
-
# @option options [Integer] :count
|
|
25
|
-
# @option options [String] :cursor
|
|
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
|
-
|
|
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
|
|
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
|
|
41
|
+
# @note This method requires an access token with RWD permissions
|
|
34
42
|
# @rate_limited Yes
|
|
35
43
|
# @authentication Requires user context
|
|
36
|
-
# @
|
|
37
|
-
#
|
|
38
|
-
# @param options [Hash] A customizable set of options
|
|
39
|
-
# @option options [Integer] :count
|
|
40
|
-
# @option options [String] :cursor
|
|
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
|
|
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
|
|
59
|
+
# @note This method requires an access token with RWD permissions
|
|
48
60
|
# @rate_limited Yes
|
|
49
61
|
# @authentication Requires user context
|
|
50
|
-
# @
|
|
51
|
-
#
|
|
52
|
-
# @param options [Hash] A customizable set of options
|
|
53
|
-
# @option options [Integer] :count
|
|
54
|
-
# @option options [String] :cursor
|
|
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
|
|
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
|
|
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
|
|
78
|
+
# @note This method requires an access token with RWD permissions
|
|
63
79
|
# @rate_limited Yes
|
|
64
80
|
# @authentication Requires user context
|
|
65
|
-
# @
|
|
66
|
-
#
|
|
67
|
-
# @param options [Hash] A customizable set of options
|
|
68
|
-
# @option options [Integer] :count
|
|
69
|
-
# @option options [String] :cursor
|
|
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
|
|
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
|
|
97
|
+
# @note This method requires an access token with RWD permissions
|
|
79
98
|
# @rate_limited Yes
|
|
80
99
|
# @authentication Requires user context
|
|
81
|
-
# @
|
|
82
|
-
#
|
|
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
|
|
114
|
+
# @note This method requires an access token with RWD permissions
|
|
93
115
|
# @rate_limited Yes
|
|
94
116
|
# @authentication Requires user context
|
|
95
|
-
# @
|
|
96
|
-
#
|
|
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,
|
|
125
|
+
perform_get_with_object("/1.1/direct_messages/events/show.json", options, DirectMessageEvent)
|
|
103
126
|
end
|
|
104
127
|
|
|
105
|
-
# Returns direct messages
|
|
106
|
-
#
|
|
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
|
-
# @
|
|
110
|
-
#
|
|
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
|
|
117
|
-
# @option options [String] :cursor
|
|
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 =
|
|
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
|
|
168
|
+
# @note This method requires an access token with RWD permissions
|
|
144
169
|
# @rate_limited Yes
|
|
145
170
|
# @authentication Requires user context
|
|
146
|
-
# @
|
|
147
|
-
#
|
|
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
|
|
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
|
-
# @
|
|
163
|
-
#
|
|
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
|
|
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),
|
|
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
|
-
#
|
|
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
|
|
230
|
+
# @note This method requires an access token with RWD permissions
|
|
179
231
|
# @rate_limited Yes
|
|
180
232
|
# @authentication Requires user context
|
|
181
|
-
# @
|
|
182
|
-
#
|
|
183
|
-
# @
|
|
184
|
-
#
|
|
185
|
-
#
|
|
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 =
|
|
188
|
-
options = arguments.options
|
|
189
|
-
options[:event] = {type: "message_create", message_create: {target: {recipient_id: extract_id(arguments
|
|
190
|
-
response =
|
|
191
|
-
|
|
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
|
-
#
|
|
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
|
|
254
|
+
# @note This method requires an access token with RWD permissions
|
|
199
255
|
# @rate_limited Yes
|
|
200
256
|
# @authentication Requires user context
|
|
201
|
-
# @
|
|
202
|
-
#
|
|
203
|
-
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object
|
|
204
|
-
# @param text [String] The text of
|
|
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")
|
|
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 =
|
|
212
|
-
|
|
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
|
-
|
|
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
|