k3cloud-sdk 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ad64f7624e0d670b5fc3d43a49469b5be650c796c2deb24588e281d84eb62867
4
+ data.tar.gz: 512b3585e661e58446308a29bdcbd2af95361805aa5802c230d6191b258847a9
5
+ SHA512:
6
+ metadata.gz: c5cc429bb8215e212b49d292da775561c774f7fb8258c9ce1249d4cfae071a51d7b91a9a0e35f67e5670d563b28221e1d434ed0eb0690d2b7ccdf177263f5dde
7
+ data.tar.gz: 21485935926a10a96f5e7258463f84281e3c06ef4bf68149be7ed30b1a2809cb30034db4a7c0673589d14bcc84a4b6ad40c34cfda990a7d4f6e1b4c42ed28cec
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-09-26
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
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.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in k3cloud.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,34 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ k3cloud-sdk (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.5.0)
10
+ rake (13.0.6)
11
+ rspec (3.12.0)
12
+ rspec-core (~> 3.12.0)
13
+ rspec-expectations (~> 3.12.0)
14
+ rspec-mocks (~> 3.12.0)
15
+ rspec-core (3.12.2)
16
+ rspec-support (~> 3.12.0)
17
+ rspec-expectations (3.12.3)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.12.0)
20
+ rspec-mocks (3.12.6)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.12.0)
23
+ rspec-support (3.12.1)
24
+
25
+ PLATFORMS
26
+ arm64-darwin-22
27
+
28
+ DEPENDENCIES
29
+ k3cloud-sdk!
30
+ rake (~> 13.0)
31
+ rspec (~> 3.0)
32
+
33
+ BUNDLED WITH
34
+ 2.4.19
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 zevinto
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # K3cloud-sdk
2
+ Ruby Gem for K3cloud API.
3
+
4
+ ## Installation
5
+
6
+ Install the gem and add to the Rails application's Gemfile by executing:
7
+
8
+ $ bundle add k3cloud-sdk
9
+
10
+ If bundler is not being used to manage dependencies, install the gem by executing:
11
+
12
+ $ gem install k3cloud-sdk
13
+
14
+ ## Usage
15
+
16
+ You'll need to configure it in `config/initializers/k3cloud.rb`:
17
+
18
+ ```ruby
19
+ K3cloud.configure do |config|
20
+ config.acct_id = ENV['K3CLOUD_ACCT_ID']
21
+ config.user_name = ENV['K3CLOUD_USERNAME']
22
+ config.app_id = ENV['K3CLOUD_APP_ID']
23
+ config.app_secret = ENV['K3CLOUD_APP_SECRET']
24
+ config.server_url = ENV['K3CLOUD_SERVER_URL']
25
+ end
26
+ ```
27
+
28
+ Then you can call the k3cloud API using the following code:
29
+ ```ruby
30
+ data = {
31
+ FormId: "",
32
+ FieldKeys: "",
33
+ FilterString: ""
34
+ }
35
+ K3cloud.execute_bill_query(data)
36
+ ```
37
+
38
+ ## Development
39
+
40
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
41
+
42
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/zevinto/k3cloud-sdk.
47
+ This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/zevinto/k3cloud-sdk/blob/main/CODE_OF_CONDUCT.md).
48
+
49
+ ## License
50
+
51
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
52
+
53
+ ## Code of Conduct
54
+
55
+ Everyone interacting in the K3cloud-sdk project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/zevinto/k3cloud-sdk/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: %i[spec]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "k3cloud"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/k3cloud.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/k3cloud/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "k3cloud-sdk"
7
+ spec.version = K3cloud::VERSION
8
+ spec.authors = ["zevinto"]
9
+ spec.email = ["aarontzf@yolanda.hk"]
10
+
11
+ spec.summary = "Ruby Gem for K3cloud API."
12
+ spec.description = "Ruby Gem for K3cloud API."
13
+ spec.homepage = "https://github.com/zevinto/k3cloud-sdk"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.0.0"
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
+ `git ls-files -z`.split("\x0").reject do |f|
22
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
23
+ end
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ # Uncomment to register a new dependency of your gem
30
+ # spec.add_dependency "faraday"
31
+
32
+ # For more information and examples about making a new gem, check out our
33
+ # guide at: https://bundler.io/guides/creating_gem.html
34
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "k3cloud"
4
+
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module K3cloud
4
+ class Configuration
5
+ # 服务Url地址(私有云必须配置金蝶云星空产品地址,K3Cloud/结尾。若为公有云则必须置空)
6
+ attr_accessor :server_url
7
+
8
+ # 账套ID(即数据中心id)
9
+ attr_accessor :acct_id
10
+
11
+ # 账套语系,默认2052
12
+ # 2052: 简体中文
13
+ # 1033: 英文
14
+ # 3076: 繁体中文
15
+ attr_accessor :lcid
16
+
17
+ # 第三方系统登录授权的集成用户名称
18
+ attr_accessor :user_name
19
+
20
+ # 集成用户登录密码
21
+ attr_accessor :password
22
+
23
+ # 第三方系统登录授权的应用ID
24
+ attr_accessor :app_id
25
+
26
+ # 第三方系统登录授权的应用密钥
27
+ attr_accessor :app_secret
28
+
29
+ # 组织编码,启用多组织时配置对应的组织编码才有效
30
+ attr_accessor :org_num
31
+
32
+ attr_accessor :connect_timeout, :request_timeout
33
+
34
+ def initialize
35
+ yield(self) if block_given?
36
+ end
37
+
38
+ def self.default
39
+ @@default ||= Configuration.new
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ class K3cloudError < StandardError
6
+ attr_accessor :message, :inner_ex_wrapper, :inner_exception
7
+
8
+ def initialize
9
+ @message = nil
10
+ @inner_ex_wrapper = nil
11
+ @inner_exception = nil
12
+ super
13
+ end
14
+
15
+ def self.parse(json)
16
+ index = json.index("{")
17
+ json = json[index..] if index >= 0
18
+
19
+ parsed_json = JSON.parse(json)
20
+ kd_error = K3cloudError.new
21
+ kd_error.message = parsed_json["Message"]
22
+ kd_error.inner_ex_wrapper = K3cloudError.parse(parsed_json["InnerExWrapper"].to_json)
23
+ kd_error.inner_exception = K3cloudError.parse(parsed_json["InnerException"].to_json)
24
+ kd_error
25
+ rescue StandardError => e
26
+ nil
27
+ end
28
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+ require "net/https"
5
+ require "uri"
6
+
7
+ module K3cloud
8
+ # HTTP Client
9
+ class Http
10
+ attr_accessor :url, :header, :body, :connect_timeout, :request_timeout
11
+
12
+ def initialize(url, header, body, connect_timeout, request_timeout)
13
+ @url = url
14
+ @header = header
15
+ @body = body
16
+ @connect_timeout = connect_timeout || 120
17
+ @request_timeout = request_timeout || 120
18
+ end
19
+
20
+ def post
21
+ uri = URI(@url)
22
+ http = Net::HTTP.new(uri.host, uri.port)
23
+ http.use_ssl = (uri.scheme == "https")
24
+ http.open_timeout = @connect_timeout * 1000
25
+ http.read_timeout = @request_timeout * 1000
26
+ request = Net::HTTP::Post.new(uri)
27
+ request.initialize_http_header(@header)
28
+ request["Content-Type"] = "application/json"
29
+ request["User-Agent"] = "Kingdee/Ruby WebApi SDK"
30
+ request.body = @body.to_json
31
+ response = http.request(request)
32
+ response.body
33
+ rescue StandardError => e
34
+ K3cloud.logger.warn "#{e.message} => K3cloud::HTTP.post('#{@url}')"
35
+ nil
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,135 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "k3cloud/web_api_client"
4
+
5
+ module K3cloud
6
+ # k3cloud Api
7
+ class K3cloudApi < WebApiClient
8
+ # 暂存
9
+ def draft(form_id, data)
10
+ execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Draft", [form_id, data])
11
+ end
12
+
13
+ # 保存
14
+ def save(form_id, data)
15
+ execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Save", [form_id, data])
16
+ end
17
+
18
+ # 批量保存
19
+ def batch_save(form_id, data)
20
+ execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.BatchSave", [form_id, data])
21
+ end
22
+
23
+ # 提交
24
+ def submit(form_id, data)
25
+ execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Submit", [form_id, data])
26
+ end
27
+
28
+ # 审核
29
+ def audit(form_id, data)
30
+ execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Audit", [form_id, data])
31
+ end
32
+
33
+ # 反审核
34
+ def un_audit(form_id, data)
35
+ execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.UnAudit", [form_id, data])
36
+ end
37
+
38
+ # 查看
39
+ def view(form_id, data)
40
+ execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.View", [form_id, data])
41
+ end
42
+
43
+ # 单据查询
44
+ def execute_bill_query(data)
45
+ execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExecuteBillQuery", [data])
46
+ end
47
+
48
+ # 删除
49
+ def delete(form_id, data)
50
+ execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Delete", [form_id, data])
51
+ end
52
+
53
+ # 撤销
54
+ def cancel_assign(form_id, data)
55
+ execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.CancelAssign", [form_id, data])
56
+ end
57
+
58
+ # 下推
59
+ def push(form_id, data)
60
+ execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Push", [form_id, data])
61
+ end
62
+
63
+ # 状态转换:如关闭、反关闭、作废、反作废等
64
+ def execute_operation(form_id, op_number, data)
65
+ execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExcuteOperation", [form_id, op_number, data])
66
+ end
67
+
68
+ # 分配
69
+ def allocate(form_id, data)
70
+ execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Allocate", [form_id, data])
71
+ end
72
+
73
+ # 取消分配
74
+ def cancel_allocate(form_id, data)
75
+ execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.CancelAllocate", [form_id, data])
76
+ end
77
+
78
+ # 分组保存
79
+ def group_save(form_id, data)
80
+ execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.GroupSave", [form_id, data])
81
+ end
82
+
83
+ # 分组信息查询
84
+ def query_group_info(data)
85
+ execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.QueryGroupInfo", [data])
86
+ end
87
+
88
+ # 分组删除
89
+ def group_delete(data)
90
+ execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.GroupDelete", [data])
91
+ end
92
+
93
+ # 附件上传
94
+ def attachment_upload(data)
95
+ execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.AttachmentUpload", [data])
96
+ end
97
+
98
+ # 附件下载
99
+ def attachment_download(data)
100
+ execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.AttachmentDownLoad", [data])
101
+ end
102
+
103
+ # 元数据查询
104
+ def query_business_info(data)
105
+ execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.QueryBusinessInfo", [data])
106
+ end
107
+
108
+ # 查询报表数据
109
+ def get_sys_report_data(form_id, data)
110
+ execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.GetSysReportData", [form_id, data])
111
+ end
112
+
113
+ def flex_save(form_id, data)
114
+ execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.FlexSave", [form_id, data])
115
+ end
116
+
117
+ def send_msg(form_id, data)
118
+ execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.SendMsg", [form_id, data])
119
+ end
120
+
121
+ def disassembly(form_id, data)
122
+ execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Disassembly", [form_id, data])
123
+ end
124
+
125
+ # 工作流审核
126
+ def workflow_audit(data)
127
+ execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.WorkflowAudit", [data])
128
+ end
129
+
130
+ # 切换组织
131
+ def switch_org(data)
132
+ execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.SwitchOrg", [data])
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "base64"
4
+
5
+ module Base64Utils
6
+ def self.encoding_to_base64(buffer)
7
+ b64buffer = Base64.strict_encode64(buffer.pack("C*"))
8
+ b64buffer.force_encoding("UTF-8")
9
+ rescue StandardError => e
10
+ raise e
11
+ end
12
+
13
+ def self.decoding_from_base64(base64)
14
+ buffer = base64.encode("UTF-8")
15
+ Base64.strict_decode64(buffer).bytes
16
+ rescue StandardError => e
17
+ raise e
18
+ end
19
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ConstDefine
4
+ X_API_CLIENT_ID = "X-Api-ClientID"
5
+
6
+ X_API_AUTH_VERSION = "X-Api-Auth-Version"
7
+
8
+ X_API_TIMESTAMP = "x-api-timestamp"
9
+
10
+ X_API_NONCE = "x-api-nonce"
11
+
12
+ X_API_SIGN_HEADERS = "x-api-signheaders"
13
+
14
+ X_API_SIGNATURE = "X-Api-Signature"
15
+
16
+ X_KD_APP_KEY = "X-Kd-Appkey"
17
+
18
+ X_KD_APP_DATA = "X-Kd-Appdata"
19
+
20
+ X_KD_SIGNATURE = "X-Kd-Signature"
21
+
22
+ KD_SERVICE_SESSIONID = "kdservice-sessionid"
23
+
24
+ SESSION_ID = "ASP.NET_SessionId"
25
+
26
+ X_KD_SID = "SID"
27
+
28
+ COOKIE_SET = "Set-Cookie"
29
+
30
+ BEGIN_METHOD_HEADER = "beginmethod"
31
+
32
+ QUERY_METHOD_HEADER = "querymethod"
33
+
34
+ BEGIN_METHOD_METHOD = "BeginQueryImpl"
35
+
36
+ QUERY_METHOD_METHOD = "QueryAsyncResult"
37
+
38
+ QUERY_INVODE_STATE_PENDING = 0
39
+
40
+ QUERY_INVODE_STATE_RUNNING = 1
41
+
42
+ QUERY_INVODE_STATE_COMPLETE = 2
43
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "digest"
4
+ require "base64"
5
+
6
+ module MD5Utils
7
+ def self.encrypt(data_str)
8
+ m = Digest::MD5.new
9
+ m.update(data_str.encode("UTF-8"))
10
+ s = m.digest
11
+ result = ""
12
+
13
+ s.each_byte do |byte|
14
+ result += (byte & 0xFF | -256).to_s(16)[6..]
15
+ end
16
+
17
+ result
18
+ rescue StandardError => e
19
+ e.backtrace
20
+ ""
21
+ end
22
+
23
+ def self.hash_mac(data, secret)
24
+ kd_mac = OpenSSL::HMAC.digest(OpenSSL::Digest.new("sha256"), secret, data)
25
+ hex_string = bytes_to_hex(kd_mac.bytes)
26
+ Base64.strict_encode64(hex_string)
27
+ rescue StandardError => e
28
+ e.backtrace
29
+ nil
30
+ end
31
+
32
+ def self.bytes_to_hex(bytes)
33
+ bytes.map { |byte| byte.to_s(16).rjust(2, "0") }.join
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module K3cloud
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,115 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "k3cloud/errors/k3cloud_error"
4
+ require "k3cloud/utils/md5_utils"
5
+ require "k3cloud/utils/base64_utils"
6
+ require "k3cloud/utils/const_define"
7
+ require "k3cloud/configuration"
8
+ require "k3cloud/http"
9
+
10
+ module K3cloud
11
+ class WebApiClient
12
+ attr_accessor :config
13
+
14
+ def initialize(config = Configuration.default)
15
+ @config = config
16
+ end
17
+
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:")
38
+ 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
43
+ else
44
+ begin
45
+ if result.include?(',"IsSuccess":false,')
46
+ raise StandardError, result
47
+ else
48
+ JSON.parse(result)
49
+ end
50
+ rescue JSON::ParserError => e
51
+ raise StandardError, "JSON parse error, response: [#{result}]", e
52
+ end
53
+ end
54
+ end
55
+
56
+ private
57
+
58
+ def get_url_path(url)
59
+ if url.start_with?("http")
60
+ index = url.index("/", 10)
61
+ index.nil? ? url : url[index..]
62
+ else
63
+ url
64
+ end
65
+ end
66
+
67
+ # @note: https://vip.kingdee.com/knowledge/specialDetail/229961573895771136?category=229964512944566016&id=423060878259269120&productLineId=1
68
+ def build_header(url)
69
+ header = {}
70
+ if @config
71
+ app_id_ary = @config.app_id.split("_")
72
+ cookie_hd = app_id_ary[0]
73
+ api_gw_sec = app_id_ary.size >= 2 ? decode_sec(app_id_ary[1]) : ""
74
+ header[ConstDefine::X_API_CLIENT_ID] = cookie_hd
75
+ header[ConstDefine::X_API_AUTH_VERSION] = "2.0"
76
+
77
+ timestamps = Time.now.to_i.to_s
78
+ header[ConstDefine::X_API_TIMESTAMP] = timestamps
79
+ header[ConstDefine::X_API_NONCE] = timestamps
80
+ header[ConstDefine::X_API_SIGN_HEADERS] = "X-Api-TimeStamp,X-Api-Nonce"
81
+
82
+ url_path = CGI.escape(url.encode("UTF-8"))
83
+ context = "POST\n#{url_path}\n\nx-api-nonce:#{timestamps}\nx-api-timestamp:#{timestamps}\n"
84
+ api_signature = api_gw_sec == "" ? "" : MD5Utils.hash_mac(context, api_gw_sec)
85
+ header[ConstDefine::X_API_SIGNATURE] = api_signature
86
+ header[ConstDefine::X_KD_APP_KEY] = @config.app_id
87
+
88
+ data = "#{@config.acct_id},#{@config.user_name},#{@config.lcid},#{@config.org_num}"
89
+ app_data = Base64Utils.encoding_to_base64(data.bytes)
90
+ header[ConstDefine::X_KD_APP_DATA] = app_data
91
+
92
+ signature_data = "#{@config.app_id}#{data}"
93
+ kd_signature = MD5Utils.hash_mac(signature_data, @config.app_secret)
94
+ header[ConstDefine::X_KD_SIGNATURE] = kd_signature
95
+ end
96
+ header
97
+ end
98
+
99
+ def decode_sec(sec)
100
+ buffer = Base64Utils.decoding_from_base64(sec)
101
+ buffer = x_or_sec(buffer)
102
+ Base64Utils.encoding_to_base64(buffer)
103
+ end
104
+
105
+ def x_or_sec(buffer)
106
+ sec_key = "0054f397c6234378b09ca7d3e5debce7"
107
+ pwd = sec_key.encode("UTF-8").bytes
108
+
109
+ buffer.each_with_index do |byte, i|
110
+ buffer[i] = byte ^ pwd[i % pwd.length]
111
+ end
112
+ buffer
113
+ end
114
+ end
115
+ end
data/lib/k3cloud.rb ADDED
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "k3cloud/version"
4
+ require "logger"
5
+ require "k3cloud/configuration"
6
+ require "k3cloud/k3cloud_api"
7
+ require "forwardable"
8
+
9
+ module K3cloud
10
+ class << self
11
+ extend Forwardable
12
+
13
+ def configure
14
+ if block_given?
15
+ yield(Configuration.default)
16
+ else
17
+ Configuration.default
18
+ end
19
+ end
20
+
21
+ def logger
22
+ @logger ||= ::Logger.new($stderr)
23
+ end
24
+
25
+ def api
26
+ @api ||= K3cloud::K3cloudApi.new
27
+ end
28
+
29
+ def_delegators :api, :draft, :save, :batch_save, :submit, :audit, :un_audit, :view, :execute_bill_query, :delete,
30
+ :cancel_assign, :push, :execute_operation, :allocate, :cancel_allocate, :group_save, :query_group_info,
31
+ :group_delete, :attachment_upload, :attachment_download, :query_business_info, :get_sys_report_data,
32
+ :flex_save, :send_msg, :disassembly, :workflow_audit, :switch_org
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: k3cloud-sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - zevinto
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-09-26 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Ruby Gem for K3cloud API.
14
+ email:
15
+ - aarontzf@yolanda.hk
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".rspec"
21
+ - ".rubocop.yml"
22
+ - CHANGELOG.md
23
+ - CODE_OF_CONDUCT.md
24
+ - Gemfile
25
+ - Gemfile.lock
26
+ - LICENSE.txt
27
+ - README.md
28
+ - Rakefile
29
+ - bin/console
30
+ - bin/setup
31
+ - k3cloud.gemspec
32
+ - lib/K3cloud-sdk.rb
33
+ - lib/k3cloud.rb
34
+ - lib/k3cloud/configuration.rb
35
+ - lib/k3cloud/errors/k3cloud_error.rb
36
+ - lib/k3cloud/http.rb
37
+ - lib/k3cloud/k3cloud_api.rb
38
+ - lib/k3cloud/utils/base64_utils.rb
39
+ - lib/k3cloud/utils/const_define.rb
40
+ - lib/k3cloud/utils/md5_utils.rb
41
+ - lib/k3cloud/version.rb
42
+ - lib/k3cloud/web_api_client.rb
43
+ homepage: https://github.com/zevinto/k3cloud-sdk
44
+ licenses:
45
+ - MIT
46
+ metadata:
47
+ homepage_uri: https://github.com/zevinto/k3cloud-sdk
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 2.0.0
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubygems_version: 3.2.33
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: Ruby Gem for K3cloud API.
67
+ test_files: []