dingtalk-ruby 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +83 -0
- data/LICENSE.txt +21 -0
- data/README.md +46 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/dingtalk.gemspec +40 -0
- data/lib/dingtalk/api/Base.rb +165 -0
- data/lib/dingtalk/api/OapiGettokenRequest.rb +20 -0
- data/lib/dingtalk/api/OapiSnsGetuserinfoBycodeRequest.rb +18 -0
- data/lib/dingtalk/api/OapiUserGetRequest.rb +18 -0
- data/lib/dingtalk/api/OapiUserGetUseridByUnionidRequest.rb +18 -0
- data/lib/dingtalk/version.rb +3 -0
- data/lib/dingtalk.rb +57 -0
- metadata +177 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 77c56bca62130c5a210a1dab6a865dc0d4e56c4cbed4d4fad1528070f78e9524
|
4
|
+
data.tar.gz: 2b54ed3c8fa5f79ef6e0c63fe1946e929abe40aea1fd6980cde332b5fa4ecdf2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 194276a18dd442a666e0dc8357873b5bcfd8256534044bba9f4a25831c3bdd7e89edf94a3c4a9a25de61863a5e4be0e991ec08626f2fdbfaebd9a66620ba8da3
|
7
|
+
data.tar.gz: cceb3a372dd28cd3d6010a9724b3e5cbd8bc36684ccfcde814e4efd0256186dec0dbfcadb6d3998f2b792462e21d54d6380cec42e60f4d9654f9d61bfa01c1de
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at zhenyuanlau@icloud.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
dingtalk-ruby (0.1.2)
|
5
|
+
activesupport
|
6
|
+
faraday
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (6.0.2)
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
i18n (>= 0.7, < 2)
|
14
|
+
minitest (~> 5.1)
|
15
|
+
tzinfo (~> 1.1)
|
16
|
+
zeitwerk (~> 2.2)
|
17
|
+
ast (2.4.0)
|
18
|
+
byebug (11.0.1)
|
19
|
+
coderay (1.1.2)
|
20
|
+
concurrent-ruby (1.1.5)
|
21
|
+
diff-lcs (1.3)
|
22
|
+
faraday (0.17.1)
|
23
|
+
multipart-post (>= 1.2, < 3)
|
24
|
+
i18n (1.7.0)
|
25
|
+
concurrent-ruby (~> 1.0)
|
26
|
+
jaro_winkler (1.5.4)
|
27
|
+
method_source (0.8.2)
|
28
|
+
minitest (5.13.0)
|
29
|
+
multipart-post (2.1.1)
|
30
|
+
parallel (1.19.1)
|
31
|
+
parser (2.6.5.0)
|
32
|
+
ast (~> 2.4.0)
|
33
|
+
pry (0.10.4)
|
34
|
+
coderay (~> 1.1.0)
|
35
|
+
method_source (~> 0.8.1)
|
36
|
+
slop (~> 3.4)
|
37
|
+
pry-byebug (3.7.0)
|
38
|
+
byebug (~> 11.0)
|
39
|
+
pry (~> 0.10)
|
40
|
+
rainbow (3.0.0)
|
41
|
+
rake (10.5.0)
|
42
|
+
rspec (3.9.0)
|
43
|
+
rspec-core (~> 3.9.0)
|
44
|
+
rspec-expectations (~> 3.9.0)
|
45
|
+
rspec-mocks (~> 3.9.0)
|
46
|
+
rspec-core (3.9.0)
|
47
|
+
rspec-support (~> 3.9.0)
|
48
|
+
rspec-expectations (3.9.0)
|
49
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
50
|
+
rspec-support (~> 3.9.0)
|
51
|
+
rspec-mocks (3.9.0)
|
52
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
53
|
+
rspec-support (~> 3.9.0)
|
54
|
+
rspec-support (3.9.0)
|
55
|
+
rubocop (0.77.0)
|
56
|
+
jaro_winkler (~> 1.5.1)
|
57
|
+
parallel (~> 1.10)
|
58
|
+
parser (>= 2.6)
|
59
|
+
rainbow (>= 2.2.2, < 4.0)
|
60
|
+
ruby-progressbar (~> 1.7)
|
61
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
62
|
+
ruby-progressbar (1.10.1)
|
63
|
+
slop (3.6.0)
|
64
|
+
thread_safe (0.3.6)
|
65
|
+
tzinfo (1.2.5)
|
66
|
+
thread_safe (~> 0.1)
|
67
|
+
unicode-display_width (1.6.0)
|
68
|
+
zeitwerk (2.2.2)
|
69
|
+
|
70
|
+
PLATFORMS
|
71
|
+
ruby
|
72
|
+
|
73
|
+
DEPENDENCIES
|
74
|
+
bundler (~> 2.0)
|
75
|
+
dingtalk-ruby!
|
76
|
+
pry (~> 0.10.3)
|
77
|
+
pry-byebug
|
78
|
+
rake (~> 10.0)
|
79
|
+
rspec (~> 3.0)
|
80
|
+
rubocop
|
81
|
+
|
82
|
+
BUNDLED WITH
|
83
|
+
2.1.0
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Zhenyuan Lau
|
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,46 @@
|
|
1
|
+
# Dingtalk
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'dingtalk-ruby'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install dingtalk-ruby
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
request = Dingtalk::Api::OapiGettokenRequest("https://oapi.dingtalk.com/gettoken")
|
23
|
+
request.userid = "userid1"
|
24
|
+
response = request.getResponse()
|
25
|
+
puts response
|
26
|
+
```
|
27
|
+
|
28
|
+
TODO: Write usage instructions here
|
29
|
+
|
30
|
+
## Development
|
31
|
+
|
32
|
+
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.
|
33
|
+
|
34
|
+
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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dingtalk. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
39
|
+
|
40
|
+
## License
|
41
|
+
|
42
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
43
|
+
|
44
|
+
## Code of Conduct
|
45
|
+
|
46
|
+
Everyone interacting in the Dingtalk project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/dingtalk/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require 'dingtalk'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
require "pry"
|
11
|
+
Pry.start
|
12
|
+
|
13
|
+
# require "irb"
|
14
|
+
# IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/dingtalk.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "dingtalk/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "dingtalk-ruby"
|
7
|
+
spec.version = Dingtalk::VERSION
|
8
|
+
spec.authors = ["Zhenyuan Lau"]
|
9
|
+
spec.email = ["zhenyuanlau@icloud.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{Dingtalk Ruby SDK}
|
12
|
+
spec.description = %q{Dingtalk Ruby SDK according official specification.}
|
13
|
+
spec.homepage = "https://github.com/zhenyuanlau/dingtalk-ruby"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = "https://github.com/zhenyuanlau/dingtalk-ruby"
|
20
|
+
spec.metadata["changelog_uri"] = "https://github.com/zhenyuanlau/dingtalk-ruby"
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.add_runtime_dependency "faraday"
|
32
|
+
spec.add_runtime_dependency "activesupport"
|
33
|
+
|
34
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
35
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
36
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
37
|
+
spec.add_development_dependency "pry", "~> 0.10.3"
|
38
|
+
spec.add_development_dependency "pry-byebug"
|
39
|
+
spec.add_development_dependency "rubocop"
|
40
|
+
end
|
@@ -0,0 +1,165 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
require "base64"
|
3
|
+
require "faraday"
|
4
|
+
require "active_support/all"
|
5
|
+
|
6
|
+
module Dingtalk
|
7
|
+
module Api
|
8
|
+
class Base
|
9
|
+
attr_accessor :__port, :__domain, :__path
|
10
|
+
|
11
|
+
def initialize(url = nil)
|
12
|
+
raise RequestException, "domain must not be empty." if url.nil?
|
13
|
+
|
14
|
+
@__port = 80
|
15
|
+
pathUrl = if url.start_with?('http://')
|
16
|
+
url.gsub('http://', '')
|
17
|
+
elsif url.start_with?('https://')
|
18
|
+
url.gsub('https://', '')
|
19
|
+
else
|
20
|
+
raise RequestException, "http protocol is not validate."
|
21
|
+
end
|
22
|
+
|
23
|
+
index = pathUrl.index('/').to_i
|
24
|
+
|
25
|
+
if index.positive?
|
26
|
+
@__domain = pathUrl[0...index]
|
27
|
+
@__path = pathUrl[index..-1]
|
28
|
+
else
|
29
|
+
@__domain = pathUrl
|
30
|
+
@__path = ''
|
31
|
+
end
|
32
|
+
|
33
|
+
# puts "domain:#{@__domain}, path: #{@__path}, port: #{@__port}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def getRequestHeader
|
37
|
+
{
|
38
|
+
'Content-type' => 'application/json;charset=UTF-8',
|
39
|
+
"Cache-Control" => "no-cache",
|
40
|
+
"Connection" => "Keep-Alive"
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
def getHttpMethod
|
45
|
+
"GET"
|
46
|
+
end
|
47
|
+
|
48
|
+
def getapiname
|
49
|
+
""
|
50
|
+
end
|
51
|
+
|
52
|
+
def getApiPath
|
53
|
+
""
|
54
|
+
end
|
55
|
+
|
56
|
+
def getMultipartParas
|
57
|
+
[]
|
58
|
+
end
|
59
|
+
|
60
|
+
def getCanonicalStringForIsv(timestamp, suiteTicket)
|
61
|
+
if suiteTicket.present?
|
62
|
+
"#{timestamp}\n#{suiteTicket}"
|
63
|
+
else
|
64
|
+
timestamp
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def getResponse(authrize: '', accessKey: '', accessSecret: '', suiteTicket: '', corpId: '', timeout: 30)
|
69
|
+
sys_parameters = {
|
70
|
+
:P_PARTNER_ID => SYSTEM_GENERATE_VERSION
|
71
|
+
}
|
72
|
+
sys_parameters[P_ACCESS_TOKEN] = authrize if authrize.present?
|
73
|
+
application_parameter = getApplicationParameters
|
74
|
+
|
75
|
+
# apiname_split = self.getapiname().split(".")
|
76
|
+
|
77
|
+
sign_parameter = sys_parameters.dup
|
78
|
+
|
79
|
+
sign_parameter.merge!(application_parameter)
|
80
|
+
|
81
|
+
# header = getRequestHeader
|
82
|
+
|
83
|
+
body = application_parameter
|
84
|
+
|
85
|
+
if accessKey.present?
|
86
|
+
timestamp = DateTime.now.strftime('%Q')
|
87
|
+
puts "timestamp:", timestamp
|
88
|
+
canonicalString = getCanonicalStringForIsv(timestamp, suiteTicket)
|
89
|
+
puts("canonicalString:" + canonicalString)
|
90
|
+
puts("accessSecret:" + accessSecret)
|
91
|
+
signature = computeSignature(accessSecret, canonicalString)
|
92
|
+
puts("signature:" + signature)
|
93
|
+
ps = {}
|
94
|
+
ps["accessKey"] = accessKey
|
95
|
+
ps["signature"] = signature
|
96
|
+
ps["timestamp"] = timestamp
|
97
|
+
ps["suiteTicket"] = suiteTicket if suiteTicket.present?
|
98
|
+
ps["corpId"] = corpId if corpId != ''
|
99
|
+
queryStr = ps.to_query
|
100
|
+
fullPath = @__path.include?("?") ? "#{@__path}&#{queryStr}" : "#{@__path}?#{queryStr}"
|
101
|
+
else
|
102
|
+
fullPath = @__path.include?("?") ? (authrize.present? ? "#{@__path}&access_token=#{authrize}" : @__path) : (authrize.present? ? "#{@__path}?access_token=#{authrize}" : @__path)
|
103
|
+
end
|
104
|
+
|
105
|
+
response = if getHttpMethod == "GET"
|
106
|
+
fullPath = fullPath.include?("?") ? "#{fullPath}&#{body.to_query}" : "#{fullPath}?#{body.to_query}"
|
107
|
+
Faraday.get("https://#{@__domain}#{fullPath}") do |req|
|
108
|
+
req.headers['Content-Type'] = 'application/json'
|
109
|
+
req.headers['Accept'] = 'application/json'
|
110
|
+
end
|
111
|
+
else
|
112
|
+
body = if getMultipartParas.present?
|
113
|
+
body
|
114
|
+
else
|
115
|
+
application_parameter.to_json
|
116
|
+
end
|
117
|
+
Faraday.post("https://#{@__domain}#{fullPath}", body, "Content-Type" => "application/json")
|
118
|
+
end
|
119
|
+
unless response.success?
|
120
|
+
raise RequestException, "invalid http status #{response.status} ,detail body: #{response.body}"
|
121
|
+
end
|
122
|
+
|
123
|
+
result = response.body
|
124
|
+
# puts "result:", result
|
125
|
+
jsonobj = JSON.parse(result)
|
126
|
+
if jsonobj.key?(P_CODE) && (jsonobj[P_CODE] != 0)
|
127
|
+
# error = TopException.new
|
128
|
+
# error.errcode = jsonobj[P_CODE]
|
129
|
+
# error.errmsg = jsonobj[P_MSG]
|
130
|
+
# error.application_host = response.headers.fetch("Application-Host", "")
|
131
|
+
# error.service_host = response.headers.fetch("Location-Host", "")
|
132
|
+
raise Error, "TopException"
|
133
|
+
end
|
134
|
+
|
135
|
+
jsonobj
|
136
|
+
end
|
137
|
+
|
138
|
+
def computeSignature(secret, canonicalString)
|
139
|
+
digest = OpenSSL::HMAC.digest('sha256', secret, canonicalString)
|
140
|
+
signature = Base64.strict_encode64(digest)
|
141
|
+
URI.encode_www_form_component(signature)
|
142
|
+
signature
|
143
|
+
end
|
144
|
+
|
145
|
+
def getApplicationParameters
|
146
|
+
application_parameter = {}
|
147
|
+
translate_parameter = getTranslateParas
|
148
|
+
instance_variable_names.each do |name|
|
149
|
+
next if name.start_with?('@__')
|
150
|
+
|
151
|
+
application_parameter[name[1..-1]] = instance_variable_get(name)
|
152
|
+
end
|
153
|
+
# application_parameter.each_key do |key|
|
154
|
+
# application_parameter[translate_parameter[key]] = application_parameter[key]
|
155
|
+
# application_parameter.delete(key)
|
156
|
+
# end
|
157
|
+
application_parameter
|
158
|
+
end
|
159
|
+
|
160
|
+
def getTranslateParas
|
161
|
+
{}
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Dingtalk
|
2
|
+
module Api
|
3
|
+
# get token
|
4
|
+
class OapiGettokenRequest < Base
|
5
|
+
attr_accessor :appkey, :appsecret
|
6
|
+
|
7
|
+
def getHttpMethod
|
8
|
+
'GET'
|
9
|
+
end
|
10
|
+
|
11
|
+
def getapiname
|
12
|
+
'dingtalk.oapi.gettoken'
|
13
|
+
end
|
14
|
+
|
15
|
+
def getResponse
|
16
|
+
super.fetch('access_token', '')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Dingtalk
|
4
|
+
module Api
|
5
|
+
# get token
|
6
|
+
class OapiSnsGetuserinfoBycodeRequest < Base
|
7
|
+
attr_accessor :tmp_auth_code
|
8
|
+
|
9
|
+
def getHttpMethod
|
10
|
+
'POST'
|
11
|
+
end
|
12
|
+
|
13
|
+
def getapiname
|
14
|
+
'dingtalk.oapi.sns.getuserinfo_bycode'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Dingtalk
|
4
|
+
module Api
|
5
|
+
# get token
|
6
|
+
class OapiUserGetRequest < Base
|
7
|
+
attr_accessor :userid
|
8
|
+
|
9
|
+
def getHttpMethod
|
10
|
+
'GET'
|
11
|
+
end
|
12
|
+
|
13
|
+
def getapiname
|
14
|
+
'dingtalk.oapi.user.get'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Dingtalk
|
4
|
+
module Api
|
5
|
+
# get token
|
6
|
+
class OapiUserGetUseridByUnionidRequest < Base
|
7
|
+
attr_accessor :unionid
|
8
|
+
|
9
|
+
def getHttpMethod
|
10
|
+
'GET'
|
11
|
+
end
|
12
|
+
|
13
|
+
def getapiname
|
14
|
+
'dingtalk.oapi.user.getUseridByUnionid'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/dingtalk.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require "dingtalk/version"
|
2
|
+
require "dingtalk/api/Base"
|
3
|
+
|
4
|
+
# Dingtalk top namespace
|
5
|
+
module Dingtalk
|
6
|
+
class Error < StandardError; end
|
7
|
+
class RequestException < RuntimeError; end
|
8
|
+
|
9
|
+
class << self
|
10
|
+
attr_accessor :configuration
|
11
|
+
|
12
|
+
def configuration
|
13
|
+
@configuration ||= Dingtalk::Configuration.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def configure
|
17
|
+
yield(configuration)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class Configuration
|
22
|
+
attr_accessor :oapi_host, :corpid, :appkey, :appsecret
|
23
|
+
|
24
|
+
def initialize
|
25
|
+
@oapi_host = "https://oapi.dingtalk.com"
|
26
|
+
@corpid = ""
|
27
|
+
@appkey = ""
|
28
|
+
@appsecret = ""
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class Client
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
P_APPKEY = "app_key".freeze
|
37
|
+
P_API = "method".freeze
|
38
|
+
P_ACCESS_TOKEN = "access_token".freeze
|
39
|
+
P_VERSION = "v".freeze
|
40
|
+
P_FORMAT = "format".freeze
|
41
|
+
P_TIMESTAMP = "timestamp".freeze
|
42
|
+
P_SIGN = "sign".freeze
|
43
|
+
P_SIGN_METHOD = "sign_method".freeze
|
44
|
+
P_PARTNER_ID = "partner_id".freeze
|
45
|
+
|
46
|
+
SYSTEM_GENERATE_VERSION = "taobao-sdk-ruby-dynamicVersionNo".freeze
|
47
|
+
|
48
|
+
P_CODE = 'errcode'.freeze
|
49
|
+
P_MSG = 'errmsg'.freeze
|
50
|
+
|
51
|
+
module Api
|
52
|
+
autoload :OapiGettokenRequest, 'dingtalk/api/OapiGettokenRequest'
|
53
|
+
autoload :OapiSnsGetuserinfoBycodeRequest, 'dingtalk/api/OapiSnsGetuserinfoBycodeRequest'
|
54
|
+
autoload :OapiUserGetUseridByUnionidRequest, 'dingtalk/api/OapiUserGetUseridByUnionidRequest'
|
55
|
+
autoload :OapiUserGetRequest, 'dingtalk/api/OapiUserGetRequest'
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dingtalk-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Zhenyuan Lau
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-12-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.10.3
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.10.3
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry-byebug
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: Dingtalk Ruby SDK according official specification.
|
126
|
+
email:
|
127
|
+
- zhenyuanlau@icloud.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rspec"
|
134
|
+
- CODE_OF_CONDUCT.md
|
135
|
+
- Gemfile
|
136
|
+
- Gemfile.lock
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.md
|
139
|
+
- Rakefile
|
140
|
+
- bin/console
|
141
|
+
- bin/setup
|
142
|
+
- dingtalk.gemspec
|
143
|
+
- lib/dingtalk.rb
|
144
|
+
- lib/dingtalk/api/Base.rb
|
145
|
+
- lib/dingtalk/api/OapiGettokenRequest.rb
|
146
|
+
- lib/dingtalk/api/OapiSnsGetuserinfoBycodeRequest.rb
|
147
|
+
- lib/dingtalk/api/OapiUserGetRequest.rb
|
148
|
+
- lib/dingtalk/api/OapiUserGetUseridByUnionidRequest.rb
|
149
|
+
- lib/dingtalk/version.rb
|
150
|
+
homepage: https://github.com/zhenyuanlau/dingtalk-ruby
|
151
|
+
licenses:
|
152
|
+
- MIT
|
153
|
+
metadata:
|
154
|
+
allowed_push_host: https://rubygems.org
|
155
|
+
homepage_uri: https://github.com/zhenyuanlau/dingtalk-ruby
|
156
|
+
source_code_uri: https://github.com/zhenyuanlau/dingtalk-ruby
|
157
|
+
changelog_uri: https://github.com/zhenyuanlau/dingtalk-ruby
|
158
|
+
post_install_message:
|
159
|
+
rdoc_options: []
|
160
|
+
require_paths:
|
161
|
+
- lib
|
162
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
168
|
+
requirements:
|
169
|
+
- - ">="
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
version: '0'
|
172
|
+
requirements: []
|
173
|
+
rubygems_version: 3.0.6
|
174
|
+
signing_key:
|
175
|
+
specification_version: 4
|
176
|
+
summary: Dingtalk Ruby SDK
|
177
|
+
test_files: []
|