docusign_monitor 1.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +7 -0
- data/LICENSE +21 -0
- data/README.md +80 -0
- data/Rakefile +8 -0
- data/docusign_monitor-1.0.0.pre.alpha.gem +0 -0
- data/docusign_monitor-1.0.1.pre.alpha.gem +0 -0
- data/docusign_monitor.gemspec +46 -0
- data/git_push.sh +55 -0
- data/lib/docusign_monitor.rb +43 -0
- data/lib/docusign_monitor/api/data_set_api.rb +95 -0
- data/lib/docusign_monitor/client/api_client.rb +591 -0
- data/lib/docusign_monitor/client/api_error.rb +37 -0
- data/lib/docusign_monitor/client/auth/oauth.rb +1061 -0
- data/lib/docusign_monitor/configuration.rb +203 -0
- data/lib/docusign_monitor/models/aggregation.rb +183 -0
- data/lib/docusign_monitor/models/cursored_result.rb +194 -0
- data/lib/docusign_monitor/models/filter.rb +183 -0
- data/lib/docusign_monitor/models/raw_request.rb +235 -0
- data/lib/docusign_monitor/models/web_query.rb +248 -0
- data/lib/docusign_monitor/version.rb +14 -0
- data/tests/Gemfile +5 -0
- data/tests/Gemfile.lock +46 -0
- data/tests/docs/Test.pdf +0 -0
- data/tests/docs/private.pem +27 -0
- data/tests/spec/unit_tests_using_jwt_spec.rb +125 -0
- metadata +291 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5a706c627c950f185c15a90ff568768725285f785690a9942f0b2831cfc2f9f6
|
4
|
+
data.tar.gz: 7afec697c7cbf634b852ca2613f2d17ccfbac8b30f1814a05df7b8de0e9c35d6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: de4654e3096578aa87ad5a48256f0a26a60b193698a42437e03c5c3437d00e06cf147433db588d8e66a1e63320819df018559de035a2b1890b582ec847827f68
|
7
|
+
data.tar.gz: af19aa01ea42949f7494d2a05d36496037ecd8c2d38374e2b3fe1aff97caf8f1b456d908464dc9fffbaa64c3202c0c977f6e681d0ad1098d7dbfe0670011f3fc
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
# DocuSign Monitor Ruby Client Changelog
|
2
|
+
See [DocuSign Support Center](https://support.docusign.com/en/releasenotes/) for Product Release Notes.
|
3
|
+
|
4
|
+
## [v1.0.0.beta1] - DocuSign Monitor API v1 - 05/14/2021
|
5
|
+
### Changed
|
6
|
+
- First BETA version of Monitor API, supports DocuSign Monitor v2.0
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2022- DocuSign, Inc. (https://www.docusign.com)
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# The Official DocuSign Monitor Client
|
2
|
+
|
3
|
+
[![RubyGems version][rubygems-image]][rubygems-url]
|
4
|
+
[![RubyGems downloads][downloads-image]][downloads-url]
|
5
|
+
[![Build status][travis-image]][travis-url]
|
6
|
+
|
7
|
+
## Requirements
|
8
|
+
|
9
|
+
- Ruby 1.9+
|
10
|
+
- Free [Developer Sandbox](https://go.docusign.com/sandbox/productshot/?elqCampaignId=16531)
|
11
|
+
|
12
|
+
## Compatibility
|
13
|
+
|
14
|
+
- Ruby 1.9+
|
15
|
+
|
16
|
+
## Note
|
17
|
+
|
18
|
+
This open-source SDK is provided for cases where you would like to make additional changes that the SDK does not provide out-of-the-box. If you simply want to use the SDK with any of the examples shown in the [Developer Center](https://developers.docusign.com/esign-rest-api/code-examples), follow the installation instructions below.
|
19
|
+
|
20
|
+
## Installation
|
21
|
+
|
22
|
+
### Install via your application's **Gemfile**:
|
23
|
+
|
24
|
+
1. In your application's **Gemfile**, add:
|
25
|
+
**gem 'docusign_monitor'**
|
26
|
+
2. Open your preferred console.
|
27
|
+
3. In your project directory, execute the installer by typing:
|
28
|
+
**bundle install**
|
29
|
+
|
30
|
+
### Manual install:
|
31
|
+
|
32
|
+
1. Open your preferred console.
|
33
|
+
2. In the console, type:
|
34
|
+
**gem install docusign_monitor**
|
35
|
+
|
36
|
+
### Dependencies
|
37
|
+
|
38
|
+
This client has the following external dependencies:
|
39
|
+
|
40
|
+
- Jwt>=1.5.2
|
41
|
+
- Json>=2.1.0
|
42
|
+
- Typhoeus>=1.0.1
|
43
|
+
|
44
|
+
## Code Examples
|
45
|
+
|
46
|
+
### Launchers
|
47
|
+
|
48
|
+
DocuSign provides a sample application code referred to as a [Launcher](https://github.com/docusign/code-examples-ruby). The Launcher contains a set of 31 common use cases and associated source files. These examples use either DocuSign's [Authorization Code Grant](https://developers.docusign.com/esign-rest-api/guides/authentication/oauth2-code-grant) or [JSON Web Tokens (JWT)](https://developers.docusign.com/esign-rest-api/guides/authentication/oauth2-jsonwebtoken) flows.
|
49
|
+
|
50
|
+
### Proof-of-concept applications
|
51
|
+
|
52
|
+
If your goal is to create a proof-of-concept application, DocuSign provides a set of [Quick Start](https://github.com/docusign/qs-ruby) examples. The Quick Start examples are meant to be used with DocuSign's [OAuth Token Generator](https://developers.docusign.com/oauth-token-generator), which will allow you to generate tokens for the Demo/Sandbox environment only. These tokens last for eight hours and will enable you to build your proof-of-concept application without the need to fully implement an OAuth solution.
|
53
|
+
|
54
|
+
## OAuth Implementations
|
55
|
+
|
56
|
+
For details regarding which type of OAuth grant will work best for your DocuSign integration, see the [REST API Authentication Overview](https://developers.docusign.com/esign-rest-api/guides/authentication) guide located on the [DocuSign Developer Center](https://developers.docusign.com/esign-rest-api/guides/authentication).
|
57
|
+
|
58
|
+
For security purposes, DocuSign recommends using the [Authorization Code Grant](https://developers.docusign.com/esign-rest-api/guides/authentication/oauth2-code-grant) flow.
|
59
|
+
|
60
|
+
|
61
|
+
## Support
|
62
|
+
|
63
|
+
Log issues against this client through GitHub. We also have an [active developer community on Stack Overflow](https://stackoverflow.com/questions/tagged/docusignapi).
|
64
|
+
|
65
|
+
## License
|
66
|
+
|
67
|
+
The DocuSign Ruby Client is licensed under the [MIT License](https://github.com/docusign/docusign-ruby-client/blob/master/LICENSE).
|
68
|
+
|
69
|
+
[rubygems-image]: https://img.shields.io/gem/v/docusign_monitor.svg?style=flat
|
70
|
+
[rubygems-url]: https://rubygems.org/gems/docusign_monitor
|
71
|
+
[downloads-image]: https://img.shields.io/gem/dt/docusign_monitor.svg?style=flat
|
72
|
+
[downloads-url]: https://rubygems.org/gems/docusign_monitor
|
73
|
+
[travis-image]: https://img.shields.io/travis/docusign/docusign-monitor-ruby-client.svg?style=flat
|
74
|
+
[travis-url]: https://travis-ci.org/docusign/docusign-monitor-ruby-client
|
75
|
+
|
76
|
+
### Additional Resources
|
77
|
+
* [DocuSign Developer Center](https://developers.docusign.com)
|
78
|
+
* [DocuSign API on Twitter](https://twitter.com/docusignapi)
|
79
|
+
* [DocuSign For Developers on LinkedIn](https://www.linkedin.com/showcase/docusign-for-developers/)
|
80
|
+
* [DocuSign For Developers on YouTube](https://www.youtube.com/channel/UCJSJ2kMs_qeQotmw4-lX2NQ)
|
data/Rakefile
ADDED
Binary file
|
Binary file
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
=begin
|
4
|
+
#DocuSign Monitor API
|
5
|
+
|
6
|
+
#An API for an integrator to access the features of DocuSign Monitor
|
7
|
+
|
8
|
+
OpenAPI spec version: v2
|
9
|
+
Contact: devcenter@docusign.com
|
10
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
11
|
+
|
12
|
+
=end
|
13
|
+
|
14
|
+
$:.push File.expand_path("../lib", __FILE__)
|
15
|
+
require "docusign_monitor/version"
|
16
|
+
|
17
|
+
Gem::Specification.new do |s|
|
18
|
+
s.name = "docusign_monitor"
|
19
|
+
s.version = DocuSign_Monitor::VERSION
|
20
|
+
s.platform = Gem::Platform::RUBY
|
21
|
+
s.authors = ["DocuSign"]
|
22
|
+
s.email = ["devcenter@docusign.com"]
|
23
|
+
s.homepage = "https://github.com/docusign/docusign-monitor-ruby-client"
|
24
|
+
s.summary = "DocuSign Monitor API Ruby Gem"
|
25
|
+
s.description = "The DocuSign package makes integrating DocuSign into your apps and websites a super fast and painless process. The library is open sourced on GitHub, look for the docusign-monitor-ruby-client repository."
|
26
|
+
s.license = "MIT"
|
27
|
+
s.required_ruby_version = ">= 1.9"
|
28
|
+
|
29
|
+
s.add_runtime_dependency 'jwt', '~> 2.2', '>= 2.2.1'
|
30
|
+
s.add_runtime_dependency 'addressable', '~> 2.7', '>= 2.7.0'
|
31
|
+
s.add_runtime_dependency 'typhoeus', '~> 1.0', '>= 1.0.1'
|
32
|
+
s.add_runtime_dependency 'json', '~> 2.1', '>= 2.1.0'
|
33
|
+
|
34
|
+
s.add_development_dependency 'rspec', '~> 3.6', '>= 3.6.0'
|
35
|
+
s.add_development_dependency 'vcr', '~> 3.0', '>= 3.0.1'
|
36
|
+
s.add_development_dependency 'webmock', '~> 1.24', '>= 1.24.3'
|
37
|
+
s.add_development_dependency 'autotest', '~> 4.4', '>= 4.4.6'
|
38
|
+
s.add_development_dependency 'autotest-rails-pure', '~> 4.1', '>= 4.1.2'
|
39
|
+
s.add_development_dependency 'autotest-growl', '~> 0.2', '>= 0.2.16'
|
40
|
+
s.add_development_dependency 'autotest-fsevent', '~> 0.2', '>= 0.2.12'
|
41
|
+
|
42
|
+
s.files = `find *`.split("\n").uniq.sort.select { |f| !f.empty? }
|
43
|
+
s.test_files = `find spec/*`.split("\n")
|
44
|
+
s.executables = []
|
45
|
+
s.require_paths = ["lib"]
|
46
|
+
end
|
data/git_push.sh
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
#
|
3
|
+
# Generated by: https://github.com/swagger-api/swagger-codegen.git
|
4
|
+
#
|
5
|
+
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
|
6
|
+
#
|
7
|
+
# Usage example: /bin/sh ./git_push.sh wing328 swagger-petstore-perl "minor update"
|
8
|
+
|
9
|
+
git_user_id=$1
|
10
|
+
git_repo_id=$2
|
11
|
+
release_note=$3
|
12
|
+
|
13
|
+
if [ "$git_user_id" = "" ]; then
|
14
|
+
git_user_id="GIT_USER_ID"
|
15
|
+
echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
|
16
|
+
fi
|
17
|
+
|
18
|
+
if [ "$git_repo_id" = "" ]; then
|
19
|
+
git_repo_id="GIT_REPO_ID"
|
20
|
+
echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
|
21
|
+
fi
|
22
|
+
|
23
|
+
if [ "$release_note" = "" ]; then
|
24
|
+
release_note="Minor update"
|
25
|
+
echo "[INFO] No command line input provided. Set \$release_note to $release_note"
|
26
|
+
fi
|
27
|
+
|
28
|
+
# Initialize the local directory as a Git repository
|
29
|
+
git init
|
30
|
+
|
31
|
+
# Adds the files in the local repository and stages them for commit.
|
32
|
+
git add .
|
33
|
+
|
34
|
+
# Commits the tracked changes and prepares them to be pushed to a remote repository.
|
35
|
+
git commit -m "$release_note"
|
36
|
+
|
37
|
+
# Sets the new remote
|
38
|
+
git_remote=`git remote`
|
39
|
+
if [ "$git_remote" = "" ]; then # git remote not defined
|
40
|
+
|
41
|
+
if [ "$GIT_TOKEN" = "" ]; then
|
42
|
+
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git crediential in your environment."
|
43
|
+
git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git
|
44
|
+
else
|
45
|
+
git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git
|
46
|
+
fi
|
47
|
+
|
48
|
+
fi
|
49
|
+
|
50
|
+
git pull origin master
|
51
|
+
|
52
|
+
# Pushes (Forces) the changes in the local repository up to the remote repository
|
53
|
+
echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git"
|
54
|
+
git push origin master 2>&1 | grep -v 'To https'
|
55
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
=begin
|
2
|
+
#DocuSign Monitor API - v2
|
3
|
+
|
4
|
+
#An API for an integrator to access the features of DocuSign Monitor
|
5
|
+
|
6
|
+
OpenAPI spec version: v2.0
|
7
|
+
Contact: devcenter@docusign.com
|
8
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
9
|
+
|
10
|
+
=end
|
11
|
+
|
12
|
+
# Common files
|
13
|
+
require 'docusign_monitor/client/api_client'
|
14
|
+
require 'docusign_monitor/client/api_error'
|
15
|
+
require 'docusign_monitor/version'
|
16
|
+
require 'docusign_monitor/configuration'
|
17
|
+
|
18
|
+
# Client Files
|
19
|
+
require 'docusign_monitor/client/auth/oauth'
|
20
|
+
|
21
|
+
# Models
|
22
|
+
require 'docusign_monitor/models/cursored_result'
|
23
|
+
|
24
|
+
# APIs
|
25
|
+
require 'docusign_monitor/api/data_set_api'
|
26
|
+
|
27
|
+
module DocuSign_Monitor
|
28
|
+
class << self
|
29
|
+
# Customize default settings for the SDK using block.
|
30
|
+
# DocuSign_Monitor.configure do |config|
|
31
|
+
# config.username = "xxx"
|
32
|
+
# config.password = "xxx"
|
33
|
+
# end
|
34
|
+
# If no block given, return the default Configuration object.
|
35
|
+
def configure
|
36
|
+
if block_given?
|
37
|
+
yield(Configuration.default)
|
38
|
+
else
|
39
|
+
Configuration.default
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
=begin
|
2
|
+
#DocuSign Monitor API - v2
|
3
|
+
|
4
|
+
#An API for an integrator to access the features of DocuSign Monitor
|
5
|
+
|
6
|
+
OpenAPI spec version: v2.0
|
7
|
+
Contact: devcenter@docusign.com
|
8
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
9
|
+
|
10
|
+
=end
|
11
|
+
|
12
|
+
require "uri"
|
13
|
+
|
14
|
+
module DocuSign_Monitor
|
15
|
+
|
16
|
+
class GetStreamOptions
|
17
|
+
# The cursor value to continue querying the data with. For an intial call, use empty string
|
18
|
+
attr_accessor :cursor
|
19
|
+
|
20
|
+
# The maximum number of records to return, minimum of 1, maximum of 2000. Defaults to 1000 if no value is provided
|
21
|
+
attr_accessor :limit
|
22
|
+
|
23
|
+
def self.default
|
24
|
+
@@default ||= GetStreamOptions.new
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
class DataSetApi
|
30
|
+
attr_accessor :api_client
|
31
|
+
|
32
|
+
def initialize(api_client = DataSetApi.default)
|
33
|
+
@api_client = api_client
|
34
|
+
end
|
35
|
+
|
36
|
+
#
|
37
|
+
# Allows for the streaming of data as it becomes available Required scopes: impersonation
|
38
|
+
# @param data_set_name The name of the dataset to stream
|
39
|
+
# @param version The requested API version
|
40
|
+
# @param DocuSign_Monitor::GetStreamOptions Options for modifying the behavior of the function.
|
41
|
+
# @return [CursoredResult]
|
42
|
+
def get_stream(data_set_name, version, options = DocuSign_Monitor::GetStreamOptions.default)
|
43
|
+
data, _status_code, _headers = get_stream_with_http_info(data_set_name, version, options)
|
44
|
+
return data
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# Allows for the streaming of data as it becomes available Required scopes: impersonation
|
49
|
+
# @param data_set_name The name of the dataset to stream
|
50
|
+
# @param version The requested API version
|
51
|
+
# @param DocuSign_Monitor::GetStreamOptions Options for modifying the behavior of the function.
|
52
|
+
# @return [Array<(CursoredResult, Fixnum, Hash)>] CursoredResult data, response status code and response headers
|
53
|
+
def get_stream_with_http_info(data_set_name, version, options = DocuSign_Monitor::GetStreamOptions.default)
|
54
|
+
if @api_client.config.debugging
|
55
|
+
@api_client.config.logger.debug "Calling API: DataSetApi.get_stream ..."
|
56
|
+
end
|
57
|
+
# verify the required parameter 'data_set_name' is set
|
58
|
+
fail ArgumentError, "Missing the required parameter 'data_set_name' when calling DataSetApi.get_stream" if data_set_name.nil?
|
59
|
+
# verify the required parameter 'version' is set
|
60
|
+
fail ArgumentError, "Missing the required parameter 'version' when calling DataSetApi.get_stream" if version.nil?
|
61
|
+
# resource path
|
62
|
+
local_var_path = "/api/v{version}/datasets/{dataSetName}/stream".sub('{format}','json').sub('{' + 'dataSetName' + '}', data_set_name.to_s).sub('{' + 'version' + '}', version.to_s)
|
63
|
+
|
64
|
+
# query parameters
|
65
|
+
query_params = {}
|
66
|
+
query_params[:'cursor'] = options.cursor if !options.cursor.nil?
|
67
|
+
query_params[:'limit'] = options.limit if !options.limit.nil?
|
68
|
+
|
69
|
+
# header parameters
|
70
|
+
header_params = {}
|
71
|
+
# HTTP header 'Accept' (if needed)
|
72
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
73
|
+
# HTTP header 'Content-Type'
|
74
|
+
header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
|
75
|
+
|
76
|
+
# form parameters
|
77
|
+
form_params = {}
|
78
|
+
|
79
|
+
# http body (model)
|
80
|
+
post_body = nil
|
81
|
+
auth_names = []
|
82
|
+
data, status_code, headers = @api_client.call_api(:GET, local_var_path,
|
83
|
+
:header_params => header_params,
|
84
|
+
:query_params => query_params,
|
85
|
+
:form_params => form_params,
|
86
|
+
:body => post_body,
|
87
|
+
:auth_names => auth_names,
|
88
|
+
:return_type => 'CursoredResult')
|
89
|
+
if @api_client.config.debugging
|
90
|
+
@api_client.config.logger.debug "API called: DataSetApi#get_stream\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
91
|
+
end
|
92
|
+
return data, status_code, headers
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,591 @@
|
|
1
|
+
=begin
|
2
|
+
#DocuSign Monitor API
|
3
|
+
|
4
|
+
#An API for an integrator to access the features of DocuSign Monitor
|
5
|
+
|
6
|
+
OpenAPI spec version: v2
|
7
|
+
Contact: devcenter@docusign.com
|
8
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
9
|
+
|
10
|
+
=end
|
11
|
+
|
12
|
+
require 'date'
|
13
|
+
require 'json'
|
14
|
+
require 'logger'
|
15
|
+
require 'tempfile'
|
16
|
+
require 'typhoeus'
|
17
|
+
require 'uri'
|
18
|
+
require 'jwt'
|
19
|
+
require 'addressable/uri'
|
20
|
+
|
21
|
+
module DocuSign_Monitor
|
22
|
+
class ApiClient
|
23
|
+
# The Configuration object holding settings to be used in the API client.
|
24
|
+
attr_accessor :config
|
25
|
+
|
26
|
+
# Defines the headers to be used in HTTP requests of all API calls by default.
|
27
|
+
#
|
28
|
+
# @return [Hash]
|
29
|
+
attr_accessor :default_headers
|
30
|
+
|
31
|
+
attr_accessor :base_path
|
32
|
+
attr_accessor :oauth_base_path
|
33
|
+
|
34
|
+
# Initializes the ApiClient
|
35
|
+
# @option config [Configuration] Configuration for initializing the object, default to Configuration.default
|
36
|
+
def initialize(config = Configuration.default)
|
37
|
+
@config = config
|
38
|
+
@user_agent = "Swagger-Codegen/#{VERSION}/ruby"
|
39
|
+
@default_headers = {
|
40
|
+
'Content-Type' => "application/json",
|
41
|
+
'User-Agent' => @user_agent
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.default
|
46
|
+
@@default ||= ApiClient.new
|
47
|
+
end
|
48
|
+
|
49
|
+
# Call an API with given options.
|
50
|
+
#
|
51
|
+
# @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
|
52
|
+
# the data deserialized from response body (could be nil), response status code and response headers.
|
53
|
+
def call_api(http_method, path, opts = {})
|
54
|
+
request = build_request(http_method, path, opts)
|
55
|
+
response = request.run
|
56
|
+
|
57
|
+
if @config.debugging
|
58
|
+
@config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
|
59
|
+
end
|
60
|
+
|
61
|
+
unless response.success?
|
62
|
+
if response.timed_out?
|
63
|
+
fail ApiError.new('Connection timed out')
|
64
|
+
elsif response.code == 0
|
65
|
+
# Errors from libcurl will be made visible here
|
66
|
+
fail ApiError.new(:code => 0,
|
67
|
+
:message => response.return_message)
|
68
|
+
else
|
69
|
+
fail ApiError.new(:code => response.code,
|
70
|
+
:response_headers => response.headers,
|
71
|
+
:response_body => response.body),
|
72
|
+
response.status_message
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
if opts[:return_type]
|
77
|
+
data = deserialize(response, opts[:return_type])
|
78
|
+
else
|
79
|
+
data = nil
|
80
|
+
end
|
81
|
+
return data, response.code, response.headers
|
82
|
+
end
|
83
|
+
|
84
|
+
# Builds the HTTP request
|
85
|
+
#
|
86
|
+
# @param [String] http_method HTTP method/verb (e.g. POST)
|
87
|
+
# @param [String] path URL path (e.g. /account/new)
|
88
|
+
# @option opts [Hash] :header_params Header parameters
|
89
|
+
# @option opts [Hash] :query_params Query parameters
|
90
|
+
# @option opts [Hash] :form_params Query parameters
|
91
|
+
# @option opts [Object] :body HTTP body (JSON/XML)
|
92
|
+
# @return [Typhoeus::Request] A Typhoeus Request
|
93
|
+
def build_request(http_method, path, opts = {})
|
94
|
+
url = build_request_url(path, opts)
|
95
|
+
http_method = http_method.to_sym.downcase
|
96
|
+
|
97
|
+
header_params = @default_headers.merge(opts[:header_params] || {})
|
98
|
+
|
99
|
+
# Add SDK default header
|
100
|
+
header_params.store("X-DocuSign-SDK", "Ruby")
|
101
|
+
|
102
|
+
query_params = opts[:query_params] || {}
|
103
|
+
form_params = opts[:form_params] || {}
|
104
|
+
|
105
|
+
update_params_for_auth! header_params, query_params, opts[:auth_names]
|
106
|
+
|
107
|
+
# set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
|
108
|
+
_verify_ssl_host = @config.verify_ssl_host ? 2 : 0
|
109
|
+
|
110
|
+
req_opts = {
|
111
|
+
:method => http_method,
|
112
|
+
:headers => header_params,
|
113
|
+
:params => query_params,
|
114
|
+
:params_encoding => @config.params_encoding,
|
115
|
+
:timeout => @config.timeout,
|
116
|
+
:ssl_verifypeer => @config.verify_ssl,
|
117
|
+
:ssl_verifyhost => _verify_ssl_host,
|
118
|
+
:sslcert => @config.cert_file,
|
119
|
+
:sslkey => @config.key_file,
|
120
|
+
:verbose => @config.debugging
|
121
|
+
}
|
122
|
+
|
123
|
+
# set custom cert, if provided
|
124
|
+
req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
|
125
|
+
|
126
|
+
if [:post, :patch, :put, :delete].include?(http_method)
|
127
|
+
req_body = build_request_body(header_params, form_params, opts[:body])
|
128
|
+
req_opts.update :body => req_body
|
129
|
+
if @config.debugging
|
130
|
+
@config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
Typhoeus::Request.new(url, req_opts)
|
135
|
+
end
|
136
|
+
|
137
|
+
# Check if the given MIME is a JSON MIME.
|
138
|
+
# JSON MIME examples:
|
139
|
+
# application/json
|
140
|
+
# application/json; charset=UTF8
|
141
|
+
# APPLICATION/JSON
|
142
|
+
# */*
|
143
|
+
# @param [String] mime MIME
|
144
|
+
# @return [Boolean] True if the MIME is application/json
|
145
|
+
def json_mime?(mime)
|
146
|
+
(mime == "*/*") || !(mime =~ /\Aapplication\/json(;.*)?\z/i).nil?
|
147
|
+
end
|
148
|
+
|
149
|
+
# Deserialize the response to the given return type.
|
150
|
+
#
|
151
|
+
# @param [Response] response HTTP response
|
152
|
+
# @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
|
153
|
+
def deserialize(response, return_type)
|
154
|
+
body = response.body
|
155
|
+
return nil if body.nil? || body.empty?
|
156
|
+
|
157
|
+
# return response body directly for String return type
|
158
|
+
return body if return_type == 'String'
|
159
|
+
|
160
|
+
# handle file downloading - save response body into a tmp file and return the File instance
|
161
|
+
return download_file(response) if return_type == 'File'
|
162
|
+
|
163
|
+
# ensuring a default content type
|
164
|
+
content_type = response.headers['Content-Type'] || 'application/json'
|
165
|
+
|
166
|
+
fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
|
167
|
+
|
168
|
+
begin
|
169
|
+
data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
|
170
|
+
rescue JSON::ParserError => e
|
171
|
+
if %w(String Date DateTime).include?(return_type)
|
172
|
+
data = body
|
173
|
+
else
|
174
|
+
raise e
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
convert_to_type data, return_type
|
179
|
+
end
|
180
|
+
|
181
|
+
# Convert data to the given return type.
|
182
|
+
# @param [Object] data Data to be converted
|
183
|
+
# @param [String] return_type Return type
|
184
|
+
# @return [Mixed] Data in a particular type
|
185
|
+
def convert_to_type(data, return_type)
|
186
|
+
return nil if data.nil?
|
187
|
+
case return_type
|
188
|
+
when 'String'
|
189
|
+
data.to_s
|
190
|
+
when 'Integer'
|
191
|
+
data.to_i
|
192
|
+
when 'Float'
|
193
|
+
data.to_f
|
194
|
+
when 'BOOLEAN'
|
195
|
+
data == true
|
196
|
+
when 'DateTime'
|
197
|
+
# parse date time (expecting ISO 8601 format)
|
198
|
+
DateTime.parse data
|
199
|
+
when 'Date'
|
200
|
+
# parse date time (expecting ISO 8601 format)
|
201
|
+
Date.parse data
|
202
|
+
when 'Object'
|
203
|
+
# generic object (usually a Hash), return directly
|
204
|
+
data
|
205
|
+
when /\AArray<(.+)>\z/
|
206
|
+
# e.g. Array<Pet>
|
207
|
+
sub_type = $1
|
208
|
+
data.map {|item| convert_to_type(item, sub_type) }
|
209
|
+
when /\AHash\<String, (.+)\>\z/
|
210
|
+
# e.g. Hash<String, Integer>
|
211
|
+
sub_type = $1
|
212
|
+
{}.tap do |hash|
|
213
|
+
data.each {|k, v| hash[k] = convert_to_type(v, sub_type) }
|
214
|
+
end
|
215
|
+
else
|
216
|
+
# models, e.g. Pet
|
217
|
+
DocuSign_Monitor.const_get(return_type).new.tap do |model|
|
218
|
+
model.build_from_hash data
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
# Save response body into a file in (the defined) temporary folder, using the filename
|
224
|
+
# from the "Content-Disposition" header if provided, otherwise a random filename.
|
225
|
+
#
|
226
|
+
# @see Configuration#temp_folder_path
|
227
|
+
# @return [Tempfile] the file downloaded
|
228
|
+
def download_file(response)
|
229
|
+
content_disposition = response.headers['Content-Disposition']
|
230
|
+
if content_disposition and content_disposition =~ /filename=/i
|
231
|
+
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
232
|
+
prefix = sanitize_filename(filename)
|
233
|
+
else
|
234
|
+
prefix = 'download-'
|
235
|
+
end
|
236
|
+
prefix = prefix + '-' unless prefix.end_with?('-')
|
237
|
+
|
238
|
+
tempfile = nil
|
239
|
+
encoding = response.body.encoding
|
240
|
+
Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding) do |file|
|
241
|
+
file.write(response.body)
|
242
|
+
tempfile = file
|
243
|
+
end
|
244
|
+
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
245
|
+
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
246
|
+
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
247
|
+
"explicitly with `tempfile.delete`"
|
248
|
+
tempfile
|
249
|
+
end
|
250
|
+
|
251
|
+
# Sanitize filename by removing path.
|
252
|
+
# e.g. ../../sun.gif becomes sun.gif
|
253
|
+
#
|
254
|
+
# @param [String] filename the filename to be sanitized
|
255
|
+
# @return [String] the sanitized filename
|
256
|
+
def sanitize_filename(filename)
|
257
|
+
filename.gsub(/.*[\/\\]/, '')
|
258
|
+
end
|
259
|
+
|
260
|
+
def build_request_url(path, opts)
|
261
|
+
# Add leading and trailing slashes to path
|
262
|
+
path = "/#{path}".gsub(/\/+/, '/')
|
263
|
+
return Addressable::URI.encode("https://" + self.get_oauth_base_path + path) if opts[:oauth]
|
264
|
+
Addressable::URI.encode(@config.base_url + path)
|
265
|
+
end
|
266
|
+
|
267
|
+
# Builds the HTTP request body
|
268
|
+
#
|
269
|
+
# @param [Hash] header_params Header parameters
|
270
|
+
# @param [Hash] form_params Query parameters
|
271
|
+
# @param [Object] body HTTP body (JSON/XML)
|
272
|
+
# @return [String] HTTP body data in the form of string
|
273
|
+
def build_request_body(header_params, form_params, body)
|
274
|
+
# http form
|
275
|
+
if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
|
276
|
+
header_params['Content-Type'] == 'multipart/form-data'
|
277
|
+
data = {}
|
278
|
+
form_params.each do |key, value|
|
279
|
+
case value
|
280
|
+
when File, Array, nil
|
281
|
+
# let typhoeus handle File, Array and nil parameters
|
282
|
+
data[key] = value
|
283
|
+
else
|
284
|
+
data[key] = value.to_s
|
285
|
+
end
|
286
|
+
end
|
287
|
+
elsif body
|
288
|
+
data = body.is_a?(String) ? body : body.to_json
|
289
|
+
else
|
290
|
+
data = nil
|
291
|
+
end
|
292
|
+
data
|
293
|
+
end
|
294
|
+
|
295
|
+
# Update hearder and query params based on authentication settings.
|
296
|
+
#
|
297
|
+
# @param [Hash] header_params Header parameters
|
298
|
+
# @param [Hash] query_params Query parameters
|
299
|
+
# @param [String] auth_names Authentication scheme name
|
300
|
+
def update_params_for_auth!(header_params, query_params, auth_names)
|
301
|
+
Array(auth_names).each do |auth_name|
|
302
|
+
auth_setting = @config.auth_settings[auth_name]
|
303
|
+
next unless auth_setting
|
304
|
+
case auth_setting[:in]
|
305
|
+
when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
|
306
|
+
when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
|
307
|
+
else fail ArgumentError, 'Authentication token must be in `query` of `header`'
|
308
|
+
end
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
# Sets user agent in HTTP header
|
313
|
+
#
|
314
|
+
# @param [String] user_agent User agent (e.g. swagger-codegen/ruby/1.0.0)
|
315
|
+
def user_agent=(user_agent)
|
316
|
+
@user_agent = user_agent
|
317
|
+
@default_headers['User-Agent'] = @user_agent
|
318
|
+
end
|
319
|
+
|
320
|
+
# Return Accept header based on an array of accepts provided.
|
321
|
+
# @param [Array] accepts array for Accept
|
322
|
+
# @return [String] the Accept header (e.g. application/json)
|
323
|
+
def select_header_accept(accepts)
|
324
|
+
return nil if accepts.nil? || accepts.empty?
|
325
|
+
# use JSON when present, otherwise use all of the provided
|
326
|
+
json_accept = accepts.find { |s| json_mime?(s) }
|
327
|
+
return json_accept || accepts.join(',')
|
328
|
+
end
|
329
|
+
|
330
|
+
# Return Content-Type header based on an array of content types provided.
|
331
|
+
# @param [Array] content_types array for Content-Type
|
332
|
+
# @return [String] the Content-Type header (e.g. application/json)
|
333
|
+
def select_header_content_type(content_types)
|
334
|
+
# use application/json by default
|
335
|
+
return 'application/json' if content_types.nil? || content_types.empty?
|
336
|
+
# use JSON when present, otherwise use the first one
|
337
|
+
json_content_type = content_types.find { |s| json_mime?(s) }
|
338
|
+
return json_content_type || content_types.first
|
339
|
+
end
|
340
|
+
|
341
|
+
# Convert object (array, hash, object, etc) to JSON string.
|
342
|
+
# @param [Object] model object to be converted into JSON string
|
343
|
+
# @return [String] JSON string representation of the object
|
344
|
+
def object_to_http_body(model)
|
345
|
+
return model if model.nil? || model.is_a?(String)
|
346
|
+
local_body = nil
|
347
|
+
if model.is_a?(Array)
|
348
|
+
local_body = model.map{|m| object_to_hash(m) }
|
349
|
+
else
|
350
|
+
local_body = object_to_hash(model)
|
351
|
+
end
|
352
|
+
local_body.to_json
|
353
|
+
end
|
354
|
+
|
355
|
+
# Convert object(non-array) to hash.
|
356
|
+
# @param [Object] obj object to be converted into JSON string
|
357
|
+
# @return [String] JSON string representation of the object
|
358
|
+
def object_to_hash(obj)
|
359
|
+
if obj.respond_to?(:to_hash)
|
360
|
+
obj.to_hash
|
361
|
+
else
|
362
|
+
obj
|
363
|
+
end
|
364
|
+
end
|
365
|
+
|
366
|
+
# Build parameter value according to the given collection format.
|
367
|
+
# @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
|
368
|
+
def build_collection_param(param, collection_format)
|
369
|
+
case collection_format
|
370
|
+
when :csv
|
371
|
+
param.join(',')
|
372
|
+
when :ssv
|
373
|
+
param.join(' ')
|
374
|
+
when :tsv
|
375
|
+
param.join("\t")
|
376
|
+
when :pipes
|
377
|
+
param.join('|')
|
378
|
+
when :multi
|
379
|
+
# return the array directly as typhoeus will handle it as expected
|
380
|
+
param
|
381
|
+
else
|
382
|
+
fail "unknown collection format: #{collection_format.inspect}"
|
383
|
+
end
|
384
|
+
end
|
385
|
+
|
386
|
+
# Helper method to set base_path
|
387
|
+
# @param [String] base_path
|
388
|
+
def set_base_path(base_path)
|
389
|
+
self.base_path = base_path
|
390
|
+
end
|
391
|
+
|
392
|
+
# Helper method to set oauth base path
|
393
|
+
# @param [String] oauth_base_path if passed nil it will determined from base_path
|
394
|
+
def set_oauth_base_path(oauth_base_path=nil)
|
395
|
+
self.oauth_base_path = oauth_base_path if oauth_base_path
|
396
|
+
return if self.oauth_base_path
|
397
|
+
|
398
|
+
# did we need this check as we can determine it from base path
|
399
|
+
#raise ArgumentError.new('oAuthBasePath cannot be empty') unless oauth_base_path
|
400
|
+
|
401
|
+
# Derive OAuth Base Path if not given
|
402
|
+
if self.base_path.start_with?("https://demo") or self.base_path.start_with?("http://demo")
|
403
|
+
self.oauth_base_path = OAuth::DEMO_OAUTH_BASE_PATH
|
404
|
+
elsif self.base_path.start_with?("https://stage") or self.base_path.start_with?("http://stage")
|
405
|
+
self.oauth_base_path = OAuth::STAGE_OAUTH_BASE_PATH
|
406
|
+
else
|
407
|
+
self.oauth_base_path = OAuth::PRODUCTION_OAUTH_BASE_PATH
|
408
|
+
end
|
409
|
+
end
|
410
|
+
|
411
|
+
# Helper method to get oauth base path
|
412
|
+
def get_oauth_base_path
|
413
|
+
if !self.oauth_base_path
|
414
|
+
self.set_oauth_base_path()
|
415
|
+
end
|
416
|
+
|
417
|
+
self.oauth_base_path
|
418
|
+
end
|
419
|
+
|
420
|
+
# Helper method to configure the OAuth accessCode/implicit flow parameters
|
421
|
+
# @param [String] client_id DocuSign OAuth Client Id(AKA Integrator Key)
|
422
|
+
# @param scopes The list of requested scopes. Client applications may be scoped to a limited set of system access.
|
423
|
+
# @param [String] redirect_uri This determines where to deliver the response containing the authorization code
|
424
|
+
# @param [String] response_type Determines the response type of the authorization request, NOTE: these response types are mutually exclusive for a client application. A public/native client application may only request a response type
|
425
|
+
# of "token". A private/trusted client application may only request a response type of "code".
|
426
|
+
# @param [String] state Allows for arbitrary state that may be useful to your application. The value in this parameter
|
427
|
+
# will be round-tripped along with the response so you can make sure it didn't change.
|
428
|
+
# @return [String]
|
429
|
+
def get_authorization_uri(client_id, scopes, redirect_uri, response_type, state=nil)
|
430
|
+
self.oauth_base_path ||= self.get_oauth_base_path
|
431
|
+
|
432
|
+
scopes = scopes.join(' ') if scopes.kind_of?(Array)
|
433
|
+
scopes = OAuth::SCOPE_SIGNATURE if scopes.empty?
|
434
|
+
|
435
|
+
uri = "https://%{base_path}/oauth/auth?response_type=%{response_type}&scope=%{scopes}&client_id=%{client_id}&redirect_uri=%{redirect_uri}"
|
436
|
+
uri += "&state=%{state}" if state
|
437
|
+
uri % {base_path: self.oauth_base_path, response_type:response_type, scopes: scopes, client_id: client_id, redirect_uri: redirect_uri, state: state}
|
438
|
+
end
|
439
|
+
|
440
|
+
# Request JWT User Token
|
441
|
+
# @param [String] client_id DocuSign OAuth Client Id(AKA Integrator Key)
|
442
|
+
# @param [String] user_id DocuSign user Id to be impersonated
|
443
|
+
# @param [String] private_key_or_filename the RSA private key
|
444
|
+
# @param [Number] expires_in number of seconds remaining before the JWT assertion is considered as invalid
|
445
|
+
# @param scopes The list of requested scopes. Client applications may be scoped to a limited set of system access.
|
446
|
+
# @return [OAuth::OAuthToken]
|
447
|
+
def request_jwt_user_token(client_id, user_id, private_key_or_filename, expires_in = 3600,scopes=OAuth::SCOPE_SIGNATURE)
|
448
|
+
raise ArgumentError.new('client_id cannot be empty') if client_id.empty?
|
449
|
+
raise ArgumentError.new('user_id cannot be empty') if user_id.empty?
|
450
|
+
raise ArgumentError.new('private_key_or_filename cannot be empty') if private_key_or_filename.empty?
|
451
|
+
|
452
|
+
scopes = scopes.join(' ') if scopes.kind_of?(Array)
|
453
|
+
scopes = OAuth::SCOPE_SIGNATURE if scopes.empty?
|
454
|
+
expires_in = 3600 if expires_in > 3600
|
455
|
+
now = Time.now.to_i
|
456
|
+
claim = {
|
457
|
+
"iss" => client_id,
|
458
|
+
"sub" => user_id,
|
459
|
+
"aud" => self.get_oauth_base_path,
|
460
|
+
"iat" => now,
|
461
|
+
"exp" => now + expires_in,
|
462
|
+
"scope"=> scopes
|
463
|
+
}
|
464
|
+
|
465
|
+
private_key = if private_key_or_filename.include?("-----BEGIN RSA PRIVATE KEY-----")
|
466
|
+
private_key_or_filename
|
467
|
+
else
|
468
|
+
File.read(private_key_or_filename)
|
469
|
+
end
|
470
|
+
|
471
|
+
private_key_bytes = OpenSSL::PKey::RSA.new private_key
|
472
|
+
token = JWT.encode claim, private_key_bytes, 'RS256'
|
473
|
+
params = {
|
474
|
+
:header_params => {"Content-Type" => "application/x-www-form-urlencoded"},
|
475
|
+
:form_params => {
|
476
|
+
"assertion" => token,
|
477
|
+
"grant_type" => OAuth::GRANT_TYPE_JWT
|
478
|
+
},
|
479
|
+
:return_type => 'OAuth::OAuthToken',
|
480
|
+
:oauth => true
|
481
|
+
}
|
482
|
+
data, status_code, headers = self.call_api("POST", "/oauth/token", params)
|
483
|
+
|
484
|
+
|
485
|
+
raise ApiError.new('Some error accrued during process') if data.nil?
|
486
|
+
|
487
|
+
self.set_default_header('Authorization', data.token_type + ' ' + data.access_token)
|
488
|
+
data
|
489
|
+
end
|
490
|
+
|
491
|
+
# Request JWT User Token
|
492
|
+
# @param [String] client_id DocuSign OAuth Client Id(AKA Integrator Key)
|
493
|
+
# @param [String] private_key_or_filename the RSA private key
|
494
|
+
# @param [Number] expires_in number of seconds remaining before the JWT assertion is considered as invalid
|
495
|
+
# @param scopes The list of requested scopes. Client applications may be scoped to a limited set of system access.
|
496
|
+
# @return [OAuth::OAuthToken]
|
497
|
+
def request_jwt_application_token(client_id, private_key_or_filename, expires_in = 3600,scopes=OAuth::SCOPE_SIGNATURE)
|
498
|
+
raise ArgumentError.new('client_id cannot be empty') if client_id.empty?
|
499
|
+
raise ArgumentError.new('private_key_or_filename cannot be empty') if private_key_or_filename.empty?
|
500
|
+
|
501
|
+
scopes = scopes.join(' ') if scopes.kind_of?(Array)
|
502
|
+
scopes = OAuth::SCOPE_SIGNATURE if scopes.empty?
|
503
|
+
expires_in = 3600 if expires_in > 3600
|
504
|
+
now = Time.now.to_i
|
505
|
+
claim = {
|
506
|
+
"iss" => client_id,
|
507
|
+
"aud" => self.get_oauth_base_path,
|
508
|
+
"iat" => now,
|
509
|
+
"exp" => now + expires_in,
|
510
|
+
"scope"=> scopes
|
511
|
+
}
|
512
|
+
|
513
|
+
private_key = if private_key_or_filename.include?("-----BEGIN RSA PRIVATE KEY-----")
|
514
|
+
private_key_or_filename
|
515
|
+
else
|
516
|
+
File.read(private_key_or_filename)
|
517
|
+
end
|
518
|
+
|
519
|
+
private_key_bytes = OpenSSL::PKey::RSA.new private_key
|
520
|
+
token = JWT.encode claim, private_key_bytes, 'RS256'
|
521
|
+
params = {
|
522
|
+
:header_params => {"Content-Type" => "application/x-www-form-urlencoded"},
|
523
|
+
:form_params => {
|
524
|
+
"assertion" => token,
|
525
|
+
"grant_type" => OAuth::GRANT_TYPE_JWT
|
526
|
+
},
|
527
|
+
:return_type => 'OAuth::OAuthToken',
|
528
|
+
:oauth => true
|
529
|
+
}
|
530
|
+
data, status_code, headers = self.call_api("POST", "/oauth/token", params)
|
531
|
+
|
532
|
+
raise ApiError.new('Some error accrued during process') if data.nil?
|
533
|
+
|
534
|
+
self.set_default_header('Authorization', data.token_type + ' ' + data.access_token)
|
535
|
+
data
|
536
|
+
end
|
537
|
+
|
538
|
+
# Get User Info method takes the accessToken to retrieve User Account Data.
|
539
|
+
# @param [String] access_token
|
540
|
+
# @return [OAuth::UserInfo]
|
541
|
+
def get_user_info(access_token)
|
542
|
+
raise ArgumentError.new('Cannot find a valid access token. Cannot find a valid access token.') if access_token.empty?
|
543
|
+
|
544
|
+
params = {
|
545
|
+
:header_params => {"Authorization" => 'Bearer ' + access_token},
|
546
|
+
:return_type => 'OAuth::UserInfo',
|
547
|
+
:oauth => true
|
548
|
+
}
|
549
|
+
data, status_code, headers = self.call_api("GET", '/oauth/userinfo', params)
|
550
|
+
data
|
551
|
+
end
|
552
|
+
|
553
|
+
# GenerateAccessToken will exchange the authorization code for an access token and refresh tokens.
|
554
|
+
# @param [String] client_id DocuSign OAuth Client Id(AKA Integrator Key)
|
555
|
+
# @param [String] client_secret The secret key you generated when you set up the integration in DocuSign Admin console.
|
556
|
+
# @param [String] code The authorization code
|
557
|
+
def generate_access_token(client_id, client_secret, code)
|
558
|
+
raise ArgumentError.new('client_id cannot be empty') if client_id.empty?
|
559
|
+
raise ArgumentError.new('client_secret cannot be empty') if client_secret.empty?
|
560
|
+
raise ArgumentError.new('code cannot be empty') if code.empty?
|
561
|
+
|
562
|
+
authcode = "Basic " + Base64.strict_encode64("#{client_id}:#{client_secret}")
|
563
|
+
params = {
|
564
|
+
:header_params => {
|
565
|
+
"Authorization" => authcode,
|
566
|
+
"Content-Type" => "application/x-www-form-urlencoded"
|
567
|
+
},
|
568
|
+
:form_params => {
|
569
|
+
"grant_type" => 'authorization_code',
|
570
|
+
"code" => code,
|
571
|
+
},
|
572
|
+
:return_type => 'OAuth::OAuthToken',
|
573
|
+
:oauth => true
|
574
|
+
}
|
575
|
+
data, status_code, headers = self.call_api("POST", '/oauth/token', params)
|
576
|
+
abort(data.inspect)
|
577
|
+
|
578
|
+
end
|
579
|
+
|
580
|
+
def set_access_token(token_obj)
|
581
|
+
self.default_headers['Authorization'] = token_obj.access_token
|
582
|
+
end
|
583
|
+
|
584
|
+
# Helper method to add default header params
|
585
|
+
# @param [String] header_name
|
586
|
+
# @param [String] header_value
|
587
|
+
def set_default_header(header_name, header_value)
|
588
|
+
@default_headers[header_name] = header_value
|
589
|
+
end
|
590
|
+
end
|
591
|
+
end
|