line-bot-api 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/line/bot/api/errors.rb +2 -1
- data/lib/line/bot/api/version.rb +1 -1
- data/lib/line/bot/api.rb +8 -0
- data/lib/line/bot/builder/multiple_message.rb +2 -2
- data/lib/line/bot/builder/rich_message.rb +13 -11
- data/lib/line/bot/client.rb +19 -7
- data/lib/line/bot/message/audio.rb +1 -1
- data/lib/line/bot/message/base.rb +8 -2
- data/lib/line/bot/message/image.rb +1 -1
- data/lib/line/bot/message/location.rb +1 -1
- data/lib/line/bot/message/recipient_type.rb +9 -0
- data/lib/line/bot/message/sticker.rb +1 -1
- data/lib/line/bot/message/text.rb +1 -1
- data/lib/line/bot/message/video.rb +1 -1
- data/lib/line/bot/message.rb +1 -0
- data/lib/line/bot/operation/{add_friend.rb → added_as_friend.rb} +1 -1
- data/lib/line/bot/operation/{block_account.rb → blocked_account.rb} +1 -1
- data/lib/line/bot/operation/op_type.rb +2 -2
- data/lib/line/bot/operation.rb +2 -2
- data/lib/line/bot/receive/message.rb +9 -9
- data/lib/line/bot/receive/operation.rb +12 -12
- data/lib/line/bot/request.rb +9 -5
- data/lib/line/bot.rb +1 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5f3cd382e3301e12f50221b2c4dd50fcf9368ec
|
4
|
+
data.tar.gz: 511638740aa7351650516316f9b0df33d218f2d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65c62c21e408228177cc08e11fe16c0f73eb4ede6ae2b5befa31f769fd4261c55507e7a7d784e601ede030b77fa311428bacb572735ba33cdc5c45a68fb984a0
|
7
|
+
data.tar.gz: f6e2bd4a49937138fbc5fa862c0e2f538499924c77aae5d185dbc7291d3b3e7d0207a8a7c05da5e6bd51331f114968f2b4c399c3c00cf03c0019adee147ed65c
|
data/lib/line/bot/api/errors.rb
CHANGED
data/lib/line/bot/api/version.rb
CHANGED
data/lib/line/bot/api.rb
ADDED
@@ -5,7 +5,7 @@ module Line
|
|
5
5
|
module Builder
|
6
6
|
class MultipleMessage
|
7
7
|
|
8
|
-
def initialize
|
8
|
+
def initialize(client)
|
9
9
|
@messages ||= []
|
10
10
|
@client = client
|
11
11
|
end
|
@@ -82,7 +82,7 @@ module Line
|
|
82
82
|
end
|
83
83
|
|
84
84
|
def event_type
|
85
|
-
|
85
|
+
Line::Bot::EventType::MULTIPLE_MESSAGE
|
86
86
|
end
|
87
87
|
|
88
88
|
def content
|
@@ -6,7 +6,7 @@ module Line
|
|
6
6
|
module Builder
|
7
7
|
class RichMessage
|
8
8
|
|
9
|
-
def initialize
|
9
|
+
def initialize(client)
|
10
10
|
@actions ||= {}
|
11
11
|
@listeners ||= []
|
12
12
|
@client = client
|
@@ -81,7 +81,7 @@ module Line
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def event_type
|
84
|
-
|
84
|
+
Line::Bot::EventType::MESSAGE
|
85
85
|
end
|
86
86
|
|
87
87
|
def content
|
@@ -112,20 +112,22 @@ module Line
|
|
112
112
|
image1: {
|
113
113
|
x: 0,
|
114
114
|
y: 0,
|
115
|
-
|
116
|
-
|
115
|
+
w: 1040, # Integer fixed value: 1040
|
116
|
+
h: height
|
117
117
|
},
|
118
118
|
},
|
119
119
|
actions: @actions,
|
120
120
|
scenes: {
|
121
121
|
scene1: {
|
122
|
-
draws:
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
122
|
+
draws: [
|
123
|
+
{
|
124
|
+
image: 'image1', # Use the image ID "image1".
|
125
|
+
x: 0,
|
126
|
+
y: 0,
|
127
|
+
w: 1040, # Integer fixed value: 1040
|
128
|
+
h: height
|
129
|
+
},
|
130
|
+
],
|
129
131
|
listeners: @listeners
|
130
132
|
}
|
131
133
|
}
|
data/lib/line/bot/client.rb
CHANGED
@@ -11,7 +11,7 @@ module Line
|
|
11
11
|
class Client
|
12
12
|
|
13
13
|
# @return [String]
|
14
|
-
attr_accessor :channel_id, :channel_secret, :channel_mid
|
14
|
+
attr_accessor :channel_id, :channel_secret, :channel_mid, :endpoint, :to_channel_id
|
15
15
|
|
16
16
|
# Initialize a new Bot Client.
|
17
17
|
#
|
@@ -25,6 +25,14 @@ module Line
|
|
25
25
|
yield(self) if block_given?
|
26
26
|
end
|
27
27
|
|
28
|
+
def endpoint
|
29
|
+
@endpoint ||= Line::Bot::API::DEFAULT_ENDPOINT
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_channel_id
|
33
|
+
@to_channel_id ||= Line::Bot::API::DEFAULT_SENDING_MESSAGE_CHANNEL_ID
|
34
|
+
end
|
35
|
+
|
28
36
|
# @return [Hash]
|
29
37
|
def credentials
|
30
38
|
{
|
@@ -162,6 +170,8 @@ module Line
|
|
162
170
|
raise Line::Bot::API::InvalidCredentialsError, 'Invalidates credentials' unless credentials?
|
163
171
|
|
164
172
|
request = Request.new do |config|
|
173
|
+
config.to_channel_id = to_channel_id
|
174
|
+
config.endpoint = endpoint
|
165
175
|
config.endpoint_path = '/v1/events'
|
166
176
|
config.credentials = credentials
|
167
177
|
config.to_mid = to_mid
|
@@ -173,25 +183,25 @@ module Line
|
|
173
183
|
|
174
184
|
# Get message content.
|
175
185
|
#
|
176
|
-
# @param
|
186
|
+
# @param identifier [String] Message's identifier
|
177
187
|
#
|
178
188
|
# @raise [ArgumentError] Error raised when supplied argument are missing message.
|
179
189
|
#
|
180
190
|
# @return [Net::HTTPResponse]
|
181
|
-
def get_message_content(
|
182
|
-
endpoint_path = "/v1/bot/message/#{
|
191
|
+
def get_message_content(identifier)
|
192
|
+
endpoint_path = "/v1/bot/message/#{identifier}/content"
|
183
193
|
get(endpoint_path)
|
184
194
|
end
|
185
195
|
|
186
196
|
# Get preview of message content.
|
187
197
|
#
|
188
|
-
# @param
|
198
|
+
# @param identifier [String] Message's identifier
|
189
199
|
#
|
190
200
|
# @raise [ArgumentError] Error raised when supplied argument are missing message.
|
191
201
|
#
|
192
202
|
# @return [Net::HTTPResponse]
|
193
|
-
def get_message_content_preview(
|
194
|
-
endpoint_path = "/v1/bot/message/#{
|
203
|
+
def get_message_content_preview(identifier)
|
204
|
+
endpoint_path = "/v1/bot/message/#{identifier}/content/preview"
|
195
205
|
get(endpoint_path)
|
196
206
|
end
|
197
207
|
|
@@ -223,6 +233,8 @@ module Line
|
|
223
233
|
raise Line::Bot::API::InvalidCredentialsError, 'Invalidates credentials' unless credentials?
|
224
234
|
|
225
235
|
request = Request.new do |config|
|
236
|
+
config.to_channel_id = to_channel_id
|
237
|
+
config.endpoint = endpoint
|
226
238
|
config.endpoint_path = endpoint_path
|
227
239
|
config.credentials = credentials
|
228
240
|
end
|
@@ -1,19 +1,25 @@
|
|
1
|
+
require 'line/bot/message/recipient_type'
|
2
|
+
|
1
3
|
module Line
|
2
4
|
module Bot
|
3
5
|
module Message
|
4
6
|
class Base
|
5
|
-
attr_reader :attrs
|
7
|
+
attr_reader :attrs, :recipient_type
|
6
8
|
|
7
9
|
def initialize(attrs = {})
|
8
10
|
@attrs = attrs
|
9
11
|
end
|
10
12
|
|
13
|
+
def recipient_type
|
14
|
+
@attrs[:recipient_type] ||= Line::Bot::Message::RecipientType::USER
|
15
|
+
end
|
16
|
+
|
11
17
|
def [](key)
|
12
18
|
@attrs[key]
|
13
19
|
end
|
14
20
|
|
15
21
|
def event_type
|
16
|
-
|
22
|
+
Line::Bot::EventType::MESSAGE
|
17
23
|
end
|
18
24
|
|
19
25
|
def content
|
data/lib/line/bot/message.rb
CHANGED
data/lib/line/bot/operation.rb
CHANGED
@@ -4,20 +4,20 @@ module Line
|
|
4
4
|
class Message
|
5
5
|
attr_reader :id, :from_mid, :to_mid, :from_channel_id, :to_channel_id, :event_type, :created_time, :content
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
@id =
|
9
|
-
@from_mid =
|
10
|
-
@to_mid =
|
7
|
+
def initialize(attrs)
|
8
|
+
@id = attrs['content']['id']
|
9
|
+
@from_mid = attrs['content']['from']
|
10
|
+
@to_mid = attrs['content']['to']
|
11
11
|
|
12
|
-
@from_channel_id =
|
13
|
-
@to_channel_id =
|
12
|
+
@from_channel_id = attrs['fromChannel']
|
13
|
+
@to_channel_id = attrs['toChannel']
|
14
14
|
|
15
|
-
@event_type =
|
15
|
+
@event_type = attrs['eventType']
|
16
16
|
|
17
|
-
(time, usec) =
|
17
|
+
(time, usec) = attrs['content']['createdTime'].to_i.divmod(1000)
|
18
18
|
@created_time = Time.at(time, usec)
|
19
19
|
|
20
|
-
@content = create_content(
|
20
|
+
@content = create_content(attrs['content'])
|
21
21
|
end
|
22
22
|
|
23
23
|
def create_content(attrs)
|
@@ -6,28 +6,28 @@ module Line
|
|
6
6
|
class Operation
|
7
7
|
attr_reader :id, :from_mid, :to_mid, :from_channel_id, :to_channel_id, :event_type, :content
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
@id =
|
11
|
-
@from_mid =
|
12
|
-
@to_mid =
|
9
|
+
def initialize(attrs)
|
10
|
+
@id = attrs['id']
|
11
|
+
@from_mid = attrs['content']['params'].first
|
12
|
+
@to_mid = attrs['to']
|
13
13
|
|
14
|
-
@from_channel_id =
|
15
|
-
@to_channel_id =
|
14
|
+
@from_channel_id = attrs['fromChannel']
|
15
|
+
@to_channel_id = attrs['toChannel']
|
16
16
|
|
17
|
-
@event_type =
|
18
|
-
@content = create_content(
|
17
|
+
@event_type = attrs['eventType']
|
18
|
+
@content = create_content(attrs['content'])
|
19
19
|
end
|
20
20
|
|
21
21
|
def create_content(attrs)
|
22
22
|
case attrs['opType']
|
23
|
-
when Line::Bot::Operation::OpType::
|
24
|
-
return Line::Bot::Operation::
|
23
|
+
when Line::Bot::Operation::OpType::ADDED_AS_FRIEND
|
24
|
+
return Line::Bot::Operation::AddedAsFriend.new(
|
25
25
|
revision: attrs['revision'],
|
26
26
|
op_type: attrs['opType'],
|
27
27
|
params: attrs['params'],
|
28
28
|
)
|
29
|
-
when Line::Bot::Operation::OpType::
|
30
|
-
return Line::Bot::Operation::
|
29
|
+
when Line::Bot::Operation::OpType::BLOCKED_ACCOUNT
|
30
|
+
return Line::Bot::Operation::BlockedAccount.new(
|
31
31
|
revision: attrs['revision'],
|
32
32
|
op_type: attrs['opType'],
|
33
33
|
params: attrs['params'],
|
data/lib/line/bot/request.rb
CHANGED
@@ -1,23 +1,27 @@
|
|
1
1
|
require 'line/bot/api/version'
|
2
2
|
require 'json'
|
3
3
|
require 'net/http'
|
4
|
+
require 'uri'
|
4
5
|
|
5
6
|
module Line
|
6
7
|
module Bot
|
7
8
|
class Request
|
8
|
-
attr_accessor :endpoint_path, :credentials, :to_mid, :message
|
9
|
+
attr_accessor :endpoint, :endpoint_path, :credentials, :to_mid, :message, :to_channel_id
|
9
10
|
|
10
11
|
# Initializes a new Request
|
11
12
|
#
|
12
|
-
# @return [LINE::Bot::
|
13
|
+
# @return [LINE::Bot::Request]
|
13
14
|
def initialize
|
14
15
|
yield(self) if block_given?
|
15
16
|
end
|
16
17
|
|
17
18
|
# @return [Net::HTTP]
|
18
19
|
def https
|
19
|
-
|
20
|
-
https
|
20
|
+
uri = URI(endpoint)
|
21
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
22
|
+
if uri.scheme == "https"
|
23
|
+
https.use_ssl = true
|
24
|
+
end
|
21
25
|
|
22
26
|
https
|
23
27
|
end
|
@@ -38,7 +42,7 @@ module Line
|
|
38
42
|
def payload
|
39
43
|
payload = {
|
40
44
|
to: to,
|
41
|
-
toChannel:
|
45
|
+
toChannel: to_channel_id,
|
42
46
|
eventType: message.event_type.to_s,
|
43
47
|
content: content
|
44
48
|
}
|
data/lib/line/bot.rb
CHANGED
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: 0.1.
|
4
|
+
version: 0.1.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: 2016-04-
|
11
|
+
date: 2016-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- LICENSE
|
106
106
|
- README.md
|
107
107
|
- lib/line/bot.rb
|
108
|
+
- lib/line/bot/api.rb
|
108
109
|
- lib/line/bot/api/errors.rb
|
109
110
|
- lib/line/bot/api/version.rb
|
110
111
|
- lib/line/bot/builder/multiple_message.rb
|
@@ -117,13 +118,14 @@ files:
|
|
117
118
|
- lib/line/bot/message/content_type.rb
|
118
119
|
- lib/line/bot/message/image.rb
|
119
120
|
- lib/line/bot/message/location.rb
|
121
|
+
- lib/line/bot/message/recipient_type.rb
|
120
122
|
- lib/line/bot/message/sticker.rb
|
121
123
|
- lib/line/bot/message/text.rb
|
122
124
|
- lib/line/bot/message/video.rb
|
123
125
|
- lib/line/bot/operation.rb
|
124
|
-
- lib/line/bot/operation/
|
126
|
+
- lib/line/bot/operation/added_as_friend.rb
|
125
127
|
- lib/line/bot/operation/base.rb
|
126
|
-
- lib/line/bot/operation/
|
128
|
+
- lib/line/bot/operation/blocked_account.rb
|
127
129
|
- lib/line/bot/operation/op_type.rb
|
128
130
|
- lib/line/bot/receive/message.rb
|
129
131
|
- lib/line/bot/receive/operation.rb
|