line-bot-api 0.1.9 → 1.0.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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +43 -221
  3. data/lib/line/bot.rb +15 -8
  4. data/lib/line/bot/api.rb +15 -2
  5. data/lib/line/bot/api/errors.rb +14 -1
  6. data/lib/line/bot/api/version.rb +15 -1
  7. data/lib/line/bot/client.rb +89 -164
  8. data/lib/line/bot/event.rb +22 -0
  9. data/lib/line/bot/event/base.rb +30 -0
  10. data/lib/line/bot/event/beacon.rb +22 -0
  11. data/lib/line/bot/event/follow.rb +22 -0
  12. data/lib/line/bot/event/join.rb +22 -0
  13. data/lib/line/bot/event/leave.rb +22 -0
  14. data/lib/line/bot/event/message.rb +43 -0
  15. data/lib/line/bot/event/postback.rb +22 -0
  16. data/lib/line/bot/event/unfollow.rb +22 -0
  17. data/lib/line/bot/httpclient.rb +14 -0
  18. data/lib/line/bot/request.rb +19 -23
  19. data/line-bot-api.gemspec +1 -5
  20. metadata +31 -89
  21. data/lib/line/bot/builder/multiple_message.rb +0 -101
  22. data/lib/line/bot/builder/rich_message.rb +0 -154
  23. data/lib/line/bot/event_type.rb +0 -15
  24. data/lib/line/bot/message.rb +0 -9
  25. data/lib/line/bot/message/audio.rb +0 -25
  26. data/lib/line/bot/message/base.rb +0 -35
  27. data/lib/line/bot/message/contact.rb +0 -18
  28. data/lib/line/bot/message/content_type.rb +0 -16
  29. data/lib/line/bot/message/image.rb +0 -23
  30. data/lib/line/bot/message/location.rb +0 -28
  31. data/lib/line/bot/message/recipient_type.rb +0 -9
  32. data/lib/line/bot/message/sticker.rb +0 -26
  33. data/lib/line/bot/message/text.rb +0 -22
  34. data/lib/line/bot/message/video.rb +0 -23
  35. data/lib/line/bot/operation.rb +0 -3
  36. data/lib/line/bot/operation/added_as_friend.rb +0 -10
  37. data/lib/line/bot/operation/base.rb +0 -17
  38. data/lib/line/bot/operation/blocked_account.rb +0 -10
  39. data/lib/line/bot/operation/op_type.rb +0 -10
  40. data/lib/line/bot/receive/message.rb +0 -69
  41. data/lib/line/bot/receive/operation.rb +0 -42
  42. data/lib/line/bot/receive/request.rb +0 -35
  43. data/lib/line/bot/response/user/contact.rb +0 -22
  44. data/lib/line/bot/response/user/profile.rb +0 -30
  45. data/lib/line/bot/utils.rb +0 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c40dda75044bfa83defb5ae32c5a3526b745f04d
4
- data.tar.gz: 6d090be70028e721310c722e1a434d5f714d3947
3
+ metadata.gz: ec45ce0d0e53493faf3ef7ed5215ed6bc7180e3a
4
+ data.tar.gz: 637d8bbbe31a5b94f5ea509f61ed5346203b7701
5
5
  SHA512:
6
- metadata.gz: 44a9a0a94db4d582313102e1403e32910565d063638b675ed41ff8664d81ffcb758d0df66cb1f205f2d299ed05dd3c1f9d04deb409e1f7fc2c7e7950b9403f49
7
- data.tar.gz: 43b334f661f50876c0bca116ae413845d9b99d3fd1d4aef2e50c359b92e3dcc91d9ed0fb2b7ed29015e68698caaa70bd9e8549be90a24f8e4fec4d132ec546db
6
+ metadata.gz: becad379a9f770893247f831f47ed84709a23deaa62a855bb1b36e0c8a5f2c70855f7cc52e0c9de430b5921d1412d29ed4d16e63b5fe6ac3bbf6d98f4d86e4ad
7
+ data.tar.gz: 6c169825a036d23fd6276bcdff694652ecef46f8d28cbeba05888d51a01b2793f1d82ac4dde8b12a1fb1a1fd59ad28452f8e0f3dd609301ab2435c1fce6cd8ee
data/README.md CHANGED
@@ -3,7 +3,17 @@
3
3
  [![Gem-version](https://img.shields.io/gem/v/line-bot-api.svg)](https://rubygems.org/gems/line-bot-api) [![Build Status](https://travis-ci.org/line/line-bot-sdk-ruby.svg?branch=master)](https://travis-ci.org/line/line-bot-sdk-ruby)
4
4
 
5
5
 
6
- Line::Bot::API - SDK of the LINE BOT API Trial for Ruby
6
+ Line::Bot::API - SDK of the LINE Messaging API for Ruby.
7
+
8
+ ## About LINE Messaging API
9
+
10
+ Please refer to the official api documents for details.
11
+
12
+ https://devdocs.line.me/
13
+
14
+ ## Synopsis
15
+
16
+ usage is:
7
17
 
8
18
  ```ruby
9
19
  # app.rb
@@ -12,27 +22,35 @@ require 'line/bot'
12
22
 
13
23
  def client
14
24
  @client ||= Line::Bot::Client.new { |config|
15
- config.channel_id = ENV["LINE_CHANNEL_ID"]
16
25
  config.channel_secret = ENV["LINE_CHANNEL_SECRET"]
17
- config.channel_mid = ENV["LINE_CHANNEL_MID"]
26
+ config.channel_token = ENV["LINE_CHANNEL_TOKEN"]
18
27
  }
19
28
  end
20
29
 
21
30
  post '/callback' do
22
- signature = request.env['HTTP_X_LINE_CHANNELSIGNATURE']
23
- unless client.validate_signature(request.body.read, signature)
31
+ body = request.body.read
32
+
33
+ signature = request.env['HTTP_X_LINE_SIGNATURE']
34
+ unless client.validate_signature(body, signature)
24
35
  error 400 do 'Bad Request' end
25
36
  end
26
37
 
27
- receive_request = Line::Bot::Receive::Request.new(request.env)
28
-
29
- receive_request.data.each { |message|
30
- case message.content
31
- when Line::Bot::Message::Text
32
- client.send_text(
33
- to_mid: message.from_mid,
34
- text: message.content[:text],
35
- )
38
+ events = client.parse_events_from(body)
39
+ events.each { |event|
40
+ case event
41
+ when Line::Bot::Event::Message
42
+ case event.type
43
+ when Line::Bot::Event::MessageType::Text
44
+ message = {
45
+ type: 'text',
46
+ text: event.message['text']
47
+ }
48
+ client.reply(event['replyToken'], message)
49
+ when Line::Bot::Event::MessageType::Image, Line::Bot::Event::MessageType::Video
50
+ response = client.get_message_content(event.message['id'])
51
+ tf = Tempfile.open("content")
52
+ tf.write(response.body)
53
+ end
36
54
  end
37
55
  }
38
56
 
@@ -56,214 +74,18 @@ Or install it yourself as:
56
74
 
57
75
  $ gem install line-bot-api
58
76
 
59
- ## Configuration
60
-
61
- ```ruby
62
- client = Line::Bot::Client.new do |config|
63
- config.channel_id = 'YOUR LINE BOT Channel ID'
64
- config.channel_secret = 'YOUR LINE BOT Channel Secret'
65
- config.channel_mid = 'YOUR LINE BOT MID'
66
- end
67
- ```
68
-
69
- ## Usage
70
-
71
- ### Sending messages
72
-
73
- After configuring a client, you can start sending messages as the following reference.
74
-
75
- - [https://developers.line.me/bot-api/api-reference#sending_message](https://developers.line.me/bot-api/api-reference#sending_message)
76
-
77
- Sending message APIs requires the following parameter.
78
- - `:to_mid` String or Array
79
-
80
- ```ruby
81
- client.send_text(
82
- to_mid: '12345678',
83
- )
84
- client.send_text(
85
- to_mid: ['12345678', '23456789'],
86
- )
87
- ```
88
-
89
- #### send_text
90
-
91
- ```ruby
92
- client.send_text(
93
- to_mid: to_mid,
94
- text: 'Hello',
95
- )
96
- ```
97
-
98
- #### send_image
99
-
100
- ```ruby
101
- client.send_image(
102
- to_mid: to_mid,
103
- image_url: 'http://example.com/image.jpg', # originalContentUrl
104
- preview_url: 'http://example.com/image_preview.jpg', # previewImageUrl
105
- )
106
- ```
107
-
108
- #### send_video
109
-
110
- ```ruby
111
- client.send_video(
112
- to_mid: to_mid,
113
- video_url: 'http://example.com/video.mp4', # originalContentUrl
114
- preview_url: 'http://example.com/video_preview.jpg' # previewImageUrl
115
- )
116
- ```
117
-
118
- #### send_audio
119
-
120
- ```ruby
121
- client.send_audio(
122
- to_mid: to_mid,
123
- audio_url: 'http://example.com/audio.mp3', # originalContentUrl
124
- duration: 120000
125
- )
126
- ```
127
-
128
- #### send_location
129
-
130
- ```ruby
131
- client.send_location(
132
- to_mid: to_mid,
133
- title: 'LINE Corporation.',
134
- address: 'Hikarie Shibuya-ku Tokyo 151-0002', # location.address
135
- latitude: 35.61823286112982, # location.latitude
136
- longitude: 139.72824096679688, # location.longitude
137
- )
138
- ```
139
-
140
- #### send_sticker
141
-
142
- See online documentation to find which sticker's you can send.
143
-
144
- - [https://developers.line.me/bot-api/api-reference#sending_message_sticker](https://developers.line.me/bot-api/api-reference#sending_message_sticker)
145
-
146
- ```ruby
147
- client.send_sticker(
148
- to_mid: to_mid,
149
- stkpkgid: 2, # contentMetadata.STKPKGID
150
- stkid: 144, # contentMetadata.STKID
151
- stkver: 100 # contentMetadata.STKVER
152
- )
153
- ```
154
-
155
- ### Sending multiple message
156
-
157
- Support on sending multiple message.
158
- - [https://developers.line.me/bot-api/api-reference#sending_multiple_messages](https://developers.line.me/bot-api/api-reference#sending_multiple_messages)
159
-
160
- ```ruby
161
- client.multiple_message.add_text(
162
- text: text,
163
- ).add_image(
164
- image_url: image_url,
165
- preview_url: preview_url,
166
- ).add_video(
167
- video_url: video_url,
168
- preview_url: preview_url,
169
- ).add_audio(
170
- audio_url: audio_url,
171
- duration: duration,
172
- ).add_location(
173
- title: 'title',
174
- latitude: latitude,
175
- longitude: longitude,
176
- ).add_sticker(
177
- stkpkgid: stkpkgid,
178
- stkid: stkid,
179
- stkver: stkver,
180
- ).send(
181
- to_mid: to_mid,
182
- )
183
- ```
184
-
185
- ### Sending rich message
186
-
187
- Support on sending rich message.
188
-
189
- See also a online document.
190
- - [https://developers.line.me/bot-api/api-reference#sending_rich_content_message](https://developers.line.me/bot-api/api-reference#sending_rich_content_message)
191
-
192
- ```ruby
193
- client.rich_message.set_action(
194
- MANGA: {
195
- text: 'manga',
196
- link_url: link_url,
197
- }
198
- ).add_listener(
199
- action: 'MANGA',
200
- x: 0,
201
- y: 0,
202
- width: 520,
203
- height: 520,
204
- ).send(
205
- to_mid: to_mid,
206
- image_url: image_url,
207
- alt_text: alt_text,
208
- )
209
- ```
210
-
211
- ### Signature validation
212
-
213
- ```ruby
214
- request = Rack::Request.new( .. )
215
- signature = request.env['HTTP_X_LINE_CHANNELSIGNATURE']
216
- unless client.validate_signature(request.body.read, signature)
217
- return 'invalidation of signature'
218
- end
219
- ```
220
-
221
- ### Receiving request
222
-
223
- ```ruby
224
- request = Rack::Request.new( .. )
225
-
226
- receive_request = Line::Bot::Receive::Request.new(request.env)
227
- receive_request.data #=> [Array<Line::Bot::Receive::Message || Line::Bot::Receive::Operation>]
228
-
229
- receive_request.data.each { |message|
230
- case message.content
231
- when Line::Bot::Message::Image, Line::Bot::Message::Video
232
- # get message content
233
- response = client.get_message_content(message.id)
234
- tf = Tempfile.open("content")
235
- tf.write(response.body)
236
-
237
- # get preview of message content
238
- preview_response = client.get_message_content_preview(message.id)
239
- ptf = Tempfile.open("content_preview")
240
- ptf.write(preview_response.body)
241
- end
242
- }
243
- ```
244
-
245
- ### Getting message content
246
-
247
- Get the original file which was sent by user.
248
-
249
- ### Getting preview of message content
250
-
251
- Get the preview image file which was sent by user.
252
-
253
- ### Getting user profile information
254
-
255
- ```ruby
256
- user_profile = client.get_user_profile("1234567")
257
- user_profile #=> [Line::Bot::Response::User::Profile]
258
- user_profile.contacts #=> [Array<Line::Bot::Response::User::Contact>]
259
- ```
260
-
261
77
  ## License
262
78
 
263
- The gem is available as open source under the terms of the [Apache License, Version 2.0](https://opensource.org/licenses/Apache-2.0).
79
+ Copyright (C) 2016 LINE Corporation.
80
+
81
+ Licensed under the Apache License, Version 2.0 (the "License");
82
+ you may not use this file except in compliance with the License.
83
+ You may obtain a copy of the License at
264
84
 
265
- ## Links
85
+ http://www.apache.org/licenses/LICENSE-2.0
266
86
 
267
- - [https://business.line.me/](https://business.line.me/)
268
- - [https://developers.line.me/bot-api/overview](https://developers.line.me/bot-api/overview)
269
- - [https://developers.line.me/bot-api/getting-started-with-bot-api-trial](https://developers.line.me/bot-api/getting-started-with-bot-api-trial)
87
+ Unless required by applicable law or agreed to in writing, software
88
+ distributed under the License is distributed on an "AS IS" BASIS,
89
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
90
+ See the License for the specific language governing permissions and
91
+ limitations under the License.
@@ -1,14 +1,21 @@
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
+
1
15
  require 'line/bot/client'
16
+ require 'line/bot/event'
2
17
  require 'line/bot/api/errors'
3
18
  require 'line/bot/api'
4
- require 'line/bot/event_type'
5
- require 'line/bot/message'
6
- require 'line/bot/operation'
7
- require 'line/bot/receive/message'
8
- require 'line/bot/receive/operation'
9
- require 'line/bot/receive/request'
10
- require 'line/bot/response/user/profile'
11
19
  require 'line/bot/request'
12
20
  require 'line/bot/httpclient'
13
- require 'line/bot/utils'
14
21
  require 'line/bot/api/version'
@@ -1,8 +1,21 @@
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
+
1
15
  module Line
2
16
  module Bot
3
17
  module API
4
- DEFAULT_ENDPOINT = "https://trialbot-api.line.me/v1"
5
- DEFAULT_SENDING_MESSAGE_CHANNEL_ID = 1383378250
18
+ DEFAULT_ENDPOINT = "https://api.line.me/v2/bot"
6
19
  end
7
20
  end
8
21
  end
@@ -1,9 +1,22 @@
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
+
1
15
  module Line
2
16
  module Bot
3
17
  module API
4
18
  class Error < StandardError; end
5
19
  class InvalidCredentialsError < Error; end
6
- class NotSupportedError < Error; end
7
20
  end
8
21
  end
9
22
  end
@@ -1,7 +1,21 @@
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
+
1
15
  module Line
2
16
  module Bot
3
17
  module API
4
- VERSION = "0.1.9"
18
+ VERSION = "1.0.0"
5
19
  end
6
20
  end
7
21
  end
@@ -1,19 +1,32 @@
1
- require 'line/bot/message'
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
+
2
15
  require 'line/bot/request'
3
- require 'line/bot/builder/rich_message'
4
- require 'line/bot/builder/multiple_message'
5
16
  require 'line/bot/api/errors'
6
17
  require 'base64'
7
18
  require 'net/http'
19
+ require 'openssl'
8
20
 
9
21
  module Line
10
22
  module Bot
11
23
  class Client
12
24
 
13
- include Line::Bot::Utils
14
-
15
25
  # @return [String]
16
- attr_accessor :channel_id, :channel_secret, :channel_mid, :endpoint, :to_channel_id, :httpclient
26
+ attr_accessor :channel_token, :channel_secret, :endpoint
27
+
28
+ # @return [Object]
29
+ attr_accessor :httpclient
17
30
 
18
31
  # Initialize a new Bot Client.
19
32
  #
@@ -25,7 +38,9 @@ module Line
25
38
  instance_variable_set("@#{key}", value)
26
39
  end
27
40
  yield(self) if block_given?
41
+ end
28
42
 
43
+ def httpclient
29
44
  @httpclient ||= Line::Bot::HTTPClient.new
30
45
  end
31
46
 
@@ -33,16 +48,10 @@ module Line
33
48
  @endpoint ||= Line::Bot::API::DEFAULT_ENDPOINT
34
49
  end
35
50
 
36
- def to_channel_id
37
- @to_channel_id ||= Line::Bot::API::DEFAULT_SENDING_MESSAGE_CHANNEL_ID
38
- end
39
-
40
51
  # @return [Hash]
41
52
  def credentials
42
53
  {
43
- 'X-Line-ChannelID' => channel_id,
44
- 'X-Line-ChannelSecret' => channel_secret,
45
- 'X-Line-Trusted-User-With-ACL' => channel_mid,
54
+ "Authorization" => "Bearer #{channel_token}",
46
55
  }
47
56
  end
48
57
 
@@ -50,137 +59,73 @@ module Line
50
59
  credentials.values.all?
51
60
  end
52
61
 
53
- # Send text to users.
54
- #
55
- # @param attrs [Hash]
56
- # @param to_mid [String or Array] User's identifiers
57
- # @param text [String]
62
+ # Push messages to line server and to users.
58
63
  #
59
- # @raise [ArgumentError] Error raised when supplied argument are missing :to_mid, :text keys.
64
+ # @param user_id [String] User's identifiers
65
+ # @param messages [Hash or Array]
60
66
  #
61
67
  # @return [Net::HTTPResponse]
62
- def send_text(attrs = {})
63
- message = Message::Text.new(
64
- text: attrs[:text],
65
- )
66
- send_message(attrs[:to_mid], message)
67
- end
68
+ def push_message(user_id, messages)
69
+ raise Line::Bot::API::InvalidCredentialsError, 'Invalidates credentials' unless credentials?
68
70
 
69
- # Send image to users.
70
- #
71
- # @param attrs [Hash]
72
- # @param to_mid [String or Array] User's identifiers
73
- # @param image_url [String] Image file's url
74
- # @param preview_url [String] Preview image file's url
75
- #
76
- # @raise [ArgumentError] Error raised when supplied argument are missing :to_mid, :image_url, :preview_url keys.
77
- #
78
- # @return [Net::HTTPResponse]
79
- def send_image(attrs = {})
80
- message = Message::Image.new(
81
- image_url: attrs[:image_url],
82
- preview_url: attrs[:preview_url],
83
- )
84
- send_message(attrs[:to_mid], message)
85
- end
71
+ messages = [messages] if messages.is_a?(Hash)
86
72
 
87
- # Send video to users.
88
- #
89
- # @param attrs [Hash]
90
- # @param to_mid [String or Array] User's identifiers
91
- # @param video_url [String] Video file's url
92
- # @param preview_url [String] Preview image file's url
93
- #
94
- # @raise [ArgumentError] Error raised when supplied argument are missing :to_mid, :video_url, :preview_url keys.
95
- #
96
- # @return [Net::HTTPResponse]
97
- def send_video(attrs = {})
98
- message = Message::Video.new(
99
- video_url: attrs[:video_url],
100
- preview_url: attrs[:preview_url],
101
- )
102
- send_message(attrs[:to_mid], message)
103
- end
73
+ request = Request.new do |config|
74
+ config.httpclient = httpclient
75
+ config.endpoint = endpoint
76
+ config.endpoint_path = '/message/push'
77
+ config.credentials = credentials
78
+ config.to = user_id
79
+ config.messages = messages
80
+ end
104
81
 
105
- # Send audio to users.
106
- #
107
- # @param attrs [Hash]
108
- # @param to_mid [String or Array] User's identifiers
109
- # @param audio_url [String] Audio file's url
110
- # @param duration [String or Integer] Voice message's length, milliseconds
111
- #
112
- # @raise [ArgumentError] Error raised when supplied argument are missing :to_mid, :audio_url, :duration keys.
113
- #
114
- # @return [Net::HTTPResponse]
115
- def send_audio(attrs = {})
116
- message = Message::Audio.new(
117
- audio_url: attrs[:audio_url],
118
- duration: attrs[:duration],
119
- )
120
- send_message(attrs[:to_mid], message)
82
+ request.post
121
83
  end
122
84
 
123
- # Send location to users.
124
- #
125
- # @param attrs [Hash]
126
- # @param to_mid [String or Array] User's identifiers
127
- # @param title [String] Location's title
128
- # @param address [String] Location's address
129
- # @param latitude [Float] Location's latitude
130
- # @param longitude [Float] Location's longitude
85
+ # Reply messages to line server and to users.
131
86
  #
132
- # @raise [ArgumentError] Error raised when supplied argument are missing :to_mid, :title, :latitude, :longitude keys.
87
+ # @param token [String]
88
+ # @param messages [Hash or Array]
133
89
  #
134
90
  # @return [Net::HTTPResponse]
135
- def send_location(attrs = {})
136
- message = Message::Location.new(
137
- title: attrs[:title],
138
- address: attrs[:address],
139
- latitude: attrs[:latitude],
140
- longitude: attrs[:longitude],
141
- )
142
- send_message(attrs[:to_mid], message)
91
+ def reply_message(token, messages)
92
+ raise Line::Bot::API::InvalidCredentialsError, 'Invalidates credentials' unless credentials?
93
+
94
+ messages = [messages] if messages.is_a?(Hash)
95
+
96
+ request = Request.new do |config|
97
+ config.httpclient = httpclient
98
+ config.endpoint = endpoint
99
+ config.endpoint_path = '/message/reply'
100
+ config.credentials = credentials
101
+ config.reply_token = token
102
+ config.messages = messages
103
+ end
104
+
105
+ request.post
143
106
  end
144
107
 
145
- # Send sticker to users.
146
- #
147
- # @param attrs [Hash]
148
- # @param to_mid [String or Array] User's identifiers
149
- # @param stkpkgid [String or Integer] Sticker's package identifier
150
- # @param stkid [String or Integer] Sticker's identifier
151
- # @param stkver [String or Integer] Sticker's version number
152
- #
153
- # @raise [ArgumentError] Error raised when supplied argument are missing :to_mid, :stkpkgid, :stkid, :stkver keys.
154
- #
155
- # @return [Net::HTTPResponse]
156
- def send_sticker(attrs = {})
157
- message = Message::Sticker.new(
158
- stkpkgid: attrs[:stkpkgid],
159
- stkid: attrs[:stkid],
160
- stkver: attrs[:stkver],
161
- )
162
- send_message(attrs[:to_mid], message)
108
+ def leave_group(group_id)
109
+ raise Line::Bot::API::InvalidCredentialsError, 'Invalidates credentials' unless credentials?
110
+
111
+ request = Request.new do |config|
112
+ config.httpclient = httpclient
113
+ config.endpoint = endpoint
114
+ config.endpoint_path = "/group/#{group_id}/leave"
115
+ config.credentials = credentials
116
+ end
117
+
118
+ request.post
163
119
  end
164
120
 
165
- # Send message to line server and to users.
166
- #
167
- # @param to_mid [String or Array] User's identifiers
168
- # @param message [Line::Bot::Message]
169
- #
170
- # @raise [ArgumentError] Error raised when supplied argument are missing message.
171
- #
172
- # @return [Net::HTTPResponse]
173
- def send_message(to_mid, message)
121
+ def leave_room(room_id)
174
122
  raise Line::Bot::API::InvalidCredentialsError, 'Invalidates credentials' unless credentials?
175
123
 
176
124
  request = Request.new do |config|
177
- config.to_channel_id = to_channel_id
178
125
  config.httpclient = httpclient
179
126
  config.endpoint = endpoint
180
- config.endpoint_path = '/events'
127
+ config.endpoint_path = "/room/#{room_id}/leave"
181
128
  config.credentials = credentials
182
- config.to_mid = to_mid
183
- config.message = message
184
129
  end
185
130
 
186
131
  request.post
@@ -190,45 +135,22 @@ module Line
190
135
  #
191
136
  # @param identifier [String] Message's identifier
192
137
  #
193
- # @raise [ArgumentError] Error raised when supplied argument are missing message.
194
- #
195
138
  # @return [Net::HTTPResponse]
196
139
  def get_message_content(identifier)
197
- endpoint_path = "/bot/message/#{identifier}/content"
140
+ endpoint_path = "/message/#{identifier}/content"
198
141
  get(endpoint_path)
199
142
  end
200
143
 
201
- # Get preview of message content.
144
+ # Get an user's profile.
202
145
  #
203
- # @param identifier [String] Message's identifier
204
- #
205
- # @raise [ArgumentError] Error raised when supplied argument are missing message.
146
+ # @param user_id [String] User's identifiers
206
147
  #
207
148
  # @return [Net::HTTPResponse]
208
- def get_message_content_preview(identifier)
209
- endpoint_path = "/bot/message/#{identifier}/content/preview"
149
+ def get_profile(user_id)
150
+ endpoint_path = "/profile/#{user_id}"
210
151
  get(endpoint_path)
211
152
  end
212
153
 
213
- # Get user profile.
214
- #
215
- # @param mids [String or Array] User's identifiers
216
- #
217
- # @raise [ArgumentError] Error raised when supplied argument are missing message.
218
- # @raise [HTTPError]
219
- #
220
- # @return [Line::Bot::Response::User::Profile]
221
- def get_user_profile(mids)
222
- raise ArgumentError, 'Wrong argument type `mids`' unless validate_mids(mids)
223
-
224
- query = mids.is_a?(Array) ? mids.join(',') : mids
225
- endpoint_path = "/profiles?mids=#{query}"
226
-
227
- response = get(endpoint_path)
228
-
229
- Line::Bot::Response::User::Profile.new(response) if !response.value
230
- end
231
-
232
154
  # Fetch data, get content of specified URL.
233
155
  #
234
156
  # @param endpoint_path [String]
@@ -238,7 +160,6 @@ module Line
238
160
  raise Line::Bot::API::InvalidCredentialsError, 'Invalidates credentials' unless credentials?
239
161
 
240
162
  request = Request.new do |config|
241
- config.to_channel_id = to_channel_id
242
163
  config.httpclient = httpclient
243
164
  config.endpoint = endpoint
244
165
  config.endpoint_path = endpoint_path
@@ -248,28 +169,32 @@ module Line
248
169
  request.get
249
170
  end
250
171
 
251
- # Create rich message to line server and to users.
172
+ # Parse events from request.body
252
173
  #
253
- # @return [Line::Bot::Builder::RichMessage]
254
- def rich_message
255
- Line::Bot::Builder::RichMessage.new(self)
256
- end
257
-
258
- # Create multiple message to line server and to users.
174
+ # @param request_body [String]
259
175
  #
260
- # @return [Line::Bot::Builder::MultipleMessage]
261
- def multiple_message
262
- Line::Bot::Builder::MultipleMessage.new(self)
176
+ # @return [Array<Line::Bot::Event::Class>]
177
+ def parse_events_from(request_body)
178
+ json = JSON.parse(request_body)
179
+
180
+ json['events'].map { |item|
181
+ begin
182
+ klass = Line::Bot::Event.const_get(item['type'].capitalize)
183
+ klass.new(item)
184
+ rescue NameError => e
185
+ Line::Bot::Event::Base.new(item)
186
+ end
187
+ }
263
188
  end
264
189
 
265
190
  # Validate signature
266
191
  #
267
192
  # @param content [String] Request's body
268
- # @param channel_signature [String] Request'header 'X-LINE-ChannelSignature' # HTTP_X_LINE_CHANNELSIGNATURE
193
+ # @param channel_signature [String] Request'header 'X-LINE-Signature' # HTTP_X_LINE_SIGNATURE
269
194
  #
270
195
  # @return [Boolean]
271
196
  def validate_signature(content = "", channel_signature)
272
- return false unless !channel_signature.nil? && credentials?
197
+ return false if !channel_signature || !channel_secret
273
198
 
274
199
  hash = OpenSSL::HMAC::digest(OpenSSL::Digest::SHA256.new, channel_secret, content)
275
200
  signature = Base64.strict_encode64(hash)