docusign_api 0.1.1

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
+ SHA1:
3
+ metadata.gz: 4df1bf27cc287812b975f9a49d270e6b5eef34b7
4
+ data.tar.gz: 51c7aa4d33323198f5a395f7bc931a67e35471af
5
+ SHA512:
6
+ metadata.gz: e9ff45481e64f365778e5122037b31da24ef48de241b16ec90a2b94cba3908cb9b42a4e646a19af8987507ab24e57ac073a0193ed5963cb791a171bf63e7ca30
7
+ data.tar.gz: dd70488419a4ddec308ff6af4563867d347a7ed16bf1293e306e086227dc51b06bd85552b8b9f2bd4580888c98b43464adb79c4565c75634a522e19dc48a0b66
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in docusign_api.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,54 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ docusign_api (0.1.0)
5
+ capistrano (~> 3.1)
6
+ curb (< 0.9)
7
+ sshkit (~> 1.2)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ addressable (2.4.0)
13
+ airbrussh (1.0.1)
14
+ sshkit (>= 1.6.1, != 1.7.0)
15
+ capistrano (3.5.0)
16
+ airbrussh (>= 1.0.0)
17
+ capistrano-harrow
18
+ i18n
19
+ rake (>= 10.0.0)
20
+ sshkit (>= 1.9.0)
21
+ capistrano-harrow (0.3.2)
22
+ crack (0.4.3)
23
+ safe_yaml (~> 1.0.0)
24
+ curb (0.8.8)
25
+ hashdiff (0.3.0)
26
+ i18n (0.7.0)
27
+ metaclass (0.0.4)
28
+ minitest (5.8.4)
29
+ mocha (1.1.0)
30
+ metaclass (~> 0.0.1)
31
+ net-scp (1.2.1)
32
+ net-ssh (>= 2.6.5)
33
+ net-ssh (3.1.1)
34
+ rake (11.1.2)
35
+ safe_yaml (1.0.4)
36
+ sshkit (1.10.0)
37
+ net-scp (>= 1.1.2)
38
+ net-ssh (>= 2.8.0)
39
+ webmock (1.22.3)
40
+ addressable (>= 2.3.6)
41
+ crack (>= 0.3.2)
42
+ hashdiff
43
+
44
+ PLATFORMS
45
+ ruby
46
+
47
+ DEPENDENCIES
48
+ docusign_api!
49
+ minitest (~> 5.8)
50
+ mocha (~> 1.1)
51
+ webmock (= 1.22.3)
52
+
53
+ BUNDLED WITH
54
+ 1.11.2
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Open Listings, Buy a home without a realtor and get a
4
+ 50% commission refund
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
7
+ this software and associated documentation files (the "Software"), to deal in
8
+ the Software without restriction, including without limitation the rights to
9
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10
+ the Software, and to permit persons to whom the Software is furnished to do so,
11
+ subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # docusign_api
2
+
3
+ A simple ruby gem for using the DocuSign REST API with libcurl.
4
+
5
+ ## Usage
6
+ Add to your Gemfile:
7
+
8
+ ```ruby
9
+ gem 'docusign_api'
10
+ ```
11
+
12
+ Initialize with your credentials, either inline or set a constant called `DOCUSIGN`
13
+
14
+ ```ruby
15
+ @api = DocusignApi.new username: 'username', password: 'password', integrator_key: 'abc1234', login_url: 'https://demo.docusign.net/restapi/v2/login_information'
16
+ ```
17
+
18
+ Use the API, the DocusignApi instance will return a [curb](https://github.com/taf2/curb) response.
19
+
20
+ The library will log you in when initialized and will prefix the pathname with the correct endpoint for your account determined by the login process.
21
+
22
+ Examples:
23
+
24
+ ### GET
25
+ Get a list of your account's templates
26
+ ```ruby
27
+ c = @api.get '/templates'
28
+
29
+ puts c.response_code
30
+ puts JSON::parse(c.body)
31
+ ```
32
+
33
+ ### POST
34
+ Create an envelope from a template
35
+ ```ruby
36
+ h = {
37
+ emailSubject: email_subject,
38
+ status: 'created',
39
+ templateRoles: [],
40
+ compositeTemplates: [{
41
+ serverTemplates: [
42
+ {
43
+ sequence: '1',
44
+ templateId: template_id
45
+ }
46
+ ],
47
+ document: {
48
+ name: 'document name',
49
+ documentId: document_id,
50
+ documentBase64: Base64.encode64(File.read(pdf)),
51
+ documentFields: [
52
+ { name: 'field1', value: 'value1' },
53
+ { name: 'field2', value: 'value2' }
54
+ ]
55
+ }
56
+ }]
57
+ }
58
+
59
+ c = @api.post '/envelopes', h.to_json
60
+
61
+ puts c.response_code
62
+ puts JSON::parse(c.body)
63
+ ```
64
+
65
+ ### PUT
66
+ Change envelope recipients
67
+ ```ruby
68
+ h = {
69
+ signers: { roleName: 'signer', email: 'test@test.com', name: 'Recipient Name', recipientId: '1' }
70
+ }
71
+ c = @api.put '/envelopes/123/recipients', h.to_json
72
+
73
+ puts c.response_code
74
+ puts JSON::parse(c.body)
75
+ ```
76
+
77
+ ### DELETE
78
+ Delete envelope recipients
79
+ ```ruby
80
+ h = {
81
+ signers: [{ recipientId: '1' }]
82
+ }
83
+ c = @api.delete '/envelopes/123/recipients', h.to_json
84
+
85
+ puts c.response_code
86
+ puts JSON::parse(c.body)
87
+ ```
88
+
89
+ ## DocuSign REST API Docs
90
+ https://www.docusign.com/p/RESTAPIGuide/RESTAPIGuide.htm
91
+
92
+ ## Source Code
93
+ This project was created and is maintained by [Open Listings Engineering](https://www.openlistings.com) <engineering@openlistings.com>
94
+
95
+ ## Contributing
96
+ Contributions are welcome via pull request. Please write tests, thanks!
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ end
6
+
7
+ desc "Run tests"
8
+ task default: :test
@@ -0,0 +1,23 @@
1
+ Gem::Specification.new do |gem|
2
+ gem.name = 'docusign_api'
3
+ gem.version = '0.1.1'
4
+ gem.date = '2016-04-25'
5
+ gem.summary = "A ruby gem for using the DocuSign REST API with libcurl"
6
+ gem.description = "A ruby gem for using the DocuSign REST API with libcurl"
7
+ gem.authors = ["Open Listings Engineering"]
8
+ gem.email = 'engineering@openlistings.com'
9
+ gem.homepage = 'https://github.com/openlistings/docusign_api'
10
+ gem.license = 'MIT'
11
+
12
+ gem.files = `git ls-files`.split($/)
13
+ gem.test_files = gem.files.grep(%r{^(test)/})
14
+ gem.require_paths = ['lib']
15
+
16
+ gem.add_dependency 'capistrano', '~> 3.1'
17
+ gem.add_dependency 'sshkit', '~> 1.2'
18
+ gem.add_dependency 'curb', '< 0.9'
19
+
20
+ gem.add_development_dependency 'minitest', '~> 5.8'
21
+ gem.add_development_dependency 'mocha', '~> 1.1'
22
+ gem.add_development_dependency 'webmock', '1.22.3'
23
+ end
@@ -0,0 +1,110 @@
1
+ class DocusignApi
2
+ def initialize( opts = {} )
3
+ @username = opts[:username] || docusign_const(:username)
4
+ @password = opts[:password] || docusign_const(:password)
5
+ @integrator_key = opts[:integrator_key] || docusign_const(:integrator_key)
6
+ @login_url = opts[:login_url] || docusign_const(:login_url)
7
+
8
+ fail "please initialize with Docusign credentials: username, password, integrator_key" unless @username && @password && @integrator_key && @login_url
9
+
10
+ @proxy_host = opts[:proxy_host]
11
+ login
12
+ end
13
+
14
+ def get( path )
15
+ perform( path, :get)
16
+ end
17
+
18
+ def post( path, body )
19
+ perform( path, :post, body: body )
20
+ end
21
+
22
+ def put( path, body, opts = {} )
23
+ perform( path, :put, opts.merge(body: body) )
24
+ end
25
+
26
+ def delete( path, body = nil )
27
+ perform( path, :delete, body: body )
28
+ end
29
+
30
+ private
31
+
32
+ def auth_headers
33
+ {
34
+ 'X-DocuSign-Authentication' => %{
35
+ <DocuSignCredentials>
36
+ <Username>#{@username}</Username>
37
+ <Password>#{@password}</Password>
38
+ <IntegratorKey>#{@integrator_key}</IntegratorKey>
39
+ </DocuSignCredentials>
40
+ }
41
+ }
42
+ end
43
+
44
+ def docusign_const(key)
45
+ DOCUSIGN[key] if defined?(DOCUSIGN)
46
+ end
47
+
48
+ def perform( path, method, opts = {} )
49
+ fail DocusignApi::UnexpectedResponseBody, "body should be nil or a JSON string" if opts[:body] && !opts[:body].is_a?(String)
50
+ url = full_url(path)
51
+
52
+ c = Curl::Easy.new(url)
53
+ c.ssl_verify_peer = false if @proxy_host
54
+ c.headers = default_headers
55
+
56
+ case method
57
+ when :put, :delete
58
+ c.put_data = opts[:body]
59
+ when :post
60
+ c.multipart_form_post = !!opts[:multipart_form_post]
61
+ c.post_body = opts[:body]
62
+ end
63
+
64
+ c.http(method)
65
+
66
+ c
67
+ end
68
+
69
+ def full_url( path )
70
+ defined?(@base_url) && @base_url ? File.join(base_url, path) : path
71
+ end
72
+
73
+ def base_url
74
+ if @proxy_host && @base_url
75
+ @base_url.gsub(%r|[^/]+\.docusign\.net|, @proxy_host)
76
+ else
77
+ @base_url
78
+ end
79
+ end
80
+
81
+ def login
82
+ c = get(login_url)
83
+
84
+ fail DocusignApi::LoginFailed, "Login failed: #{[c.response_code, c.body].inspect}" unless 200 == c.response_code
85
+ login_response = JSON::parse(c.body)
86
+ @base_url = login_response['loginAccounts'][0]['baseUrl']
87
+ end
88
+
89
+ def login_url
90
+ if @proxy_host
91
+ @login_url.gsub(%r|[^/]+\.docusign\.net|, @proxy_host)
92
+ else
93
+ @login_url
94
+ end
95
+ end
96
+
97
+ def default_headers
98
+ {
99
+ 'Content-Type' => 'application/json',
100
+ 'Accept' => 'application/json'
101
+ }.merge(auth_headers)
102
+ end
103
+
104
+ end
105
+
106
+ class DocusignApi::LoginFailed < StandardError
107
+ end
108
+
109
+ class DocusignApi::UnexpectedResponseBody < StandardError
110
+ end
@@ -0,0 +1,12 @@
1
+ {
2
+ "loginAccounts": [{
3
+ "name": "Docusign API User",
4
+ "accountId": "1234567",
5
+ "baseUrl": "https://demo.docusign.net/restapi/v2/accounts/1234567",
6
+ "isDefault": "true",
7
+ "userName": "Docusign User",
8
+ "userId": "111111ee-41fd-4331-975e-123e51234eff",
9
+ "email": "nobody@e.e",
10
+ "siteDescription": ""
11
+ }]
12
+ }
@@ -0,0 +1,51 @@
1
+ require 'test_helper'
2
+
3
+ require 'docusign_api'
4
+
5
+ class DocusignApiTest < Minitest::Test
6
+ def setup
7
+ stub_docusign_login
8
+ @api = DocusignApi.new username: 'username', password: 'password', integrator_key: '12345', login_url: 'https://demo.docusign.net/restapi/v2/login_information'
9
+ end
10
+
11
+ def test_get
12
+ url = File.join(DOCUSIGN_ACCOUNT_BASE_URL, 'templates')
13
+ @req = stub_request(:get, url).
14
+ with(headers: DOCUSIGN_DEFAULT_HEADERS).
15
+ to_return( status: 200, body: '{}' )
16
+
17
+ @api.get '/templates'
18
+ assert_requested @req
19
+ end
20
+
21
+ def test_post
22
+ url = File.join(DOCUSIGN_ACCOUNT_BASE_URL, 'templates')
23
+ @req = stub_request(:post, url).
24
+ with(headers: DOCUSIGN_DEFAULT_HEADERS, body: '{}').
25
+ to_return( status: 200, body: '{}' )
26
+
27
+ @api.post '/templates', '{}'
28
+ assert_requested @req
29
+ end
30
+
31
+ def test_put
32
+ url = File.join(DOCUSIGN_ACCOUNT_BASE_URL, 'templates')
33
+ @req = stub_request(:put, url).
34
+ with(headers: DOCUSIGN_DEFAULT_HEADERS, body: '{}').
35
+ to_return( status: 200, body: '{}' )
36
+
37
+ @api.put '/templates', '{}'
38
+ assert_requested @req
39
+ end
40
+
41
+ def test_delete
42
+ url = File.join(DOCUSIGN_ACCOUNT_BASE_URL, 'templates')
43
+ @req = stub_request(:delete, url).
44
+ with(headers: DOCUSIGN_DEFAULT_HEADERS).
45
+ to_return( status: 200, body: '{}' )
46
+
47
+ @api.delete '/templates', '{}'
48
+ assert_requested @req
49
+ end
50
+
51
+ end
@@ -0,0 +1,21 @@
1
+ require 'minitest/autorun'
2
+ require 'mocha/mini_test'
3
+
4
+ require 'webmock'
5
+ require 'webmock/minitest'
6
+ include WebMock::API
7
+
8
+ DOCUSIGN_ACCOUNT_BASE_URL = 'https://demo.docusign.net/restapi/v2/accounts/1234567'.freeze
9
+ DOCUSIGN_LOGIN_URL = 'https://demo.docusign.net/restapi/v2/login_information'.freeze
10
+ DOCUSIGN_DEFAULT_HEADERS = {
11
+ 'Accept'=>'application/json',
12
+ 'Content-Type'=>'application/json',
13
+ 'X-Docusign-Authentication' => \
14
+ %r|<DocuSignCredentials>.*<Username>.+</Username>.*<Password>.+</Password>.*<IntegratorKey>.+</IntegratorKey>.*</DocuSignCredentials>|m
15
+ }.freeze
16
+
17
+ def stub_docusign_login
18
+ stub_request(:get, DOCUSIGN_LOGIN_URL).
19
+ with(headers: DOCUSIGN_DEFAULT_HEADERS).
20
+ to_return(status: 200, body: File.read('test/data/login_information.json'))
21
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: docusign_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Open Listings Engineering
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capistrano
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sshkit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: curb
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "<"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.9'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "<"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mocha
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 1.22.3
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 1.22.3
97
+ description: A ruby gem for using the DocuSign REST API with libcurl
98
+ email: engineering@openlistings.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - ".ruby-version"
104
+ - Gemfile
105
+ - Gemfile.lock
106
+ - LICENSE
107
+ - README.md
108
+ - Rakefile
109
+ - docusign_api.gemspec
110
+ - lib/docusign_api.rb
111
+ - test/data/login_information.json
112
+ - test/test_docusign_api.rb
113
+ - test/test_helper.rb
114
+ homepage: https://github.com/openlistings/docusign_api
115
+ licenses:
116
+ - MIT
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.5.1
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: A ruby gem for using the DocuSign REST API with libcurl
138
+ test_files:
139
+ - test/data/login_information.json
140
+ - test/test_docusign_api.rb
141
+ - test/test_helper.rb