line-bot-api 1.13.0 → 1.17.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf4665d3f64bd345493bbd462ff4a69f14089803a0ccbfa2af4a33ddba6dde87
4
- data.tar.gz: ff297dbf91d2f862384a4e56a44496f28e6639dc90be48dffcd1f5e026195dea
3
+ metadata.gz: e837c0acd52ebd33855c78b8708ad54ab2837dc76576bb386bbe4861eeae20e3
4
+ data.tar.gz: 9e175c41953a8603f0a1b0e35285160fe2ed63cf028296a94272a6d65dac4a9f
5
5
  SHA512:
6
- metadata.gz: 6a15e26e9071d289cbf00238cc4e15a50923db911a538f2756be9503f800a53ed8518da5435717f49b714d0c2a44b51be67a5ab2a0ff16405c5e2583483f20d3
7
- data.tar.gz: e282f0efc0ffa2ae259de6ebdcb9cd7b9a650dad7d979ceaf13c8bdff4056695207850e7ed8195d03065509eabe9b712ebcfb62fbfc0b77ae40dd49ffc5170ed
6
+ metadata.gz: 303b7cd0c88d07dd31fa5d4ee3d0784ba7999fb4677bd9bf3a801adad54d8926e0697ae87dc0a457593849fba0d30e2ddbeb4eba647adac5974115ad81a56b58
7
+ data.tar.gz: 1ddbcb86b9737d3d7b106489768fa9f1af38608a5eda8d0c59dd7713da4ba6a41e675677b99e26f8f6060be09e24df36a3e24bea721b2faad9d44e4ef38b144f
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:
@@ -19,10 +19,11 @@ module Line
19
19
  module API
20
20
  DEFAULT_ENDPOINT = "https://api.line.me/v2"
21
21
  DEFAULT_BLOB_ENDPOINT = "https://api-data.line.me/v2"
22
+ DEFAULT_LIFF_ENDPOINT = "https://api.line.me/liff/v1"
22
23
 
23
24
  DEFAULT_HEADERS = {
24
25
  'Content-Type' => 'application/json; charset=UTF-8',
25
- 'User-Agent' => "LINE-BotSDK-Ruby/#{Line::Bot::API::VERSION}"
26
+ 'User-Agent' => "LINE-BotSDK-Ruby/#{VERSION}"
26
27
  }.freeze
27
28
  end
28
29
  end
@@ -15,7 +15,7 @@
15
15
  module Line
16
16
  module Bot
17
17
  module API
18
- VERSION = "1.13.0"
18
+ VERSION = "1.17.0"
19
19
  end
20
20
  end
21
21
  end
@@ -19,6 +19,13 @@ 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
31
  attr_accessor :channel_token, :channel_id, :channel_secret, :endpoint, :blob_endpoint
@@ -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,24 +48,28 @@ 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
50
56
  end
51
57
 
52
58
  def blob_endpoint
53
59
  return @blob_endpoint if @blob_endpoint
54
60
 
55
- @blob_endpoint = if endpoint == Line::Bot::API::DEFAULT_ENDPOINT
56
- Line::Bot::API::DEFAULT_BLOB_ENDPOINT
61
+ @blob_endpoint = if endpoint == API::DEFAULT_ENDPOINT
62
+ API::DEFAULT_BLOB_ENDPOINT
57
63
  else
58
64
  # for backward compatible
59
65
  endpoint
60
66
  end
61
67
  end
62
68
 
69
+ def liff_endpoint
70
+ @liff_endpoint ||= API::DEFAULT_LIFF_ENDPOINT
71
+ end
72
+
63
73
  # @return [Hash]
64
74
  def credentials
65
75
  {
@@ -96,27 +106,41 @@ module Line
96
106
  post(endpoint, endpoint_path, payload, headers)
97
107
  end
98
108
 
99
- # Push messages to line server and to user.
100
- #
101
- # @param user_id [String] User's identifiers
102
- # @param messages [Hash or Array]
109
+ # Push messages to a user using user_id.
103
110
  #
111
+ # @param user_id [String] User Id
112
+ # @param messages [Hash or Array] Message Objects
113
+ # @param headers [Hash] HTTP Headers
104
114
  # @return [Net::HTTPResponse]
105
- def push_message(user_id, messages)
115
+ def push_message(user_id, messages, headers: {})
106
116
  channel_token_required
107
117
 
108
118
  messages = [messages] if messages.is_a?(Hash)
109
119
 
110
120
  endpoint_path = '/bot/message/push'
111
121
  payload = { to: user_id, messages: messages }.to_json
112
- post(endpoint, endpoint_path, payload, credentials)
122
+ post(endpoint, endpoint_path, payload, credentials.merge(headers))
113
123
  end
114
124
 
115
- # Reply messages to line server and to users.
125
+ # Reply messages to a user using replyToken.
116
126
  #
117
- # @param token [String]
118
- # @param messages [Hash or Array]
127
+ # @example Send a balloon to a user.
128
+ # message = {
129
+ # type: 'text',
130
+ # text: 'Hello, World!'
131
+ # }
132
+ # client.reply_message(event['replyToken'], message)
133
+ #
134
+ # @example Send multiple balloons to a user.
135
+ #
136
+ # messages = [
137
+ # {type: 'text', text: 'Message1'},
138
+ # {type: 'text', text: 'Message2'}
139
+ # ]
140
+ # client.reply_message(event['replyToken'], messages)
119
141
  #
142
+ # @param token [String] Reply Token
143
+ # @param messages [Hash or Array] Message Objects
120
144
  # @return [Net::HTTPResponse]
121
145
  def reply_message(token, messages)
122
146
  channel_token_required
@@ -128,13 +152,13 @@ module Line
128
152
  post(endpoint, endpoint_path, payload, credentials)
129
153
  end
130
154
 
131
- # Multicast messages to line server and to users.
132
- #
133
- # @param to [Array or String]
134
- # @param messages [Hash or Array]
155
+ # Send messages to multiple users using userIds.
135
156
  #
157
+ # @param to [Array or String] Array of userIds
158
+ # @param messages [Hash or Array] Message Objects
159
+ # @param headers [Hash] HTTP Headers
136
160
  # @return [Net::HTTPResponse]
137
- def multicast(to, messages)
161
+ def multicast(to, messages, headers: {})
138
162
  channel_token_required
139
163
 
140
164
  to = [to] if to.is_a?(String)
@@ -142,22 +166,50 @@ module Line
142
166
 
143
167
  endpoint_path = '/bot/message/multicast'
144
168
  payload = { to: to, messages: messages }.to_json
145
- post(endpoint, endpoint_path, payload, credentials)
169
+ post(endpoint, endpoint_path, payload, credentials.merge(headers))
146
170
  end
147
171
 
148
- # Broadcast messages to users
172
+ # Send messages to all friends.
149
173
  #
150
- # @param messages [Hash or Array]
174
+ # @param messages [Hash or Array] Message Objects
175
+ # @param headers [Hash] HTTP Headers
151
176
  #
152
177
  # @return [Net::HTTPResponse]
153
- def broadcast(messages)
178
+ def broadcast(messages, headers: {})
154
179
  channel_token_required
155
180
 
156
181
  messages = [messages] if messages.is_a?(Hash)
157
182
 
158
183
  endpoint_path = '/bot/message/broadcast'
159
184
  payload = { messages: messages }.to_json
160
- post(endpoint, endpoint_path, payload, credentials)
185
+ post(endpoint, endpoint_path, payload, credentials.merge(headers))
186
+ end
187
+
188
+ # Narrowcast messages to users
189
+ #
190
+ # API Documentation is here.
191
+ # https://developers.line.biz/en/reference/messaging-api/#send-narrowcast-message
192
+ #
193
+ # @param messages [Hash or Array]
194
+ # @param recipient [Hash]
195
+ # @param filter [Hash]
196
+ # @param limit [Hash]
197
+ # @param headers [Hash] HTTP Headers
198
+ #
199
+ # @return [Net::HTTPResponse]
200
+ def narrowcast(messages, recipient: nil, filter: nil, limit: nil, headers: {})
201
+ channel_token_required
202
+
203
+ messages = [messages] if messages.is_a?(Hash)
204
+
205
+ endpoint_path = '/bot/message/narrowcast'
206
+ payload = {
207
+ messages: messages,
208
+ recipient: recipient,
209
+ filter: filter,
210
+ limit: limit
211
+ }.to_json
212
+ post(endpoint, endpoint_path, payload, credentials.merge(headers))
161
213
  end
162
214
 
163
215
  def leave_group(group_id)
@@ -177,7 +229,6 @@ module Line
177
229
  # Get message content.
178
230
  #
179
231
  # @param identifier [String] Message's identifier
180
- #
181
232
  # @return [Net::HTTPResponse]
182
233
  def get_message_content(identifier)
183
234
  channel_token_required
@@ -188,8 +239,7 @@ module Line
188
239
 
189
240
  # Get an user's profile.
190
241
  #
191
- # @param user_id [String] User's identifier
192
- #
242
+ # @param user_id [String] User Id user_id
193
243
  # @return [Net::HTTPResponse]
194
244
  def get_profile(user_id)
195
245
  channel_token_required
@@ -201,7 +251,7 @@ module Line
201
251
  # Get an user's profile of a group.
202
252
  #
203
253
  # @param group_id [String] Group's identifier
204
- # @param user_id [String] User's identifier
254
+ # @param user_id [String] User Id user_id
205
255
  #
206
256
  # @return [Net::HTTPResponse]
207
257
  def get_group_member_profile(group_id, user_id)
@@ -214,7 +264,7 @@ module Line
214
264
  # Get an user's profile of a room.
215
265
  #
216
266
  # @param room_id [String] Room's identifier
217
- # @param user_id [String] User's identifier
267
+ # @param user_id [String] User Id user_id
218
268
  #
219
269
  # @return [Net::HTTPResponse]
220
270
  def get_room_member_profile(room_id, user_id)
@@ -241,7 +291,7 @@ module Line
241
291
 
242
292
  # Get user IDs of a room
243
293
  #
244
- # @param group_id [String] Room's identifier
294
+ # @param room_id [String] Room's identifier
245
295
  # @param continuation_token [String] Identifier to return next page
246
296
  # (next property to be included in the response)
247
297
  #
@@ -254,6 +304,42 @@ module Line
254
304
  get(endpoint, endpoint_path, credentials)
255
305
  end
256
306
 
307
+ # Gets the group ID, group name, and group icon URL of a group where the LINE Official Account is a member.
308
+ #
309
+ # @param group_id [String] Group's identifier
310
+ #
311
+ # @return [Net::HTTPResponse]
312
+ def get_group_summary(group_id)
313
+ channel_token_required
314
+
315
+ endpoint_path = "/bot/group/#{group_id}/summary"
316
+ get(endpoint, endpoint_path, credentials)
317
+ end
318
+
319
+ # Gets the user IDs of the members of a group that the bot is in.
320
+ #
321
+ # @param group_id [String] Group's identifier
322
+ #
323
+ # @return [Net::HTTPResponse]
324
+ def get_group_members_count(group_id)
325
+ channel_token_required
326
+
327
+ endpoint_path = "/bot/group/#{group_id}/members/count"
328
+ get(endpoint, endpoint_path, credentials)
329
+ end
330
+
331
+ # Gets the count of members in a room.
332
+ #
333
+ # @param room_id [String] Room's identifier
334
+ #
335
+ # @return [Net::HTTPResponse]
336
+ def get_room_members_count(room_id)
337
+ channel_token_required
338
+
339
+ endpoint_path = "/bot/room/#{room_id}/members/count"
340
+ get(endpoint, endpoint_path, credentials)
341
+ end
342
+
257
343
  # Get a list of all uploaded rich menus
258
344
  #
259
345
  # @return [Net::HTTPResponse]
@@ -394,6 +480,9 @@ module Line
394
480
 
395
481
  # Link a rich menu to a user
396
482
  #
483
+ # If you want to link a rich menu to multiple users,
484
+ # please consider to use bulk_link_rich_menus.
485
+ #
397
486
  # @param user_id [String] ID of the user
398
487
  # @param rich_menu_id [String] ID of an uploaded rich menu
399
488
  #
@@ -463,15 +552,8 @@ module Line
463
552
  def create_rich_menu_image(rich_menu_id, file)
464
553
  channel_token_required
465
554
 
466
- content_type = case file.path
467
- when /\.jpe?g\z/i then 'image/jpeg'
468
- when /\.png\z/i then 'image/png'
469
- else
470
- raise ArgumentError, "invalid file extension: #{file.path}"
471
- end
472
-
473
555
  endpoint_path = "/bot/richmenu/#{rich_menu_id}/content"
474
- headers = credentials.merge('Content-Type' => content_type)
556
+ headers = credentials.merge('Content-Type' => content_type(file))
475
557
  post(blob_endpoint, endpoint_path, file.rewind && file.read, headers)
476
558
  end
477
559
 
@@ -519,6 +601,18 @@ module Line
519
601
  get(endpoint, endpoint_path, credentials)
520
602
  end
521
603
 
604
+ # Returns statistics about how users interact with narrowcast messages or broadcast messages sent from your LINE Official Account.
605
+ #
606
+ # @param [String] request_id
607
+ #
608
+ # @return [Net::HTTPResponse]
609
+ def get_user_interaction_statistics(request_id)
610
+ channel_token_required
611
+
612
+ endpoint_path = "/bot/insight/message/event?requestId=#{request_id}"
613
+ get(endpoint, endpoint_path, credentials)
614
+ end
615
+
522
616
  # Returns the number of followers
523
617
  #
524
618
  # @param [String] date (Format:yyyyMMdd, Example:20191231)
@@ -531,7 +625,7 @@ module Line
531
625
  get(endpoint, endpoint_path, credentials)
532
626
  end
533
627
 
534
- # Retrieves the demographic attributes for a bot's friends.
628
+ # Get the demographic attributes for a bot's friends.
535
629
  #
536
630
  # @return [Net::HTTPResponse]
537
631
  def get_friend_demographics
@@ -541,6 +635,192 @@ module Line
541
635
  get(endpoint, endpoint_path, credentials)
542
636
  end
543
637
 
638
+ # Gets a bot's basic information.
639
+ #
640
+ # @return [Net::HTTPResponse]
641
+ def get_bot_info
642
+ channel_token_required
643
+
644
+ endpoint_path = '/bot/info'
645
+ get(endpoint, endpoint_path, credentials)
646
+ end
647
+
648
+ def get_liff_apps
649
+ channel_token_required
650
+
651
+ endpoint_path = '/apps'
652
+ get(liff_endpoint, endpoint_path, credentials)
653
+ end
654
+
655
+ def create_liff_app(app)
656
+ channel_token_required
657
+
658
+ endpoint_path = '/apps'
659
+ post(liff_endpoint, endpoint_path, app.to_json, credentials)
660
+ end
661
+
662
+ def update_liff_app(liff_id, app)
663
+ channel_token_required
664
+
665
+ endpoint_path = "/apps/#{liff_id}"
666
+ put(liff_endpoint, endpoint_path, app.to_json, credentials)
667
+ end
668
+
669
+ def delete_liff_app(liff_id)
670
+ channel_token_required
671
+
672
+ endpoint_path = "/apps/#{liff_id}"
673
+ delete(liff_endpoint, endpoint_path, credentials)
674
+ end
675
+
676
+ # Create an audience group by uploading user_ids
677
+ #
678
+ # Parameters are described here.
679
+ # https://developers.line.biz/en/reference/messaging-api/#create-upload-audience-group
680
+ #
681
+ # @param params [Hash] options
682
+ #
683
+ # @return [Net::HTTPResponse] This response includes an audience_group_id.
684
+ def create_user_id_audience(params)
685
+ channel_token_required
686
+
687
+ endpoint_path = '/bot/audienceGroup/upload'
688
+ post(endpoint, endpoint_path, params.to_json, credentials)
689
+ end
690
+
691
+ # Update an audience group
692
+ #
693
+ # Parameters are described here.
694
+ # https://developers.line.biz/en/reference/messaging-api/#update-upload-audience-group
695
+ #
696
+ # @param params [Hash] options
697
+ #
698
+ # @return [Net::HTTPResponse] This response includes an audience_group_id.
699
+ def update_user_id_audience(params)
700
+ channel_token_required
701
+
702
+ endpoint_path = '/bot/audienceGroup/upload'
703
+ put(endpoint, endpoint_path, params.to_json, credentials)
704
+ end
705
+
706
+ # Create an audience group of users that clicked a URL in a message sent in the past
707
+ #
708
+ # Parameters are described here.
709
+ # https://developers.line.biz/en/reference/messaging-api/#create-click-audience-group
710
+ #
711
+ # @param params [Hash] options
712
+ #
713
+ # @return [Net::HTTPResponse] This response includes an audience_group_id.
714
+ def create_click_audience(params)
715
+ channel_token_required
716
+
717
+ endpoint_path = '/bot/audienceGroup/click'
718
+ post(endpoint, endpoint_path, params.to_json, credentials)
719
+ end
720
+
721
+ # Create an audience group of users that opened a message sent in the past
722
+ #
723
+ # Parameters are described here.
724
+ # https://developers.line.biz/en/reference/messaging-api/#create-imp-audience-group
725
+ #
726
+ # @param params [Hash] options
727
+ #
728
+ # @return [Net::HTTPResponse] This response includes an audience_group_id.
729
+ def create_impression_audience(params)
730
+ channel_token_required
731
+
732
+ endpoint_path = '/bot/audienceGroup/imp'
733
+ post(endpoint, endpoint_path, params.to_json, credentials)
734
+ end
735
+
736
+ # Rename an existing audience group
737
+ #
738
+ # @param audience_group_id [Integer]
739
+ # @param description [String]
740
+ #
741
+ # @return [Net::HTTPResponse]
742
+ def rename_audience(audience_group_id, description)
743
+ channel_token_required
744
+
745
+ endpoint_path = "/bot/audienceGroup/#{audience_group_id}/updateDescription"
746
+ body = {description: description}
747
+ put(endpoint, endpoint_path, body.to_json, credentials)
748
+ end
749
+
750
+ # Delete an existing audience group
751
+ #
752
+ # Parameters are described here.
753
+ # https://developers.line.biz/en/reference/messaging-api/#delete-audience-group
754
+ #
755
+ # @param audience_group_id [Integer]
756
+ #
757
+ # @return [Net::HTTPResponse]
758
+ def delete_audience(audience_group_id)
759
+ channel_token_required
760
+
761
+ endpoint_path = "/bot/audienceGroup/#{audience_group_id}"
762
+ delete(endpoint, endpoint_path, credentials)
763
+ end
764
+
765
+ # Get audience group data
766
+ #
767
+ # Parameters are described here.
768
+ # https://developers.line.biz/en/reference/messaging-api/#get-audience-group
769
+ #
770
+ # @param audience_group_id [Integer]
771
+ #
772
+ # @return [Net::HTTPResponse]
773
+ def get_audience(audience_group_id)
774
+ channel_token_required
775
+
776
+ endpoint_path = "/bot/audienceGroup/#{audience_group_id}"
777
+ get(endpoint, endpoint_path, credentials)
778
+ end
779
+
780
+ # Get data for more than one audience group
781
+ #
782
+ # Parameters are described here.
783
+ # https://developers.line.biz/en/reference/messaging-api/#get-audience-groups
784
+ #
785
+ # @param params [Hash] key name `page` is required
786
+ #
787
+ # @return [Net::HTTPResponse]
788
+ def get_audiences(params)
789
+ channel_token_required
790
+
791
+ endpoint_path = "/bot/audienceGroup/list?" + URI.encode_www_form(params)
792
+ get(endpoint, endpoint_path, credentials)
793
+ end
794
+
795
+ # Get the authority level of the audience
796
+ #
797
+ # Parameters are described here.
798
+ # https://developers.line.biz/en/reference/messaging-api/#get-authority-level
799
+ #
800
+ # @return [Net::HTTPResponse]
801
+ def get_audience_authority_level
802
+ channel_token_required
803
+
804
+ endpoint_path = "/bot/audienceGroup/authorityLevel"
805
+ get(endpoint, endpoint_path, credentials)
806
+ end
807
+
808
+ # Change the authority level of the audience
809
+ #
810
+ # Parameters are described here.
811
+ # https://developers.line.biz/en/reference/messaging-api/#change-authority-level
812
+ #
813
+ # @param authority_level [String] value must be `PUBLIC` or `PRIVATE`
814
+ #
815
+ # @return [Net::HTTPResponse]
816
+ def update_audience_authority_level(authority_level)
817
+ channel_token_required
818
+
819
+ endpoint_path = "/bot/audienceGroup/authorityLevel"
820
+ body = {authorityLevel: authority_level}
821
+ put(endpoint, endpoint_path, body.to_json, credentials)
822
+ end
823
+
544
824
  # Fetch data, get content of specified URL.
545
825
  #
546
826
  # @param endpoint_base [String]
@@ -549,7 +829,7 @@ module Line
549
829
  #
550
830
  # @return [Net::HTTPResponse]
551
831
  def get(endpoint_base, endpoint_path, headers = {})
552
- headers = Line::Bot::API::DEFAULT_HEADERS.merge(headers)
832
+ headers = API::DEFAULT_HEADERS.merge(headers)
553
833
  httpclient.get(endpoint_base + endpoint_path, headers)
554
834
  end
555
835
 
@@ -562,10 +842,23 @@ module Line
562
842
  #
563
843
  # @return [Net::HTTPResponse]
564
844
  def post(endpoint_base, endpoint_path, payload = nil, headers = {})
565
- headers = Line::Bot::API::DEFAULT_HEADERS.merge(headers)
845
+ headers = API::DEFAULT_HEADERS.merge(headers)
566
846
  httpclient.post(endpoint_base + endpoint_path, payload, headers)
567
847
  end
568
848
 
849
+ # Put data, get content of specified URL.
850
+ #
851
+ # @param endpoint_base [String]
852
+ # @param endpoint_path [String]
853
+ # @param payload [String or NilClass]
854
+ # @param headers [Hash]
855
+ #
856
+ # @return [Net::HTTPResponse]
857
+ def put(endpoint_base, endpoint_path, payload = nil, headers = {})
858
+ headers = API::DEFAULT_HEADERS.merge(headers)
859
+ httpclient.put(endpoint_base + endpoint_path, payload, headers)
860
+ end
861
+
569
862
  # Delete content of specified URL.
570
863
  #
571
864
  # @param endpoint_base [String]
@@ -574,7 +867,7 @@ module Line
574
867
  #
575
868
  # @return [Net::HTTPResponse]
576
869
  def delete(endpoint_base, endpoint_path, headers = {})
577
- headers = Line::Bot::API::DEFAULT_HEADERS.merge(headers)
870
+ headers = API::DEFAULT_HEADERS.merge(headers)
578
871
  httpclient.delete(endpoint_base + endpoint_path, headers)
579
872
  end
580
873
 
@@ -588,15 +881,17 @@ module Line
588
881
 
589
882
  json['events'].map do |item|
590
883
  begin
591
- klass = Line::Bot::Event.const_get(Line::Bot::Util.camelize(item['type']))
884
+ klass = Event.const_get(Util.camelize(item['type']))
592
885
  klass.new(item)
593
886
  rescue NameError
594
- Line::Bot::Event::Base.new(item)
887
+ Event::Base.new(item)
595
888
  end
596
889
  end
597
890
  end
598
891
 
599
- # Validate signature
892
+ # Validate signature of a webhook event.
893
+ #
894
+ # https://developers.line.biz/en/reference/messaging-api/#signature-validation
600
895
  #
601
896
  # @param content [String] Request's body
602
897
  # @param channel_signature [String] Request'header 'X-LINE-Signature' # HTTP_X_LINE_SIGNATURE
@@ -633,6 +928,21 @@ module Line
633
928
  res == 0
634
929
  end
635
930
 
931
+ def content_type(file)
932
+ if file.respond_to?(:content_type)
933
+ content_type = file.content_type
934
+ raise ArgumentError, "invalid content type: #{content_type}" unless ['image/jpeg', 'image/png'].include?(content_type)
935
+ content_type
936
+ else
937
+ case file.path
938
+ when /\.jpe?g\z/i then 'image/jpeg'
939
+ when /\.png\z/i then 'image/png'
940
+ else
941
+ raise ArgumentError, "invalid file extension: #{file.path}"
942
+ end
943
+ end
944
+ end
945
+
636
946
  def channel_token_required
637
947
  raise ArgumentError, '`channel_token` is not configured' unless channel_token
638
948
  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
@@ -57,6 +57,11 @@ module Line
57
57
  http(uri).post(uri.request_uri, payload, header)
58
58
  end
59
59
 
60
+ def put(url, payload, header = {})
61
+ uri = URI(url)
62
+ http(uri).put(uri.request_uri, payload, header)
63
+ end
64
+
60
65
  def delete(url, header = {})
61
66
  uri = URI(url)
62
67
  http(uri).delete(uri.request_uri, header)
@@ -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.13.0
4
+ version: 1.17.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-12-24 00:00:00.000000000 Z
11
+ date: 2020-12-18 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,8 @@ 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
+ rubyforge_project:
125
+ rubygems_version: 2.7.6
123
126
  signing_key:
124
127
  specification_version: 4
125
128
  summary: SDK of the LINE Messaging API