line-bot-lite 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -7
- data/lib/line/bot/client.rb +4 -0
- data/lib/line/bot/event.rb +7 -2
- data/lib/line/bot/message.rb +1 -0
- data/lib/line/bot/message/image.rb +22 -0
- data/lib/line/bot/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9c8979c599240209f74ff04ebcce0184876fa32
|
4
|
+
data.tar.gz: 272f486d381f98f7f464873fbba6016dc7b3b728
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98390a9ea5586624889f83c4052b1c8c68049904f4a9bd876c859bc58c31e1620c5e338b29672097729da99381ace86d6729612f4907fe6bec09814150e07117
|
7
|
+
data.tar.gz: 52673d5b8bdc430aae2042619607d611d7d4d99a6181aa01e056c2d7deda66dde43d54e15c5a55f54ca131d097cd405ddcdc593c292d07ea869b1704ddb8b633
|
data/README.md
CHANGED
@@ -41,18 +41,17 @@ end
|
|
41
41
|
|
42
42
|
post '/callback' do
|
43
43
|
signature = request.env['HTTP_X_LINE_CHANNELSIGNATURE']
|
44
|
-
unless client.certentials.validate_signature
|
44
|
+
unless client.certentials.validate_signature(request.body.read, signature)
|
45
45
|
error 400 do 'Bad Request' end
|
46
46
|
end
|
47
47
|
|
48
48
|
request.body.rewind
|
49
|
-
|
50
|
-
result = json['result']
|
49
|
+
events = Line::Bot::Response.new(request.body.read)
|
51
50
|
|
52
|
-
|
53
|
-
case
|
54
|
-
when Line::Bot::Receive::EventType::MESSAGE
|
55
|
-
client.send_text(
|
51
|
+
events.each do |event|
|
52
|
+
case event.event_type
|
53
|
+
when Line::Bot::Receive::EventType::MESSAGE
|
54
|
+
client.send_text(event.from_mid, event.content[:text])
|
56
55
|
end
|
57
56
|
end
|
58
57
|
|
data/lib/line/bot/client.rb
CHANGED
@@ -13,6 +13,10 @@ module Line
|
|
13
13
|
send_message(to_mid, Message::Text.new(text: message))
|
14
14
|
end
|
15
15
|
|
16
|
+
def send_image(to_mid, image_url, preview_url)
|
17
|
+
send_message(to_mid, Message::Image.new( image_url: image_url, preview_url: preview_url) )
|
18
|
+
end
|
19
|
+
|
16
20
|
def send_message(to_mid, message)
|
17
21
|
request = Request.new do |config|
|
18
22
|
config.to_mid = to_mid
|
data/lib/line/bot/event.rb
CHANGED
@@ -35,8 +35,13 @@ module Line
|
|
35
35
|
return if @data.nil?
|
36
36
|
case @data['contentType']
|
37
37
|
when Message::ContentType::TEXT
|
38
|
-
|
39
|
-
|
38
|
+
return Message::Text.new(text: @data['text'])
|
39
|
+
when Message::ContentType::IMAGE
|
40
|
+
return Message::Image.new(
|
41
|
+
image_url: @data['originalContentUrl'],
|
42
|
+
preview_url: @data['previewImageUrl']
|
43
|
+
)
|
44
|
+
# TODO: Implement other type message type
|
40
45
|
end
|
41
46
|
end
|
42
47
|
|
data/lib/line/bot/message.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Line
|
2
|
+
module Bot
|
3
|
+
module Message
|
4
|
+
class Image < Base
|
5
|
+
attr_reader :image_url, :preview_url
|
6
|
+
|
7
|
+
def content
|
8
|
+
{
|
9
|
+
contentType: ContentType::IMAGE,
|
10
|
+
toType: recipient_type,
|
11
|
+
originalContentUrl: self[:image_url],
|
12
|
+
previewImageUrl: self[:preview_url]
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
def valid?
|
17
|
+
!self[:image_url].nil? && ![:preview_url].nil?
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/line/bot/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: line-bot-lite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 蒼時弦也
|
@@ -135,6 +135,7 @@ files:
|
|
135
135
|
- lib/line/bot/message.rb
|
136
136
|
- lib/line/bot/message/base.rb
|
137
137
|
- lib/line/bot/message/content_type.rb
|
138
|
+
- lib/line/bot/message/image.rb
|
138
139
|
- lib/line/bot/message/recipient_type.rb
|
139
140
|
- lib/line/bot/message/text.rb
|
140
141
|
- lib/line/bot/request.rb
|