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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 64edfbc80dd87e13e211abd1b332268ecbce2a2c
4
- data.tar.gz: 60c8f4ecd0c249647bd10a15bf7bc06d76cf32c2
3
+ metadata.gz: a9c8979c599240209f74ff04ebcce0184876fa32
4
+ data.tar.gz: 272f486d381f98f7f464873fbba6016dc7b3b728
5
5
  SHA512:
6
- metadata.gz: 3a8813b28ed1f1dc082c986d2e963dac7b98f3f6ac407fc6e65131463bf3913afc05691297b7715f3bfd56f92ddc02f85598f08781609cd7a98d0a46149b65c1
7
- data.tar.gz: 3353820adfe020d99b577c53dc837b3aceeca10d53e3be8b8b43853718fe5f01efd1966f54a996a70e7beaadee9487b75825815dc6d9d3713a5b4502235725c0
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?(request.body.read, 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
- json = JSON.parse(request.body.read)
50
- result = json['result']
49
+ events = Line::Bot::Response.new(request.body.read)
51
50
 
52
- result.each do |message|
53
- case message['eventType']
54
- when Line::Bot::Receive::EventType::MESSAGE.to_s
55
- client.send_text(message['content']['from'], message['content']['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
 
@@ -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
@@ -35,8 +35,13 @@ module Line
35
35
  return if @data.nil?
36
36
  case @data['contentType']
37
37
  when Message::ContentType::TEXT
38
- return Message::Text.new(text: @data['text'])
39
- # TODO: Implement other type message type
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
 
@@ -4,3 +4,4 @@ require 'line/bot/message/recipient_type'
4
4
 
5
5
  require 'line/bot/message/base'
6
6
  require 'line/bot/message/text'
7
+ require 'line/bot/message/image'
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Line
2
2
  module Bot
3
- VERSION = "0.2.1"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
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.2.1
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