line-bot-api 1.11.0 → 1.12.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 191b846d917a61448e7e38976390aeb56846229ccdc2a69c404d0ca04a3bcb89
4
- data.tar.gz: 595b93123023a3c9060190969657ca06d2bc7472281bcfe43ee1ef7b4c95324a
3
+ metadata.gz: ec352e50cd2b13df2d2c4d0f14ae9f6d3346c33358f343ae43448a1d489a3203
4
+ data.tar.gz: 26e0c32ab9671267628fe4749ae039558409a4087f991869e310e293276ff386
5
5
  SHA512:
6
- metadata.gz: '094bbf24cc58e2b444a410b02052d15bcd545ad77e62a4cf8765d5a6d8e5e4011ff735196bffd3d95d2ab77e6cdb70a17240dfe524f71380d2633b5efea5455b'
7
- data.tar.gz: f54a7e01bd1b28f28eac6e299e739a8d59d390056acac28fb7d5a957f56e2f28fa71a26a3e07a7bed212c605af735486e2213465aa417025e18aafe6d95c05d7
6
+ metadata.gz: 1b924857b1fa6732824b648aebc131885e1638aba7e4f28beb281e1c402b74260727c9a1700ed8174fc6f312bad38eeef6e5bcf4be6bdd908f6a2e0d04df8f26
7
+ data.tar.gz: e513999b3e4d52985efd98fcdcca98bbd45c48602f28911d49518a341b5ceeeee0ed8e1326d862f1ee51c1bfb93a51860b938cfec5b059277ca6a6da7e7d0a65
data/README.md CHANGED
@@ -77,6 +77,7 @@ post '/callback' do
77
77
  end
78
78
  end
79
79
 
80
+ # Don't forget to return a successful response
80
81
  "OK"
81
82
  end
82
83
  ```
@@ -96,7 +97,7 @@ This project respects semantic versioning.
96
97
  See https://semver.org/
97
98
 
98
99
  ## Contributing
99
- Please check [CONTRIBUTING](contributing.md) before making a contribution.
100
+ Please check [CONTRIBUTING](CONTRIBUTING.md) before making a contribution.
100
101
 
101
102
  ## License
102
103
  ```
@@ -17,6 +17,5 @@ require 'line/bot/client'
17
17
  require 'line/bot/event'
18
18
  require 'line/bot/api/errors'
19
19
  require 'line/bot/api'
20
- require 'line/bot/request'
21
20
  require 'line/bot/httpclient'
22
21
  require 'line/bot/api/version'
@@ -12,10 +12,17 @@
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
+
22
+ DEFAULT_HEADERS = {
23
+ 'Content-Type' => 'application/json; charset=UTF-8',
24
+ 'User-Agent' => "LINE-BotSDK-Ruby/#{Line::Bot::API::VERSION}"
25
+ }.freeze
19
26
  end
20
27
  end
21
28
  end
@@ -15,7 +15,7 @@
15
15
  module Line
16
16
  module Bot
17
17
  module API
18
- VERSION = "1.11.0"
18
+ VERSION = "1.12.0"
19
19
  end
20
20
  end
21
21
  end
@@ -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'
@@ -66,38 +65,24 @@ module Line
66
65
  channel_id_required
67
66
  channel_secret_required
68
67
 
68
+ endpoint_path = '/oauth/accessToken'
69
69
  payload = URI.encode_www_form(
70
70
  grant_type: grant_type,
71
71
  client_id: channel_id,
72
72
  client_secret: channel_secret
73
73
  )
74
-
75
- request = Request.new do |config|
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
74
+ headers = { 'Content-Type' => 'application/x-www-form-urlencoded' }
75
+ post(endpoint_path, payload, headers)
84
76
  end
85
77
 
86
78
  # Revoke channel access token
87
79
  #
88
80
  # @return [Net::HTTPResponse]
89
81
  def revoke_channel_token(access_token)
82
+ endpoint_path = '/oauth/revoke'
90
83
  payload = URI.encode_www_form(access_token: access_token)
91
-
92
- request = Request.new do |config|
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
84
+ headers = { 'Content-Type' => 'application/x-www-form-urlencoded' }
85
+ post(endpoint_path, payload, headers)
101
86
  end
102
87
 
103
88
  # Push messages to line server and to user.
@@ -111,16 +96,9 @@ module Line
111
96
 
112
97
  messages = [messages] if messages.is_a?(Hash)
113
98
 
114
- request = Request.new do |config|
115
- config.httpclient = httpclient
116
- config.endpoint = endpoint
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
99
+ endpoint_path = '/bot/message/push'
100
+ payload = { to: user_id, messages: messages }.to_json
101
+ post(endpoint_path, payload, credentials)
124
102
  end
125
103
 
126
104
  # Reply messages to line server and to users.
@@ -134,16 +112,9 @@ module Line
134
112
 
135
113
  messages = [messages] if messages.is_a?(Hash)
136
114
 
137
- request = Request.new do |config|
138
- config.httpclient = httpclient
139
- config.endpoint = endpoint
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
115
+ endpoint_path = '/bot/message/reply'
116
+ payload = { replyToken: token, messages: messages }.to_json
117
+ post(endpoint_path, payload, credentials)
147
118
  end
148
119
 
149
120
  # Multicast messages to line server and to users.
@@ -158,16 +129,9 @@ module Line
158
129
  to = [to] if to.is_a?(String)
159
130
  messages = [messages] if messages.is_a?(Hash)
160
131
 
161
- request = Request.new do |config|
162
- config.httpclient = httpclient
163
- config.endpoint = endpoint
164
- config.endpoint_path = '/bot/message/multicast'
165
- config.credentials = credentials
166
- config.to = to
167
- config.messages = messages
168
- end
169
-
170
- request.post
132
+ endpoint_path = '/bot/message/multicast'
133
+ payload = { to: to, messages: messages }.to_json
134
+ post(endpoint_path, payload, credentials)
171
135
  end
172
136
 
173
137
  # Broadcast messages to users
@@ -180,41 +144,23 @@ module Line
180
144
 
181
145
  messages = [messages] if messages.is_a?(Hash)
182
146
 
183
- request = Request.new do |config|
184
- config.httpclient = httpclient
185
- config.endpoint = endpoint
186
- config.endpoint_path = '/bot/message/broadcast'
187
- config.credentials = credentials
188
- config.messages = messages
189
- end
190
-
191
- request.post
147
+ endpoint_path = '/bot/message/broadcast'
148
+ payload = { messages: messages }.to_json
149
+ post(endpoint_path, payload, credentials)
192
150
  end
193
151
 
194
152
  def leave_group(group_id)
195
153
  channel_token_required
196
154
 
197
- request = Request.new do |config|
198
- config.httpclient = httpclient
199
- config.endpoint = endpoint
200
- config.endpoint_path = "/bot/group/#{group_id}/leave"
201
- config.credentials = credentials
202
- end
203
-
204
- request.post
155
+ endpoint_path = "/bot/group/#{group_id}/leave"
156
+ post(endpoint_path, nil, credentials)
205
157
  end
206
158
 
207
159
  def leave_room(room_id)
208
160
  channel_token_required
209
161
 
210
- request = Request.new do |config|
211
- config.httpclient = httpclient
212
- config.endpoint = endpoint
213
- config.endpoint_path = "/bot/room/#{room_id}/leave"
214
- config.credentials = credentials
215
- end
216
-
217
- request.post
162
+ endpoint_path = "/bot/room/#{room_id}/leave"
163
+ post(endpoint_path, nil, credentials)
218
164
  end
219
165
 
220
166
  # Get message content.
@@ -223,8 +169,10 @@ module Line
223
169
  #
224
170
  # @return [Net::HTTPResponse]
225
171
  def get_message_content(identifier)
226
- endpoint_path = "/bot/message/#{identifier}/content"
227
- get(endpoint_path)
172
+ channel_token_required
173
+
174
+ endpoint_path = "/bot/message/#{identifier}/content"
175
+ get(endpoint_path, credentials)
228
176
  end
229
177
 
230
178
  # Get an user's profile.
@@ -233,8 +181,10 @@ module Line
233
181
  #
234
182
  # @return [Net::HTTPResponse]
235
183
  def get_profile(user_id)
236
- endpoint_path = "/bot/profile/#{user_id}"
237
- get(endpoint_path)
184
+ channel_token_required
185
+
186
+ endpoint_path = "/bot/profile/#{user_id}"
187
+ get(endpoint_path, credentials)
238
188
  end
239
189
 
240
190
  # Get an user's profile of a group.
@@ -244,8 +194,10 @@ module Line
244
194
  #
245
195
  # @return [Net::HTTPResponse]
246
196
  def get_group_member_profile(group_id, user_id)
197
+ channel_token_required
198
+
247
199
  endpoint_path = "/bot/group/#{group_id}/member/#{user_id}"
248
- get(endpoint_path)
200
+ get(endpoint_path, credentials)
249
201
  end
250
202
 
251
203
  # Get an user's profile of a room.
@@ -255,8 +207,10 @@ module Line
255
207
  #
256
208
  # @return [Net::HTTPResponse]
257
209
  def get_room_member_profile(room_id, user_id)
210
+ channel_token_required
211
+
258
212
  endpoint_path = "/bot/room/#{room_id}/member/#{user_id}"
259
- get(endpoint_path)
213
+ get(endpoint_path, credentials)
260
214
  end
261
215
 
262
216
  # Get user IDs of a group
@@ -267,9 +221,11 @@ module Line
267
221
  #
268
222
  # @return [Net::HTTPResponse]
269
223
  def get_group_member_ids(group_id, continuation_token = nil)
270
- endpoint_path = "/bot/group/#{group_id}/members/ids"
224
+ channel_token_required
225
+
226
+ endpoint_path = "/bot/group/#{group_id}/members/ids"
271
227
  endpoint_path += "?start=#{continuation_token}" if continuation_token
272
- get(endpoint_path)
228
+ get(endpoint_path, credentials)
273
229
  end
274
230
 
275
231
  # Get user IDs of a room
@@ -280,17 +236,21 @@ module Line
280
236
  #
281
237
  # @return [Net::HTTPResponse]
282
238
  def get_room_member_ids(room_id, continuation_token = nil)
283
- endpoint_path = "/bot/room/#{room_id}/members/ids"
239
+ channel_token_required
240
+
241
+ endpoint_path = "/bot/room/#{room_id}/members/ids"
284
242
  endpoint_path += "?start=#{continuation_token}" if continuation_token
285
- get(endpoint_path)
243
+ get(endpoint_path, credentials)
286
244
  end
287
245
 
288
246
  # Get a list of all uploaded rich menus
289
247
  #
290
248
  # @return [Net::HTTPResponse]
291
249
  def get_rich_menus
250
+ channel_token_required
251
+
292
252
  endpoint_path = '/bot/richmenu/list'
293
- get(endpoint_path)
253
+ get(endpoint_path, credentials)
294
254
  end
295
255
 
296
256
  # Get a rich menu via a rich menu ID
@@ -299,8 +259,10 @@ module Line
299
259
  #
300
260
  # @return [Net::HTTPResponse]
301
261
  def get_rich_menu(rich_menu_id)
262
+ channel_token_required
263
+
302
264
  endpoint_path = "/bot/richmenu/#{rich_menu_id}"
303
- get(endpoint_path)
265
+ get(endpoint_path, credentials)
304
266
  end
305
267
 
306
268
  # Gets the number of messages sent with the /bot/message/reply endpoint.
@@ -309,8 +271,10 @@ module Line
309
271
  #
310
272
  # @return [Net::HTTPResponse]
311
273
  def get_message_delivery_reply(date)
274
+ channel_token_required
275
+
312
276
  endpoint_path = "/bot/message/delivery/reply?date=#{date}"
313
- get(endpoint_path)
277
+ get(endpoint_path, credentials)
314
278
  end
315
279
 
316
280
  # Gets the number of messages sent with the /bot/message/push endpoint.
@@ -319,8 +283,10 @@ module Line
319
283
  #
320
284
  # @return [Net::HTTPResponse]
321
285
  def get_message_delivery_push(date)
286
+ channel_token_required
287
+
322
288
  endpoint_path = "/bot/message/delivery/push?date=#{date}"
323
- get(endpoint_path)
289
+ get(endpoint_path, credentials)
324
290
  end
325
291
 
326
292
  # Gets the number of messages sent with the /bot/message/multicast endpoint.
@@ -329,8 +295,10 @@ module Line
329
295
  #
330
296
  # @return [Net::HTTPResponse]
331
297
  def get_message_delivery_multicast(date)
298
+ channel_token_required
299
+
332
300
  endpoint_path = "/bot/message/delivery/multicast?date=#{date}"
333
- get(endpoint_path)
301
+ get(endpoint_path, credentials)
334
302
  end
335
303
 
336
304
  # Gets the number of messages sent with the /bot/message/multicast endpoint.
@@ -339,8 +307,10 @@ module Line
339
307
  #
340
308
  # @return [Net::HTTPResponse]
341
309
  def get_message_delivery_broadcast(date)
310
+ channel_token_required
311
+
342
312
  endpoint_path = "/bot/message/delivery/broadcast?date=#{date}"
343
- get(endpoint_path)
313
+ get(endpoint_path, credentials)
344
314
  end
345
315
 
346
316
  # Create a rich menu
@@ -349,15 +319,10 @@ module Line
349
319
  #
350
320
  # @return [Net::HTTPResponse]
351
321
  def create_rich_menu(rich_menu)
352
- request = Request.new do |config|
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
322
+ channel_token_required
359
323
 
360
- request.post
324
+ endpoint_path = '/bot/richmenu'
325
+ post(endpoint_path, rich_menu.to_json, credentials)
361
326
  end
362
327
 
363
328
  # Delete a rich menu
@@ -366,8 +331,10 @@ module Line
366
331
  #
367
332
  # @return [Net::HTTPResponse]
368
333
  def delete_rich_menu(rich_menu_id)
334
+ channel_token_required
335
+
369
336
  endpoint_path = "/bot/richmenu/#{rich_menu_id}"
370
- delete(endpoint_path)
337
+ delete(endpoint_path, credentials)
371
338
  end
372
339
 
373
340
  # Get the ID of the rich menu linked to a user
@@ -376,16 +343,20 @@ module Line
376
343
  #
377
344
  # @return [Net::HTTPResponse]
378
345
  def get_user_rich_menu(user_id)
346
+ channel_token_required
347
+
379
348
  endpoint_path = "/bot/user/#{user_id}/richmenu"
380
- get(endpoint_path)
349
+ get(endpoint_path, credentials)
381
350
  end
382
351
 
383
352
  # Get default rich menu
384
353
  #
385
354
  # @return [Net::HTTPResponse]
386
355
  def get_default_rich_menu
356
+ channel_token_required
357
+
387
358
  endpoint_path = '/bot/user/all/richmenu'
388
- get(endpoint_path)
359
+ get(endpoint_path, credentials)
389
360
  end
390
361
 
391
362
  # Set default rich menu (Link a rich menu to all user)
@@ -394,16 +365,20 @@ module Line
394
365
  #
395
366
  # @return [Net::HTTPResponse]
396
367
  def set_default_rich_menu(rich_menu_id)
368
+ channel_token_required
369
+
397
370
  endpoint_path = "/bot/user/all/richmenu/#{rich_menu_id}"
398
- post(endpoint_path)
371
+ post(endpoint_path, nil, credentials)
399
372
  end
400
373
 
401
374
  # Unset default rich menu (Unlink a rich menu from all user)
402
375
  #
403
376
  # @return [Net::HTTPResponse]
404
377
  def unset_default_rich_menu
378
+ channel_token_required
379
+
405
380
  endpoint_path = "/bot/user/all/richmenu"
406
- delete(endpoint_path)
381
+ delete(endpoint_path, credentials)
407
382
  end
408
383
 
409
384
  # Link a rich menu to a user
@@ -413,14 +388,10 @@ module Line
413
388
  #
414
389
  # @return [Net::HTTPResponse]
415
390
  def link_user_rich_menu(user_id, rich_menu_id)
416
- request = Request.new do |config|
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
391
+ channel_token_required
422
392
 
423
- request.post
393
+ endpoint_path = "/bot/user/#{user_id}/richmenu/#{rich_menu_id}"
394
+ post(endpoint_path, nil, credentials)
424
395
  end
425
396
 
426
397
  # Unlink a rich menu from a user
@@ -429,8 +400,10 @@ module Line
429
400
  #
430
401
  # @return [Net::HTTPResponse]
431
402
  def unlink_user_rich_menu(user_id)
432
- endpoint_path = "/bot/user/#{user_id}/richmenu"
433
- delete(endpoint_path)
403
+ channel_token_required
404
+
405
+ endpoint_path = "/bot/user/#{user_id}/richmenu"
406
+ delete(endpoint_path, credentials)
434
407
  end
435
408
 
436
409
  # To link a rich menu to multiple users at a time
@@ -440,7 +413,10 @@ module Line
440
413
  #
441
414
  # @return [Net::HTTPResponse]
442
415
  def bulk_link_rich_menus(user_ids, rich_menu_id)
443
- post("/bot/richmenu/bulk/link", {richMenuId: rich_menu_id, userIds: user_ids}.to_json)
416
+ channel_token_required
417
+
418
+ endpoint_path = "/bot/richmenu/bulk/link"
419
+ post(endpoint_path, { richMenuId: rich_menu_id, userIds: user_ids }.to_json, credentials)
444
420
  end
445
421
 
446
422
  # To unlink a rich menu from multiple users at a time
@@ -449,7 +425,10 @@ module Line
449
425
  #
450
426
  # @return [Net::HTTPResponse]
451
427
  def bulk_unlink_rich_menus(user_ids)
452
- post("/bot/richmenu/bulk/unlink", {userIds: user_ids}.to_json)
428
+ channel_token_required
429
+
430
+ endpoint_path = "/bot/richmenu/bulk/unlink"
431
+ post(endpoint_path, { userIds: user_ids }.to_json, credentials)
453
432
  end
454
433
 
455
434
  # Download an image associated with a rich menu
@@ -458,8 +437,10 @@ module Line
458
437
  #
459
438
  # @return [Net::HTTPResponse]
460
439
  def get_rich_menu_image(rich_menu_id)
440
+ channel_token_required
441
+
461
442
  endpoint_path = "/bot/richmenu/#{rich_menu_id}/content"
462
- get(endpoint_path)
443
+ get(endpoint_path, credentials)
463
444
  end
464
445
 
465
446
  # Upload and attaches an image to a rich menu
@@ -469,15 +450,18 @@ module Line
469
450
  #
470
451
  # @return [Net::HTTPResponse]
471
452
  def create_rich_menu_image(rich_menu_id, file)
472
- request = Request.new do |config|
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
453
+ channel_token_required
479
454
 
480
- request.post
455
+ content_type = case file.path
456
+ when /\.jpe?g\z/i then 'image/jpeg'
457
+ when /\.png\z/i then 'image/png'
458
+ else
459
+ raise ArgumentError, "invalid file extension: #{file.path}"
460
+ end
461
+
462
+ endpoint_path = "/bot/richmenu/#{rich_menu_id}/content"
463
+ headers = credentials.merge('Content-Type' => content_type)
464
+ post(endpoint_path, file.rewind && file.read, headers)
481
465
  end
482
466
 
483
467
  # Issue a link token to a user
@@ -486,79 +470,98 @@ module Line
486
470
  #
487
471
  # @return [Net::HTTPResponse]
488
472
  def create_link_token(user_id)
473
+ channel_token_required
474
+
489
475
  endpoint_path = "/bot/user/#{user_id}/linkToken"
490
- post(endpoint_path)
476
+ post(endpoint_path, nil, credentials)
491
477
  end
492
478
 
493
479
  # Get the target limit for additional messages
494
480
  #
495
481
  # @return [Net::HTTPResponse]
496
482
  def get_quota
483
+ channel_token_required
484
+
497
485
  endpoint_path = "/bot/message/quota"
498
- get(endpoint_path)
486
+ get(endpoint_path, credentials)
499
487
  end
500
488
 
501
489
  # Get number of messages sent this month
502
490
  #
503
491
  # @return [Net::HTTPResponse]
504
492
  def get_quota_consumption
493
+ channel_token_required
494
+
505
495
  endpoint_path = "/bot/message/quota/consumption"
506
- get(endpoint_path)
496
+ get(endpoint_path, credentials)
507
497
  end
508
498
 
509
- # Fetch data, get content of specified URL.
499
+ # Returns the number of messages sent on a specified day
510
500
  #
511
- # @param endpoint_path [String]
501
+ # @param [String] date (Format:yyyyMMdd, Example:20191231)
512
502
  #
513
503
  # @return [Net::HTTPResponse]
514
- def get(endpoint_path)
504
+ def get_number_of_message_deliveries(date)
515
505
  channel_token_required
516
506
 
517
- request = Request.new do |config|
518
- config.httpclient = httpclient
519
- config.endpoint = endpoint
520
- config.endpoint_path = endpoint_path
521
- config.credentials = credentials
522
- end
523
-
524
- request.get
507
+ endpoint_path = "/bot/insight/message/delivery?date=#{date}"
508
+ get(endpoint_path, credentials)
525
509
  end
526
510
 
527
- # Post data, get content of specified URL.
511
+ # Returns the number of followers
528
512
  #
529
- # @param endpoint_path [String]
513
+ # @param [String] date (Format:yyyyMMdd, Example:20191231)
530
514
  #
531
515
  # @return [Net::HTTPResponse]
532
- def post(endpoint_path, payload = nil)
516
+ def get_number_of_followers(date)
533
517
  channel_token_required
534
518
 
535
- request = Request.new do |config|
536
- config.httpclient = httpclient
537
- config.endpoint = endpoint
538
- config.endpoint_path = endpoint_path
539
- config.credentials = credentials
540
- config.payload = payload if payload
541
- end
519
+ endpoint_path = "/bot/insight/followers?date=#{date}"
520
+ get(endpoint_path, credentials)
521
+ end
542
522
 
543
- request.post
523
+ # Retrieves the demographic attributes for a bot's friends.
524
+ #
525
+ # @return [Net::HTTPResponse]
526
+ def get_friend_demographics
527
+ channel_token_required
528
+
529
+ endpoint_path = '/bot/insight/demographic'
530
+ get(endpoint_path, credentials)
544
531
  end
545
532
 
546
- # Delete content of specified URL.
533
+ # Fetch data, get content of specified URL.
547
534
  #
548
535
  # @param endpoint_path [String]
536
+ # @param headers [Hash]
549
537
  #
550
538
  # @return [Net::HTTPResponse]
551
- def delete(endpoint_path)
552
- channel_token_required
539
+ def get(endpoint_path, headers = {})
540
+ headers = Line::Bot::API::DEFAULT_HEADERS.merge(headers)
541
+ httpclient.get(endpoint + endpoint_path, headers)
542
+ end
553
543
 
554
- request = Request.new do |config|
555
- config.httpclient = httpclient
556
- config.endpoint = endpoint
557
- config.endpoint_path = endpoint_path
558
- config.credentials = credentials
559
- end
544
+ # Post data, get content of specified URL.
545
+ #
546
+ # @param endpoint_path [String]
547
+ # @param payload [String or NilClass]
548
+ # @param headers [Hash]
549
+ #
550
+ # @return [Net::HTTPResponse]
551
+ def post(endpoint_path, payload = nil, headers = {})
552
+ headers = Line::Bot::API::DEFAULT_HEADERS.merge(headers)
553
+ httpclient.post(endpoint + endpoint_path, payload, headers)
554
+ end
560
555
 
561
- request.delete
556
+ # Delete content of specified URL.
557
+ #
558
+ # @param endpoint_path [String]
559
+ # @param headers [Hash]
560
+ #
561
+ # @return [Net::HTTPResponse]
562
+ def delete(endpoint_path, headers = {})
563
+ headers = Line::Bot::API::DEFAULT_HEADERS.merge(headers)
564
+ httpclient.delete(endpoint + endpoint_path, headers)
562
565
  end
563
566
 
564
567
  # Parse events from request.body
@@ -18,6 +18,7 @@ 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
 
@@ -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'
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.11.0
4
+ version: 1.12.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: 2019-06-04 00:00:00.000000000 Z
11
+ date: 2019-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -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
@@ -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