line-bot-api 0.1.1 → 0.1.2

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: 53328dc34338632959e4d41e639b22fb47c0c2b5
4
- data.tar.gz: ce8777fa1029e0ab4094e86591684795911f0089
3
+ metadata.gz: 8b35492a0cc51c944088a4f3837e609d23d0e11d
4
+ data.tar.gz: 1160d8e67dc7dd7f8001a8dcc17df23f0ad33c18
5
5
  SHA512:
6
- metadata.gz: c9edcef377b3c0cbc1a70260eec62addfb93b4bf4353ca19b45ffc0545008b328369d8428fb0d36b776914c6ca933eff6cc4296b56c861d6f520b92aa02554a5
7
- data.tar.gz: b577b38f12b817325958a474578010c404c9069d93409d0d32e6593210e50f5b76c2df33656c32a62498483449aa30d977e535c589ccd009ae917771632c83e0
6
+ metadata.gz: 832ca392ab39f819f7b15cb3b6824e74fb90a4a3175fc1fa5435b39f3c3137c1e0e4a96606b233442a01b0c2eaa111070e4328693e441836dcaa484d0540e8ac
7
+ data.tar.gz: 43e8eb81314369f4275bf17f04f134ab91a3d096512e1269a7a3149943f5596b9fb3ed04a4caae2ba221a5c876167b0562283bd10c6267f8e9ad81c8888a7ca1
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Line::Bot::API - SDK of the LINE BOT API Trial for Ruby
4
4
 
5
- [![Gem-version](https://img.shields.io/gem/v/line-bot-api.svg)](https://rubygems.org/gems/) [![Build Status](https://travis-ci.org/line/line-bot-sdk-ruby.svg?branch=master)](https://travis-ci.org/line/line-bot-sdk-ruby)
5
+ [![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)
6
6
 
7
7
  ## Installation
8
8
 
@@ -188,7 +188,7 @@ end
188
188
  request_from_rack = Rack::Request.new( .. )
189
189
 
190
190
  request = Line::Bot::Receive::Request.new(request_from_rack.env)
191
- request.data #=> [Array] Line::Bot::Receive::Message || Line::Bot::Receive::Operation
191
+ request.data #=> [Array<Line::Bot::Receive::Message || Line::Bot::Receive::Operation>]
192
192
 
193
193
  request.data.each { |message|
194
194
  case message.content
@@ -219,7 +219,7 @@ Get the preview image file which was sent by user.
219
219
  ```
220
220
  user_profile = client.get_user_profile("1234567")
221
221
  user_profile #=> [Line::Bot::Response::User::Profile]
222
- user_profile.contacts #=> [Array] Line::Bot::Response::User::Contact
222
+ user_profile.contacts #=> [Array<Line::Bot::Response::User::Contact>]
223
223
  ```
224
224
 
225
225
  ## License
@@ -1,7 +1,7 @@
1
1
  module Line
2
2
  module Bot
3
3
  module API
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
6
6
  end
7
7
  end
@@ -9,13 +9,19 @@ require 'net/http'
9
9
  module Line
10
10
  module Bot
11
11
  class Client
12
+
13
+ # @return [String]
12
14
  attr_accessor :channel_id, :channel_secret, :channel_mid
13
15
 
14
- # Initializes a new Bot Client
16
+ # Initialize a new Bot Client.
15
17
  #
16
18
  # @param options [Hash]
19
+ #
17
20
  # @return [LINE::Bot::Client]
18
- def initialize
21
+ def initialize(options = {})
22
+ options.each do |key, value|
23
+ instance_variable_set("@#{key}", value)
24
+ end
19
25
  yield(self) if block_given?
20
26
  end
21
27
 
@@ -32,11 +38,12 @@ module Line
32
38
  credentials.values.all?
33
39
  end
34
40
 
35
- # Sends text to users
41
+ # Send text to users.
36
42
  #
37
43
  # @param attrs [Hash]
38
- # @param attrs [:to_mid] [String or Array] User's indentifiers
39
- # @param attrs [:text] [String]
44
+ # @param to_mid [String or Array] User's identifiers
45
+ # @param text [String]
46
+ #
40
47
  # @raise [ArgumentError] Error raised when supplied argument are missing :to_mid, :text keys.
41
48
  #
42
49
  # @return [Net::HTTPResponse]
@@ -47,12 +54,13 @@ module Line
47
54
  send_message(attrs[:to_mid], message)
48
55
  end
49
56
 
50
- # Sends image to users
57
+ # Send image to users.
51
58
  #
52
59
  # @param attrs [Hash]
53
- # @param attrs [:to_mid] [String or Array] User's indentifiers
54
- # @param attrs [:image_url] [String] Image file's url
55
- # @param attrs [:preview_url] [String] Preview image file's url
60
+ # @param to_mid [String or Array] User's identifiers
61
+ # @param image_url [String] Image file's url
62
+ # @param preview_url [String] Preview image file's url
63
+ #
56
64
  # @raise [ArgumentError] Error raised when supplied argument are missing :to_mid, :image_url, :preview_url keys.
57
65
  #
58
66
  # @return [Net::HTTPResponse]
@@ -64,12 +72,13 @@ module Line
64
72
  send_message(attrs[:to_mid], message)
65
73
  end
66
74
 
67
- # Sends video to users
75
+ # Send video to users.
68
76
  #
69
77
  # @param attrs [Hash]
70
- # @param attrs [:to_mid] [String or Array] User's indentifiers
71
- # @param attrs [:video_url] [String] Video file's url
72
- # @param attrs [:preview_url] [String] Preview image file's url
78
+ # @param to_mid [String or Array] User's identifiers
79
+ # @param video_url [String] Video file's url
80
+ # @param preview_url [String] Preview image file's url
81
+ #
73
82
  # @raise [ArgumentError] Error raised when supplied argument are missing :to_mid, :video_url, :preview_url keys.
74
83
  #
75
84
  # @return [Net::HTTPResponse]
@@ -81,12 +90,13 @@ module Line
81
90
  send_message(attrs[:to_mid], message)
82
91
  end
83
92
 
84
- # Sends audio to users
93
+ # Send audio to users.
85
94
  #
86
95
  # @param attrs [Hash]
87
- # @param attrs [:to_mid] [String or Array] User's indentifiers
88
- # @param attrs [:audio_url] [String] Audio file's url
89
- # @param attrs [:duration] [String or Integer] Voice message's length, milliseconds
96
+ # @param to_mid [String or Array] User's identifiers
97
+ # @param audio_url [String] Audio file's url
98
+ # @param duration [String or Integer] Voice message's length, milliseconds
99
+ #
90
100
  # @raise [ArgumentError] Error raised when supplied argument are missing :to_mid, :audio_url, :duration keys.
91
101
  #
92
102
  # @return [Net::HTTPResponse]
@@ -98,14 +108,15 @@ module Line
98
108
  send_message(attrs[:to_mid], message)
99
109
  end
100
110
 
101
- # Sends location to users
111
+ # Send location to users.
102
112
  #
103
113
  # @param attrs [Hash]
104
- # @param attrs [:to_mid] [String or Array] User's indentifiers
105
- # @param attrs [:title] [String] Location's title
106
- # @param attrs [:address] [String] Location's address
107
- # @param attrs [:latitude] [Float] Location's latitude
108
- # @param attrs [:longitude] [Float] Location's longitude
114
+ # @param to_mid [String or Array] User's identifiers
115
+ # @param title [String] Location's title
116
+ # @param address [String] Location's address
117
+ # @param latitude [Float] Location's latitude
118
+ # @param longitude [Float] Location's longitude
119
+ #
109
120
  # @raise [ArgumentError] Error raised when supplied argument are missing :to_mid, :title, :latitude, :longitude keys.
110
121
  #
111
122
  # @return [Net::HTTPResponse]
@@ -119,13 +130,14 @@ module Line
119
130
  send_message(attrs[:to_mid], message)
120
131
  end
121
132
 
122
- # Sends sticker to users
133
+ # Send sticker to users.
123
134
  #
124
135
  # @param attrs [Hash]
125
- # @param attrs [:to_mid] [String or Array] User's indentifiers
126
- # @param attrs [:stkpkgid] [String or Integer] Sticker's package identifier
127
- # @param attrs [:stkid] [String or Integer] Sticker's identifier
128
- # @param attrs [:stkver] [String or Integer] Sticker's version number
136
+ # @param to_mid [String or Array] User's identifiers
137
+ # @param stkpkgid [String or Integer] Sticker's package identifier
138
+ # @param stkid [String or Integer] Sticker's identifier
139
+ # @param stkver [String or Integer] Sticker's version number
140
+ #
129
141
  # @raise [ArgumentError] Error raised when supplied argument are missing :to_mid, :stkpkgid, :stkid, :stkver keys.
130
142
  #
131
143
  # @return [Net::HTTPResponse]
@@ -138,10 +150,11 @@ module Line
138
150
  send_message(attrs[:to_mid], message)
139
151
  end
140
152
 
141
- # Sends message to line server and to users
153
+ # Send message to line server and to users.
142
154
  #
143
- # @param attrs [:to_mid] [String or Array] User's indentifiers
155
+ # @param to_mid [String or Array] User's identifiers
144
156
  # @param message [Line::Bot::Message]
157
+ #
145
158
  # @raise [ArgumentError] Error raised when supplied argument are missing message.
146
159
  #
147
160
  # @return [Net::HTTPResponse]
@@ -158,7 +171,7 @@ module Line
158
171
  request.post
159
172
  end
160
173
 
161
- # Gets message content
174
+ # Get message content.
162
175
  #
163
176
  # @param identifer [String] Message's identifier
164
177
  #
@@ -170,7 +183,7 @@ module Line
170
183
  get(endpoint_path)
171
184
  end
172
185
 
173
- # Gets preview of message content
186
+ # Get preview of message content.
174
187
  #
175
188
  # @param identifer [String] Message's identifier
176
189
  #
@@ -182,15 +195,17 @@ module Line
182
195
  get(endpoint_path)
183
196
  end
184
197
 
185
- # Gets user profile
198
+ # Get user profile.
186
199
  #
187
- # @param attrs [:to_mid] [String or Array] User's indentifiers
200
+ # @param mids [String or Array] User's identifiers
188
201
  #
189
202
  # @raise [ArgumentError] Error raised when supplied argument are missing message.
190
203
  # @raise [HTTPError]
191
204
  #
192
205
  # @return [Line::Bot::Response::User::Profile]
193
206
  def get_user_profile(mids)
207
+ raise ArgumentError, 'Invalid arguments, mids' unless mids.instance_of?(String) || mids.instance_of?(Array)
208
+
194
209
  mids = mids.instance_of?(String) ? [mids] : mids
195
210
  endpoint_path = "/v1/profiles?mids=#{mids.join(',')}"
196
211
 
@@ -199,7 +214,7 @@ module Line
199
214
  Line::Bot::Response::User::Profile.new(response) if !response.value
200
215
  end
201
216
 
202
- # Fetches data
217
+ # Fetch data, get content of specified URL.
203
218
  #
204
219
  # @param endpoint_path [String]
205
220
  #
@@ -215,21 +230,21 @@ module Line
215
230
  request.get
216
231
  end
217
232
 
218
- # Creates rich message to line server and to users
233
+ # Create rich message to line server and to users.
219
234
  #
220
235
  # @return [Line::Bot::Builder::RichMessage]
221
236
  def rich_message
222
237
  Line::Bot::Builder::RichMessage.new(self)
223
238
  end
224
239
 
225
- # Creates multiple message to line server and to users
240
+ # Create multiple message to line server and to users.
226
241
  #
227
242
  # @return [Line::Bot::Builder::MultipleMessage]
228
243
  def multiple_message
229
244
  Line::Bot::Builder::MultipleMessage.new(self)
230
245
  end
231
246
 
232
- # Validates signature
247
+ # Validate signature
233
248
  #
234
249
  # @param content [String] Request's body
235
250
  # @param channel_signature [String] Request'header 'X-LINE-ChannelSignature' # HTTP_X_LINE_CHANNELSIGNATURE
@@ -244,15 +259,17 @@ module Line
244
259
  variable_secure_compare(channel_signature, signature)
245
260
  end
246
261
 
247
- private
262
+ private
248
263
  # Constant time string comparison.
249
264
  #
250
265
  # via timing attacks.
251
266
  # reference: https://github.com/rails/rails/blob/master/activesupport/lib/active_support/security_utils.rb
267
+ # @return [Boolean]
252
268
  def variable_secure_compare(a, b)
253
269
  secure_compare(::Digest::SHA256.hexdigest(a), ::Digest::SHA256.hexdigest(b))
254
270
  end
255
271
 
272
+ # @return [Boolean]
256
273
  def secure_compare(a, b)
257
274
  return false unless a.bytesize == b.bytesize
258
275
 
@@ -7,9 +7,9 @@ module Line
7
7
  attr_reader :id, :from_mid, :to_mid, :from_channel_id, :to_channel_id, :event_type, :content
8
8
 
9
9
  def initialize(env)
10
- @id = env['content']['id']
11
- @from_mid = env['content']['from']
12
- @to_mid = env['content']['to']
10
+ @id = env['id']
11
+ @from_mid = env['content']['params'].first
12
+ @to_mid = env['to']
13
13
 
14
14
  @from_channel_id = env['fromChannel']
15
15
  @to_channel_id = env['toChannel']
@@ -7,10 +7,14 @@ module Line
7
7
  class Request
8
8
  attr_accessor :endpoint_path, :credentials, :to_mid, :message
9
9
 
10
+ # Initializes a new Request
11
+ #
12
+ # @return [LINE::Bot::Client]
10
13
  def initialize
11
14
  yield(self) if block_given?
12
15
  end
13
16
 
17
+ # @return [Net::HTTP]
14
18
  def https
15
19
  https = Net::HTTP.new('trialbot-api.line.me', 443)
16
20
  https.use_ssl = true
@@ -18,14 +22,19 @@ module Line
18
22
  https
19
23
  end
20
24
 
25
+ # @return [Array]
21
26
  def to
27
+ raise ArgumentError, 'Invalid arguments, to_mid' unless to_mid.instance_of?(String) || to_mid.instance_of?(Array)
28
+
22
29
  to_mid.instance_of?(String) ? [to_mid] : to_mid
23
30
  end
24
31
 
32
+ # @return [Line::Bot::Message::Base#content]
25
33
  def content
26
34
  message.content
27
35
  end
28
36
 
37
+ # @return [Hash]
29
38
  def payload
30
39
  payload = {
31
40
  to: to,
@@ -37,6 +46,7 @@ module Line
37
46
  payload.to_json
38
47
  end
39
48
 
49
+ # @return [Hash]
40
50
  def header
41
51
  header = {
42
52
  'Content-Type' => 'application/json; charset=UTF-8',
@@ -47,12 +57,22 @@ module Line
47
57
  header.merge(hash)
48
58
  end
49
59
 
60
+ # Get content of specified URL.
61
+ #
62
+ # @raise [ArgumentError]
63
+ #
64
+ # @return [Net::HTTPResponse]
50
65
  def get
51
66
  raise ArgumentError, "Invalid arguments" unless validate_for_getting_message?
52
67
 
53
68
  https.get(endpoint_path, header)
54
69
  end
55
70
 
71
+ # Post content of specified URL.
72
+ #
73
+ # @raise [ArgumentError]
74
+ #
75
+ # @return [Net::HTTPResponse]
56
76
  def post
57
77
  raise ArgumentError, "Invalid arguments" unless validate_for_posting_message?
58
78
 
@@ -6,10 +6,10 @@ require 'line/bot/api/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "line-bot-api"
8
8
  spec.version = Line::Bot::API::VERSION
9
- spec.authors = ["LINE Corporation", "Hirohisa Kawasaki"]
9
+ spec.authors = ["LINE Corporation"]
10
10
  spec.email = ["hirohisa.kawasaki@gmail.com"]
11
11
 
12
- spec.description = "LINE::Bot::API - SDK of the LINE BOT API"
12
+ spec.description = "Line::Bot::API - SDK of the LINE BOT API"
13
13
  spec.summary = spec.description
14
14
  spec.homepage = "https://github.com/line/line-bot-sdk-ruby"
15
15
  spec.license = "Apache License, Version 2.0"
@@ -20,10 +20,11 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.required_ruby_version = '>= 2.0.0'
22
22
 
23
- spec.add_dependency 'rack', '~> 1.6.4'
23
+ spec.add_dependency 'rack', '~> 1.6'
24
24
 
25
25
  spec.add_development_dependency "bundler", "~> 1.11"
26
26
  spec.add_development_dependency "rake", "~> 10.0"
27
27
  spec.add_development_dependency "webmock", "~> 1.24"
28
+ spec.add_development_dependency "addressable", ">= 2.3.6"
28
29
  spec.add_development_dependency "rspec", "~> 3.0"
29
30
  end
metadata CHANGED
@@ -1,15 +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.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - LINE Corporation
8
- - Hirohisa Kawasaki
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2016-04-18 00:00:00.000000000 Z
11
+ date: 2016-04-19 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rack
@@ -17,14 +16,14 @@ dependencies:
17
16
  requirements:
18
17
  - - ~>
19
18
  - !ruby/object:Gem::Version
20
- version: 1.6.4
19
+ version: '1.6'
21
20
  type: :runtime
22
21
  prerelease: false
23
22
  version_requirements: !ruby/object:Gem::Requirement
24
23
  requirements:
25
24
  - - ~>
26
25
  - !ruby/object:Gem::Version
27
- version: 1.6.4
26
+ version: '1.6'
28
27
  - !ruby/object:Gem::Dependency
29
28
  name: bundler
30
29
  requirement: !ruby/object:Gem::Requirement
@@ -67,6 +66,20 @@ dependencies:
67
66
  - - ~>
68
67
  - !ruby/object:Gem::Version
69
68
  version: '1.24'
69
+ - !ruby/object:Gem::Dependency
70
+ name: addressable
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: 2.3.6
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: 2.3.6
70
83
  - !ruby/object:Gem::Dependency
71
84
  name: rspec
72
85
  requirement: !ruby/object:Gem::Requirement
@@ -81,7 +94,7 @@ dependencies:
81
94
  - - ~>
82
95
  - !ruby/object:Gem::Version
83
96
  version: '3.0'
84
- description: LINE::Bot::API - SDK of the LINE BOT API
97
+ description: Line::Bot::API - SDK of the LINE BOT API
85
98
  email:
86
99
  - hirohisa.kawasaki@gmail.com
87
100
  executables: []
@@ -142,5 +155,5 @@ rubyforge_project:
142
155
  rubygems_version: 2.4.8
143
156
  signing_key:
144
157
  specification_version: 4
145
- summary: LINE::Bot::API - SDK of the LINE BOT API
158
+ summary: Line::Bot::API - SDK of the LINE BOT API
146
159
  test_files: []