hellosign-ruby-sdk 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/.gitignore +18 -0
  2. data/.rspec +2 -0
  3. data/.travis.yml +15 -0
  4. data/Gemfile +13 -0
  5. data/Guardfile +14 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +58 -0
  8. data/Rakefile +16 -0
  9. data/hellosign-ruby-sdk.gemspec +27 -0
  10. data/lib/hello_sign.rb +32 -0
  11. data/lib/hello_sign/api.rb +7 -0
  12. data/lib/hello_sign/api/account.rb +69 -0
  13. data/lib/hello_sign/api/embedded.rb +27 -0
  14. data/lib/hello_sign/api/oauth.rb +63 -0
  15. data/lib/hello_sign/api/signature_request.rb +286 -0
  16. data/lib/hello_sign/api/team.rb +88 -0
  17. data/lib/hello_sign/api/template.rb +77 -0
  18. data/lib/hello_sign/api/unclaimed_draft.rb +127 -0
  19. data/lib/hello_sign/client.rb +211 -0
  20. data/lib/hello_sign/configuration.rb +56 -0
  21. data/lib/hello_sign/error.rb +48 -0
  22. data/lib/hello_sign/resource.rb +8 -0
  23. data/lib/hello_sign/resource/account.rb +24 -0
  24. data/lib/hello_sign/resource/base_resource.rb +60 -0
  25. data/lib/hello_sign/resource/embedded.rb +24 -0
  26. data/lib/hello_sign/resource/resource_array.rb +33 -0
  27. data/lib/hello_sign/resource/signature_request.rb +25 -0
  28. data/lib/hello_sign/resource/team.rb +24 -0
  29. data/lib/hello_sign/resource/template.rb +25 -0
  30. data/lib/hello_sign/resource/unclaimed_draft.rb +25 -0
  31. data/lib/hello_sign/version.rb +3 -0
  32. data/spec/fixtures/account.json +1 -0
  33. data/spec/fixtures/embedded.json +6 -0
  34. data/spec/fixtures/error.json +6 -0
  35. data/spec/fixtures/file.json +0 -0
  36. data/spec/fixtures/signature_request.json +2 -0
  37. data/spec/fixtures/signature_requests.json +14 -0
  38. data/spec/fixtures/team.json +19 -0
  39. data/spec/fixtures/template.json +1 -0
  40. data/spec/fixtures/templates.json +11 -0
  41. data/spec/fixtures/token.json +14 -0
  42. data/spec/fixtures/unclaimed_draft.json +6 -0
  43. data/spec/hello_sign/api/account_spec.rb +36 -0
  44. data/spec/hello_sign/api/embedded_spec.rb +19 -0
  45. data/spec/hello_sign/api/oauth_spec.rb +28 -0
  46. data/spec/hello_sign/api/signature_request_spec.rb +126 -0
  47. data/spec/hello_sign/api/team_spec.rb +94 -0
  48. data/spec/hello_sign/api/template_spec.rb +67 -0
  49. data/spec/hello_sign/api/unclaimed_draft_spec.rb +35 -0
  50. data/spec/hello_sign/client_spec.rb +132 -0
  51. data/spec/hello_sign/resource/base_resource_spec.rb +50 -0
  52. data/spec/hello_sign_spec.rb +35 -0
  53. data/spec/spec_helper.rb +78 -0
  54. metadata +216 -0
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .idea
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.1
4
+ - 2.1.0
5
+ - 2.0.0
6
+ - 1.9.3
7
+ - jruby-19mode
8
+ - ruby-head
9
+ - jruby-head
10
+
11
+ matrix:
12
+ allow_failures:
13
+ - rvm: jruby-head
14
+ - rvm: ruby-head
15
+ fast_finish: true
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hello_sign.gemspec
4
+ gemspec
5
+
6
+ group :development, :spec do
7
+ gem 'pry'
8
+ gem 'growl' if `uname` =~ /Darwin/
9
+ gem 'guard'
10
+ gem 'guard-bundler'
11
+ gem 'guard-rspec'
12
+ gem 'coveralls', :require => false
13
+ end
@@ -0,0 +1,14 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ notification :growl if `uname` =~ /Darwin/
5
+
6
+ guard :bundler do
7
+ watch('Gemfile')
8
+ end
9
+
10
+ guard :rspec do
11
+ watch(%r{^spec/.+_spec\.rb$})
12
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
13
+ watch('spec/spec_helper.rb') { "spec" }
14
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 HelloSign, Inc
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,58 @@
1
+ # HelloSign Ruby SDK
2
+
3
+ In addition to this readme, checkout our quickstart guide here:
4
+ https://www.hellosign.com/api/gettingStarted#QuickStart
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'hellosign-ruby-sdk'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+
17
+ ## Configuration
18
+
19
+ Create a config block. At a minimum you'll want to set your [API Key](https://www.hellosign.com/home/myAccount/current_tab/integrations#api) but depending on your usage you'll possibly
20
+ want to set your app's [Client ID](https://www.hellosign.com/oauth/createAppForm) and [Client Secret](https://www.hellosign.com/oauth/createAppForma). In Rails you can place it in `config/initializers/hello_sign.rb`
21
+
22
+ ```ruby
23
+ require 'hello_sign'
24
+ HelloSign.configure do |config|
25
+ config.api_key = 'api_key'
26
+ # You can use email_address and password instead of api_key. But api_key is recommended
27
+ # If api_key, email_address and password are all present, api_key will be used
28
+ # config.email_address = 'email_address'
29
+ # config.password = 'password'
30
+ config.client_id = 'your_cliend_id' #required only when you want to use embedded or OAuth
31
+ config.client_secret = 'your_cliend_secret' #required only when you want to use OAuth
32
+ end
33
+ ```
34
+
35
+ ##Usage
36
+ When you have configured your app like above, you can start using it:
37
+
38
+ ```ruby
39
+ # get your account
40
+ my_account = HelloSign.get_account
41
+
42
+ # get your signature requests
43
+ my_signature_requests = HelloSign.get_signature_requests
44
+
45
+ # view a specific signature request
46
+ signature_request = HelloSign.get_signature_requests :signature_request_id => '42383e7327eda33f4b8b91217cbe95408cc1285f'
47
+ ```
48
+
49
+ If you need to authenticate for multiple users and you want a separated client for them, you can run:
50
+ ```ruby
51
+ client2 = HelloSign::Client.new :api_key => 'your_user_api_key'
52
+ user_account = client2.get_account
53
+ ```
54
+
55
+ ##Testing
56
+
57
+ Testing relies on built in hard-coded fixtures. You can run the tests without affecting your actual account data. To do so
58
+ from the root of your project run <code>rake spec</code>.
@@ -0,0 +1,16 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
8
+
9
+ task :console do
10
+ require 'irb'
11
+ require 'irb/completion'
12
+ require 'hello_sign' # You know what to do.
13
+ @client = HelloSign::Client.new :email_address => 'testuser@example.com', :password => '12345678', :client_id => '7f91612ee160dd56bd899cd1688bbefc', :client_secret => 'a403773af1e1aee206976257a47249cf'
14
+ ARGV.clear
15
+ IRB.start
16
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hello_sign/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hellosign-ruby-sdk"
8
+ spec.version = HelloSign::VERSION
9
+ spec.authors = "HelloSign"
10
+ spec.email = "support@hellosign.com"
11
+ spec.summary = "A Ruby SDK for the HelloSign API."
12
+ spec.description = ""
13
+ spec.homepage = "http://www.hellosign.com"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.5'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'rspec'
24
+ spec.add_development_dependency 'webmock'
25
+ spec.add_runtime_dependency 'faraday'
26
+ spec.add_runtime_dependency 'multi_json'
27
+ end
@@ -0,0 +1,32 @@
1
+ require 'hello_sign/version'
2
+ require 'hello_sign/configuration'
3
+ require 'hello_sign/client'
4
+
5
+ module HelloSign
6
+ extend Configuration
7
+
8
+ #
9
+ # # If HelloSign module don't respond_to? method, then delegate it to HelloSign::Client
10
+ # @param method [Symbol] method name
11
+ # @param *args [Array] arguments passed into the method
12
+ # @param &block [Block] a block passed into the method
13
+ #
14
+ def self.method_missing(method, *args, &block)
15
+ return super unless client.respond_to?(method)
16
+ client.send(method, *args, &block)
17
+ end
18
+
19
+
20
+ #
21
+ # If HelloSign module don't respond_to? method, ask HelloSign::Client whether it respond or not
22
+ # @param method [Symbol] method name
23
+ #
24
+ def self.respond_to?(method)
25
+ return super || client.respond_to?(method)
26
+ end
27
+
28
+ private
29
+ def self.client
30
+ HelloSign::Client.new
31
+ end
32
+ end
@@ -0,0 +1,7 @@
1
+ require 'hello_sign/api/account'
2
+ require 'hello_sign/api/embedded'
3
+ require 'hello_sign/api/template'
4
+ require 'hello_sign/api/signature_request'
5
+ require 'hello_sign/api/team'
6
+ require 'hello_sign/api/unclaimed_draft'
7
+ require 'hello_sign/api/oauth'
@@ -0,0 +1,69 @@
1
+ module HelloSign
2
+ module Api
3
+
4
+
5
+ #
6
+ # Contains all the api calls for the Account resource.
7
+ # Take a look at our {https://www.hellosign.com/api/reference#Account account api document}
8
+ # for more information about this.
9
+ #
10
+ # @author [hellosign]
11
+ #
12
+ module Account
13
+
14
+ #
15
+ # Returns the current user's account information.
16
+ #
17
+ # @return [HelloSign::Resource::Account] current user's account
18
+ #
19
+ # @example
20
+ # account = @client.get_account
21
+ #
22
+ def get_account
23
+ HelloSign::Resource::Account.new get("/account")
24
+ end
25
+
26
+ #
27
+ # Creates a new HelloSign account. The user will still need to validate their email address
28
+ # to complete the creation process.
29
+ #
30
+ # Note: This request does not require authentication.
31
+ #
32
+ # @option opts [String] email_address New user's email address
33
+ # @option opts [String] password New user's password
34
+ #
35
+ # @return [HelloSign::Resource::Account] New user's account information
36
+ #
37
+ # @example
38
+ # account = @client.create_account :email_address => 'newuser@example.com', :password => 'securePW'
39
+ #
40
+ def create_account opts
41
+ HelloSign::Resource::Account.new post("/account/create", :body => opts)
42
+ end
43
+
44
+
45
+ #
46
+ # Updates the current user's callback URL
47
+ # @option opts [String] callback_url New user's callback url
48
+ #
49
+ # @return [HelloSign::Resource::Account] Updated user's account information
50
+ #
51
+ # @example
52
+ # account = @client.update_account :callback_url => 'https://www.example.com/callback'
53
+ #
54
+ def update_account opts
55
+ HelloSign::Resource::Account.new post("/account", :body => opts)
56
+ end
57
+
58
+
59
+ #
60
+ # Check whether an account exists
61
+ # @option opts [String] email_address user email
62
+ #
63
+ # @return [Bool] true if exists, else false
64
+ def verify opts
65
+ post("/account/verify", :body => opts).empty? ? false : true
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,27 @@
1
+ module HelloSign
2
+ module Api
3
+
4
+ #
5
+ # HelloSign allows you to embed the signing page on your site in an iFrame
6
+ # without the need for the end-user to create a HelloSign account.
7
+ # Take a look at our {https://www.hellosign.com/api/embeddedSigningWalkthrough embedded signing walkthrough}
8
+ # for more information about this.
9
+ #
10
+ # @author [hellosign]
11
+ #
12
+ module Embedded
13
+
14
+ #
15
+ # Retrieves the embedded signature request url.
16
+ # @option opts [String] signature_id The id of the signature to get a signature url for
17
+ #
18
+ # @return [HelloSign::Resource::Embedded] Returns an Embedded object
19
+ # @example
20
+ # embedded = @client.get_embedded_sign_url :signature_id => '50e3542f738adfa7ddd4cbd4c00d2a8ab6e4194b'
21
+ #
22
+ def get_embedded_sign_url opts
23
+ HelloSign::Resource::Embedded.new get("/embedded/sign_url/#{opts[:signature_id]}")
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,63 @@
1
+ module HelloSign
2
+ module Api
3
+
4
+ #
5
+ # OAuth allows you to perform actions on behalf of other users after they grant you the authorization to do so.
6
+ # For example, you could send signature requests on behalf of your users. This page lays out the basic steps to do that.
7
+ # IMPORTANT
8
+ #
9
+ # With OAuth, you (the app owner) will be charged for all signature requests sent on behalf of other users via your app.
10
+ #
11
+ # @author [hellosign]
12
+ #
13
+ module OAuth
14
+
15
+ #
16
+ # Return the oath url where users can give permission for your application to perform actions on their behalf.
17
+ # @param state [String] used for security and must match throughout the flow for a given user.
18
+ # It can be set to the value of your choice (preferably something random). You should verify it matches the expected value when validating the OAuth callback.
19
+ # @return [type] [description]
20
+ def oauth_url state
21
+ "#{self.oauth_end_point}/oauth/authorize?response_type=code&client_id=#{self.client_id}&state=#{state}"
22
+ end
23
+
24
+ #
25
+ # Retrieving the OAuth token
26
+ #
27
+ # @option opts [String] state variable that was used when you created oauth_url for a specific user
28
+ # @option opts [String] code The authorization code passed to your callback when the user granted access
29
+ #
30
+ # @return [Hash] oauth data of the user
31
+ def get_oauth_token opts
32
+ opts[:client_id] = self.client_id
33
+ opts[:client_secret] = self.client_secret
34
+ opts[:grant_type] = 'authorization_code'
35
+ post('/oauth/token', {:body => opts, :oauth_request => true})
36
+
37
+ end
38
+
39
+
40
+ #
41
+ # refresh user oauth token.
42
+ #
43
+ # @return [Hash] refreshed oauth info
44
+ def refresh_oauth_token refresh_token
45
+ post('/oauth/token', {:body => {:grant_type => 'refresh_token', :refresh_token => refresh_token}, :oauth_request => true})
46
+ end
47
+
48
+
49
+ #
50
+ # Create new user and get their OAuth token. The user will receive an email asking them to confirm the access being granted. Your app will not be able to perform actions on behalf of this user until they confirm.
51
+ # @option opts [String] email_address new user email address
52
+ # @option opts [String] password new user password
53
+ #
54
+ # @return [Hash] details about new user, including oath data
55
+ def oauth_create_account opts
56
+ opts[:client_id] = self.client_id
57
+ opts[:client_secret] = self.client_secret
58
+
59
+ HelloSign::Resource::Account.new post('/account/create', {:body => opts})
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,286 @@
1
+ module HelloSign
2
+ module Api
3
+
4
+ #
5
+ # Contains all the api about the SignatureRequest resource.
6
+ # Take a look at our {https://www.hellosign.com/api/reference#SignatureRequest signature request api document}
7
+ # for more information about this.
8
+ #
9
+ # @author [hellosign]
10
+ #
11
+ module SignatureRequest
12
+
13
+ #
14
+ # Retrieves a Signature Request with the given ID.
15
+ # @option opts [String] signature_request_id The id of the SignatureRequest to retrieve.
16
+ #
17
+ # @return [HelloSign::Resource::SignatureRequest] a SignatureRequest object
18
+ #
19
+ # @example
20
+ # signature_request = @client.get_signature_request :signature_request_id => '75cdf7dc8b323d43b347e4a3614d1f822bd09491'
21
+ #
22
+ def get_signature_request opts
23
+ HelloSign::Resource::SignatureRequest.new get("/signature_request/#{opts[:signature_request_id]}")
24
+ end
25
+
26
+ #
27
+ # Returns a list of SignatureRequests that you can access. This includes SignatureRequests you have sent as well as received, but not ones that you have been CCed on.
28
+ # @option opts [Integer] page (1) Which page number of the Template List to return.
29
+ #
30
+ # @return [HelloSign::Resource::ResourceArray]
31
+ #
32
+ # @example
33
+ # signature_requests = @client.get_signature_requests :page => 1
34
+ #
35
+ def get_signature_requests opts={}
36
+ path = '/signature_request/list'
37
+ path += opts[:page] ? "?page=#{opts[:page]}" : ""
38
+ HelloSign::Resource::ResourceArray.new get(path, opts), 'signature_requests', HelloSign::Resource::SignatureRequest
39
+ end
40
+
41
+ #
42
+ # Creates and sends a new SignatureRequest with the submitted documents.
43
+ # If form_fields_per_document is not specified, a signature page will be affixed at the end
44
+ # and all signers will be required to add their signature there.
45
+ # @option opts [Integer] test_mode (0) Whether this is a test, the signature request will not be legally binding if set to 1.
46
+ # @option opts [Array<String>] files Use files to indicate the uploaded file(s) to send for signature. Currently we only support use of either the files parameter or file_urls parameter, not both.
47
+ # @option opts [Array<String>] file_urls Use file_urls to have HelloSign download the file(s) to send for signature. Currently we only support use of either the files parameter or file_urls parameter, not both.
48
+ # @option opts [String] title The title you want to assign to the SignatureRequest.
49
+ # @option opts [String] subject The subject in the email that will be sent to the signers.
50
+ # @option opts [String] message The custom message in the email that will be sent to the signers.
51
+ # @option opts [String] signing_redirect_url The URL you want the signer redirected to after they successfully sign. (optional)
52
+ # @option opts [Array<Hash>] signers List of signers, each item is a Hash with these keys:
53
+ # * :name (String) Sender' name
54
+ # * :email_address (String) Sender's email address
55
+ # * :order (Integer) The order the signer is required to sign in
56
+ # * :pin (Integer) The 4- to 12-character access code that will secure this signer's signature page. You must have a business plan to use this feature.
57
+ # @option opts [Array<String>] cc_email_addresses The email addresses that should be CCed.
58
+ # @option opts [String] form_fields_per_document
59
+ #
60
+ # @return [HelloSign::Resource::SignatureRequest] a SignatureRequest
61
+ #
62
+ # @example
63
+ # signature_request = @client.send_signature_request(
64
+ # :test_mode => 1,
65
+ # :title => 'NDA with Acme Co.',
66
+ # :subject => 'The NDA we talked about',
67
+ # :message => 'Please sign this NDA and then we can discuss more. Let me know if you have any questions.',
68
+ # :signers => [{
69
+ # :email_address => 'jack@example.com',
70
+ # :name => 'Jack',
71
+ # :order => 0,
72
+ # },{
73
+ # :email_address => 'jill@example.com',
74
+ # :name => 'Jill',
75
+ # :order => 1,
76
+ # }
77
+ # ],
78
+ # :cc_email_addresses => ['lawyer@example.com', 'lawyer@example2.com'],
79
+ # :files => ['NDA.pdf', 'AppendixA.pdf']
80
+ # )
81
+ #
82
+
83
+ def send_signature_request opts
84
+ prepare_files opts
85
+ prepare_signers opts
86
+
87
+ HelloSign::Resource::SignatureRequest.new post('/signature_request/send', :body => opts)
88
+ end
89
+
90
+ #
91
+ # Creates and sends a new SignatureRequest based off of the Template specified with the template_id parameter.
92
+ # @option opts [Integer] test_mode (0) Whether this is a test, the signature request will not be legally binding if set to 1.
93
+ # @option opts [String] template_id The id of the Template to use when creating the SignatureRequest.
94
+ # @option opts [String] title The title you want to assign to the SignatureRequest.
95
+ # @option opts [String] subject The subject in the email that will be sent to the signers.
96
+ # @option opts [String] message The custom message in the email that will be sent to the signers.
97
+ # @option opts [String] signing_redirect_url The URL you want the signer redirected to after they successfully sign. (optional)
98
+ # @option opts [Array<Hash>] signers List of signers
99
+ # * :name (String) Sender' name
100
+ # * :email_address (String) Sender's email address
101
+ # * :order (Integer) The order the signer is required to sign in
102
+ # * :pin (Integer) The 4- to 12-character access code that will secure this signer's signature page. You must have a business plan to use this feature.
103
+ # @option opts [Array<Hash>] ccs The email addresses CC destinations. Required when a CC role exists for the Template.
104
+ # @option opts [Array<Hash>] custom_fields The value to fill in for the custom field with the name of CustomFieldName. Required when a CustomField exists in the Template.
105
+ #
106
+ # @return [HelloSign::Resource::SignatureRequest] a SignatureRequest
107
+ # @example
108
+ # signature_request = @client.send_signature_request_with_template(
109
+ # :test_mode => 1,
110
+ # :template_id => 'c26b8a16784a872da37ea946b9ddec7c1e11dff6',
111
+ # :title => 'Purchase Order',
112
+ # :subject => 'Purchase Order',
113
+ # :message => 'Glad we could come to an agreement.',
114
+ # :signers => [
115
+ # {
116
+ # :email_address => 'george@example.com',
117
+ # :name => 'George',
118
+ # :role => 'Client'
119
+ # }
120
+ # ],
121
+ # :ccs => [
122
+ # {
123
+ # :email_address =>'accounting@example.com',
124
+ # :role => "Accounting"
125
+ # }
126
+ # ],
127
+ # :custom_fields => [
128
+ # {
129
+ # :CustomFieldName => '$20,000'
130
+ # }
131
+ # ]
132
+ # )
133
+ #
134
+ def send_signature_request_with_template opts
135
+ prepare_signers opts
136
+ prepare_ccs opts
137
+ HelloSign::Resource::SignatureRequest.new post('/signature_request/send_with_template', :body => opts)
138
+ end
139
+
140
+ #
141
+ # Sends an email to the signer reminding them to sign the signature request.
142
+ # @option opts [String] signature_request_id The id of the SignatureRequest to send a reminder for.
143
+ # @option opts [String] email_address The email address of the signer to send a reminder to.
144
+ #
145
+ # @return [HelloSign::Resource::SignatureRequest] a SignatureRequest
146
+ # @example
147
+ # signature_request = @client.remind_signature_request :signature_request_id => '75cdf7dc8b323d43b347e4a3614d1f822bd09491', :email_address => 'john@example.com'
148
+ #
149
+ def remind_signature_request opts
150
+ HelloSign::Resource::SignatureRequest.new post("/signature_request/remind/#{opts[:signature_request_id]}", :body => opts)
151
+ end
152
+
153
+ #
154
+ # Cancels a SignatureRequest.
155
+ # @option opts [String] signature_request_id The id of the SignatureRequest to cancel.
156
+ #
157
+ # @example
158
+ # @client.cancel_signature_request :signature_request_id => '75cdf7dc8b323d43b347e4a3614d1f822bd09491'
159
+ def cancel_signature_request opts
160
+ post("/signature_request/cancel/#{opts[:signature_request_id]}", :body => opts)
161
+ end
162
+
163
+ #
164
+ # Download the PDF copy of the current documents specified by the signature_request_id parameter.
165
+ # @option opts [String] file_type Either 'pdf' or 'zip' depending on the file type desired. Defaults to pdf.
166
+ # @option opts [String] signature_request_id The id of the SignatureRequest to retrieve.
167
+ #
168
+ # @return a PDF
169
+ #
170
+ # @example
171
+ # pdf = @client.signature_request_files :signature_request_id => '75cdf7dc8b323d43b347e4a3614d1f822bd09491'
172
+ #
173
+ def signature_request_files opts
174
+ path = "/signature_request/files/#{opts[:signature_request_id]}"
175
+ if opts[:file_type]
176
+ path = path + "?file_type=#{opts[:file_type]}"
177
+ end
178
+ get(path)
179
+ end
180
+
181
+ #
182
+ # Creates a new SignatureRequest with the submitted documents to be signed in an embedded iFrame.
183
+ # If form_fields_per_document is not specified, a signature page will be affixed where all signers will be required to add their signature, signifying their agreement to all contained documents.
184
+ # Note that embedded signature requests can only be signed in embedded iFrames whereas normal signature requests can only be signed on HelloSign.
185
+ # @option opts [Integer] test_mode (0) Whether this is a test, the signature request will not be legally binding if set to 1.
186
+ # @option opts [String] client_id Client id of the app you're using to create this embedded signature request. Visit our {https://www.hellosign.com/api/reference#Embedded embedded page} page to learn more about this parameter.
187
+ # @option opts [Array<String>] files Use files to indicate the uploaded file(s) to send for signature. Currently we only support use of either the files parameter or file_urls parameter, not both.
188
+ # @option opts [Array<String>] file_urls Use file_urls to have HelloSign download the file(s) to send for signature. Currently we only support use of either the files parameter or file_urls parameter, not both.
189
+ # @option opts [String] title The title you want to assign to the SignatureRequest.
190
+ # @option opts [String] subject The subject in the email that will be sent to the signers.
191
+ # @option opts [String] message The custom message in the email that will be sent to the signers.
192
+ # @option opts [String] signing_redirect_url The URL you want the signer redirected to after they successfully sign. (optional)
193
+ # @option opts [Array<Hash>] signers List of signers, each item is a Hash with these keys:
194
+ # * :name (String) Sender' name
195
+ # * :email_address (String) Sender's email address
196
+ # * :order (Integer) The order the signer is required to sign in
197
+ # * :pin (Integer) The 4- to 12-character access code that will secure this signer's signature page. You must have a business plan to use this feature.
198
+ # @option opts [Array<String>] cc_email_addresses The email addresses that should be CCed.
199
+ # @option opts [String] form_fields_per_document
200
+ #
201
+ # @return [HelloSign::Resource::SignatureRequest] a SignatureRequest
202
+ # @example
203
+ # request = @client.create_embedded_signature_request(
204
+ # :test_mode => 1,
205
+ # :client_id => 'b6b8e7deaf8f0b95c029dca049356d4a2cf9710a',
206
+ # :title => 'NDA with Acme Co.',
207
+ # :subject => 'The NDA we talked about',
208
+ # :message => 'Please sign this NDA and then we can discuss more. Let me know if you have any questions.',
209
+ # :signers => [{
210
+ # :email_address => 'jack@example.com',
211
+ # :name => 'Jack',
212
+ # :order => 0,
213
+ # },{
214
+ # :email_address => 'jill@example.com',
215
+ # :name => 'Jill',
216
+ # :order => 1,
217
+ # }
218
+ # ],
219
+ # :cc_email_addresses => ['lawyer@example.com', 'lawyer@example2.com'],
220
+ # :files => ['NDA.pdf', 'AppendixA.pdf']
221
+ # )
222
+ #
223
+ def create_embedded_signature_request opts
224
+ opts[:client_id] ||= self.client_id
225
+ prepare_files opts
226
+ prepare_signers opts
227
+
228
+ HelloSign::Resource::SignatureRequest.new post('/signature_request/create_embedded', :body => opts)
229
+ end
230
+
231
+ #
232
+ # Creates a new SignatureRequest based on the given Template to be signed in an embedded iFrame.
233
+ # Note that embedded signature requests can only be signed in embedded iFrames whereas normal signature requests can only be signed on HelloSign.
234
+ # @option opts [Integer] test_mode (0) Whether this is a test, the signature request will not be legally binding if set to 1.
235
+ # @option opts [String] client_id Client id of the app you're using to create this embedded signature request. Visit our {https://www.hellosign.com/api/reference#Embedded embedded page} page to learn more about this parameter.
236
+ # @option opts [String] template_id The id of the Template to use when creating the SignatureRequest.
237
+ # @option opts [String] title The title you want to assign to the SignatureRequest.
238
+ # @option opts [String] subject The subject in the email that will be sent to the signers.
239
+ # @option opts [String] message The custom message in the email that will be sent to the signers.
240
+ # @option opts [String] signing_redirect_url The URL you want the signer redirected to after they successfully sign. (optional)
241
+ # @option opts [Integer] hide_text_tags Whether or not your text tags hidden after parsing
242
+ # @option opts [Integer] use_text_tags Whether or not your document contains parseable text-tags
243
+ # @option opts [Array<Hash>] signers List of signers, each item is a Hash with these keys:
244
+ # * :name (String) Sender' name
245
+ # * :email_address (String) Sender's email address
246
+ # * :order (Integer) The order the signer is required to sign in
247
+ # * :pin (Integer) The 4- to 12-character access code that will secure this signer's signature page. You must have a business plan to use this feature.
248
+ # @option opts [Hash] ccs The email address of the CC filling the role of RoleName. Required when a CC role exists for the Template.
249
+ # @option opts [Hash] custom_fields The value to fill in for custom field with the name of CustomFieldName. Required when a CustomField exists in the Template.
250
+ # @return [HelloSign::Resource::SignatureRequest] a SignatureRequest
251
+ # @example
252
+ # request = @client.create_embedded_signature_request_with_template(
253
+ # :test_mode => 1,
254
+ # :client_id => 'b6b8e7deaf8f0b95c029dca049356d4a2cf9710a',
255
+ # :template_id => 'c26b8a16784a872da37ea946b9ddec7c1e11dff6',
256
+ # :title => 'Purchase Order',
257
+ # :subject => 'Purchase Order',
258
+ # :message => 'Glad we could come to an agreement.',
259
+ # :signers => [
260
+ # {
261
+ # :email_address => 'george@example.com',
262
+ # :name => 'George',
263
+ # :role => 'Client'
264
+ # }
265
+ # ],
266
+ # :ccs => [
267
+ # {
268
+ # :email_address =>'accounting@example.com',
269
+ # :role => "Accounting"
270
+ # }
271
+ # ],
272
+ # :custom_fields => {
273
+ # :Cost => '$20,000'
274
+ # }
275
+ # )
276
+ #
277
+ def create_embedded_signature_request_with_template opts
278
+ opts[:client_id] ||= self.client_id
279
+ prepare_signers opts
280
+ prepare_ccs opts
281
+
282
+ HelloSign::Resource::SignatureRequest.new post('/signature_request/create_embedded_with_template', :body => opts)
283
+ end
284
+ end
285
+ end
286
+ end