line-bot-api 1.19.0 → 1.23.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: a8864bff59b1e7a50a3f63bd2aef939319c9731b9facbb4116d0aa4bb7894101
4
- data.tar.gz: df898ac583f61824837b3e92f98867be4aafb74fbdc5b89ad094edf164e098ee
3
+ metadata.gz: 17ed6a316ad332e424e59aa498c8e9ee3bc7062204f191ea3b78e44f74a623b0
4
+ data.tar.gz: 3a9cc6bbf3cbf658685873f4ea92c501cda4d73d6b6f969ec1620af4d34322ba
5
5
  SHA512:
6
- metadata.gz: 921d2f1896c8c60759eeccbd3ca40a57bd2d401558a1d5d5bedceb967f00d1be6d56b1d886987e7883cd9b2b43541b555ec895759607235265accd787aed6653
7
- data.tar.gz: 3a50ac3a250aa087eb7285a7a1144e4f64c15443acaca6d28e747f979198902ef887bc589fad8e31aa74fb526820ebc3eff1e4413f83460b227caa327021e172
6
+ metadata.gz: 264355c41cc59a4063284d83902639df915df5dfa82b9787d1a4a973dfe4af2d729c171428c12b013e9f87ca6b667e1f8f0c41de5b93843a37040cafb1ea7f54
7
+ data.tar.gz: '08ef6e828069cf6a8d971450f054fc8c4a662b6244da697138cb33305b38e0a6711e0e75d82fccb9574f88b86e9f7bb8cf7cd13e247bab53c612c989572efc55'
@@ -15,7 +15,7 @@
15
15
  module Line
16
16
  module Bot
17
17
  module API
18
- VERSION = "1.19.0"
18
+ VERSION = "1.23.0"
19
19
  end
20
20
  end
21
21
  end
data/lib/line/bot/api.rb CHANGED
@@ -17,6 +17,7 @@ require 'line/bot/api/version'
17
17
  module Line
18
18
  module Bot
19
19
  module API
20
+ DEFAULT_OAUTH_ENDPOINT = "https://api.line.me"
20
21
  DEFAULT_ENDPOINT = "https://api.line.me/v2"
21
22
  DEFAULT_BLOB_ENDPOINT = "https://api-data.line.me/v2"
22
23
  DEFAULT_LIFF_ENDPOINT = "https://api.line.me/liff/v1"
@@ -55,6 +55,10 @@ module Line
55
55
  @endpoint ||= API::DEFAULT_ENDPOINT
56
56
  end
57
57
 
58
+ def oauth_endpoint
59
+ @oauth_endpoint ||= API::DEFAULT_OAUTH_ENDPOINT
60
+ end
61
+
58
62
  def blob_endpoint
59
63
  return @blob_endpoint if @blob_endpoint
60
64
 
@@ -106,19 +110,71 @@ module Line
106
110
  post(endpoint, endpoint_path, payload, headers)
107
111
  end
108
112
 
113
+ # Issue channel access token v2.1
114
+ #
115
+ # @param jwt [String]
116
+ #
117
+ # @return [Net::HTTPResponse]
118
+ def issue_channel_access_token_jwt(jwt)
119
+ endpoint_path = '/oauth2/v2.1/token'
120
+ payload = URI.encode_www_form(
121
+ grant_type: 'client_credentials',
122
+ client_assertion_type: 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer',
123
+ client_assertion: jwt
124
+ )
125
+ headers = { 'Content-Type' => 'application/x-www-form-urlencoded' }
126
+ post(oauth_endpoint, endpoint_path, payload, headers)
127
+ end
128
+
129
+ # Revoke channel access token v2.1
130
+ #
131
+ # @param access_token [String]
132
+ #
133
+ # @return [Net::HTTPResponse]
134
+ def revoke_channel_access_token_jwt(access_token)
135
+ channel_id_required
136
+ channel_secret_required
137
+
138
+ endpoint_path = '/oauth2/v2.1/revoke'
139
+ payload = URI.encode_www_form(
140
+ client_id: channel_id,
141
+ client_secret: channel_secret,
142
+ access_token: access_token
143
+ )
144
+ headers = { 'Content-Type' => 'application/x-www-form-urlencoded' }
145
+ post(oauth_endpoint, endpoint_path, payload, headers)
146
+ end
147
+
148
+ # Get all valid channel access token key IDs v2.1
149
+ #
150
+ # @param jwt [String]
151
+ #
152
+ # @return [Net::HTTPResponse]
153
+ def get_channel_access_token_key_ids_jwt(jwt)
154
+ payload = URI.encode_www_form(
155
+ client_assertion_type: 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer',
156
+ client_assertion: jwt
157
+ )
158
+ endpoint_path = "/oauth2/v2.1/tokens/kid?#{payload}"
159
+
160
+ headers = { 'Content-Type' => 'application/x-www-form-urlencoded' }
161
+ get(oauth_endpoint, endpoint_path, headers)
162
+ end
163
+
109
164
  # Push messages to a user using user_id.
110
165
  #
111
166
  # @param user_id [String] User Id
112
167
  # @param messages [Hash or Array] Message Objects
113
168
  # @param headers [Hash] HTTP Headers
169
+ # @param payload [Hash] Additional request body
114
170
  # @return [Net::HTTPResponse]
115
- def push_message(user_id, messages, headers: {})
171
+ def push_message(user_id, messages, headers: {}, payload: {})
116
172
  channel_token_required
117
173
 
118
174
  messages = [messages] if messages.is_a?(Hash)
119
175
 
120
176
  endpoint_path = '/bot/message/push'
121
- payload = { to: user_id, messages: messages }.to_json
177
+ payload = payload.merge({ to: user_id, messages: messages }).to_json
122
178
  post(endpoint, endpoint_path, payload, credentials.merge(headers))
123
179
  end
124
180
 
@@ -157,15 +213,16 @@ module Line
157
213
  # @param to [Array or String] Array of userIds
158
214
  # @param messages [Hash or Array] Message Objects
159
215
  # @param headers [Hash] HTTP Headers
216
+ # @param payload [Hash] Additional request body
160
217
  # @return [Net::HTTPResponse]
161
- def multicast(to, messages, headers: {})
218
+ def multicast(to, messages, headers: {}, payload: {})
162
219
  channel_token_required
163
220
 
164
221
  to = [to] if to.is_a?(String)
165
222
  messages = [messages] if messages.is_a?(Hash)
166
223
 
167
224
  endpoint_path = '/bot/message/multicast'
168
- payload = { to: to, messages: messages }.to_json
225
+ payload = payload.merge({ to: to, messages: messages }).to_json
169
226
  post(endpoint, endpoint_path, payload, credentials.merge(headers))
170
227
  end
171
228
 
@@ -276,15 +333,22 @@ module Line
276
333
 
277
334
  # Get user IDs of who added your LINE Official Account as a friend
278
335
  #
279
- # @param continuation_token [String] Identifier to return next page
280
- # (next property to be included in the response)
336
+ # @param start [String] Identifier to return next page (next property to be included in the response)
337
+ # @param limit [Integer] The maximum number of user IDs to retrieve in a single request
281
338
  #
282
339
  # @return [Net::HTTPResponse]
283
- def get_follower_ids(continuation_token = nil)
340
+ def get_follower_ids(deprecated_continuation_token = nil, start: nil, limit: nil)
284
341
  channel_token_required
285
342
 
343
+ if deprecated_continuation_token
344
+ warn "continuation_token as the first argument is deprecated. Please use :start instead."
345
+ start = deprecated_continuation_token
346
+ end
347
+
348
+ params = { start: start, limit: limit }.compact
349
+
286
350
  endpoint_path = "/bot/followers/ids"
287
- endpoint_path += "?start=#{continuation_token}" if continuation_token
351
+ endpoint_path += "?" + URI.encode_www_form(params) unless params.empty?
288
352
  get(endpoint, endpoint_path, credentials)
289
353
  end
290
354
 
@@ -492,6 +556,66 @@ module Line
492
556
  delete(endpoint, endpoint_path, credentials)
493
557
  end
494
558
 
559
+ # Set rich menu alias
560
+ #
561
+ # @param rich_menu_id [String] ID of an uploaded rich menu
562
+ # @param rich_menu_alias_id [String] string of alias words rich menu
563
+ #
564
+ # @return [Net::HTTPResponse]
565
+ def set_rich_menus_alias(rich_menu_id, rich_menu_alias_id)
566
+ channel_token_required
567
+
568
+ endpoint_path = '/bot/richmenu/alias'
569
+ post(endpoint, endpoint_path, { richMenuId: rich_menu_id, richMenuAliasId: rich_menu_alias_id }.to_json, credentials)
570
+ end
571
+
572
+ # Unset rich menu alias
573
+ #
574
+ # @param rich_menu_alias_id [String] string of alias words rich menu
575
+ #
576
+ # @return [Net::HTTPResponse]
577
+ def unset_rich_menus_alias(rich_menu_alias_id)
578
+ channel_token_required
579
+
580
+ endpoint_path = "/bot/richmenu/alias/#{rich_menu_alias_id}"
581
+ delete(endpoint, endpoint_path, credentials)
582
+ end
583
+
584
+ # Update rich menu alias
585
+ #
586
+ # @param rich_menu_id [String] ID of an uploaded rich menu
587
+ # @param rich_menu_alias_id [String] string of alias words rich menu
588
+ #
589
+ # @return [Net::HTTPResponse]
590
+ def update_rich_menus_alias(rich_menu_id, rich_menu_alias_id)
591
+ channel_token_required
592
+
593
+ endpoint_path = "/bot/richmenu/alias/#{rich_menu_alias_id}"
594
+ post(endpoint, endpoint_path, { richMenuId: rich_menu_id }.to_json, credentials)
595
+ end
596
+
597
+ # Get a rich menu alias via a rich menu alias ID
598
+ #
599
+ # @param rich_menu_alias_id [String] string of alias words rich menu
600
+ #
601
+ # @return [Net::HTTPResponse]
602
+ def get_rich_menus_alias(rich_menu_alias_id)
603
+ channel_token_required
604
+
605
+ endpoint_path = "/bot/richmenu/alias/#{rich_menu_alias_id}"
606
+ get(endpoint, endpoint_path, credentials)
607
+ end
608
+
609
+ # Get a list of all uploaded rich menus alias
610
+ #
611
+ # @return [Net::HTTPResponse]
612
+ def get_rich_menus_alias_list
613
+ channel_token_required
614
+
615
+ endpoint_path = "/bot/richmenu/alias/list"
616
+ get(endpoint, endpoint_path, credentials)
617
+ end
618
+
495
619
  # Link a rich menu to a user
496
620
  #
497
621
  # If you want to link a rich menu to multiple users,
@@ -875,6 +999,45 @@ module Line
875
999
  put(endpoint, endpoint_path, body.to_json, credentials)
876
1000
  end
877
1001
 
1002
+ # Get the per-unit statistics of how users interact with push messages and multicast messages.
1003
+ #
1004
+ # @param unit [String] Case-sensitive name of aggregation unit specified when sending the message.
1005
+ # @param from [String] Start date of aggregation period in UTC+9 with `yyyyMMdd` format
1006
+ # @param to [String] End date of aggregation period in UTC+9 with `yyyyMMdd` format.
1007
+ #
1008
+ # @return [Net::HTTPResponse]
1009
+ def get_statistics_per_unit(unit:, from:, to:)
1010
+ channel_token_required
1011
+
1012
+ params = {customAggregationUnit: unit, from: from, to: to}
1013
+ endpoint_path = "/bot/insight/message/event/aggregation?" + URI.encode_www_form(params)
1014
+ get(endpoint, endpoint_path, credentials)
1015
+ end
1016
+
1017
+ # Get the number of aggregation units used this month.
1018
+ #
1019
+ # @return [Net::HTTPResponse]
1020
+ def get_aggregation_info
1021
+ channel_token_required
1022
+
1023
+ endpoint_path = "/bot/message/aggregation/info"
1024
+ get(endpoint, endpoint_path, credentials)
1025
+ end
1026
+
1027
+ # Get the name list of units used this month for statistics aggregation.
1028
+ #
1029
+ # @param limit [Integer] Maximum number of aggregation units per request. Maximum: 100, Default: 100.
1030
+ # @param start [String] Value of the continuation token found in the `next` property of the JSON object returned in the response.
1031
+ #
1032
+ # @return [Net::HTTPResponse]
1033
+ def get_aggregation_list(limit: nil, start: nil)
1034
+ channel_token_required
1035
+
1036
+ params = {limit: limit, start: start}.compact
1037
+ endpoint_path = "/bot/message/aggregation/list?" + URI.encode_www_form(params)
1038
+ get(endpoint, endpoint_path, credentials)
1039
+ end
1040
+
878
1041
  # Fetch data, get content of specified URL.
879
1042
  #
880
1043
  # @param endpoint_base [String]
@@ -954,7 +1117,7 @@ module Line
954
1117
  def validate_signature(content, channel_signature)
955
1118
  return false if !channel_signature || !channel_secret
956
1119
 
957
- hash = OpenSSL::HMAC.digest(OpenSSL::Digest::SHA256.new, channel_secret, content)
1120
+ hash = OpenSSL::HMAC.digest(OpenSSL::Digest.new('SHA256'), channel_secret, content)
958
1121
  signature = Base64.strict_encode64(hash)
959
1122
 
960
1123
  variable_secure_compare(channel_signature, signature)
@@ -986,6 +1149,7 @@ module Line
986
1149
  if file.respond_to?(:content_type)
987
1150
  content_type = file.content_type
988
1151
  raise ArgumentError, "invalid content type: #{content_type}" unless ['image/jpeg', 'image/png'].include?(content_type)
1152
+
989
1153
  content_type
990
1154
  else
991
1155
  case file.path
@@ -38,10 +38,8 @@ module Line
38
38
  http.use_ssl = true
39
39
  end
40
40
 
41
- if http_options
42
- http_options.each do |key, value|
43
- http.send("#{key}=", value)
44
- end
41
+ http_options&.each do |key, value|
42
+ http.send("#{key}=", value)
45
43
  end
46
44
 
47
45
  http
data/line-bot-api.gemspec CHANGED
@@ -17,10 +17,9 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.required_ruby_version = '>= 2.0.0'
20
+ spec.required_ruby_version = '>= 2.4.0'
21
21
 
22
22
  spec.add_development_dependency "addressable", "~> 2.3"
23
- spec.add_development_dependency "bundler", "~> 1.11" if RUBY_VERSION < "2.3"
24
23
  spec.add_development_dependency 'rake', "~> 13.0"
25
24
  spec.add_development_dependency "rspec", "~> 3.0"
26
25
  spec.add_development_dependency "webmock", "~> 3.8"
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.19.0
4
+ version: 1.23.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: 2021-03-23 00:00:00.000000000 Z
11
+ date: 2022-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -114,15 +114,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: 2.0.0
117
+ version: 2.4.0
118
118
  required_rubygems_version: !ruby/object:Gem::Requirement
119
119
  requirements:
120
120
  - - ">="
121
121
  - !ruby/object:Gem::Version
122
122
  version: '0'
123
123
  requirements: []
124
- rubyforge_project:
125
- rubygems_version: 2.7.6
124
+ rubygems_version: 3.1.6
126
125
  signing_key:
127
126
  specification_version: 4
128
127
  summary: SDK of the LINE Messaging API