lark-sdk 1.2.0 → 1.2.1

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: 984dbad3f83acdb46fa85412a40a4a24ace271a77f78be3d1ace8db19ad7853b
4
- data.tar.gz: 8bda6a46d00120a07cb8211d1810125bdde4a1514a8d07d8edb13081d9ceeb73
3
+ metadata.gz: 7f85b0fe40fd06b6433cc6e3d5d2dfb324fc8587054e3e5338a0bcc255eae20d
4
+ data.tar.gz: 978dffe16def339df6de1459bb8a7ea21adea598cee7b864b649c21a051549f1
5
5
  SHA512:
6
- metadata.gz: 8e46b2b15de32650c6a9d1351445b580da7293fec1e09566c510e16ed04490b090ddeaaf4be6f3c6b765d7accdee591c6910f6145ad20b4b94af6282bcdd4ca8
7
- data.tar.gz: d59629e8c97033036f10b65d59d0473523f9a80bd862745e70269abd10e31c76565ccabe011f016857a03f1f79b90a734d3773873c2f4641062319c0b4d6608e
6
+ metadata.gz: 5379f843398ca53a26fdd905bbff9a4f1a98872c8f655ca574881da048c56334832965424d8339986ec96718de0ab6f3e8b8b3581deee32ff2c27604be72e499
7
+ data.tar.gz: b23e6499d47d352caa05eeef4de1baa1943347fce24b65143c369eff59b274a472e5f966b0a2ac0c4e2770aef6f2b45b1fd433af6a2d7650ef94b999f5f30a48
data/README.md CHANGED
@@ -12,13 +12,13 @@ gem 'lark-sdk'
12
12
 
13
13
  And then execute:
14
14
 
15
- $ bundle install
15
+ $ bundle install
16
16
 
17
17
  Or install it yourself as:
18
18
 
19
- $ gem install lark-sdk
19
+ $ gem install lark-sdk
20
20
 
21
- require 'lark/sdk'
21
+ require 'lark/sdk'
22
22
 
23
23
  ## 使用
24
24
 
@@ -32,6 +32,7 @@ Lark.configure do |config|
32
32
  config.default_app_id = 'xxx' # 应用 app ID
33
33
  config.default_app_secret = 'xxx' # 应用 app secret
34
34
  config.default_isv = true # 自建应用: false, 应用商店应用: true
35
+ config.api_base_url = 'https://open.feishu.cn/open-apis/' # API 地址,默认:https://open.feishu.cn/open-apis/
35
36
  # ...
36
37
  end
37
38
  ```
@@ -40,10 +41,10 @@ end
40
41
 
41
42
  ```ruby
42
43
  api = Lark::Api.new(
43
- app_id: 'xxx', # default: Lark.config.default_app_id
44
- app_secret: 'xxx', # default: Lark.config.default_app_secret
45
- isv: false/true, # default: Lark.config.default_app_secret
46
- tenant_key: 'xxx' # required while internal app
44
+ app_id: 'xxx', # default: Lark.config.default_app_id
45
+ app_secret: 'xxx', # default: Lark.config.default_app_secret
46
+ isv: false/true, # default: Lark.config.default_app_secret
47
+ tenant_key: 'xxx' # required while internal app
47
48
  )
48
49
  ```
49
50
 
data/Rakefile CHANGED
@@ -8,3 +8,7 @@ Rake::TestTask.new(:test) do |t|
8
8
  end
9
9
 
10
10
  task :default => :test
11
+
12
+ task :console do
13
+ sh 'irb -I lib -r lark.rb'
14
+ end
data/lib/lark.rb CHANGED
@@ -11,8 +11,6 @@ Dir["#{lib_path}/apis/**/*.rb", "#{lib_path}/token_store/*.rb"].each { |path| r
11
11
  require 'lark/api'
12
12
 
13
13
  module Lark
14
- API_BASE_URL = 'https://open.feishu.cn/open-apis/'.freeze
15
-
16
14
  # Exceptions
17
15
  class RedisNotConfigException < RuntimeError; end
18
16
  class AppNotConfigException < RuntimeError; end
data/lib/lark/api.rb CHANGED
@@ -39,7 +39,7 @@ module Lark
39
39
  end
40
40
 
41
41
  def request
42
- @request ||= Lark::Request.new(false)
42
+ @request ||= Lark::Request.new
43
43
  end
44
44
 
45
45
  def get(path, headers = {})
@@ -5,7 +5,7 @@ module Lark
5
5
  module Authen
6
6
  def index(redirect_uri, state)
7
7
  uri = ERB::Util.url_encode(redirect_uri)
8
- "#{URI::join(API_BASE_URL, 'authen/v1/index')}?redirect_uri=#{uri}&app_id=#{app_id}&state=#{state}"
8
+ "#{URI.join(Lark.api_base_url, 'authen/v1/index')}?redirect_uri=#{uri}&app_id=#{app_id}&state=#{state}"
9
9
  end
10
10
 
11
11
  def access_token(code)
@@ -25,8 +25,8 @@ module Lark
25
25
  end
26
26
 
27
27
  def user_info(user_access_token)
28
- request.get 'authen/v1/user_info', {access_token: user_access_token}
28
+ request.get 'authen/v1/user_info', { access_token: user_access_token }
29
29
  end
30
30
  end
31
31
  end
32
- end
32
+ end
@@ -5,8 +5,8 @@ module Lark
5
5
  post_file 'image/v4/put/', image, params: { image_type: image_type }
6
6
  end
7
7
 
8
- def download(image_key)
9
- get 'image/v4/get', params: { image_key: image_key }, as: :file
8
+ def download(image_key, params = {})
9
+ get 'image/v4/get', params: params.merge(image_key: image_key), as: :file
10
10
  end
11
11
  end
12
12
  end
data/lib/lark/config.rb CHANGED
@@ -23,11 +23,17 @@ module Lark
23
23
  end
24
24
 
25
25
  def http_timeout_options
26
- config.http_timeout_options || {write: 2, connect: 5, read: 10}
26
+ config.http_timeout_options || { write: 2, connect: 5, read: 10 }
27
+ end
28
+
29
+ def api_base_url
30
+ return @api_base_url if defined?(@api_base_url)
31
+
32
+ @api_base_url = config.api_base_url || 'https://open.feishu.cn/open-apis/'.freeze
27
33
  end
28
34
  end
29
35
 
30
36
  class Config
31
- attr_accessor :default_app_id, :default_app_secret, :default_isv, :redis, :http_timeout_options, :logger
37
+ attr_accessor :default_app_id, :default_app_secret, :default_isv, :redis, :http_timeout_options, :logger, :api_base_url
32
38
  end
33
39
  end
data/lib/lark/request.rb CHANGED
@@ -7,7 +7,7 @@ module Lark
7
7
  def initialize(skip_verify_ssl = true)
8
8
  @http = HTTP.timeout(**Lark.http_timeout_options)
9
9
  @ssl_context = OpenSSL::SSL::SSLContext.new
10
- @ssl_context.ssl_version = :TLSv1
10
+ #@ssl_context.ssl_version = :TLSv1_2
11
11
  @ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE if skip_verify_ssl
12
12
  end
13
13
 
@@ -45,10 +45,12 @@ module Lark
45
45
  private
46
46
 
47
47
  def request(path, header = {}, &_block)
48
- url = URI.join(API_BASE_URL, path)
49
- Lark.logger.info "request url(#{url}) with headers: #{header}"
48
+ url = URI.join(Lark.api_base_url, path)
49
+ request_uuid = SecureRandom.uuid
50
+ Lark.logger.info "[#{request_uuid}] request url(#{url}) with headers: #{header}"
50
51
  as = header.delete(:as)
51
52
  header['Accept'] = 'application/json'
53
+ header['X-Request-ID'] = request_uuid
52
54
  response = yield(url, header)
53
55
  unless response.status.success?
54
56
  Lark.logger.error "request #{url} happen error: #{response.body}"
@@ -79,7 +81,7 @@ module Lark
79
81
  Lark.logger.info "response body: #{body}"
80
82
  data = JSON.parse body.to_s
81
83
  result = Result.new(data)
82
- raise ::Lark::AccessTokenExpiredError if [99991663, 99991664].include?(result.code)
84
+ raise ::Lark::AccessTokenExpiredError if [99_991_663, 99_991_664].include?(result.code)
83
85
 
84
86
  result
85
87
  end
data/lib/lark/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lark
2
- VERSION = '1.2.0'.freeze
2
+ VERSION = '1.2.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lark-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Dong
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-09 00:00:00.000000000 Z
11
+ date: 2021-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http