k3cloud-sdk 0.4.3 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -2
- data/lib/k3cloud/configuration.rb +9 -9
- data/lib/k3cloud/errors/k3cloud_error.rb +1 -1
- data/lib/k3cloud/http.rb +35 -15
- data/lib/k3cloud/k3cloud_api.rb +13 -1
- data/lib/k3cloud/version.rb +1 -1
- data/lib/k3cloud/web_api_client.rb +12 -9
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4eb5a3114bbb90e9d4ef2ccc079b87c8fa4ff8982c5567475f638a8f8e50bbe
|
4
|
+
data.tar.gz: e346af656cd09b7bb3f0c745ded7f41655dfe2584f380ddfa24816f9e37ede47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38be2feabc87804721feb2ceeb5dc6f551f73f1fca676f597c683614e28f7e930f398ecb15a1754c291c69bb01ff019bdbad2af8d849e2f7e5370459a3460a12
|
7
|
+
data.tar.gz: 769f509e8a9e7a430571c7feedd2e1d4ab305b8d5c62f973a1aaf1b73baa86e2f44ac625374c3575f5e8a324fe4fbc4728004e3d1e551ca5b3bba574aa2f5657
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
k3cloud-sdk (0.4.
|
4
|
+
k3cloud-sdk (0.4.5)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -24,6 +24,7 @@ GEM
|
|
24
24
|
|
25
25
|
PLATFORMS
|
26
26
|
arm64-darwin-22
|
27
|
+
arm64-darwin-23
|
27
28
|
|
28
29
|
DEPENDENCIES
|
29
30
|
k3cloud-sdk!
|
@@ -31,4 +32,4 @@ DEPENDENCIES
|
|
31
32
|
rspec (~> 3.0)
|
32
33
|
|
33
34
|
BUNDLED WITH
|
34
|
-
2.4.
|
35
|
+
2.4.14
|
@@ -32,15 +32,15 @@ module K3cloud
|
|
32
32
|
attr_accessor :connect_timeout, :request_timeout
|
33
33
|
|
34
34
|
def initialize(options = {})
|
35
|
-
@acct_id
|
36
|
-
@user_name
|
37
|
-
@password
|
38
|
-
@app_id
|
39
|
-
@app_secret
|
40
|
-
@server_url
|
41
|
-
@org_num
|
42
|
-
@connect_timeout
|
43
|
-
@request_timeout
|
35
|
+
@acct_id = options[:acct_id]
|
36
|
+
@user_name = options[:user_name]
|
37
|
+
@password = options[:password]
|
38
|
+
@app_id = options[:app_id]
|
39
|
+
@app_secret = options[:app_secret]
|
40
|
+
@server_url = options[:server_url]
|
41
|
+
@org_num = options[:org_num]
|
42
|
+
@connect_timeout = options[:connect_timeout]
|
43
|
+
@request_timeout = options[:request_timeout]
|
44
44
|
|
45
45
|
yield(self) if block_given?
|
46
46
|
end
|
@@ -24,7 +24,7 @@ module K3cloud
|
|
24
24
|
kd_error.inner_exception = K3cloudError.parse(parsed_json["InnerException"].to_json)
|
25
25
|
kd_error
|
26
26
|
rescue StandardError => e
|
27
|
-
K3cloud.logger.error("
|
27
|
+
K3cloud.logger.error({ errmsg: "Failed to parse exception message. #{e.message}", backtrace: "#{e.backtrace}", type: 'error', lever: 'ERROR' })
|
28
28
|
nil
|
29
29
|
end
|
30
30
|
end
|
data/lib/k3cloud/http.rb
CHANGED
@@ -4,36 +4,56 @@ require "k3cloud/errors/response_error"
|
|
4
4
|
require "net/http"
|
5
5
|
require "net/https"
|
6
6
|
require "uri"
|
7
|
+
require "json"
|
7
8
|
|
8
9
|
module K3cloud
|
9
10
|
# HTTP Client
|
10
11
|
class Http
|
11
|
-
attr_accessor :url, :header, :body, :connect_timeout, :request_timeout
|
12
|
+
attr_accessor :url, :header, :body, :connect_timeout, :request_timeout, :status_code
|
12
13
|
|
13
|
-
def initialize(url, header, body, connect_timeout, request_timeout)
|
14
|
+
def initialize(url, header, body, connect_timeout = 120, request_timeout = 120)
|
14
15
|
@url = url
|
15
|
-
@header = header
|
16
|
+
@header = header || {}
|
16
17
|
@body = body
|
17
|
-
@connect_timeout = connect_timeout
|
18
|
-
@request_timeout = request_timeout
|
18
|
+
@connect_timeout = connect_timeout
|
19
|
+
@request_timeout = request_timeout
|
19
20
|
end
|
20
21
|
|
21
22
|
def post
|
22
|
-
uri = URI(@url)
|
23
|
+
uri = URI.parse(@url)
|
23
24
|
http = Net::HTTP.new(uri.host, uri.port)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
# SSL/TLS configuration
|
26
|
+
if uri.scheme == "https"
|
27
|
+
http.use_ssl = true
|
28
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
29
|
+
end
|
30
|
+
|
31
|
+
http.open_timeout = @connect_timeout
|
32
|
+
http.read_timeout = @request_timeout
|
33
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
28
34
|
request.initialize_http_header(@header)
|
29
35
|
request["Content-Type"] = "application/json"
|
30
|
-
request["User-Agent"] =
|
31
|
-
request.body = @body.to_json
|
36
|
+
request["User-Agent"] = generate_user_agent
|
37
|
+
request.body = @body.is_a?(String) ? @body : @body.to_json
|
38
|
+
|
32
39
|
response = http.request(request)
|
33
|
-
|
34
|
-
|
35
|
-
|
40
|
+
@status_code = response.code.to_i
|
41
|
+
raise K3cloud::ResponseError, "status: #{response.code}, desc: #{response.body}" if @status_code >= 400
|
42
|
+
|
36
43
|
response.body
|
44
|
+
rescue Errno::ETIMEDOUT, Net::OpenTimeout, Net::ReadTimeout => e
|
45
|
+
raise K3cloud::ResponseError, "Request timed out: #{e.message}"
|
46
|
+
rescue Net::HTTPServerError => e
|
47
|
+
raise K3cloud::ResponseError, "Server error: #{e.message}"
|
48
|
+
rescue => e
|
49
|
+
raise K3cloud::ResponseError, "Unexpected error: #{e.message}"
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
# Generate User-Agent string with client info
|
55
|
+
def generate_user_agent
|
56
|
+
"Kingdee/Ruby WebApi SDK(v#{K3cloud::VERSION}) (Ruby #{RUBY_VERSION}; #{RUBY_PLATFORM})"
|
37
57
|
end
|
38
58
|
end
|
39
59
|
end
|
data/lib/k3cloud/k3cloud_api.rb
CHANGED
@@ -42,7 +42,8 @@ module K3cloud
|
|
42
42
|
|
43
43
|
# 单据查询
|
44
44
|
def execute_bill_query(data)
|
45
|
-
execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExecuteBillQuery", [data])
|
45
|
+
rows = execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExecuteBillQuery", [data])
|
46
|
+
handle_query_result(rows)
|
46
47
|
end
|
47
48
|
|
48
49
|
# 删除
|
@@ -131,5 +132,16 @@ module K3cloud
|
|
131
132
|
def switch_org(data)
|
132
133
|
execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.SwitchOrg", [data])
|
133
134
|
end
|
135
|
+
|
136
|
+
private
|
137
|
+
|
138
|
+
def handle_query_result(rows)
|
139
|
+
if !rows[0].nil? && (result = rows[0][0]).is_a?(Hash)
|
140
|
+
K3cloud.logger.error({ errmsg: result, type: 'error', lever: 'ERROR' })
|
141
|
+
[]
|
142
|
+
else
|
143
|
+
[]
|
144
|
+
end
|
145
|
+
end
|
134
146
|
end
|
135
147
|
end
|
data/lib/k3cloud/version.rb
CHANGED
@@ -37,14 +37,8 @@ module K3cloud
|
|
37
37
|
private
|
38
38
|
|
39
39
|
def execute_json(service_name, parameters)
|
40
|
-
url =
|
41
|
-
|
42
|
-
"https://api.kingdee.com/galaxyapi/"
|
43
|
-
else
|
44
|
-
url.to_s.strip.chomp("/")
|
45
|
-
end
|
46
|
-
url = "#{url}/#{service_name}.common.kdsvc"
|
47
|
-
K3cloud.logger.info("request_url: #{url}")
|
40
|
+
url = build_url(service_name)
|
41
|
+
K3cloud.logger.info("Request URL: #{url}")
|
48
42
|
|
49
43
|
header = build_header(url_path(url))
|
50
44
|
body = { parameters: parameters }
|
@@ -52,6 +46,15 @@ module K3cloud
|
|
52
46
|
request.post
|
53
47
|
end
|
54
48
|
|
49
|
+
def build_url(service_name)
|
50
|
+
base_url = if @config.server_url.nil? || @config.server_url.empty?
|
51
|
+
"https://api.kingdee.com/galaxyapi/"
|
52
|
+
else
|
53
|
+
@config.server_url.to_s.strip.chomp("/")
|
54
|
+
end
|
55
|
+
"#{base_url}/#{service_name}.common.kdsvc"
|
56
|
+
end
|
57
|
+
|
55
58
|
def url_path(url)
|
56
59
|
if url.start_with?("http")
|
57
60
|
index = url.index("/", 10)
|
@@ -92,7 +95,7 @@ module K3cloud
|
|
92
95
|
end
|
93
96
|
header
|
94
97
|
rescue StandardError => e
|
95
|
-
K3cloud.logger.
|
98
|
+
K3cloud.logger.error({ errmsg: "Build header exception.", backtrace: "#{e.backtrace}", type: 'error', lever: 'ERROR' })
|
96
99
|
{}
|
97
100
|
end
|
98
101
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: k3cloud-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zevinto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ruby Gem for K3cloud OpenApi that uses cryptographic signature technology
|
14
14
|
to avoid plaintext transmission of keys and enables automatic login.
|
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
64
|
- !ruby/object:Gem::Version
|
65
65
|
version: '0'
|
66
66
|
requirements: []
|
67
|
-
rubygems_version: 3.
|
67
|
+
rubygems_version: 3.5.18
|
68
68
|
signing_key:
|
69
69
|
specification_version: 4
|
70
70
|
summary: Ruby Gem for K3cloud API.
|