lark-sdk 1.1.2 → 1.2.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
  SHA256:
3
- metadata.gz: 9552cdde34c23f537cf389250697d3fc0bbe7e987961de95fcc638a66d78e785
4
- data.tar.gz: 11ad0bde0365ca9a9a7ab7197d117747b23f8149f75f4082c329268377f6b3ce
3
+ metadata.gz: a9b71f299fbc4d5d5a1c54877b328779832e2a0c23e1a98b5d8207d188f1cba9
4
+ data.tar.gz: f89c8b9b7569bf90001b3dbfc852bef459c21a35fa991b5167125921dd077339
5
5
  SHA512:
6
- metadata.gz: 707ab49de07187d9904a2aa28cc43e914c32dbb9ac3a6b66d0b99198b2c66a88a0fd3ebe91262d95d38462d67dfd1ea4e25b50d1c6b2e6dfec1c438be3fe5f9b
7
- data.tar.gz: 4964f7bad268c6cefa516ab8e5faca75bb64d4bd964a248f85070ec5eb1313179c7d11547d3c87f52617e8412732279661770aff210f5f98970b748dcf264655
6
+ metadata.gz: 1eef0f0a55768a49ca1dab343a99cf6751541ed964530b63f8445c4ebd753060255683547a604bda38d3ea1ae86e8e9d2ebd38b1b27ae0f2a07decc5f66e04b5
7
+ data.tar.gz: dd779b48d5a20cdce779f6a3faa8726126f2184ed0b28cec4ab3f9f98e58fccd6525e21bca2c0cb7360117bdb77be18a676261dae597c9e6bc1e046d2778c5f0
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
 
@@ -60,7 +61,7 @@ cipher.decrypt(message)
60
61
  cipher.encrypt(message)
61
62
  ```
62
63
 
63
- [Api 列表](https://github.com/mycolorway/lark-ruby-sdk/wiki/API-List)
64
+ [Api 列表](https://github.com/seandong/lark-ruby-sdk/wiki/apis)
64
65
 
65
66
 
66
67
  ## 贡献
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/lark.gemspec CHANGED
@@ -8,15 +8,15 @@ Gem::Specification.new do |spec|
8
8
 
9
9
  spec.summary = %q{Lark(飞书) API SDKs for ruby}
10
10
  spec.description = %q{Lark(飞书) API SDKs for ruby https://open.feishu.cn}
11
- spec.homepage = "https://github.com/mycolorway/lark-ruby-sdk"
11
+ spec.homepage = "https://github.com/seandong/lark-ruby-sdk"
12
12
  spec.license = "MIT"
13
13
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
14
 
15
15
  spec.metadata["allowed_push_host"] = "https://rubygems.org/"
16
16
 
17
17
  spec.metadata["homepage_uri"] = spec.homepage
18
- spec.metadata["source_code_uri"] = "https://github.com/mycolorway/lark-ruby-sdk"
19
- spec.metadata["changelog_uri"] = "https://github.com/mycolorway/lark-ruby-sdk"
18
+ spec.metadata["source_code_uri"] = "https://github.com/seandong/lark-ruby-sdk"
19
+ spec.metadata["changelog_uri"] = "https://github.com/seandong/lark-ruby-sdk"
20
20
 
21
21
  # Specify which files should be added to the gem when it is released.
22
22
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
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
@@ -8,6 +8,7 @@ module Lark
8
8
  api_mount :authen
9
9
  api_mount :contact
10
10
  api_mount :user
11
+ api_mount :search
11
12
  api_mount :application
12
13
  api_mount :pay
13
14
  api_mount :chat
@@ -23,7 +24,7 @@ module Lark
23
24
 
24
25
  attr_reader :app_id, :app_secret, :tenant_key, :isv, :options
25
26
 
26
- def initialize options={}
27
+ def initialize(options = {})
27
28
  @app_id = options.delete(:app_id) || Lark.config.default_app_id
28
29
  @app_secret = options.delete(:app_secret) || Lark.config.default_app_secret
29
30
  raise AppNotConfigException if @app_id.nil? || @app_id.empty?
@@ -38,29 +39,29 @@ module Lark
38
39
  end
39
40
 
40
41
  def request
41
- @request ||= Lark::Request.new(false)
42
+ @request ||= Lark::Request.new
42
43
  end
43
44
 
44
- def get(path, headers={})
45
- with_token(headers) do |headers|
46
- request.get path, headers
45
+ def get(path, headers = {})
46
+ with_token(headers) do |headers_with_token|
47
+ request.get path, headers_with_token
47
48
  end
48
49
  end
49
50
 
50
- def post(path, payload, headers={})
51
- with_token(headers) do |headers|
52
- request.post path, payload, headers
51
+ def post(path, payload, headers = {})
52
+ with_token(headers) do |headers_with_token|
53
+ request.post path, payload, headers_with_token
53
54
  end
54
55
  end
55
56
 
56
- def post_file(path, file, headers={})
57
- with_token(headers) do |headers|
58
- request.post_file path, file, headers
57
+ def post_file(path, file, headers = {})
58
+ with_token(headers) do |headers_with_token|
59
+ request.post_file path, file, headers_with_token
59
60
  end
60
61
  end
61
62
 
62
- def app_ticket= ticket
63
- Lark.redis.set "APP_TICKET_#{app_id}", ticket
63
+ def app_ticket=(new_ticket)
64
+ Lark.redis.set "APP_TICKET_#{app_id}", new_ticket
64
65
  end
65
66
 
66
67
  def app_ticket
@@ -91,7 +92,7 @@ module Lark
91
92
  @tenant_token_store = klass.new(self)
92
93
  end
93
94
 
94
- def with_token(headers, tries=2)
95
+ def with_token(headers, tries = 2)
95
96
  token = headers[:access_token]
96
97
  if token.nil?
97
98
  via = headers[:via] || 'tenant'
@@ -28,6 +28,14 @@ module Lark
28
28
  def app_update_visibility(payload={})
29
29
  post 'application/v3/app/update_visibility', payload
30
30
  end
31
+
32
+ def scopes
33
+ get 'application/v6/scopes'
34
+ end
35
+
36
+ def scopes_apply
37
+ post 'application/v6/scopes/apply'
38
+ end
31
39
  end
32
40
  end
33
- end
41
+ end
@@ -3,9 +3,9 @@ require "erb"
3
3
  module Lark
4
4
  module Apis
5
5
  module Authen
6
- def index(redirect_uri, state)
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
@@ -82,6 +82,10 @@ module Lark
82
82
  get 'contact/v1/user/batch_get', params: params
83
83
  end
84
84
 
85
+ def get_user_info(user_id, params={})
86
+ get "contact/v3/users/#{user_id}", params: params
87
+ end
88
+
85
89
  def tenant_custom_attr_get
86
90
  get 'contact/v1/tenant/custom_attr/get'
87
91
  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
@@ -0,0 +1,16 @@
1
+ module Lark
2
+ module Apis
3
+ module Search
4
+ def user(query:, user_access_token:, page_size: 20, page_token: nil)
5
+ get 'search/v1/user', {
6
+ access_token: user_access_token,
7
+ params: {
8
+ query: query,
9
+ page_size: page_size,
10
+ page_token: page_token
11
+ }.compact
12
+ }
13
+ end
14
+ end
15
+ end
16
+ 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
@@ -4,14 +4,14 @@ module Lark
4
4
  class Request
5
5
  attr_reader :ssl_context, :http
6
6
 
7
- def initialize(skip_verify_ssl=true)
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
 
14
- def get(path, get_header={})
14
+ def get(path, get_header = {})
15
15
  request(path, get_header) do |url, header|
16
16
  params = header.delete(:params)
17
17
  http.headers(header).get(url, params: params, ssl_context: ssl_context)
@@ -19,7 +19,7 @@ module Lark
19
19
  end
20
20
  alias delete get
21
21
 
22
- def post(path, post_body, post_header={})
22
+ def post(path, post_body, post_header = {})
23
23
  request(path, post_header) do |url, header|
24
24
  Lark.logger.info "payload: #{post_body}"
25
25
  params = header.delete(:params)
@@ -27,7 +27,7 @@ module Lark
27
27
  end
28
28
  end
29
29
 
30
- def post_file(path, file, post_header={})
30
+ def post_file(path, file, post_header = {})
31
31
  request(path, post_header) do |url, header|
32
32
  params = header.delete(:params)
33
33
  http.headers(header).post(
@@ -44,11 +44,13 @@ module Lark
44
44
 
45
45
  private
46
46
 
47
- def request(path, header={}, &_block)
48
- url = URI::join(API_BASE_URL, path)
49
- Lark.logger.info "request url(#{url}) with headers: #{header}"
47
+ def request(path, header = {}, &_block)
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,8 @@ 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)
85
+
83
86
  result
84
87
  end
85
88
 
@@ -102,7 +105,7 @@ module Lark
102
105
  end
103
106
 
104
107
  def success?
105
- code == 0
108
+ code.zero?
106
109
  end
107
110
  end
108
111
  end
data/lib/lark/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lark
2
- VERSION = '1.1.2'.freeze
2
+ VERSION = '1.2.2'.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.1.2
4
+ version: 1.2.2
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-10-26 00:00:00.000000000 Z
11
+ date: 2021-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -128,6 +128,7 @@ files:
128
128
  - lib/lark/apis/mina.rb
129
129
  - lib/lark/apis/notify.rb
130
130
  - lib/lark/apis/pay.rb
131
+ - lib/lark/apis/search.rb
131
132
  - lib/lark/apis/user.rb
132
133
  - lib/lark/cipher.rb
133
134
  - lib/lark/config.rb
@@ -140,14 +141,14 @@ files:
140
141
  - lib/lark/token_store/isv_tenant_token.rb
141
142
  - lib/lark/token_store/tenant_token.rb
142
143
  - lib/lark/version.rb
143
- homepage: https://github.com/mycolorway/lark-ruby-sdk
144
+ homepage: https://github.com/seandong/lark-ruby-sdk
144
145
  licenses:
145
146
  - MIT
146
147
  metadata:
147
148
  allowed_push_host: https://rubygems.org/
148
- homepage_uri: https://github.com/mycolorway/lark-ruby-sdk
149
- source_code_uri: https://github.com/mycolorway/lark-ruby-sdk
150
- changelog_uri: https://github.com/mycolorway/lark-ruby-sdk
149
+ homepage_uri: https://github.com/seandong/lark-ruby-sdk
150
+ source_code_uri: https://github.com/seandong/lark-ruby-sdk
151
+ changelog_uri: https://github.com/seandong/lark-ruby-sdk
151
152
  post_install_message:
152
153
  rdoc_options: []
153
154
  require_paths: