line-bot-api 1.10.0 → 1.11.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
  SHA256:
3
- metadata.gz: '0258918c87b7575b3311c3b5418e0902150fdddcfda4f6efba06622e44ec4bec'
4
- data.tar.gz: 339c25cea7f80a9049591ca5236b0a35240ee57f07d4de7b0549bba91799ab31
3
+ metadata.gz: 191b846d917a61448e7e38976390aeb56846229ccdc2a69c404d0ca04a3bcb89
4
+ data.tar.gz: 595b93123023a3c9060190969657ca06d2bc7472281bcfe43ee1ef7b4c95324a
5
5
  SHA512:
6
- metadata.gz: 554a0d06637e0887ab60e89ea4e52d7c6e0e29df6ac8878926a5a21ef3e69e0ac920d2ec465a2b164ae3adcbf0d31a031bae22def8964b66057d1246210c081a
7
- data.tar.gz: 074c31b20b2ba958eb22542b4332624e1f0b63e854148c1d8c9b7da0c34a1b1f9d44dd342caa3d40e1bd93431d2cebc50c8f5c2deea0caa5efb3d611f7cb7be2
6
+ metadata.gz: '094bbf24cc58e2b444a410b02052d15bcd545ad77e62a4cf8765d5a6d8e5e4011ff735196bffd3d95d2ab77e6cdb70a17240dfe524f71380d2633b5efea5455b'
7
+ data.tar.gz: f54a7e01bd1b28f28eac6e299e739a8d59d390056acac28fb7d5a957f56e2f28fa71a26a3e07a7bed212c605af735486e2213465aa417025e18aafe6d95c05d7
data/README.md CHANGED
@@ -23,7 +23,7 @@ gem 'line-bot-api'
23
23
 
24
24
  And then execute:
25
25
 
26
- ```ruby
26
+ ```sh
27
27
  bundle
28
28
  ```
29
29
 
@@ -44,6 +44,7 @@ require 'line/bot'
44
44
 
45
45
  def client
46
46
  @client ||= Line::Bot::Client.new { |config|
47
+ config.channel_id = ENV["LINE_CHANNEL_ID"]
47
48
  config.channel_secret = ENV["LINE_CHANNEL_SECRET"]
48
49
  config.channel_token = ENV["LINE_CHANNEL_TOKEN"]
49
50
  }
@@ -16,7 +16,6 @@ module Line
16
16
  module Bot
17
17
  module API
18
18
  class Error < StandardError; end
19
- class InvalidCredentialsError < Error; end
20
19
  end
21
20
  end
22
21
  end
@@ -15,7 +15,7 @@
15
15
  module Line
16
16
  module Bot
17
17
  module API
18
- VERSION = "1.10.0"
18
+ VERSION = "1.11.0"
19
19
  end
20
20
  end
21
21
  end
@@ -13,16 +13,16 @@
13
13
  # under the License.
14
14
 
15
15
  require 'line/bot/request'
16
- require 'line/bot/api/errors'
17
16
  require 'base64'
18
17
  require 'net/http'
19
18
  require 'openssl'
19
+ require 'uri'
20
20
 
21
21
  module Line
22
22
  module Bot
23
23
  class Client
24
24
  # @return [String]
25
- attr_accessor :channel_token, :channel_secret, :endpoint
25
+ attr_accessor :channel_token, :channel_id, :channel_secret, :endpoint
26
26
 
27
27
  # @return [Object]
28
28
  attr_accessor :httpclient
@@ -57,8 +57,47 @@ module Line
57
57
  }
58
58
  end
59
59
 
60
- def credentials?
61
- credentials.values.all?
60
+ # Issue channel access token
61
+ #
62
+ # @param grant_type [String] Grant type
63
+ #
64
+ # @return [Net::HTTPResponse]
65
+ def issue_channel_token(grant_type = 'client_credentials')
66
+ channel_id_required
67
+ channel_secret_required
68
+
69
+ payload = URI.encode_www_form(
70
+ grant_type: grant_type,
71
+ client_id: channel_id,
72
+ client_secret: channel_secret
73
+ )
74
+
75
+ request = Request.new do |config|
76
+ config.httpclient = httpclient
77
+ config.endpoint = endpoint
78
+ config.endpoint_path = '/oauth/accessToken'
79
+ config.content_type = 'application/x-www-form-urlencoded'
80
+ config.payload = payload
81
+ end
82
+
83
+ request.post
84
+ end
85
+
86
+ # Revoke channel access token
87
+ #
88
+ # @return [Net::HTTPResponse]
89
+ def revoke_channel_token(access_token)
90
+ payload = URI.encode_www_form(access_token: access_token)
91
+
92
+ request = Request.new do |config|
93
+ config.httpclient = httpclient
94
+ config.endpoint = endpoint
95
+ config.endpoint_path = '/oauth/revoke'
96
+ config.content_type = 'application/x-www-form-urlencoded'
97
+ config.payload = payload
98
+ end
99
+
100
+ request.post
62
101
  end
63
102
 
64
103
  # Push messages to line server and to user.
@@ -68,7 +107,7 @@ module Line
68
107
  #
69
108
  # @return [Net::HTTPResponse]
70
109
  def push_message(user_id, messages)
71
- raise Line::Bot::API::InvalidCredentialsError, 'Invalidates credentials' unless credentials?
110
+ channel_token_required
72
111
 
73
112
  messages = [messages] if messages.is_a?(Hash)
74
113
 
@@ -91,7 +130,7 @@ module Line
91
130
  #
92
131
  # @return [Net::HTTPResponse]
93
132
  def reply_message(token, messages)
94
- raise Line::Bot::API::InvalidCredentialsError, 'Invalidates credentials' unless credentials?
133
+ channel_token_required
95
134
 
96
135
  messages = [messages] if messages.is_a?(Hash)
97
136
 
@@ -114,7 +153,7 @@ module Line
114
153
  #
115
154
  # @return [Net::HTTPResponse]
116
155
  def multicast(to, messages)
117
- raise Line::Bot::API::InvalidCredentialsError, 'Invalidates credentials' unless credentials?
156
+ channel_token_required
118
157
 
119
158
  to = [to] if to.is_a?(String)
120
159
  messages = [messages] if messages.is_a?(Hash)
@@ -137,7 +176,7 @@ module Line
137
176
  #
138
177
  # @return [Net::HTTPResponse]
139
178
  def broadcast(messages)
140
- raise Line::Bot::API::InvalidCredentialsError, 'Invalidates credentials' unless credentials?
179
+ channel_token_required
141
180
 
142
181
  messages = [messages] if messages.is_a?(Hash)
143
182
 
@@ -153,7 +192,7 @@ module Line
153
192
  end
154
193
 
155
194
  def leave_group(group_id)
156
- raise Line::Bot::API::InvalidCredentialsError, 'Invalidates credentials' unless credentials?
195
+ channel_token_required
157
196
 
158
197
  request = Request.new do |config|
159
198
  config.httpclient = httpclient
@@ -166,7 +205,7 @@ module Line
166
205
  end
167
206
 
168
207
  def leave_room(room_id)
169
- raise Line::Bot::API::InvalidCredentialsError, 'Invalidates credentials' unless credentials?
208
+ channel_token_required
170
209
 
171
210
  request = Request.new do |config|
172
211
  config.httpclient = httpclient
@@ -473,7 +512,7 @@ module Line
473
512
  #
474
513
  # @return [Net::HTTPResponse]
475
514
  def get(endpoint_path)
476
- raise Line::Bot::API::InvalidCredentialsError, 'Invalidates credentials' unless credentials?
515
+ channel_token_required
477
516
 
478
517
  request = Request.new do |config|
479
518
  config.httpclient = httpclient
@@ -491,7 +530,7 @@ module Line
491
530
  #
492
531
  # @return [Net::HTTPResponse]
493
532
  def post(endpoint_path, payload = nil)
494
- raise Line::Bot::API::InvalidCredentialsError, 'Invalidates credentials' unless credentials?
533
+ channel_token_required
495
534
 
496
535
  request = Request.new do |config|
497
536
  config.httpclient = httpclient
@@ -510,7 +549,7 @@ module Line
510
549
  #
511
550
  # @return [Net::HTTPResponse]
512
551
  def delete(endpoint_path)
513
- raise Line::Bot::API::InvalidCredentialsError, 'Invalidates credentials' unless credentials?
552
+ channel_token_required
514
553
 
515
554
  request = Request.new do |config|
516
555
  config.httpclient = httpclient
@@ -576,6 +615,18 @@ module Line
576
615
  b.each_byte { |byte| res |= byte ^ l.shift }
577
616
  res == 0
578
617
  end
618
+
619
+ def channel_token_required
620
+ raise ArgumentError, '`channel_token` is not configured' unless channel_token
621
+ end
622
+
623
+ def channel_id_required
624
+ raise ArgumentError, '`channel_id` is not configured' unless channel_id
625
+ end
626
+
627
+ def channel_secret_required
628
+ raise ArgumentError, '`channel_secret` is not configured' unless channel_secret
629
+ end
579
630
  end
580
631
  end
581
632
  end
@@ -22,6 +22,8 @@ module Line
22
22
  class Request
23
23
  attr_accessor :endpoint, :endpoint_path, :credentials, :to, :reply_token, :messages, :httpclient, :payload, :file
24
24
 
25
+ attr_writer :content_type
26
+
25
27
  # Initializes a new Request
26
28
  #
27
29
  # @return [Line::Bot::Request]
@@ -44,27 +46,22 @@ module Line
44
46
 
45
47
  # @return [Hash]
46
48
  def header
47
- content_type =
48
- if file.is_a? File
49
- case file.path
50
- when /\.png\z/i then 'image/png'
51
- when /\.jpe?g\z/i then 'image/jpeg'
52
- else
53
- raise ArgumentError.new("invalid file extension: #{file.path}")
54
- end
55
- else
56
- 'application/json; charset=UTF-8'
57
- end
58
-
59
49
  header = {
60
50
  'Content-Type' => content_type,
61
51
  'User-Agent' => "LINE-BotSDK-Ruby/#{Line::Bot::API::VERSION}",
62
52
  }
63
- hash = credentials.inject({}) { |h, (k, v)| h[k] = v.to_s; h }
53
+ hash = (credentials || {}).inject({}) { |h, (k, v)| h[k] = v.to_s; h }
64
54
 
65
55
  header.merge(hash)
66
56
  end
67
57
 
58
+ # @return [String]
59
+ def content_type
60
+ return @content_type if @content_type
61
+
62
+ guess_content_type
63
+ end
64
+
68
65
  # Get content of specified URL.
69
66
  #
70
67
  # @return [Net::HTTPResponse]
@@ -99,6 +96,22 @@ module Line
99
96
  def assert_for_deleting_message
100
97
  raise ArgumentError, 'Wrong argument type `endpoint_path`' unless endpoint_path.is_a?(String)
101
98
  end
99
+
100
+ private
101
+
102
+ # @return [String]
103
+ def guess_content_type
104
+ if file.is_a? File
105
+ case file.path
106
+ when /\.png\z/i then 'image/png'
107
+ when /\.jpe?g\z/i then 'image/jpeg'
108
+ else
109
+ raise ArgumentError.new("invalid file extension: #{file.path}")
110
+ end
111
+ else
112
+ 'application/json; charset=UTF-8'
113
+ end
114
+ end
102
115
  end
103
116
  end
104
117
  end
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: 1.10.0
4
+ version: 1.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - LINE Corporation
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-28 00:00:00.000000000 Z
11
+ date: 2019-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -120,8 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  - !ruby/object:Gem::Version
121
121
  version: '0'
122
122
  requirements: []
123
- rubyforge_project:
124
- rubygems_version: 2.7.6
123
+ rubygems_version: 3.0.3
125
124
  signing_key:
126
125
  specification_version: 4
127
126
  summary: SDK of the LINE Messaging API