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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b35492a0cc51c944088a4f3837e609d23d0e11d
4
- data.tar.gz: 1160d8e67dc7dd7f8001a8dcc17df23f0ad33c18
3
+ metadata.gz: a5f3cd382e3301e12f50221b2c4dd50fcf9368ec
4
+ data.tar.gz: 511638740aa7351650516316f9b0df33d218f2d2
5
5
  SHA512:
6
- metadata.gz: 832ca392ab39f819f7b15cb3b6824e74fb90a4a3175fc1fa5435b39f3c3137c1e0e4a96606b233442a01b0c2eaa111070e4328693e441836dcaa484d0540e8ac
7
- data.tar.gz: 43e8eb81314369f4275bf17f04f134ab91a3d096512e1269a7a3149943f5596b9fb3ed04a4caae2ba221a5c876167b0562283bd10c6267f8e9ad81c8888a7ca1
6
+ metadata.gz: 65c62c21e408228177cc08e11fe16c0f73eb4ede6ae2b5befa31f769fd4261c55507e7a7d784e601ede030b77fa311428bacb572735ba33cdc5c45a68fb984a0
7
+ data.tar.gz: f6e2bd4a49937138fbc5fa862c0e2f538499924c77aae5d185dbc7291d3b3e7d0207a8a7c05da5e6bd51331f114968f2b4c399c3c00cf03c0019adee147ed65c
@@ -1,7 +1,8 @@
1
1
  module Line
2
2
  module Bot
3
3
  module API
4
- class InvalidCredentialsError < StandardError; end
4
+ class Error < StandardError; end
5
+ class InvalidCredentialsError < Error; end
5
6
  end
6
7
  end
7
8
  end
@@ -1,7 +1,7 @@
1
1
  module Line
2
2
  module Bot
3
3
  module API
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.3"
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,8 @@
1
+ module Line
2
+ module Bot
3
+ module API
4
+ DEFAULT_ENDPOINT = "https://trialbot-api.line.me"
5
+ DEFAULT_SENDING_MESSAGE_CHANNEL_ID = 1383378250
6
+ end
7
+ end
8
+ end
@@ -5,7 +5,7 @@ module Line
5
5
  module Builder
6
6
  class MultipleMessage
7
7
 
8
- def initialize client
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
- 140177271400161403
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 client
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
- 138311608800106203
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
- width: 1040, # Integer fixed value: 1040
116
- height: height
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
- image: 'image1', # Use the image ID "image1".
124
- x: 0,
125
- y: 0,
126
- width: 1040, # Integer fixed value: 1040
127
- height: height
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
  }
@@ -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 identifer [String] Message's identifier
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(identifer)
182
- endpoint_path = "/v1/bot/message/#{identifer}/content"
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 identifer [String] Message's identifier
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(identifer)
194
- endpoint_path = "/v1/bot/message/#{identifer}/content/preview"
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
@@ -8,7 +8,7 @@ module Line
8
8
  def content
9
9
  {
10
10
  contentType: ContentType::AUDIO,
11
- toType: 1,
11
+ toType: recipient_type,
12
12
  originalContentUrl: attrs[:audio_url],
13
13
  contentMetadata: {
14
14
  AUDLEN: attrs[:duration].to_s,
@@ -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
- 138311608800106203
22
+ Line::Bot::EventType::MESSAGE
17
23
  end
18
24
 
19
25
  def content
@@ -8,7 +8,7 @@ module Line
8
8
  def content
9
9
  {
10
10
  contentType: ContentType::IMAGE,
11
- toType: 1,
11
+ toType: recipient_type,
12
12
  originalContentUrl: attrs[:image_url],
13
13
  previewImageUrl: attrs[:preview_url],
14
14
  }
@@ -8,7 +8,7 @@ module Line
8
8
  def content
9
9
  {
10
10
  contentType: ContentType::LOCATION,
11
- toType: 1,
11
+ toType: recipient_type,
12
12
  text: attrs[:address] || attrs[:title],
13
13
  location: {
14
14
  title: attrs[:title],
@@ -0,0 +1,9 @@
1
+ module Line
2
+ module Bot
3
+ module Message
4
+ module RecipientType
5
+ USER = 1
6
+ end
7
+ end
8
+ end
9
+ end
@@ -8,7 +8,7 @@ module Line
8
8
  def content
9
9
  {
10
10
  contentType: ContentType::STICKER,
11
- toType: 1,
11
+ toType: recipient_type,
12
12
  contentMetadata: {
13
13
  STKPKGID: attrs[:stkpkgid].to_s,
14
14
  STKID: attrs[:stkid].to_s,
@@ -8,7 +8,7 @@ module Line
8
8
  def content
9
9
  {
10
10
  contentType: ContentType::TEXT,
11
- toType: 1,
11
+ toType: recipient_type,
12
12
  text: attrs[:text]
13
13
  }
14
14
  end
@@ -8,7 +8,7 @@ module Line
8
8
  def content
9
9
  {
10
10
  contentType: ContentType::VIDEO,
11
- toType: 1,
11
+ toType: recipient_type,
12
12
  originalContentUrl: attrs[:video_url],
13
13
  previewImageUrl: attrs[:preview_url],
14
14
  }
@@ -5,3 +5,4 @@ require 'line/bot/message/video'
5
5
  require 'line/bot/message/audio'
6
6
  require 'line/bot/message/location'
7
7
  require 'line/bot/message/sticker'
8
+ require 'line/bot/message/recipient_type'
@@ -3,7 +3,7 @@ require 'line/bot/operation/base'
3
3
  module Line
4
4
  module Bot
5
5
  module Operation
6
- class AddFriend < Line::Bot::Operation::Base
6
+ class AddedAsFriend < Line::Bot::Operation::Base
7
7
  end
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ require 'line/bot/operation/base'
3
3
  module Line
4
4
  module Bot
5
5
  module Operation
6
- class BlockAccount < Line::Bot::Operation::Base
6
+ class BlockedAccount < Line::Bot::Operation::Base
7
7
  end
8
8
  end
9
9
  end
@@ -2,8 +2,8 @@ module Line
2
2
  module Bot
3
3
  module Operation
4
4
  module OpType
5
- ADD_FRIEND = 4
6
- BLOCK_ACCOUNT = 8
5
+ ADDED_AS_FRIEND = 4
6
+ BLOCKED_ACCOUNT = 8
7
7
  end
8
8
  end
9
9
  end
@@ -1,3 +1,3 @@
1
- require 'line/bot/operation/add_friend'
2
- require 'line/bot/operation/block_account'
3
1
  require 'line/bot/operation/op_type'
2
+ require 'line/bot/operation/added_as_friend'
3
+ require 'line/bot/operation/blocked_account'
@@ -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(env)
8
- @id = env['content']['id']
9
- @from_mid = env['content']['from']
10
- @to_mid = env['content']['to']
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 = env['fromChannel']
13
- @to_channel_id = env['toChannel']
12
+ @from_channel_id = attrs['fromChannel']
13
+ @to_channel_id = attrs['toChannel']
14
14
 
15
- @event_type = env['eventType']
15
+ @event_type = attrs['eventType']
16
16
 
17
- (time, usec) = env['content']['createdTime'].to_i.divmod(1000)
17
+ (time, usec) = attrs['content']['createdTime'].to_i.divmod(1000)
18
18
  @created_time = Time.at(time, usec)
19
19
 
20
- @content = create_content(env['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(env)
10
- @id = env['id']
11
- @from_mid = env['content']['params'].first
12
- @to_mid = env['to']
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 = env['fromChannel']
15
- @to_channel_id = env['toChannel']
14
+ @from_channel_id = attrs['fromChannel']
15
+ @to_channel_id = attrs['toChannel']
16
16
 
17
- @event_type = env['eventType']
18
- @content = create_content(env['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::ADD_FRIEND
24
- return Line::Bot::Operation::AddFriend.new(
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::BLOCK_ACCOUNT
30
- return Line::Bot::Operation::BlockAccount.new(
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'],
@@ -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::Client]
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
- https = Net::HTTP.new('trialbot-api.line.me', 443)
20
- https.use_ssl = true
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: 1383378250, # Fixed value
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
@@ -1,5 +1,6 @@
1
1
  require 'line/bot/client'
2
2
  require 'line/bot/api/errors'
3
+ require 'line/bot/api'
3
4
  require 'line/bot/event_type'
4
5
  require 'line/bot/message'
5
6
  require 'line/bot/operation'
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.2
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-19 00:00:00.000000000 Z
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/add_friend.rb
126
+ - lib/line/bot/operation/added_as_friend.rb
125
127
  - lib/line/bot/operation/base.rb
126
- - lib/line/bot/operation/block_account.rb
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