k3cloud-sdk 0.4.4 → 0.4.6

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: 9c129198e6a505d9b23108206100c842f1b0f94c0af6e23d7861653959ad45aa
4
- data.tar.gz: dba6a6547c17d7e80fbf0aacee553a4c9f96f9c81c69d26867a52732ffdad93b
3
+ metadata.gz: 148509b4c220bf006114ffc6d60dec5b540abe2e33761dad837ef395e3553923
4
+ data.tar.gz: 93a6ae34b81c0998a1b02cc9405404ddae16eb4238497bf042cbd00fe53e5726
5
5
  SHA512:
6
- metadata.gz: 53fd09b1ea66c3c07c282fbc61ba19b98a34976e91786bd92f3e9f692f69e782ce3d7680011db3191575a11a5746a87b5d173027768217f92fbd86dfeca89d13
7
- data.tar.gz: d3878ab3f399a20c9d915feb73f0cd0b0c2b23148924b71640a9239a4f77cd29b3988549397be8cbc7b3152b2de97429d791bf6f3efa4638fc62c3698c91e876
6
+ metadata.gz: b2c060e153416fd6bb8fcf9d3b3c06127a4beb9fde7a66d276742d60b422d929d2aa6d1f7dbfdf8cd8cc17175f1c48197f3c022707fed89bd73601829713f931
7
+ data.tar.gz: 9505afcb1b6ff35e631abec3d9f97db35c8add981c6046ddfbac17560c9aaea5ffd29b6c62d548fd0e51e98e039f0c82a141f15e96e2d7e24a8b14cc6a2fe3d6
data/CODE_OF_CONDUCT.md CHANGED
@@ -20,7 +20,7 @@ Examples of unacceptable behavior include:
20
20
 
21
21
  * The use of sexualized language or imagery, and sexual attention or
22
22
  advances of any kind
23
- * Trolling, insulting or derogatory comments, and personal or political attacks
23
+ * Trolling, insulting, or derogatory comments, and personal or political attacks
24
24
  * Public or private harassment
25
25
  * Publishing others' private information, such as a physical or email
26
26
  address, without their explicit permission
@@ -39,7 +39,9 @@ This Code of Conduct applies within all community spaces, and also applies when
39
39
 
40
40
  ## Enforcement
41
41
 
42
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at tianzhenfei@yolanda.hk. All complaints will be reviewed and investigated promptly and fairly.
42
+ Instances of abusive, harassing,
43
+ or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at zevinto@163.com.
44
+ All complaints will be reviewed and investigated promptly and fairly.
43
45
 
44
46
  All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
47
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- k3cloud-sdk (0.4.4)
4
+ k3cloud-sdk (0.4.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -32,15 +32,15 @@ module K3cloud
32
32
  attr_accessor :connect_timeout, :request_timeout
33
33
 
34
34
  def initialize(options = {})
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]
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("k3cloud Failed to parse exception message: #{e.message}")
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,52 +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 || 2
18
- @request_timeout = request_timeout || 2
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
- http.use_ssl = (uri.scheme == "https")
25
- http.open_timeout = @connect_timeout * 60
26
- http.read_timeout = @request_timeout * 60
27
- request = Net::HTTP::Post.new(uri)
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"] = "Kingdee/Ruby WebApi SDK"
31
- request.body = @body.to_json
32
- max_retries = 5 # 最大重试次数
33
- retry_count = 0
34
- sleep_interval = 5 # 重试间隔时间,单位秒
35
-
36
- begin
37
- response = http.request(request)
38
- if response.code.to_i != 200 && response.code.to_i != 206
39
- raise K3cloud::ResponseError, "status: #{response.code}, desc: #{response.body}"
40
- end
41
- response.body
42
- rescue Errno::ETIMEDOUT, Net::OpenTimeout, Net::ReadTimeout => e
43
- K3cloud.logger.error("Request timed out: #{e.message}")
44
- if retry_count < max_retries
45
- retry_count += 1
46
- K3cloud.logger.info("Request timed out. Retrying #{retry_count}/#{max_retries} in #{sleep_interval} seconds...")
47
- sleep(sleep_interval)
48
- retry
49
- else
50
- raise K3cloud::ResponseError, "Request failed after #{max_retries} retries: #{e.message}, backtrace: #{e.backtrace}"
51
- end
52
- end
36
+ request["User-Agent"] = generate_user_agent
37
+ request.body = @body.is_a?(String) ? @body : @body.to_json
38
+
39
+ response = http.request(request)
40
+ @status_code = response.code.to_i
41
+ raise K3cloud::ResponseError, "status: #{response.code}, desc: #{response.body}" if @status_code >= 400
42
+
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})"
53
57
  end
54
58
  end
55
59
  end
@@ -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? && !rows[0].empty? && (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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module K3cloud
4
- VERSION = "0.4.4"
4
+ VERSION = "0.4.6"
5
5
  end
@@ -37,14 +37,8 @@ module K3cloud
37
37
  private
38
38
 
39
39
  def execute_json(service_name, parameters)
40
- url = @config.server_url
41
- url = if url.nil? || url.empty?
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.info("#{e.backtrace}")
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
4
+ version: 0.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - zevinto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-19 00:00:00.000000000 Z
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.2.33
67
+ rubygems_version: 3.5.18
68
68
  signing_key:
69
69
  specification_version: 4
70
70
  summary: Ruby Gem for K3cloud API.