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 +4 -4
- data/README.md +8 -7
- data/Rakefile +4 -0
- data/lib/lark.rb +0 -2
- data/lib/lark/api.rb +1 -1
- data/lib/lark/apis/authen.rb +3 -3
- data/lib/lark/apis/image.rb +2 -2
- data/lib/lark/config.rb +8 -2
- data/lib/lark/request.rb +6 -4
- data/lib/lark/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f85b0fe40fd06b6433cc6e3d5d2dfb324fc8587054e3e5338a0bcc255eae20d
|
4
|
+
data.tar.gz: 978dffe16def339df6de1459bb8a7ea21adea598cee7b864b649c21a051549f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
15
|
+
$ bundle install
|
16
16
|
|
17
17
|
Or install it yourself as:
|
18
18
|
|
19
|
-
|
19
|
+
$ gem install lark-sdk
|
20
20
|
|
21
|
-
|
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
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
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
data/lib/lark/apis/authen.rb
CHANGED
@@ -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
|
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
|
data/lib/lark/apis/image.rb
CHANGED
@@ -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:
|
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
|
-
|
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(
|
49
|
-
|
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 [
|
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
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.
|
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:
|
11
|
+
date: 2021-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|