line-bot-api 1.11.0 → 1.15.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.
- checksums.yaml +4 -4
- data/README.md +6 -1
- data/lib/line/bot.rb +0 -1
- data/lib/line/bot/api.rb +8 -0
- data/lib/line/bot/api/version.rb +1 -1
- data/lib/line/bot/client.rb +311 -187
- data/lib/line/bot/event/account_link.rb +5 -0
- data/lib/line/bot/event/beacon.rb +6 -0
- data/lib/line/bot/event/follow.rb +4 -0
- data/lib/line/bot/event/join.rb +3 -0
- data/lib/line/bot/event/leave.rb +5 -0
- data/lib/line/bot/event/member_joined.rb +3 -0
- data/lib/line/bot/event/member_left.rb +5 -0
- data/lib/line/bot/event/message.rb +5 -2
- data/lib/line/bot/event/postback.rb +3 -0
- data/lib/line/bot/event/things.rb +8 -2
- data/lib/line/bot/event/unfollow.rb +5 -0
- data/lib/line/bot/httpclient.rb +1 -2
- data/line-bot-api.gemspec +2 -2
- metadata +8 -8
- data/lib/line/bot/request.rb +0 -117
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1352650b47d2d00a2d08061982b02c3489594f710c064bc06aebea8fc1bc4da
|
4
|
+
data.tar.gz: 3f74b50c38d6765d66800cfcf4558146bbb0dbce9225b4ecf5c4a81a686bd6d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3de07c49edb984b2d362369c2e900b2c9d4dfd5b6399e9367cf6e14d46b4b343f07ef775aa785cc71d57db4af26eb22b27fcb0fe43c1ad160384011a9cd12c37
|
7
|
+
data.tar.gz: 31f1423914851cfbb501d24bb9f2ae6d6112880f1de5106649dc5eb1a6591a178afbc88a7c6a2cb5639594e2e954bad1a798fbb3fb957144e5fa6272a18d912a
|
data/README.md
CHANGED
@@ -13,6 +13,10 @@ See the official API documentation for more information
|
|
13
13
|
- English: https://developers.line.biz/en/docs/messaging-api/overview/
|
14
14
|
- Japanese: https://developers.line.biz/ja/docs/messaging-api/overview/
|
15
15
|
|
16
|
+
Also, generated documentation by YARD is available.
|
17
|
+
|
18
|
+
- https://rubydoc.info/gems/line-bot-api
|
19
|
+
|
16
20
|
## Installation
|
17
21
|
|
18
22
|
Add this line to your application's Gemfile:
|
@@ -77,6 +81,7 @@ post '/callback' do
|
|
77
81
|
end
|
78
82
|
end
|
79
83
|
|
84
|
+
# Don't forget to return a successful response
|
80
85
|
"OK"
|
81
86
|
end
|
82
87
|
```
|
@@ -96,7 +101,7 @@ This project respects semantic versioning.
|
|
96
101
|
See https://semver.org/
|
97
102
|
|
98
103
|
## Contributing
|
99
|
-
Please check [CONTRIBUTING](
|
104
|
+
Please check [CONTRIBUTING](CONTRIBUTING.md) before making a contribution.
|
100
105
|
|
101
106
|
## License
|
102
107
|
```
|
data/lib/line/bot.rb
CHANGED
data/lib/line/bot/api.rb
CHANGED
@@ -12,10 +12,18 @@
|
|
12
12
|
# License for the specific language governing permissions and limitations
|
13
13
|
# under the License.
|
14
14
|
|
15
|
+
require 'line/bot/api/version'
|
16
|
+
|
15
17
|
module Line
|
16
18
|
module Bot
|
17
19
|
module API
|
18
20
|
DEFAULT_ENDPOINT = "https://api.line.me/v2"
|
21
|
+
DEFAULT_BLOB_ENDPOINT = "https://api-data.line.me/v2"
|
22
|
+
|
23
|
+
DEFAULT_HEADERS = {
|
24
|
+
'Content-Type' => 'application/json; charset=UTF-8',
|
25
|
+
'User-Agent' => "LINE-BotSDK-Ruby/#{VERSION}"
|
26
|
+
}.freeze
|
19
27
|
end
|
20
28
|
end
|
21
29
|
end
|
data/lib/line/bot/api/version.rb
CHANGED
data/lib/line/bot/client.rb
CHANGED
@@ -12,7 +12,6 @@
|
|
12
12
|
# License for the specific language governing permissions and limitations
|
13
13
|
# under the License.
|
14
14
|
|
15
|
-
require 'line/bot/request'
|
16
15
|
require 'base64'
|
17
16
|
require 'net/http'
|
18
17
|
require 'openssl'
|
@@ -20,9 +19,16 @@ require 'uri'
|
|
20
19
|
|
21
20
|
module Line
|
22
21
|
module Bot
|
22
|
+
# API Client of LINE Bot SDK Ruby
|
23
|
+
#
|
24
|
+
# @client ||= Line::Bot::Client.new do |config|
|
25
|
+
# config.channel_id = ENV["LINE_CHANNEL_ID"]
|
26
|
+
# config.channel_secret = ENV["LINE_CHANNEL_SECRET"]
|
27
|
+
# config.channel_token = ENV["LINE_CHANNEL_TOKEN"]
|
28
|
+
# end
|
23
29
|
class Client
|
24
30
|
# @return [String]
|
25
|
-
attr_accessor :channel_token, :channel_id, :channel_secret, :endpoint
|
31
|
+
attr_accessor :channel_token, :channel_id, :channel_secret, :endpoint, :blob_endpoint
|
26
32
|
|
27
33
|
# @return [Object]
|
28
34
|
attr_accessor :httpclient
|
@@ -30,10 +36,9 @@ module Line
|
|
30
36
|
# @return [Hash]
|
31
37
|
attr_accessor :http_options
|
32
38
|
|
33
|
-
# Initialize a new
|
39
|
+
# Initialize a new client.
|
34
40
|
#
|
35
41
|
# @param options [Hash]
|
36
|
-
#
|
37
42
|
# @return [Line::Bot::Client]
|
38
43
|
def initialize(options = {})
|
39
44
|
options.each do |key, value|
|
@@ -43,11 +48,22 @@ module Line
|
|
43
48
|
end
|
44
49
|
|
45
50
|
def httpclient
|
46
|
-
@httpclient ||=
|
51
|
+
@httpclient ||= HTTPClient.new(http_options)
|
47
52
|
end
|
48
53
|
|
49
54
|
def endpoint
|
50
|
-
@endpoint ||=
|
55
|
+
@endpoint ||= API::DEFAULT_ENDPOINT
|
56
|
+
end
|
57
|
+
|
58
|
+
def blob_endpoint
|
59
|
+
return @blob_endpoint if @blob_endpoint
|
60
|
+
|
61
|
+
@blob_endpoint = if endpoint == API::DEFAULT_ENDPOINT
|
62
|
+
API::DEFAULT_BLOB_ENDPOINT
|
63
|
+
else
|
64
|
+
# for backward compatible
|
65
|
+
endpoint
|
66
|
+
end
|
51
67
|
end
|
52
68
|
|
53
69
|
# @return [Hash]
|
@@ -66,197 +82,192 @@ module Line
|
|
66
82
|
channel_id_required
|
67
83
|
channel_secret_required
|
68
84
|
|
85
|
+
endpoint_path = '/oauth/accessToken'
|
69
86
|
payload = URI.encode_www_form(
|
70
87
|
grant_type: grant_type,
|
71
88
|
client_id: channel_id,
|
72
89
|
client_secret: channel_secret
|
73
90
|
)
|
74
|
-
|
75
|
-
|
76
|
-
config.httpclient = httpclient
|
77
|
-
config.endpoint = endpoint
|
78
|
-
config.endpoint_path = '/oauth/accessToken'
|
79
|
-
config.content_type = 'application/x-www-form-urlencoded'
|
80
|
-
config.payload = payload
|
81
|
-
end
|
82
|
-
|
83
|
-
request.post
|
91
|
+
headers = { 'Content-Type' => 'application/x-www-form-urlencoded' }
|
92
|
+
post(endpoint, endpoint_path, payload, headers)
|
84
93
|
end
|
85
94
|
|
86
95
|
# Revoke channel access token
|
87
96
|
#
|
88
97
|
# @return [Net::HTTPResponse]
|
89
98
|
def revoke_channel_token(access_token)
|
99
|
+
endpoint_path = '/oauth/revoke'
|
90
100
|
payload = URI.encode_www_form(access_token: access_token)
|
91
|
-
|
92
|
-
|
93
|
-
config.httpclient = httpclient
|
94
|
-
config.endpoint = endpoint
|
95
|
-
config.endpoint_path = '/oauth/revoke'
|
96
|
-
config.content_type = 'application/x-www-form-urlencoded'
|
97
|
-
config.payload = payload
|
98
|
-
end
|
99
|
-
|
100
|
-
request.post
|
101
|
+
headers = { 'Content-Type' => 'application/x-www-form-urlencoded' }
|
102
|
+
post(endpoint, endpoint_path, payload, headers)
|
101
103
|
end
|
102
104
|
|
103
|
-
# Push messages to
|
104
|
-
#
|
105
|
-
# @param user_id [String] User's identifiers
|
106
|
-
# @param messages [Hash or Array]
|
105
|
+
# Push messages to a user using user_id.
|
107
106
|
#
|
107
|
+
# @param user_id [String] User Id
|
108
|
+
# @param messages [Hash or Array] Message Objects
|
109
|
+
# @param headers [Hash] HTTP Headers
|
108
110
|
# @return [Net::HTTPResponse]
|
109
|
-
def push_message(user_id, messages)
|
111
|
+
def push_message(user_id, messages, headers: {})
|
110
112
|
channel_token_required
|
111
113
|
|
112
114
|
messages = [messages] if messages.is_a?(Hash)
|
113
115
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
config.endpoint_path = '/bot/message/push'
|
118
|
-
config.credentials = credentials
|
119
|
-
config.to = user_id
|
120
|
-
config.messages = messages
|
121
|
-
end
|
122
|
-
|
123
|
-
request.post
|
116
|
+
endpoint_path = '/bot/message/push'
|
117
|
+
payload = { to: user_id, messages: messages }.to_json
|
118
|
+
post(endpoint, endpoint_path, payload, credentials.merge(headers))
|
124
119
|
end
|
125
120
|
|
126
|
-
# Reply messages to
|
121
|
+
# Reply messages to a user using replyToken.
|
127
122
|
#
|
128
|
-
# @
|
129
|
-
#
|
123
|
+
# @example Send a balloon to a user.
|
124
|
+
# message = {
|
125
|
+
# type: 'text',
|
126
|
+
# text: 'Hello, World!'
|
127
|
+
# }
|
128
|
+
# client.reply_message(event['replyToken'], message)
|
130
129
|
#
|
130
|
+
# @example Send multiple balloons to a user.
|
131
|
+
#
|
132
|
+
# messages = [
|
133
|
+
# {type: 'text', text: 'Message1'},
|
134
|
+
# {type: 'text', text: 'Message2'}
|
135
|
+
# ]
|
136
|
+
# client.reply_message(event['replyToken'], messages)
|
137
|
+
#
|
138
|
+
# @param token [String] Reply Token
|
139
|
+
# @param messages [Hash or Array] Message Objects
|
131
140
|
# @return [Net::HTTPResponse]
|
132
141
|
def reply_message(token, messages)
|
133
142
|
channel_token_required
|
134
143
|
|
135
144
|
messages = [messages] if messages.is_a?(Hash)
|
136
145
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
config.endpoint_path = '/bot/message/reply'
|
141
|
-
config.credentials = credentials
|
142
|
-
config.reply_token = token
|
143
|
-
config.messages = messages
|
144
|
-
end
|
145
|
-
|
146
|
-
request.post
|
146
|
+
endpoint_path = '/bot/message/reply'
|
147
|
+
payload = { replyToken: token, messages: messages }.to_json
|
148
|
+
post(endpoint, endpoint_path, payload, credentials)
|
147
149
|
end
|
148
150
|
|
149
|
-
#
|
150
|
-
#
|
151
|
-
# @param to [Array or String]
|
152
|
-
# @param messages [Hash or Array]
|
151
|
+
# Send messages to multiple users using userIds.
|
153
152
|
#
|
153
|
+
# @param to [Array or String] Array of userIds
|
154
|
+
# @param messages [Hash or Array] Message Objects
|
155
|
+
# @param headers [Hash] HTTP Headers
|
154
156
|
# @return [Net::HTTPResponse]
|
155
|
-
def multicast(to, messages)
|
157
|
+
def multicast(to, messages, headers: {})
|
156
158
|
channel_token_required
|
157
159
|
|
158
160
|
to = [to] if to.is_a?(String)
|
159
161
|
messages = [messages] if messages.is_a?(Hash)
|
160
162
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
163
|
+
endpoint_path = '/bot/message/multicast'
|
164
|
+
payload = { to: to, messages: messages }.to_json
|
165
|
+
post(endpoint, endpoint_path, payload, credentials.merge(headers))
|
166
|
+
end
|
167
|
+
|
168
|
+
# Send messages to all friends.
|
169
|
+
#
|
170
|
+
# @param messages [Hash or Array] Message Objects
|
171
|
+
# @param headers [Hash] HTTP Headers
|
172
|
+
#
|
173
|
+
# @return [Net::HTTPResponse]
|
174
|
+
def broadcast(messages, headers: {})
|
175
|
+
channel_token_required
|
176
|
+
|
177
|
+
messages = [messages] if messages.is_a?(Hash)
|
169
178
|
|
170
|
-
|
179
|
+
endpoint_path = '/bot/message/broadcast'
|
180
|
+
payload = { messages: messages }.to_json
|
181
|
+
post(endpoint, endpoint_path, payload, credentials.merge(headers))
|
171
182
|
end
|
172
183
|
|
173
|
-
#
|
184
|
+
# Narrowcast messages to users
|
185
|
+
#
|
186
|
+
# API Documentation is here.
|
187
|
+
# https://developers.line.biz/en/reference/messaging-api/#send-narrowcast-message
|
174
188
|
#
|
175
189
|
# @param messages [Hash or Array]
|
190
|
+
# @param recipient [Hash]
|
191
|
+
# @param filter [Hash]
|
192
|
+
# @param limit [Hash]
|
193
|
+
# @param headers [Hash] HTTP Headers
|
176
194
|
#
|
177
195
|
# @return [Net::HTTPResponse]
|
178
|
-
def
|
196
|
+
def narrowcast(messages, recipient: nil, filter: nil, limit: nil, headers: {})
|
179
197
|
channel_token_required
|
180
198
|
|
181
199
|
messages = [messages] if messages.is_a?(Hash)
|
182
200
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
request.post
|
201
|
+
endpoint_path = '/bot/message/narrowcast'
|
202
|
+
payload = {
|
203
|
+
messages: messages,
|
204
|
+
recipient: recipient,
|
205
|
+
filter: filter,
|
206
|
+
limit: limit
|
207
|
+
}.to_json
|
208
|
+
post(endpoint, endpoint_path, payload, credentials.merge(headers))
|
192
209
|
end
|
193
210
|
|
194
211
|
def leave_group(group_id)
|
195
212
|
channel_token_required
|
196
213
|
|
197
|
-
|
198
|
-
|
199
|
-
config.endpoint = endpoint
|
200
|
-
config.endpoint_path = "/bot/group/#{group_id}/leave"
|
201
|
-
config.credentials = credentials
|
202
|
-
end
|
203
|
-
|
204
|
-
request.post
|
214
|
+
endpoint_path = "/bot/group/#{group_id}/leave"
|
215
|
+
post(endpoint, endpoint_path, nil, credentials)
|
205
216
|
end
|
206
217
|
|
207
218
|
def leave_room(room_id)
|
208
219
|
channel_token_required
|
209
220
|
|
210
|
-
|
211
|
-
|
212
|
-
config.endpoint = endpoint
|
213
|
-
config.endpoint_path = "/bot/room/#{room_id}/leave"
|
214
|
-
config.credentials = credentials
|
215
|
-
end
|
216
|
-
|
217
|
-
request.post
|
221
|
+
endpoint_path = "/bot/room/#{room_id}/leave"
|
222
|
+
post(endpoint, endpoint_path, nil, credentials)
|
218
223
|
end
|
219
224
|
|
220
225
|
# Get message content.
|
221
226
|
#
|
222
227
|
# @param identifier [String] Message's identifier
|
223
|
-
#
|
224
228
|
# @return [Net::HTTPResponse]
|
225
229
|
def get_message_content(identifier)
|
226
|
-
|
227
|
-
|
230
|
+
channel_token_required
|
231
|
+
|
232
|
+
endpoint_path = "/bot/message/#{identifier}/content"
|
233
|
+
get(blob_endpoint, endpoint_path, credentials)
|
228
234
|
end
|
229
235
|
|
230
236
|
# Get an user's profile.
|
231
237
|
#
|
232
|
-
# @param user_id [String] User
|
233
|
-
#
|
238
|
+
# @param user_id [String] User Id user_id
|
234
239
|
# @return [Net::HTTPResponse]
|
235
240
|
def get_profile(user_id)
|
236
|
-
|
237
|
-
|
241
|
+
channel_token_required
|
242
|
+
|
243
|
+
endpoint_path = "/bot/profile/#{user_id}"
|
244
|
+
get(endpoint, endpoint_path, credentials)
|
238
245
|
end
|
239
246
|
|
240
247
|
# Get an user's profile of a group.
|
241
248
|
#
|
242
249
|
# @param group_id [String] Group's identifier
|
243
|
-
# @param user_id [String] User
|
250
|
+
# @param user_id [String] User Id user_id
|
244
251
|
#
|
245
252
|
# @return [Net::HTTPResponse]
|
246
253
|
def get_group_member_profile(group_id, user_id)
|
254
|
+
channel_token_required
|
255
|
+
|
247
256
|
endpoint_path = "/bot/group/#{group_id}/member/#{user_id}"
|
248
|
-
get(endpoint_path)
|
257
|
+
get(endpoint, endpoint_path, credentials)
|
249
258
|
end
|
250
259
|
|
251
260
|
# Get an user's profile of a room.
|
252
261
|
#
|
253
262
|
# @param room_id [String] Room's identifier
|
254
|
-
# @param user_id [String] User
|
263
|
+
# @param user_id [String] User Id user_id
|
255
264
|
#
|
256
265
|
# @return [Net::HTTPResponse]
|
257
266
|
def get_room_member_profile(room_id, user_id)
|
267
|
+
channel_token_required
|
268
|
+
|
258
269
|
endpoint_path = "/bot/room/#{room_id}/member/#{user_id}"
|
259
|
-
get(endpoint_path)
|
270
|
+
get(endpoint, endpoint_path, credentials)
|
260
271
|
end
|
261
272
|
|
262
273
|
# Get user IDs of a group
|
@@ -267,30 +278,72 @@ module Line
|
|
267
278
|
#
|
268
279
|
# @return [Net::HTTPResponse]
|
269
280
|
def get_group_member_ids(group_id, continuation_token = nil)
|
270
|
-
|
281
|
+
channel_token_required
|
282
|
+
|
283
|
+
endpoint_path = "/bot/group/#{group_id}/members/ids"
|
271
284
|
endpoint_path += "?start=#{continuation_token}" if continuation_token
|
272
|
-
get(endpoint_path)
|
285
|
+
get(endpoint, endpoint_path, credentials)
|
273
286
|
end
|
274
287
|
|
275
288
|
# Get user IDs of a room
|
276
289
|
#
|
277
|
-
# @param
|
290
|
+
# @param room_id [String] Room's identifier
|
278
291
|
# @param continuation_token [String] Identifier to return next page
|
279
292
|
# (next property to be included in the response)
|
280
293
|
#
|
281
294
|
# @return [Net::HTTPResponse]
|
282
295
|
def get_room_member_ids(room_id, continuation_token = nil)
|
283
|
-
|
296
|
+
channel_token_required
|
297
|
+
|
298
|
+
endpoint_path = "/bot/room/#{room_id}/members/ids"
|
284
299
|
endpoint_path += "?start=#{continuation_token}" if continuation_token
|
285
|
-
get(endpoint_path)
|
300
|
+
get(endpoint, endpoint_path, credentials)
|
301
|
+
end
|
302
|
+
|
303
|
+
# Gets the group ID, group name, and group icon URL of a group where the LINE Official Account is a member.
|
304
|
+
#
|
305
|
+
# @param group_id [String] Group's identifier
|
306
|
+
#
|
307
|
+
# @return [Net::HTTPResponse]
|
308
|
+
def get_group_summary(group_id)
|
309
|
+
channel_token_required
|
310
|
+
|
311
|
+
endpoint_path = "/bot/group/#{group_id}/summary"
|
312
|
+
get(endpoint, endpoint_path, credentials)
|
313
|
+
end
|
314
|
+
|
315
|
+
# Gets the user IDs of the members of a group that the bot is in.
|
316
|
+
#
|
317
|
+
# @param group_id [String] Group's identifier
|
318
|
+
#
|
319
|
+
# @return [Net::HTTPResponse]
|
320
|
+
def get_group_members_count(group_id)
|
321
|
+
channel_token_required
|
322
|
+
|
323
|
+
endpoint_path = "/bot/group/#{group_id}/members/count"
|
324
|
+
get(endpoint, endpoint_path, credentials)
|
325
|
+
end
|
326
|
+
|
327
|
+
# Gets the count of members in a room.
|
328
|
+
#
|
329
|
+
# @param room_id [String] Room's identifier
|
330
|
+
#
|
331
|
+
# @return [Net::HTTPResponse]
|
332
|
+
def get_room_members_count(room_id)
|
333
|
+
channel_token_required
|
334
|
+
|
335
|
+
endpoint_path = "/bot/room/#{room_id}/members/count"
|
336
|
+
get(endpoint, endpoint_path, credentials)
|
286
337
|
end
|
287
338
|
|
288
339
|
# Get a list of all uploaded rich menus
|
289
340
|
#
|
290
341
|
# @return [Net::HTTPResponse]
|
291
342
|
def get_rich_menus
|
343
|
+
channel_token_required
|
344
|
+
|
292
345
|
endpoint_path = '/bot/richmenu/list'
|
293
|
-
get(endpoint_path)
|
346
|
+
get(endpoint, endpoint_path, credentials)
|
294
347
|
end
|
295
348
|
|
296
349
|
# Get a rich menu via a rich menu ID
|
@@ -299,8 +352,10 @@ module Line
|
|
299
352
|
#
|
300
353
|
# @return [Net::HTTPResponse]
|
301
354
|
def get_rich_menu(rich_menu_id)
|
355
|
+
channel_token_required
|
356
|
+
|
302
357
|
endpoint_path = "/bot/richmenu/#{rich_menu_id}"
|
303
|
-
get(endpoint_path)
|
358
|
+
get(endpoint, endpoint_path, credentials)
|
304
359
|
end
|
305
360
|
|
306
361
|
# Gets the number of messages sent with the /bot/message/reply endpoint.
|
@@ -309,8 +364,10 @@ module Line
|
|
309
364
|
#
|
310
365
|
# @return [Net::HTTPResponse]
|
311
366
|
def get_message_delivery_reply(date)
|
367
|
+
channel_token_required
|
368
|
+
|
312
369
|
endpoint_path = "/bot/message/delivery/reply?date=#{date}"
|
313
|
-
get(endpoint_path)
|
370
|
+
get(endpoint, endpoint_path, credentials)
|
314
371
|
end
|
315
372
|
|
316
373
|
# Gets the number of messages sent with the /bot/message/push endpoint.
|
@@ -319,8 +376,10 @@ module Line
|
|
319
376
|
#
|
320
377
|
# @return [Net::HTTPResponse]
|
321
378
|
def get_message_delivery_push(date)
|
379
|
+
channel_token_required
|
380
|
+
|
322
381
|
endpoint_path = "/bot/message/delivery/push?date=#{date}"
|
323
|
-
get(endpoint_path)
|
382
|
+
get(endpoint, endpoint_path, credentials)
|
324
383
|
end
|
325
384
|
|
326
385
|
# Gets the number of messages sent with the /bot/message/multicast endpoint.
|
@@ -329,8 +388,10 @@ module Line
|
|
329
388
|
#
|
330
389
|
# @return [Net::HTTPResponse]
|
331
390
|
def get_message_delivery_multicast(date)
|
391
|
+
channel_token_required
|
392
|
+
|
332
393
|
endpoint_path = "/bot/message/delivery/multicast?date=#{date}"
|
333
|
-
get(endpoint_path)
|
394
|
+
get(endpoint, endpoint_path, credentials)
|
334
395
|
end
|
335
396
|
|
336
397
|
# Gets the number of messages sent with the /bot/message/multicast endpoint.
|
@@ -339,8 +400,10 @@ module Line
|
|
339
400
|
#
|
340
401
|
# @return [Net::HTTPResponse]
|
341
402
|
def get_message_delivery_broadcast(date)
|
403
|
+
channel_token_required
|
404
|
+
|
342
405
|
endpoint_path = "/bot/message/delivery/broadcast?date=#{date}"
|
343
|
-
get(endpoint_path)
|
406
|
+
get(endpoint, endpoint_path, credentials)
|
344
407
|
end
|
345
408
|
|
346
409
|
# Create a rich menu
|
@@ -349,15 +412,10 @@ module Line
|
|
349
412
|
#
|
350
413
|
# @return [Net::HTTPResponse]
|
351
414
|
def create_rich_menu(rich_menu)
|
352
|
-
|
353
|
-
config.httpclient = httpclient
|
354
|
-
config.endpoint = endpoint
|
355
|
-
config.endpoint_path = '/bot/richmenu'
|
356
|
-
config.credentials = credentials
|
357
|
-
config.payload = rich_menu.to_json
|
358
|
-
end
|
415
|
+
channel_token_required
|
359
416
|
|
360
|
-
|
417
|
+
endpoint_path = '/bot/richmenu'
|
418
|
+
post(endpoint, endpoint_path, rich_menu.to_json, credentials)
|
361
419
|
end
|
362
420
|
|
363
421
|
# Delete a rich menu
|
@@ -366,8 +424,10 @@ module Line
|
|
366
424
|
#
|
367
425
|
# @return [Net::HTTPResponse]
|
368
426
|
def delete_rich_menu(rich_menu_id)
|
427
|
+
channel_token_required
|
428
|
+
|
369
429
|
endpoint_path = "/bot/richmenu/#{rich_menu_id}"
|
370
|
-
delete(endpoint_path)
|
430
|
+
delete(endpoint, endpoint_path, credentials)
|
371
431
|
end
|
372
432
|
|
373
433
|
# Get the ID of the rich menu linked to a user
|
@@ -376,16 +436,20 @@ module Line
|
|
376
436
|
#
|
377
437
|
# @return [Net::HTTPResponse]
|
378
438
|
def get_user_rich_menu(user_id)
|
439
|
+
channel_token_required
|
440
|
+
|
379
441
|
endpoint_path = "/bot/user/#{user_id}/richmenu"
|
380
|
-
get(endpoint_path)
|
442
|
+
get(endpoint, endpoint_path, credentials)
|
381
443
|
end
|
382
444
|
|
383
445
|
# Get default rich menu
|
384
446
|
#
|
385
447
|
# @return [Net::HTTPResponse]
|
386
448
|
def get_default_rich_menu
|
449
|
+
channel_token_required
|
450
|
+
|
387
451
|
endpoint_path = '/bot/user/all/richmenu'
|
388
|
-
get(endpoint_path)
|
452
|
+
get(endpoint, endpoint_path, credentials)
|
389
453
|
end
|
390
454
|
|
391
455
|
# Set default rich menu (Link a rich menu to all user)
|
@@ -394,33 +458,36 @@ module Line
|
|
394
458
|
#
|
395
459
|
# @return [Net::HTTPResponse]
|
396
460
|
def set_default_rich_menu(rich_menu_id)
|
461
|
+
channel_token_required
|
462
|
+
|
397
463
|
endpoint_path = "/bot/user/all/richmenu/#{rich_menu_id}"
|
398
|
-
post(endpoint_path)
|
464
|
+
post(endpoint, endpoint_path, nil, credentials)
|
399
465
|
end
|
400
466
|
|
401
467
|
# Unset default rich menu (Unlink a rich menu from all user)
|
402
468
|
#
|
403
469
|
# @return [Net::HTTPResponse]
|
404
470
|
def unset_default_rich_menu
|
471
|
+
channel_token_required
|
472
|
+
|
405
473
|
endpoint_path = "/bot/user/all/richmenu"
|
406
|
-
delete(endpoint_path)
|
474
|
+
delete(endpoint, endpoint_path, credentials)
|
407
475
|
end
|
408
476
|
|
409
477
|
# Link a rich menu to a user
|
410
478
|
#
|
479
|
+
# If you want to link a rich menu to multiple users,
|
480
|
+
# please consider to use bulk_link_rich_menus.
|
481
|
+
#
|
411
482
|
# @param user_id [String] ID of the user
|
412
483
|
# @param rich_menu_id [String] ID of an uploaded rich menu
|
413
484
|
#
|
414
485
|
# @return [Net::HTTPResponse]
|
415
486
|
def link_user_rich_menu(user_id, rich_menu_id)
|
416
|
-
|
417
|
-
config.httpclient = httpclient
|
418
|
-
config.endpoint = endpoint
|
419
|
-
config.endpoint_path = "/bot/user/#{user_id}/richmenu/#{rich_menu_id}"
|
420
|
-
config.credentials = credentials
|
421
|
-
end
|
487
|
+
channel_token_required
|
422
488
|
|
423
|
-
|
489
|
+
endpoint_path = "/bot/user/#{user_id}/richmenu/#{rich_menu_id}"
|
490
|
+
post(endpoint, endpoint_path, nil, credentials)
|
424
491
|
end
|
425
492
|
|
426
493
|
# Unlink a rich menu from a user
|
@@ -429,8 +496,10 @@ module Line
|
|
429
496
|
#
|
430
497
|
# @return [Net::HTTPResponse]
|
431
498
|
def unlink_user_rich_menu(user_id)
|
432
|
-
|
433
|
-
|
499
|
+
channel_token_required
|
500
|
+
|
501
|
+
endpoint_path = "/bot/user/#{user_id}/richmenu"
|
502
|
+
delete(endpoint, endpoint_path, credentials)
|
434
503
|
end
|
435
504
|
|
436
505
|
# To link a rich menu to multiple users at a time
|
@@ -440,7 +509,10 @@ module Line
|
|
440
509
|
#
|
441
510
|
# @return [Net::HTTPResponse]
|
442
511
|
def bulk_link_rich_menus(user_ids, rich_menu_id)
|
443
|
-
|
512
|
+
channel_token_required
|
513
|
+
|
514
|
+
endpoint_path = "/bot/richmenu/bulk/link"
|
515
|
+
post(endpoint, endpoint_path, { richMenuId: rich_menu_id, userIds: user_ids }.to_json, credentials)
|
444
516
|
end
|
445
517
|
|
446
518
|
# To unlink a rich menu from multiple users at a time
|
@@ -449,7 +521,10 @@ module Line
|
|
449
521
|
#
|
450
522
|
# @return [Net::HTTPResponse]
|
451
523
|
def bulk_unlink_rich_menus(user_ids)
|
452
|
-
|
524
|
+
channel_token_required
|
525
|
+
|
526
|
+
endpoint_path = "/bot/richmenu/bulk/unlink"
|
527
|
+
post(endpoint, endpoint_path, { userIds: user_ids }.to_json, credentials)
|
453
528
|
end
|
454
529
|
|
455
530
|
# Download an image associated with a rich menu
|
@@ -458,8 +533,10 @@ module Line
|
|
458
533
|
#
|
459
534
|
# @return [Net::HTTPResponse]
|
460
535
|
def get_rich_menu_image(rich_menu_id)
|
536
|
+
channel_token_required
|
537
|
+
|
461
538
|
endpoint_path = "/bot/richmenu/#{rich_menu_id}/content"
|
462
|
-
get(endpoint_path)
|
539
|
+
get(blob_endpoint, endpoint_path, credentials)
|
463
540
|
end
|
464
541
|
|
465
542
|
# Upload and attaches an image to a rich menu
|
@@ -469,15 +546,11 @@ module Line
|
|
469
546
|
#
|
470
547
|
# @return [Net::HTTPResponse]
|
471
548
|
def create_rich_menu_image(rich_menu_id, file)
|
472
|
-
|
473
|
-
config.httpclient = httpclient
|
474
|
-
config.endpoint = endpoint
|
475
|
-
config.endpoint_path = "/bot/richmenu/#{rich_menu_id}/content"
|
476
|
-
config.credentials = credentials
|
477
|
-
config.file = file
|
478
|
-
end
|
549
|
+
channel_token_required
|
479
550
|
|
480
|
-
|
551
|
+
endpoint_path = "/bot/richmenu/#{rich_menu_id}/content"
|
552
|
+
headers = credentials.merge('Content-Type' => content_type(file))
|
553
|
+
post(blob_endpoint, endpoint_path, file.rewind && file.read, headers)
|
481
554
|
end
|
482
555
|
|
483
556
|
# Issue a link token to a user
|
@@ -486,79 +559,113 @@ module Line
|
|
486
559
|
#
|
487
560
|
# @return [Net::HTTPResponse]
|
488
561
|
def create_link_token(user_id)
|
562
|
+
channel_token_required
|
563
|
+
|
489
564
|
endpoint_path = "/bot/user/#{user_id}/linkToken"
|
490
|
-
post(endpoint_path)
|
565
|
+
post(endpoint, endpoint_path, nil, credentials)
|
491
566
|
end
|
492
567
|
|
493
568
|
# Get the target limit for additional messages
|
494
569
|
#
|
495
570
|
# @return [Net::HTTPResponse]
|
496
571
|
def get_quota
|
572
|
+
channel_token_required
|
573
|
+
|
497
574
|
endpoint_path = "/bot/message/quota"
|
498
|
-
get(endpoint_path)
|
575
|
+
get(endpoint, endpoint_path, credentials)
|
499
576
|
end
|
500
577
|
|
501
578
|
# Get number of messages sent this month
|
502
579
|
#
|
503
580
|
# @return [Net::HTTPResponse]
|
504
581
|
def get_quota_consumption
|
582
|
+
channel_token_required
|
583
|
+
|
505
584
|
endpoint_path = "/bot/message/quota/consumption"
|
506
|
-
get(endpoint_path)
|
585
|
+
get(endpoint, endpoint_path, credentials)
|
507
586
|
end
|
508
587
|
|
509
|
-
#
|
588
|
+
# Returns the number of messages sent on a specified day
|
510
589
|
#
|
511
|
-
# @param
|
590
|
+
# @param [String] date (Format:yyyyMMdd, Example:20191231)
|
512
591
|
#
|
513
592
|
# @return [Net::HTTPResponse]
|
514
|
-
def
|
593
|
+
def get_number_of_message_deliveries(date)
|
515
594
|
channel_token_required
|
516
595
|
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
596
|
+
endpoint_path = "/bot/insight/message/delivery?date=#{date}"
|
597
|
+
get(endpoint, endpoint_path, credentials)
|
598
|
+
end
|
599
|
+
|
600
|
+
# Returns statistics about how users interact with narrowcast messages or broadcast messages sent from your LINE Official Account.
|
601
|
+
#
|
602
|
+
# @param [String] request_id
|
603
|
+
#
|
604
|
+
# @return [Net::HTTPResponse]
|
605
|
+
def get_user_interaction_statistics(request_id)
|
606
|
+
channel_token_required
|
523
607
|
|
524
|
-
|
608
|
+
endpoint_path = "/bot/insight/message/event?requestId=#{request_id}"
|
609
|
+
get(endpoint, endpoint_path, credentials)
|
525
610
|
end
|
526
611
|
|
527
|
-
#
|
612
|
+
# Returns the number of followers
|
528
613
|
#
|
529
|
-
# @param
|
614
|
+
# @param [String] date (Format:yyyyMMdd, Example:20191231)
|
530
615
|
#
|
531
616
|
# @return [Net::HTTPResponse]
|
532
|
-
def
|
617
|
+
def get_number_of_followers(date)
|
533
618
|
channel_token_required
|
534
619
|
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
620
|
+
endpoint_path = "/bot/insight/followers?date=#{date}"
|
621
|
+
get(endpoint, endpoint_path, credentials)
|
622
|
+
end
|
623
|
+
|
624
|
+
# Get the demographic attributes for a bot's friends.
|
625
|
+
#
|
626
|
+
# @return [Net::HTTPResponse]
|
627
|
+
def get_friend_demographics
|
628
|
+
channel_token_required
|
542
629
|
|
543
|
-
|
630
|
+
endpoint_path = '/bot/insight/demographic'
|
631
|
+
get(endpoint, endpoint_path, credentials)
|
544
632
|
end
|
545
633
|
|
546
|
-
#
|
634
|
+
# Fetch data, get content of specified URL.
|
547
635
|
#
|
636
|
+
# @param endpoint_base [String]
|
548
637
|
# @param endpoint_path [String]
|
638
|
+
# @param headers [Hash]
|
549
639
|
#
|
550
640
|
# @return [Net::HTTPResponse]
|
551
|
-
def
|
552
|
-
|
641
|
+
def get(endpoint_base, endpoint_path, headers = {})
|
642
|
+
headers = API::DEFAULT_HEADERS.merge(headers)
|
643
|
+
httpclient.get(endpoint_base + endpoint_path, headers)
|
644
|
+
end
|
553
645
|
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
646
|
+
# Post data, get content of specified URL.
|
647
|
+
#
|
648
|
+
# @param endpoint_base [String]
|
649
|
+
# @param endpoint_path [String]
|
650
|
+
# @param payload [String or NilClass]
|
651
|
+
# @param headers [Hash]
|
652
|
+
#
|
653
|
+
# @return [Net::HTTPResponse]
|
654
|
+
def post(endpoint_base, endpoint_path, payload = nil, headers = {})
|
655
|
+
headers = API::DEFAULT_HEADERS.merge(headers)
|
656
|
+
httpclient.post(endpoint_base + endpoint_path, payload, headers)
|
657
|
+
end
|
560
658
|
|
561
|
-
|
659
|
+
# Delete content of specified URL.
|
660
|
+
#
|
661
|
+
# @param endpoint_base [String]
|
662
|
+
# @param endpoint_path [String]
|
663
|
+
# @param headers [Hash]
|
664
|
+
#
|
665
|
+
# @return [Net::HTTPResponse]
|
666
|
+
def delete(endpoint_base, endpoint_path, headers = {})
|
667
|
+
headers = API::DEFAULT_HEADERS.merge(headers)
|
668
|
+
httpclient.delete(endpoint_base + endpoint_path, headers)
|
562
669
|
end
|
563
670
|
|
564
671
|
# Parse events from request.body
|
@@ -571,15 +678,17 @@ module Line
|
|
571
678
|
|
572
679
|
json['events'].map do |item|
|
573
680
|
begin
|
574
|
-
klass =
|
681
|
+
klass = Event.const_get(Util.camelize(item['type']))
|
575
682
|
klass.new(item)
|
576
683
|
rescue NameError
|
577
|
-
|
684
|
+
Event::Base.new(item)
|
578
685
|
end
|
579
686
|
end
|
580
687
|
end
|
581
688
|
|
582
|
-
# Validate signature
|
689
|
+
# Validate signature of a webhook event.
|
690
|
+
#
|
691
|
+
# https://developers.line.biz/en/reference/messaging-api/#signature-validation
|
583
692
|
#
|
584
693
|
# @param content [String] Request's body
|
585
694
|
# @param channel_signature [String] Request'header 'X-LINE-Signature' # HTTP_X_LINE_SIGNATURE
|
@@ -616,6 +725,21 @@ module Line
|
|
616
725
|
res == 0
|
617
726
|
end
|
618
727
|
|
728
|
+
def content_type(file)
|
729
|
+
if file.respond_to?(:content_type)
|
730
|
+
content_type = file.content_type
|
731
|
+
raise ArgumentError, "invalid content type: #{content_type}" unless ['image/jpeg', 'image/png'].include?(content_type)
|
732
|
+
content_type
|
733
|
+
else
|
734
|
+
case file.path
|
735
|
+
when /\.jpe?g\z/i then 'image/jpeg'
|
736
|
+
when /\.png\z/i then 'image/png'
|
737
|
+
else
|
738
|
+
raise ArgumentError, "invalid file extension: #{file.path}"
|
739
|
+
end
|
740
|
+
end
|
741
|
+
end
|
742
|
+
|
619
743
|
def channel_token_required
|
620
744
|
raise ArgumentError, '`channel_token` is not configured' unless channel_token
|
621
745
|
end
|
@@ -15,11 +15,16 @@
|
|
15
15
|
module Line
|
16
16
|
module Bot
|
17
17
|
module Event
|
18
|
+
# Event object for when a user has linked his/her LINE account with a provider's service account.
|
19
|
+
#
|
20
|
+
# https://developers.line.biz/en/reference/messaging-api/#account-link-event
|
18
21
|
class AccountLink < Base
|
22
|
+
# @return [String]
|
19
23
|
def result
|
20
24
|
@src['link']['result']
|
21
25
|
end
|
22
26
|
|
27
|
+
# @return [String]
|
23
28
|
def nonce
|
24
29
|
@src['link']['nonce']
|
25
30
|
end
|
@@ -15,15 +15,21 @@
|
|
15
15
|
module Line
|
16
16
|
module Bot
|
17
17
|
module Event
|
18
|
+
# Event object for when a user enters the range of a LINE Beacon.
|
19
|
+
#
|
20
|
+
# https://developers.line.biz/en/reference/messaging-api/#beacon-event
|
18
21
|
class Beacon < Base
|
22
|
+
# @return [String]
|
19
23
|
def type
|
20
24
|
@src['beacon']['type']
|
21
25
|
end
|
22
26
|
|
27
|
+
# @return [String]
|
23
28
|
def hwid
|
24
29
|
@src['beacon']['hwid']
|
25
30
|
end
|
26
31
|
|
32
|
+
# @return [String]
|
27
33
|
def deviceMessage
|
28
34
|
[@src['beacon']['dm']].pack('H*')
|
29
35
|
end
|
@@ -15,6 +15,10 @@
|
|
15
15
|
module Line
|
16
16
|
module Bot
|
17
17
|
module Event
|
18
|
+
# Event object for when your LINE official account is added as a friend (or unblocked).
|
19
|
+
# You can reply to follow events.
|
20
|
+
#
|
21
|
+
# https://developers.line.biz/en/reference/messaging-api/#follow-event
|
18
22
|
class Follow < Base
|
19
23
|
end
|
20
24
|
end
|
data/lib/line/bot/event/join.rb
CHANGED
data/lib/line/bot/event/leave.rb
CHANGED
@@ -15,6 +15,11 @@
|
|
15
15
|
module Line
|
16
16
|
module Bot
|
17
17
|
module Event
|
18
|
+
# Event object for when a user removes your LINE official account from a group or when your LINE official account leaves a group or room.
|
19
|
+
#
|
20
|
+
# No replyToken is generated for this event.
|
21
|
+
#
|
22
|
+
# https://developers.line.biz/en/reference/messaging-api/#leave-event
|
18
23
|
class Leave < Base
|
19
24
|
end
|
20
25
|
end
|
@@ -15,6 +15,9 @@
|
|
15
15
|
module Line
|
16
16
|
module Bot
|
17
17
|
module Event
|
18
|
+
# Event object for when a user joins a group or room that the LINE official account is in.
|
19
|
+
#
|
20
|
+
# https://developers.line.biz/en/reference/messaging-api/#member-joined-event
|
18
21
|
class MemberJoined < Base
|
19
22
|
end
|
20
23
|
end
|
@@ -15,6 +15,11 @@
|
|
15
15
|
module Line
|
16
16
|
module Bot
|
17
17
|
module Event
|
18
|
+
# Event object for when a user leaves a group or room that the LINE official account is in.
|
19
|
+
#
|
20
|
+
# No replyToken is generated for this event.
|
21
|
+
#
|
22
|
+
# https://developers.line.biz/en/reference/messaging-api/#member-left-event
|
18
23
|
class MemberLeft < Base
|
19
24
|
end
|
20
25
|
end
|
@@ -26,11 +26,14 @@ module Line
|
|
26
26
|
Unsupport = 'unsupport'
|
27
27
|
end
|
28
28
|
|
29
|
+
# Webhook event object which contains the sent message.
|
30
|
+
#
|
31
|
+
# https://developers.line.biz/en/reference/messaging-api/#message-event
|
29
32
|
class Message < Base
|
30
33
|
def type
|
31
|
-
|
34
|
+
MessageType.const_get(@src['message']['type'].capitalize)
|
32
35
|
rescue NameError => e
|
33
|
-
|
36
|
+
MessageType::Unsupport
|
34
37
|
end
|
35
38
|
|
36
39
|
def message
|
@@ -18,14 +18,20 @@ module Line
|
|
18
18
|
module ThingsType
|
19
19
|
Link = 'link'
|
20
20
|
Unlink = 'unlink'
|
21
|
+
ScenarioResult = 'scenarioResult'
|
21
22
|
Unsupport = 'unsupport'
|
22
23
|
end
|
23
24
|
|
25
|
+
# LINE Things API related events.
|
26
|
+
#
|
27
|
+
# * https://developers.line.biz/en/reference/messaging-api/#device-link-event
|
28
|
+
# * https://developers.line.biz/en/reference/messaging-api/#device-unlink-event
|
29
|
+
# * https://developers.line.biz/en/reference/messaging-api/#scenario-result-event
|
24
30
|
class Things < Base
|
25
31
|
def type
|
26
|
-
|
32
|
+
ThingsType.const_get(Util.camelize(@src['things']['type']))
|
27
33
|
rescue NameError
|
28
|
-
|
34
|
+
ThingsType::Unsupport
|
29
35
|
end
|
30
36
|
|
31
37
|
def device_id
|
@@ -15,6 +15,11 @@
|
|
15
15
|
module Line
|
16
16
|
module Bot
|
17
17
|
module Event
|
18
|
+
# Event object for when your LINE official account is blocked.
|
19
|
+
#
|
20
|
+
# No replyToken is generated for this event.
|
21
|
+
#
|
22
|
+
# https://developers.line.biz/en/reference/messaging-api/#unfollow-event
|
18
23
|
class Unfollow < Base
|
19
24
|
end
|
20
25
|
end
|
data/lib/line/bot/httpclient.rb
CHANGED
@@ -12,7 +12,6 @@
|
|
12
12
|
# License for the specific language governing permissions and limitations
|
13
13
|
# under the License.
|
14
14
|
|
15
|
-
require 'line/bot/api/version'
|
16
15
|
require 'json'
|
17
16
|
require 'net/http'
|
18
17
|
require 'uri'
|
@@ -20,7 +19,7 @@ require 'uri'
|
|
20
19
|
module Line
|
21
20
|
module Bot
|
22
21
|
class HTTPClient
|
23
|
-
#
|
22
|
+
# @return [Hash]
|
24
23
|
attr_accessor :http_options
|
25
24
|
|
26
25
|
# Initialize a new HTTPClient
|
data/line-bot-api.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
spec.add_development_dependency "addressable", "~> 2.3"
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.11" if RUBY_VERSION < "2.3"
|
24
|
-
spec.add_development_dependency 'rake', "~>
|
24
|
+
spec.add_development_dependency 'rake', "~> 13.0"
|
25
25
|
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
-
spec.add_development_dependency "webmock", "~>
|
26
|
+
spec.add_development_dependency "webmock", "~> 3.8"
|
27
27
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: line-bot-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.15.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- LINE Corporation
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '13.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '13.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '3.8'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '3.8'
|
69
69
|
description: Line::Bot::API - SDK of the LINE Messaging API for Ruby
|
70
70
|
email:
|
71
71
|
- kimoto@linecorp.com
|
@@ -98,7 +98,6 @@ files:
|
|
98
98
|
- lib/line/bot/event/things.rb
|
99
99
|
- lib/line/bot/event/unfollow.rb
|
100
100
|
- lib/line/bot/httpclient.rb
|
101
|
-
- lib/line/bot/request.rb
|
102
101
|
- lib/line/bot/util.rb
|
103
102
|
- line-bot-api.gemspec
|
104
103
|
homepage: https://github.com/line/line-bot-sdk-ruby
|
@@ -120,7 +119,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
119
|
- !ruby/object:Gem::Version
|
121
120
|
version: '0'
|
122
121
|
requirements: []
|
123
|
-
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.7.6
|
124
124
|
signing_key:
|
125
125
|
specification_version: 4
|
126
126
|
summary: SDK of the LINE Messaging API
|
data/lib/line/bot/request.rb
DELETED
@@ -1,117 +0,0 @@
|
|
1
|
-
# Copyright 2016 LINE
|
2
|
-
#
|
3
|
-
# LINE Corporation licenses this file to you under the Apache License,
|
4
|
-
# version 2.0 (the "License"); you may not use this file except in compliance
|
5
|
-
# with the License. You may obtain a copy of the License at:
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
11
|
-
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
12
|
-
# License for the specific language governing permissions and limitations
|
13
|
-
# under the License.
|
14
|
-
|
15
|
-
require 'line/bot/api/version'
|
16
|
-
require 'json'
|
17
|
-
require 'net/http'
|
18
|
-
require 'uri'
|
19
|
-
|
20
|
-
module Line
|
21
|
-
module Bot
|
22
|
-
class Request
|
23
|
-
attr_accessor :endpoint, :endpoint_path, :credentials, :to, :reply_token, :messages, :httpclient, :payload, :file
|
24
|
-
|
25
|
-
attr_writer :content_type
|
26
|
-
|
27
|
-
# Initializes a new Request
|
28
|
-
#
|
29
|
-
# @return [Line::Bot::Request]
|
30
|
-
def initialize
|
31
|
-
yield(self) if block_given?
|
32
|
-
end
|
33
|
-
|
34
|
-
# @return [String]
|
35
|
-
def payload
|
36
|
-
return file.seek(0) && file.read if file.is_a? File
|
37
|
-
return @payload if @payload.is_a? String
|
38
|
-
payload = {
|
39
|
-
to: to,
|
40
|
-
replyToken: reply_token,
|
41
|
-
messages: messages
|
42
|
-
}
|
43
|
-
|
44
|
-
payload.delete_if { |k, v| v.nil? }.to_json
|
45
|
-
end
|
46
|
-
|
47
|
-
# @return [Hash]
|
48
|
-
def header
|
49
|
-
header = {
|
50
|
-
'Content-Type' => content_type,
|
51
|
-
'User-Agent' => "LINE-BotSDK-Ruby/#{Line::Bot::API::VERSION}",
|
52
|
-
}
|
53
|
-
hash = (credentials || {}).inject({}) { |h, (k, v)| h[k] = v.to_s; h }
|
54
|
-
|
55
|
-
header.merge(hash)
|
56
|
-
end
|
57
|
-
|
58
|
-
# @return [String]
|
59
|
-
def content_type
|
60
|
-
return @content_type if @content_type
|
61
|
-
|
62
|
-
guess_content_type
|
63
|
-
end
|
64
|
-
|
65
|
-
# Get content of specified URL.
|
66
|
-
#
|
67
|
-
# @return [Net::HTTPResponse]
|
68
|
-
def get
|
69
|
-
assert_for_getting_message
|
70
|
-
httpclient.get(endpoint + endpoint_path, header)
|
71
|
-
end
|
72
|
-
|
73
|
-
# Post content of specified URL.
|
74
|
-
#
|
75
|
-
# @raise [ArgumentError]
|
76
|
-
#
|
77
|
-
# @return [Net::HTTPResponse]
|
78
|
-
def post
|
79
|
-
assert_for_posting_message
|
80
|
-
httpclient.post(endpoint + endpoint_path, payload, header)
|
81
|
-
end
|
82
|
-
|
83
|
-
def delete
|
84
|
-
assert_for_deleting_message
|
85
|
-
httpclient.delete(endpoint + endpoint_path, header)
|
86
|
-
end
|
87
|
-
|
88
|
-
def assert_for_getting_message
|
89
|
-
raise ArgumentError, 'Wrong argument type `endpoint_path`' unless endpoint_path.is_a?(String)
|
90
|
-
end
|
91
|
-
|
92
|
-
def assert_for_posting_message
|
93
|
-
raise ArgumentError, 'Wrong argument type `endpoint_path`' unless endpoint_path.is_a?(String)
|
94
|
-
end
|
95
|
-
|
96
|
-
def assert_for_deleting_message
|
97
|
-
raise ArgumentError, 'Wrong argument type `endpoint_path`' unless endpoint_path.is_a?(String)
|
98
|
-
end
|
99
|
-
|
100
|
-
private
|
101
|
-
|
102
|
-
# @return [String]
|
103
|
-
def guess_content_type
|
104
|
-
if file.is_a? File
|
105
|
-
case file.path
|
106
|
-
when /\.png\z/i then 'image/png'
|
107
|
-
when /\.jpe?g\z/i then 'image/jpeg'
|
108
|
-
else
|
109
|
-
raise ArgumentError.new("invalid file extension: #{file.path}")
|
110
|
-
end
|
111
|
-
else
|
112
|
-
'application/json; charset=UTF-8'
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|