line-bot-api 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +1 -1
- data/lib/line/bot/api/version.rb +1 -1
- data/lib/line/bot/client.rb +128 -0
- data/lib/line/bot/httpclient.rb +5 -0
- data/lib/line/bot/request.rb +25 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a7c9c3b5ab7ef63c00c035e1e93b7561dd6aadd92fbf87c0e8b1121dab5bff23
|
4
|
+
data.tar.gz: 9bc0619998d2d987669af2370c3ee979d759dbdf6dbccb50e6f7eceffdb68f84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ebd489a9ba85e38081ec16313b94d43e712f8bc43cf9b55ac72539d0c8be6a9eb69cb81a37e57d0bc13d28dc16fab2b4be7dd0d55eedceaccb83319305d1c5c
|
7
|
+
data.tar.gz: de0a7308371d809fabd19b4b43400deb717d902c4aa58401d527bb6c2b6fe9ac4e8eb0ae85fdbfa9ec6d96ec245fd311f9706ffa268bbccb55e1eca464a9fdd1
|
data/README.md
CHANGED
data/lib/line/bot/api/version.rb
CHANGED
data/lib/line/bot/client.rb
CHANGED
@@ -223,6 +223,116 @@ module Line
|
|
223
223
|
get(endpoint_path)
|
224
224
|
end
|
225
225
|
|
226
|
+
# Get a list of all uploaded rich menus
|
227
|
+
#
|
228
|
+
# @return [Net::HTTPResponse]
|
229
|
+
def get_rich_menus
|
230
|
+
endpoint_path = '/bot/richmenu/list'
|
231
|
+
get(endpoint_path)
|
232
|
+
end
|
233
|
+
|
234
|
+
# Get a rich menu via a rich menu ID
|
235
|
+
#
|
236
|
+
# @param rich_menu_id [String] ID of an uploaded rich menu
|
237
|
+
#
|
238
|
+
# @return [Net::HTTPResponse]
|
239
|
+
def get_rich_menu(rich_menu_id)
|
240
|
+
endpoint_path = "/bot/richmenu/#{rich_menu_id}"
|
241
|
+
get(endpoint_path)
|
242
|
+
end
|
243
|
+
|
244
|
+
# Create a rich menu
|
245
|
+
#
|
246
|
+
# @param rich_menu [Hash] The rich menu represented as a rich menu object
|
247
|
+
#
|
248
|
+
# @return [Net::HTTPResponse]
|
249
|
+
def create_rich_menu(rich_menu)
|
250
|
+
request = Request.new do |config|
|
251
|
+
config.httpclient = httpclient
|
252
|
+
config.endpoint = endpoint
|
253
|
+
config.endpoint_path = '/bot/richmenu'
|
254
|
+
config.credentials = credentials
|
255
|
+
config.payload = rich_menu.to_json
|
256
|
+
end
|
257
|
+
|
258
|
+
request.post
|
259
|
+
end
|
260
|
+
|
261
|
+
# Delete a rich menu
|
262
|
+
#
|
263
|
+
# @param rich_menu_id [String] ID of an uploaded rich menu
|
264
|
+
#
|
265
|
+
# @return [Net::HTTPResponse]
|
266
|
+
def delete_rich_menu(rich_menu_id)
|
267
|
+
endpoint_path = "/bot/richmenu/#{rich_menu_id}"
|
268
|
+
delete(endpoint_path)
|
269
|
+
end
|
270
|
+
|
271
|
+
# Get the ID of the rich menu linked to a user
|
272
|
+
#
|
273
|
+
# @param user_id [String] ID of the user
|
274
|
+
#
|
275
|
+
# @return [Net::HTTPResponse]
|
276
|
+
def get_user_rich_menu(user_id)
|
277
|
+
endpoint_path = "/bot/user/#{user_id}/richmenu"
|
278
|
+
get(endpoint_path)
|
279
|
+
end
|
280
|
+
|
281
|
+
# Link a rich menu to a user
|
282
|
+
#
|
283
|
+
# @param user_id [String] ID of the user
|
284
|
+
# @param rich_menu_id [String] ID of an uploaded rich menu
|
285
|
+
#
|
286
|
+
# @return [Net::HTTPResponse]
|
287
|
+
def link_user_rich_menu(user_id, rich_menu_id)
|
288
|
+
request = Request.new do |config|
|
289
|
+
config.httpclient = httpclient
|
290
|
+
config.endpoint = endpoint
|
291
|
+
config.endpoint_path = "/bot/user/#{user_id}/richmenu/#{rich_menu_id}"
|
292
|
+
config.credentials = credentials
|
293
|
+
end
|
294
|
+
|
295
|
+
request.post
|
296
|
+
end
|
297
|
+
|
298
|
+
# Unlink a rich menu from a user
|
299
|
+
#
|
300
|
+
# @param user_id [String] ID of the user
|
301
|
+
#
|
302
|
+
# @return [Net::HTTPResponse]
|
303
|
+
def unlink_user_rich_menu(user_id)
|
304
|
+
endpoint_path = "/bot/user/#{user_id}/richmenu"
|
305
|
+
delete(endpoint_path)
|
306
|
+
end
|
307
|
+
|
308
|
+
# Download an image associated with a rich menu
|
309
|
+
#
|
310
|
+
# @param rich_menu_id [String] ID of an uploaded rich menu
|
311
|
+
#
|
312
|
+
# @return [Net::HTTPResponse]
|
313
|
+
def get_rich_menu_image(rich_menu_id)
|
314
|
+
endpoint_path = "/bot/richmenu/#{rich_menu_id}/content"
|
315
|
+
get(endpoint_path)
|
316
|
+
end
|
317
|
+
|
318
|
+
# Upload and attaches an image to a rich menu
|
319
|
+
#
|
320
|
+
# @param rich_menu_id [String] The ID of the rich menu to attach the image to
|
321
|
+
# @param file [File] Image file to attach rich menu
|
322
|
+
#
|
323
|
+
# @return [Net::HTTPResponse]
|
324
|
+
def create_rich_menu_image(rich_menu_id, file)
|
325
|
+
request = Request.new do |config|
|
326
|
+
config.httpclient = httpclient
|
327
|
+
config.endpoint = endpoint
|
328
|
+
config.endpoint_path = "/bot/richmenu/#{rich_menu_id}/content"
|
329
|
+
config.credentials = credentials
|
330
|
+
config.file = file
|
331
|
+
end
|
332
|
+
|
333
|
+
request.post
|
334
|
+
end
|
335
|
+
|
226
336
|
# Fetch data, get content of specified URL.
|
227
337
|
#
|
228
338
|
# @param endpoint_path [String]
|
@@ -241,6 +351,24 @@ module Line
|
|
241
351
|
request.get
|
242
352
|
end
|
243
353
|
|
354
|
+
# Delete content of specified URL.
|
355
|
+
#
|
356
|
+
# @param endpoint_path [String]
|
357
|
+
#
|
358
|
+
# @return [Net::HTTPResponse]
|
359
|
+
def delete(endpoint_path)
|
360
|
+
raise Line::Bot::API::InvalidCredentialsError, 'Invalidates credentials' unless credentials?
|
361
|
+
|
362
|
+
request = Request.new do |config|
|
363
|
+
config.httpclient = httpclient
|
364
|
+
config.endpoint = endpoint
|
365
|
+
config.endpoint_path = endpoint_path
|
366
|
+
config.credentials = credentials
|
367
|
+
end
|
368
|
+
|
369
|
+
request.delete
|
370
|
+
end
|
371
|
+
|
244
372
|
# Parse events from request.body
|
245
373
|
#
|
246
374
|
# @param request_body [String]
|
data/lib/line/bot/httpclient.rb
CHANGED
data/lib/line/bot/request.rb
CHANGED
@@ -20,7 +20,7 @@ require 'uri'
|
|
20
20
|
module Line
|
21
21
|
module Bot
|
22
22
|
class Request
|
23
|
-
attr_accessor :endpoint, :endpoint_path, :credentials, :to, :reply_token, :messages, :httpclient
|
23
|
+
attr_accessor :endpoint, :endpoint_path, :credentials, :to, :reply_token, :messages, :httpclient, :payload, :file
|
24
24
|
|
25
25
|
# Initializes a new Request
|
26
26
|
#
|
@@ -29,8 +29,10 @@ module Line
|
|
29
29
|
yield(self) if block_given?
|
30
30
|
end
|
31
31
|
|
32
|
-
# @return [
|
32
|
+
# @return [String]
|
33
33
|
def payload
|
34
|
+
return file.seek(0) && file.read if file.is_a? File
|
35
|
+
return @payload if @payload.is_a? String
|
34
36
|
payload = {
|
35
37
|
to: to,
|
36
38
|
replyToken: reply_token,
|
@@ -42,8 +44,20 @@ module Line
|
|
42
44
|
|
43
45
|
# @return [Hash]
|
44
46
|
def header
|
47
|
+
content_type =
|
48
|
+
if file.is_a? File
|
49
|
+
case file.path
|
50
|
+
when /\.png\z/i then 'image/png'
|
51
|
+
when /\.jpe?g\z/i then 'image/jpeg'
|
52
|
+
else
|
53
|
+
raise ArgumentError.new("invalid file extension: #{file.path}")
|
54
|
+
end
|
55
|
+
else
|
56
|
+
'application/json; charset=UTF-8'
|
57
|
+
end
|
58
|
+
|
45
59
|
header = {
|
46
|
-
'Content-Type' =>
|
60
|
+
'Content-Type' => content_type,
|
47
61
|
'User-Agent' => "LINE-BotSDK-Ruby/#{Line::Bot::API::VERSION}",
|
48
62
|
}
|
49
63
|
hash = credentials.inject({}) { |h, (k, v)| h[k] = v.to_s; h }
|
@@ -69,6 +83,11 @@ module Line
|
|
69
83
|
httpclient.post(endpoint + endpoint_path, payload, header)
|
70
84
|
end
|
71
85
|
|
86
|
+
def delete
|
87
|
+
assert_for_deleting_message
|
88
|
+
httpclient.delete(endpoint + endpoint_path, header)
|
89
|
+
end
|
90
|
+
|
72
91
|
def assert_for_getting_message
|
73
92
|
raise ArgumentError, 'Wrong argument type `endpoint_path`' unless endpoint_path.is_a?(String)
|
74
93
|
end
|
@@ -77,6 +96,9 @@ module Line
|
|
77
96
|
raise ArgumentError, 'Wrong argument type `endpoint_path`' unless endpoint_path.is_a?(String)
|
78
97
|
end
|
79
98
|
|
99
|
+
def assert_for_deleting_message
|
100
|
+
raise ArgumentError, 'Wrong argument type `endpoint_path`' unless endpoint_path.is_a?(String)
|
101
|
+
end
|
80
102
|
end
|
81
103
|
end
|
82
104
|
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.2.
|
4
|
+
version: 1.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- LINE Corporation
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
127
|
version: '0'
|
128
128
|
requirements: []
|
129
129
|
rubyforge_project:
|
130
|
-
rubygems_version: 2.
|
130
|
+
rubygems_version: 2.7.6
|
131
131
|
signing_key:
|
132
132
|
specification_version: 4
|
133
133
|
summary: SDK of the LINE Messaging API
|