k3cloud-sdk 0.4.0 → 0.4.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: 3fcdb39f0120d7be1d75b2b05088eae22fd6ac5d3fdb422bf25f6a472b729fb3
4
- data.tar.gz: 36d2bf34f18781c5a7574b03cbe62dcdbbba8e20b2c63b23860e7c08dc3e9aac
3
+ metadata.gz: cb22e56d62809750b9a0184ca7c85f3d0b54cad33808cae01dea08f387e950d4
4
+ data.tar.gz: 8811b5a8226229361ba16038253540509c37a43ccebd193a973b4ce59670201b
5
5
  SHA512:
6
- metadata.gz: c72cc86924e218be315fb570958bd9289c58a475cc4ac6014de43447030c5f09ab642d784601e5acfea43fdefe0788bcb8ccfa9cb38e221bc549d139180bd80d
7
- data.tar.gz: 311051445ab1bb7b3dd719aa17a34538337be2edafce4ce094404fc7d80e2b8b1f0549820f1ee66a3a6bc822f1606cf59af0b9f13f749ae0185e4f5882f6a725
6
+ metadata.gz: 1ad03ae0ad58d2d5b11ab541f46f1786d76d2567d1e4ab24ab27fe991ac5031fa50a291ca620aeeafba5df934276d98c4dc82bae5e57f717d5ddf800f3329c76
7
+ data.tar.gz: 2b66ed76217f6984789149e893e35328163feed7e0be687ff99accf0cc802c22463791d0267957de4ffa9b14f0a2632bab4ada8be08b520f5f42223628727a3a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- k3cloud-sdk (0.4.0)
4
+ k3cloud-sdk (0.4.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # K3cloud-sdk
2
- Ruby Gem for K3cloud API.
2
+ Ruby Gem for K3cloud OpenApi that uses cryptographic signature technology to avoid plaintext transmission of keys and enables automatic login.
3
3
 
4
4
  ## Installation
5
5
 
data/k3cloud.gemspec CHANGED
@@ -6,10 +6,10 @@ Gem::Specification.new do |spec|
6
6
  spec.name = "k3cloud-sdk"
7
7
  spec.version = K3cloud::VERSION
8
8
  spec.authors = ["zevinto"]
9
- spec.email = ["aarontzf@yolanda.hk"]
9
+ spec.email = ["zevinto@163.com"]
10
10
 
11
11
  spec.summary = "Ruby Gem for K3cloud API."
12
- spec.description = "Ruby Gem for K3cloud API."
12
+ spec.description = "Ruby Gem for K3Cloud that uses cryptographic signature technology to avoid plaintext transmission of keys and enables automatic login."
13
13
  spec.homepage = "https://github.com/zevinto/k3cloud-sdk"
14
14
  spec.license = "MIT"
15
15
  spec.required_ruby_version = ">= 2.0.0"
data/lib/k3cloud/http.rb CHANGED
@@ -29,10 +29,10 @@ module K3cloud
29
29
  request["User-Agent"] = "Kingdee/Ruby WebApi SDK"
30
30
  request.body = @body.to_json
31
31
  response = http.request(request)
32
+ if response.code.to_i != 200 && response.code.to_i != 206
33
+ raise StandardError, "status: #{response.code}, desc: #{response.body}"
34
+ end
32
35
  response.body
33
- rescue StandardError => e
34
- K3cloud.logger.warn "#{e.message} => K3cloud::HTTP.post('#{@url}')"
35
- nil
36
36
  end
37
37
  end
38
38
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module K3cloud
4
- VERSION = "0.4.0"
4
+ VERSION = "0.4.2"
5
5
  end
@@ -16,38 +16,22 @@ module K3cloud
16
16
  end
17
17
 
18
18
  def execute(service_name, parameters)
19
- url = @config.server_url
20
- if url.nil? || url.empty?
21
- url = "https://api.kingdee.com/galaxyapi/"
22
- else
23
- url = url.to_s.strip.chomp("/")
24
- url = "#{url}/#{service_name}.common.kdsvc"
25
- end
26
-
27
- header = build_header(get_url_path(url))
28
- body = {
29
- "format" => 1,
30
- "useragent" => "ApiClient",
31
- "parameters" => parameters,
32
- "v" => "1.0"
33
- }
34
- request = Http.new(url, header, body, @config.connect_timeout, @config.request_timeout)
35
- result = request.post
36
-
37
- if result&.start_with?("response_error:")
19
+ result = execute_json(service_name, parameters)
20
+ if result.start_with?("response_error:")
38
21
  error = K3cloudError.parse(result)
39
- raise StandardError, result if error.nil?
40
-
41
- message = error.inner_ex_wrapper.nil? ? error.message : "#{error.message} --> #{error.inner_ex_wrapper.message}"
42
- raise StandardError, message
22
+ if error.nil?
23
+ raise StandardError, result
24
+ else
25
+ message = error.inner_ex_wrapper.nil? ? error.message : "#{error.message} --> #{error.inner_ex_wrapper&.message}"
26
+ raise StandardError, message
27
+ end
43
28
  else
44
29
  begin
45
- if result.include?(',"IsSuccess":false,')
46
- raise StandardError, result
47
- else
48
- JSON.parse(result)
49
- end
50
- rescue JSON::ParserError => e
30
+ json = JSON.parse(result)
31
+ raise StandardError, json if result.include?(',"IsSuccess":false,')
32
+
33
+ json
34
+ rescue StandardError => e
51
35
  raise StandardError, "JSON parse error, response: [#{result}]", e
52
36
  end
53
37
  end
@@ -55,10 +39,26 @@ module K3cloud
55
39
 
56
40
  private
57
41
 
58
- def get_url_path(url)
42
+ def execute_json(service_name, parameters)
43
+ url = @config.server_url
44
+ if url.nil? || url.empty?
45
+ url = "https://api.kingdee.com/galaxyapi/"
46
+ else
47
+ url = url.to_s.strip.chomp("/")
48
+ end
49
+ url = "#{url}/#{service_name}.common.kdsvc"
50
+ K3cloud.logger.info("request_url: #{url}")
51
+
52
+ header = build_header(url_path(url))
53
+ body = { parameters: parameters }
54
+ request = Http.new(url, header, body, @config.connect_timeout, @config.request_timeout)
55
+ request.post
56
+ end
57
+
58
+ def url_path(url)
59
59
  if url.start_with?("http")
60
60
  index = url.index("/", 10)
61
- index.nil? ? url : url[index..-1]
61
+ index > -1 ? url[index..-1] : url
62
62
  else
63
63
  url
64
64
  end
@@ -94,6 +94,9 @@ module K3cloud
94
94
  header[ConstDefine::X_KD_SIGNATURE] = kd_signature
95
95
  end
96
96
  header
97
+ rescue StandardError => e
98
+ K3cloud.logger.info("#{e.backtrace}")
99
+ {}
97
100
  end
98
101
 
99
102
  def decode_sec(sec)
metadata CHANGED
@@ -1,18 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: k3cloud-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - zevinto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-11-17 00:00:00.000000000 Z
11
+ date: 2023-11-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Ruby Gem for K3cloud API.
13
+ description: Ruby Gem for K3Cloud that uses cryptographic signature technology to
14
+ avoid plaintext transmission of keys and enables automatic login.
14
15
  email:
15
- - aarontzf@yolanda.hk
16
+ - zevinto@163.com
16
17
  executables: []
17
18
  extensions: []
18
19
  extra_rdoc_files: []