line-bot-api 1.12.0 → 1.16.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: ec352e50cd2b13df2d2c4d0f14ae9f6d3346c33358f343ae43448a1d489a3203
4
- data.tar.gz: 26e0c32ab9671267628fe4749ae039558409a4087f991869e310e293276ff386
3
+ metadata.gz: a645b77594506a826cd1009e65bed3f4af60674579d3d23403ca32136cd697f7
4
+ data.tar.gz: cdeee7ee13ce1c099342573e4514b57e49cb08dd1f8835a609a22c9f8810a52d
5
5
  SHA512:
6
- metadata.gz: 1b924857b1fa6732824b648aebc131885e1638aba7e4f28beb281e1c402b74260727c9a1700ed8174fc6f312bad38eeef6e5bcf4be6bdd908f6a2e0d04df8f26
7
- data.tar.gz: e513999b3e4d52985efd98fcdcca98bbd45c48602f28911d49518a341b5ceeeee0ed8e1326d862f1ee51c1bfb93a51860b938cfec5b059277ca6a6da7e7d0a65
6
+ metadata.gz: f83a596fc0a844e0d4e237e197e00c8afba3c7cfc39f136897b78645cac659b87cd3103c701227ccaeffdac692af2f9a89e9250b3cc3d97c9c460078ae629c42
7
+ data.tar.gz: 26f4b4ba5a7b23afb4da95bdbf3a3d4b5dd5e31e7ebfe919046944fae1ceed5c3c66e011fe3609bce511ad2523bd2721a78f30afc1a9e3021ac710723b5426ae
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:
@@ -18,10 +18,11 @@ module Line
18
18
  module Bot
19
19
  module API
20
20
  DEFAULT_ENDPOINT = "https://api.line.me/v2"
21
+ DEFAULT_BLOB_ENDPOINT = "https://api-data.line.me/v2"
21
22
 
22
23
  DEFAULT_HEADERS = {
23
24
  'Content-Type' => 'application/json; charset=UTF-8',
24
- 'User-Agent' => "LINE-BotSDK-Ruby/#{Line::Bot::API::VERSION}"
25
+ 'User-Agent' => "LINE-BotSDK-Ruby/#{VERSION}"
25
26
  }.freeze
26
27
  end
27
28
  end
@@ -15,7 +15,7 @@
15
15
  module Line
16
16
  module Bot
17
17
  module API
18
- VERSION = "1.12.0"
18
+ VERSION = "1.16.0"
19
19
  end
20
20
  end
21
21
  end
@@ -19,9 +19,16 @@ require 'uri'
19
19
 
20
20
  module Line
21
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
22
29
  class Client
23
30
  # @return [String]
24
- attr_accessor :channel_token, :channel_id, :channel_secret, :endpoint
31
+ attr_accessor :channel_token, :channel_id, :channel_secret, :endpoint, :blob_endpoint
25
32
 
26
33
  # @return [Object]
27
34
  attr_accessor :httpclient
@@ -29,10 +36,9 @@ module Line
29
36
  # @return [Hash]
30
37
  attr_accessor :http_options
31
38
 
32
- # Initialize a new Bot Client.
39
+ # Initialize a new client.
33
40
  #
34
41
  # @param options [Hash]
35
- #
36
42
  # @return [Line::Bot::Client]
37
43
  def initialize(options = {})
38
44
  options.each do |key, value|
@@ -42,11 +48,22 @@ module Line
42
48
  end
43
49
 
44
50
  def httpclient
45
- @httpclient ||= Line::Bot::HTTPClient.new(http_options)
51
+ @httpclient ||= HTTPClient.new(http_options)
46
52
  end
47
53
 
48
54
  def endpoint
49
- @endpoint ||= Line::Bot::API::DEFAULT_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
50
67
  end
51
68
 
52
69
  # @return [Hash]
@@ -72,7 +89,7 @@ module Line
72
89
  client_secret: channel_secret
73
90
  )
74
91
  headers = { 'Content-Type' => 'application/x-www-form-urlencoded' }
75
- post(endpoint_path, payload, headers)
92
+ post(endpoint, endpoint_path, payload, headers)
76
93
  end
77
94
 
78
95
  # Revoke channel access token
@@ -82,30 +99,44 @@ module Line
82
99
  endpoint_path = '/oauth/revoke'
83
100
  payload = URI.encode_www_form(access_token: access_token)
84
101
  headers = { 'Content-Type' => 'application/x-www-form-urlencoded' }
85
- post(endpoint_path, payload, headers)
102
+ post(endpoint, endpoint_path, payload, headers)
86
103
  end
87
104
 
88
- # Push messages to line server and to user.
89
- #
90
- # @param user_id [String] User's identifiers
91
- # @param messages [Hash or Array]
105
+ # Push messages to a user using user_id.
92
106
  #
107
+ # @param user_id [String] User Id
108
+ # @param messages [Hash or Array] Message Objects
109
+ # @param headers [Hash] HTTP Headers
93
110
  # @return [Net::HTTPResponse]
94
- def push_message(user_id, messages)
111
+ def push_message(user_id, messages, headers: {})
95
112
  channel_token_required
96
113
 
97
114
  messages = [messages] if messages.is_a?(Hash)
98
115
 
99
116
  endpoint_path = '/bot/message/push'
100
117
  payload = { to: user_id, messages: messages }.to_json
101
- post(endpoint_path, payload, credentials)
118
+ post(endpoint, endpoint_path, payload, credentials.merge(headers))
102
119
  end
103
120
 
104
- # Reply messages to line server and to users.
121
+ # Reply messages to a user using replyToken.
105
122
  #
106
- # @param token [String]
107
- # @param messages [Hash or Array]
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)
129
+ #
130
+ # @example Send multiple balloons to a user.
108
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
109
140
  # @return [Net::HTTPResponse]
110
141
  def reply_message(token, messages)
111
142
  channel_token_required
@@ -114,16 +145,16 @@ module Line
114
145
 
115
146
  endpoint_path = '/bot/message/reply'
116
147
  payload = { replyToken: token, messages: messages }.to_json
117
- post(endpoint_path, payload, credentials)
148
+ post(endpoint, endpoint_path, payload, credentials)
118
149
  end
119
150
 
120
- # Multicast messages to line server and to users.
121
- #
122
- # @param to [Array or String]
123
- # @param messages [Hash or Array]
151
+ # Send messages to multiple users using userIds.
124
152
  #
153
+ # @param to [Array or String] Array of userIds
154
+ # @param messages [Hash or Array] Message Objects
155
+ # @param headers [Hash] HTTP Headers
125
156
  # @return [Net::HTTPResponse]
126
- def multicast(to, messages)
157
+ def multicast(to, messages, headers: {})
127
158
  channel_token_required
128
159
 
129
160
  to = [to] if to.is_a?(String)
@@ -131,86 +162,112 @@ module Line
131
162
 
132
163
  endpoint_path = '/bot/message/multicast'
133
164
  payload = { to: to, messages: messages }.to_json
134
- post(endpoint_path, payload, credentials)
165
+ post(endpoint, endpoint_path, payload, credentials.merge(headers))
135
166
  end
136
167
 
137
- # Broadcast messages to users
168
+ # Send messages to all friends.
138
169
  #
139
- # @param messages [Hash or Array]
170
+ # @param messages [Hash or Array] Message Objects
171
+ # @param headers [Hash] HTTP Headers
140
172
  #
141
173
  # @return [Net::HTTPResponse]
142
- def broadcast(messages)
174
+ def broadcast(messages, headers: {})
143
175
  channel_token_required
144
176
 
145
177
  messages = [messages] if messages.is_a?(Hash)
146
178
 
147
179
  endpoint_path = '/bot/message/broadcast'
148
180
  payload = { messages: messages }.to_json
149
- post(endpoint_path, payload, credentials)
181
+ post(endpoint, endpoint_path, payload, credentials.merge(headers))
182
+ end
183
+
184
+ # Narrowcast messages to users
185
+ #
186
+ # API Documentation is here.
187
+ # https://developers.line.biz/en/reference/messaging-api/#send-narrowcast-message
188
+ #
189
+ # @param messages [Hash or Array]
190
+ # @param recipient [Hash]
191
+ # @param filter [Hash]
192
+ # @param limit [Hash]
193
+ # @param headers [Hash] HTTP Headers
194
+ #
195
+ # @return [Net::HTTPResponse]
196
+ def narrowcast(messages, recipient: nil, filter: nil, limit: nil, headers: {})
197
+ channel_token_required
198
+
199
+ messages = [messages] if messages.is_a?(Hash)
200
+
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))
150
209
  end
151
210
 
152
211
  def leave_group(group_id)
153
212
  channel_token_required
154
213
 
155
214
  endpoint_path = "/bot/group/#{group_id}/leave"
156
- post(endpoint_path, nil, credentials)
215
+ post(endpoint, endpoint_path, nil, credentials)
157
216
  end
158
217
 
159
218
  def leave_room(room_id)
160
219
  channel_token_required
161
220
 
162
221
  endpoint_path = "/bot/room/#{room_id}/leave"
163
- post(endpoint_path, nil, credentials)
222
+ post(endpoint, endpoint_path, nil, credentials)
164
223
  end
165
224
 
166
225
  # Get message content.
167
226
  #
168
227
  # @param identifier [String] Message's identifier
169
- #
170
228
  # @return [Net::HTTPResponse]
171
229
  def get_message_content(identifier)
172
230
  channel_token_required
173
231
 
174
232
  endpoint_path = "/bot/message/#{identifier}/content"
175
- get(endpoint_path, credentials)
233
+ get(blob_endpoint, endpoint_path, credentials)
176
234
  end
177
235
 
178
236
  # Get an user's profile.
179
237
  #
180
- # @param user_id [String] User's identifier
181
- #
238
+ # @param user_id [String] User Id user_id
182
239
  # @return [Net::HTTPResponse]
183
240
  def get_profile(user_id)
184
241
  channel_token_required
185
242
 
186
243
  endpoint_path = "/bot/profile/#{user_id}"
187
- get(endpoint_path, credentials)
244
+ get(endpoint, endpoint_path, credentials)
188
245
  end
189
246
 
190
247
  # Get an user's profile of a group.
191
248
  #
192
249
  # @param group_id [String] Group's identifier
193
- # @param user_id [String] User's identifier
250
+ # @param user_id [String] User Id user_id
194
251
  #
195
252
  # @return [Net::HTTPResponse]
196
253
  def get_group_member_profile(group_id, user_id)
197
254
  channel_token_required
198
255
 
199
256
  endpoint_path = "/bot/group/#{group_id}/member/#{user_id}"
200
- get(endpoint_path, credentials)
257
+ get(endpoint, endpoint_path, credentials)
201
258
  end
202
259
 
203
260
  # Get an user's profile of a room.
204
261
  #
205
262
  # @param room_id [String] Room's identifier
206
- # @param user_id [String] User's identifier
263
+ # @param user_id [String] User Id user_id
207
264
  #
208
265
  # @return [Net::HTTPResponse]
209
266
  def get_room_member_profile(room_id, user_id)
210
267
  channel_token_required
211
268
 
212
269
  endpoint_path = "/bot/room/#{room_id}/member/#{user_id}"
213
- get(endpoint_path, credentials)
270
+ get(endpoint, endpoint_path, credentials)
214
271
  end
215
272
 
216
273
  # Get user IDs of a group
@@ -225,12 +282,12 @@ module Line
225
282
 
226
283
  endpoint_path = "/bot/group/#{group_id}/members/ids"
227
284
  endpoint_path += "?start=#{continuation_token}" if continuation_token
228
- get(endpoint_path, credentials)
285
+ get(endpoint, endpoint_path, credentials)
229
286
  end
230
287
 
231
288
  # Get user IDs of a room
232
289
  #
233
- # @param group_id [String] Room's identifier
290
+ # @param room_id [String] Room's identifier
234
291
  # @param continuation_token [String] Identifier to return next page
235
292
  # (next property to be included in the response)
236
293
  #
@@ -240,7 +297,43 @@ module Line
240
297
 
241
298
  endpoint_path = "/bot/room/#{room_id}/members/ids"
242
299
  endpoint_path += "?start=#{continuation_token}" if continuation_token
243
- get(endpoint_path, credentials)
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)
244
337
  end
245
338
 
246
339
  # Get a list of all uploaded rich menus
@@ -250,7 +343,7 @@ module Line
250
343
  channel_token_required
251
344
 
252
345
  endpoint_path = '/bot/richmenu/list'
253
- get(endpoint_path, credentials)
346
+ get(endpoint, endpoint_path, credentials)
254
347
  end
255
348
 
256
349
  # Get a rich menu via a rich menu ID
@@ -262,7 +355,7 @@ module Line
262
355
  channel_token_required
263
356
 
264
357
  endpoint_path = "/bot/richmenu/#{rich_menu_id}"
265
- get(endpoint_path, credentials)
358
+ get(endpoint, endpoint_path, credentials)
266
359
  end
267
360
 
268
361
  # Gets the number of messages sent with the /bot/message/reply endpoint.
@@ -274,7 +367,7 @@ module Line
274
367
  channel_token_required
275
368
 
276
369
  endpoint_path = "/bot/message/delivery/reply?date=#{date}"
277
- get(endpoint_path, credentials)
370
+ get(endpoint, endpoint_path, credentials)
278
371
  end
279
372
 
280
373
  # Gets the number of messages sent with the /bot/message/push endpoint.
@@ -286,7 +379,7 @@ module Line
286
379
  channel_token_required
287
380
 
288
381
  endpoint_path = "/bot/message/delivery/push?date=#{date}"
289
- get(endpoint_path, credentials)
382
+ get(endpoint, endpoint_path, credentials)
290
383
  end
291
384
 
292
385
  # Gets the number of messages sent with the /bot/message/multicast endpoint.
@@ -298,7 +391,7 @@ module Line
298
391
  channel_token_required
299
392
 
300
393
  endpoint_path = "/bot/message/delivery/multicast?date=#{date}"
301
- get(endpoint_path, credentials)
394
+ get(endpoint, endpoint_path, credentials)
302
395
  end
303
396
 
304
397
  # Gets the number of messages sent with the /bot/message/multicast endpoint.
@@ -310,7 +403,7 @@ module Line
310
403
  channel_token_required
311
404
 
312
405
  endpoint_path = "/bot/message/delivery/broadcast?date=#{date}"
313
- get(endpoint_path, credentials)
406
+ get(endpoint, endpoint_path, credentials)
314
407
  end
315
408
 
316
409
  # Create a rich menu
@@ -322,7 +415,7 @@ module Line
322
415
  channel_token_required
323
416
 
324
417
  endpoint_path = '/bot/richmenu'
325
- post(endpoint_path, rich_menu.to_json, credentials)
418
+ post(endpoint, endpoint_path, rich_menu.to_json, credentials)
326
419
  end
327
420
 
328
421
  # Delete a rich menu
@@ -334,7 +427,7 @@ module Line
334
427
  channel_token_required
335
428
 
336
429
  endpoint_path = "/bot/richmenu/#{rich_menu_id}"
337
- delete(endpoint_path, credentials)
430
+ delete(endpoint, endpoint_path, credentials)
338
431
  end
339
432
 
340
433
  # Get the ID of the rich menu linked to a user
@@ -346,7 +439,7 @@ module Line
346
439
  channel_token_required
347
440
 
348
441
  endpoint_path = "/bot/user/#{user_id}/richmenu"
349
- get(endpoint_path, credentials)
442
+ get(endpoint, endpoint_path, credentials)
350
443
  end
351
444
 
352
445
  # Get default rich menu
@@ -356,7 +449,7 @@ module Line
356
449
  channel_token_required
357
450
 
358
451
  endpoint_path = '/bot/user/all/richmenu'
359
- get(endpoint_path, credentials)
452
+ get(endpoint, endpoint_path, credentials)
360
453
  end
361
454
 
362
455
  # Set default rich menu (Link a rich menu to all user)
@@ -368,7 +461,7 @@ module Line
368
461
  channel_token_required
369
462
 
370
463
  endpoint_path = "/bot/user/all/richmenu/#{rich_menu_id}"
371
- post(endpoint_path, nil, credentials)
464
+ post(endpoint, endpoint_path, nil, credentials)
372
465
  end
373
466
 
374
467
  # Unset default rich menu (Unlink a rich menu from all user)
@@ -378,11 +471,14 @@ module Line
378
471
  channel_token_required
379
472
 
380
473
  endpoint_path = "/bot/user/all/richmenu"
381
- delete(endpoint_path, credentials)
474
+ delete(endpoint, endpoint_path, credentials)
382
475
  end
383
476
 
384
477
  # Link a rich menu to a user
385
478
  #
479
+ # If you want to link a rich menu to multiple users,
480
+ # please consider to use bulk_link_rich_menus.
481
+ #
386
482
  # @param user_id [String] ID of the user
387
483
  # @param rich_menu_id [String] ID of an uploaded rich menu
388
484
  #
@@ -391,7 +487,7 @@ module Line
391
487
  channel_token_required
392
488
 
393
489
  endpoint_path = "/bot/user/#{user_id}/richmenu/#{rich_menu_id}"
394
- post(endpoint_path, nil, credentials)
490
+ post(endpoint, endpoint_path, nil, credentials)
395
491
  end
396
492
 
397
493
  # Unlink a rich menu from a user
@@ -403,7 +499,7 @@ module Line
403
499
  channel_token_required
404
500
 
405
501
  endpoint_path = "/bot/user/#{user_id}/richmenu"
406
- delete(endpoint_path, credentials)
502
+ delete(endpoint, endpoint_path, credentials)
407
503
  end
408
504
 
409
505
  # To link a rich menu to multiple users at a time
@@ -416,7 +512,7 @@ module Line
416
512
  channel_token_required
417
513
 
418
514
  endpoint_path = "/bot/richmenu/bulk/link"
419
- post(endpoint_path, { richMenuId: rich_menu_id, userIds: user_ids }.to_json, credentials)
515
+ post(endpoint, endpoint_path, { richMenuId: rich_menu_id, userIds: user_ids }.to_json, credentials)
420
516
  end
421
517
 
422
518
  # To unlink a rich menu from multiple users at a time
@@ -428,7 +524,7 @@ module Line
428
524
  channel_token_required
429
525
 
430
526
  endpoint_path = "/bot/richmenu/bulk/unlink"
431
- post(endpoint_path, { userIds: user_ids }.to_json, credentials)
527
+ post(endpoint, endpoint_path, { userIds: user_ids }.to_json, credentials)
432
528
  end
433
529
 
434
530
  # Download an image associated with a rich menu
@@ -440,7 +536,7 @@ module Line
440
536
  channel_token_required
441
537
 
442
538
  endpoint_path = "/bot/richmenu/#{rich_menu_id}/content"
443
- get(endpoint_path, credentials)
539
+ get(blob_endpoint, endpoint_path, credentials)
444
540
  end
445
541
 
446
542
  # Upload and attaches an image to a rich menu
@@ -452,16 +548,9 @@ module Line
452
548
  def create_rich_menu_image(rich_menu_id, file)
453
549
  channel_token_required
454
550
 
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
551
  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)
552
+ headers = credentials.merge('Content-Type' => content_type(file))
553
+ post(blob_endpoint, endpoint_path, file.rewind && file.read, headers)
465
554
  end
466
555
 
467
556
  # Issue a link token to a user
@@ -473,7 +562,7 @@ module Line
473
562
  channel_token_required
474
563
 
475
564
  endpoint_path = "/bot/user/#{user_id}/linkToken"
476
- post(endpoint_path, nil, credentials)
565
+ post(endpoint, endpoint_path, nil, credentials)
477
566
  end
478
567
 
479
568
  # Get the target limit for additional messages
@@ -483,7 +572,7 @@ module Line
483
572
  channel_token_required
484
573
 
485
574
  endpoint_path = "/bot/message/quota"
486
- get(endpoint_path, credentials)
575
+ get(endpoint, endpoint_path, credentials)
487
576
  end
488
577
 
489
578
  # Get number of messages sent this month
@@ -493,7 +582,7 @@ module Line
493
582
  channel_token_required
494
583
 
495
584
  endpoint_path = "/bot/message/quota/consumption"
496
- get(endpoint_path, credentials)
585
+ get(endpoint, endpoint_path, credentials)
497
586
  end
498
587
 
499
588
  # Returns the number of messages sent on a specified day
@@ -505,7 +594,19 @@ module Line
505
594
  channel_token_required
506
595
 
507
596
  endpoint_path = "/bot/insight/message/delivery?date=#{date}"
508
- get(endpoint_path, credentials)
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
607
+
608
+ endpoint_path = "/bot/insight/message/event?requestId=#{request_id}"
609
+ get(endpoint, endpoint_path, credentials)
509
610
  end
510
611
 
511
612
  # Returns the number of followers
@@ -517,51 +618,54 @@ module Line
517
618
  channel_token_required
518
619
 
519
620
  endpoint_path = "/bot/insight/followers?date=#{date}"
520
- get(endpoint_path, credentials)
621
+ get(endpoint, endpoint_path, credentials)
521
622
  end
522
623
 
523
- # Retrieves the demographic attributes for a bot's friends.
624
+ # Get the demographic attributes for a bot's friends.
524
625
  #
525
626
  # @return [Net::HTTPResponse]
526
627
  def get_friend_demographics
527
628
  channel_token_required
528
629
 
529
630
  endpoint_path = '/bot/insight/demographic'
530
- get(endpoint_path, credentials)
631
+ get(endpoint, endpoint_path, credentials)
531
632
  end
532
633
 
533
634
  # Fetch data, get content of specified URL.
534
635
  #
636
+ # @param endpoint_base [String]
535
637
  # @param endpoint_path [String]
536
638
  # @param headers [Hash]
537
639
  #
538
640
  # @return [Net::HTTPResponse]
539
- def get(endpoint_path, headers = {})
540
- headers = Line::Bot::API::DEFAULT_HEADERS.merge(headers)
541
- httpclient.get(endpoint + endpoint_path, headers)
641
+ def get(endpoint_base, endpoint_path, headers = {})
642
+ headers = API::DEFAULT_HEADERS.merge(headers)
643
+ httpclient.get(endpoint_base + endpoint_path, headers)
542
644
  end
543
645
 
544
646
  # Post data, get content of specified URL.
545
647
  #
648
+ # @param endpoint_base [String]
546
649
  # @param endpoint_path [String]
547
650
  # @param payload [String or NilClass]
548
651
  # @param headers [Hash]
549
652
  #
550
653
  # @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)
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)
554
657
  end
555
658
 
556
659
  # Delete content of specified URL.
557
660
  #
661
+ # @param endpoint_base [String]
558
662
  # @param endpoint_path [String]
559
663
  # @param headers [Hash]
560
664
  #
561
665
  # @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)
666
+ def delete(endpoint_base, endpoint_path, headers = {})
667
+ headers = API::DEFAULT_HEADERS.merge(headers)
668
+ httpclient.delete(endpoint_base + endpoint_path, headers)
565
669
  end
566
670
 
567
671
  # Parse events from request.body
@@ -574,15 +678,17 @@ module Line
574
678
 
575
679
  json['events'].map do |item|
576
680
  begin
577
- klass = Line::Bot::Event.const_get(Line::Bot::Util.camelize(item['type']))
681
+ klass = Event.const_get(Util.camelize(item['type']))
578
682
  klass.new(item)
579
683
  rescue NameError
580
- Line::Bot::Event::Base.new(item)
684
+ Event::Base.new(item)
581
685
  end
582
686
  end
583
687
  end
584
688
 
585
- # Validate signature
689
+ # Validate signature of a webhook event.
690
+ #
691
+ # https://developers.line.biz/en/reference/messaging-api/#signature-validation
586
692
  #
587
693
  # @param content [String] Request's body
588
694
  # @param channel_signature [String] Request'header 'X-LINE-Signature' # HTTP_X_LINE_SIGNATURE
@@ -619,6 +725,21 @@ module Line
619
725
  res == 0
620
726
  end
621
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
+
622
743
  def channel_token_required
623
744
  raise ArgumentError, '`channel_token` is not configured' unless channel_token
624
745
  end
@@ -21,6 +21,8 @@ require 'line/bot/event/leave'
21
21
  require 'line/bot/event/message'
22
22
  require 'line/bot/event/postback'
23
23
  require 'line/bot/event/unfollow'
24
+ require 'line/bot/event/unsend'
24
25
  require 'line/bot/event/member_joined'
25
26
  require 'line/bot/event/member_left'
26
27
  require 'line/bot/event/things'
28
+ require 'line/bot/event/video_play_complete'
@@ -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
@@ -15,6 +15,9 @@
15
15
  module Line
16
16
  module Bot
17
17
  module Event
18
+ # Event object for when your LINE official account joins a group or room.
19
+ #
20
+ # https://developers.line.biz/en/reference/messaging-api/#join-event
18
21
  class Join < 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 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
- Line::Bot::Event::MessageType.const_get(@src['message']['type'].capitalize)
34
+ MessageType.const_get(@src['message']['type'].capitalize)
32
35
  rescue NameError => e
33
- Line::Bot::Event::MessageType::Unsupport
36
+ MessageType::Unsupport
34
37
  end
35
38
 
36
39
  def message
@@ -15,6 +15,9 @@
15
15
  module Line
16
16
  module Bot
17
17
  module Event
18
+ # Event object for when a user performs a postback action which initiates a postback.
19
+ #
20
+ # https://developers.line.biz/en/reference/messaging-api/#postback-event
18
21
  class Postback < Base
19
22
  end
20
23
  end
@@ -22,11 +22,16 @@ module Line
22
22
  Unsupport = 'unsupport'
23
23
  end
24
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
25
30
  class Things < Base
26
31
  def type
27
- Line::Bot::Event::ThingsType.const_get(Line::Bot::Util.camelize(@src['things']['type']))
32
+ ThingsType.const_get(Util.camelize(@src['things']['type']))
28
33
  rescue NameError
29
- Line::Bot::Event::ThingsType::Unsupport
34
+ ThingsType::Unsupport
30
35
  end
31
36
 
32
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
@@ -0,0 +1,27 @@
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
+ module Line
16
+ module Bot
17
+ module Event
18
+ # Event object for when the user unsends a message in a group or room.
19
+ #
20
+ # No replyToken is generated for this event.
21
+ #
22
+ # https://developers.line.biz/en/reference/messaging-api/#unsend-event
23
+ class Unsend < Base
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,25 @@
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
+ module Line
16
+ module Bot
17
+ module Event
18
+ # Event for when a user finishes viewing a video at least once with the specified trackingId sent by the LINE Official Account.
19
+ #
20
+ # https://developers.line.biz/en/reference/messaging-api/#video-viewing-complete
21
+ class VideoPlayComplete < Base
22
+ end
23
+ end
24
+ end
25
+ end
@@ -19,7 +19,7 @@ require 'uri'
19
19
  module Line
20
20
  module Bot
21
21
  class HTTPClient
22
- # @return [Hash]
22
+ # @return [Hash]
23
23
  attr_accessor :http_options
24
24
 
25
25
  # Initialize a new HTTPClient
@@ -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', "~> 10.4"
24
+ spec.add_development_dependency 'rake', "~> 13.0"
25
25
  spec.add_development_dependency "rspec", "~> 3.0"
26
- spec.add_development_dependency "webmock", "~> 1.24"
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.12.0
4
+ version: 1.16.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-07-16 00:00:00.000000000 Z
11
+ date: 2020-08-13 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: '10.4'
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: '10.4'
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: '1.24'
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: '1.24'
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
@@ -97,6 +97,8 @@ files:
97
97
  - lib/line/bot/event/postback.rb
98
98
  - lib/line/bot/event/things.rb
99
99
  - lib/line/bot/event/unfollow.rb
100
+ - lib/line/bot/event/unsend.rb
101
+ - lib/line/bot/event/video_play_complete.rb
100
102
  - lib/line/bot/httpclient.rb
101
103
  - lib/line/bot/util.rb
102
104
  - line-bot-api.gemspec
@@ -119,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
121
  - !ruby/object:Gem::Version
120
122
  version: '0'
121
123
  requirements: []
122
- rubygems_version: 3.0.3
124
+ rubygems_version: 3.1.2
123
125
  signing_key:
124
126
  specification_version: 4
125
127
  summary: SDK of the LINE Messaging API