hellosign-ruby-sdk 3.7.5 → 3.7.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +2 -2
  3. data/lib/hello_sign.rb +7 -12
  4. data/lib/hello_sign/api.rb +1 -2
  5. data/lib/hello_sign/api/account.rb +17 -30
  6. data/lib/hello_sign/api/api_app.rb +27 -25
  7. data/lib/hello_sign/api/bulk_send_job.rb +62 -0
  8. data/lib/hello_sign/api/embedded.rb +17 -23
  9. data/lib/hello_sign/api/oauth.rb +26 -34
  10. data/lib/hello_sign/api/signature_request.rb +370 -261
  11. data/lib/hello_sign/api/team.rb +21 -26
  12. data/lib/hello_sign/api/template.rb +79 -70
  13. data/lib/hello_sign/api/unclaimed_draft.rb +193 -142
  14. data/lib/hello_sign/client.rb +58 -22
  15. data/lib/hello_sign/configuration.rb +3 -7
  16. data/lib/hello_sign/error.rb +2 -3
  17. data/lib/hello_sign/resource.rb +1 -2
  18. data/lib/hello_sign/resource/account.rb +3 -6
  19. data/lib/hello_sign/resource/api_app.rb +3 -6
  20. data/lib/hello_sign/resource/base_resource.rb +5 -9
  21. data/lib/hello_sign/resource/bulk_send_job.rb +43 -0
  22. data/lib/hello_sign/resource/embedded.rb +7 -10
  23. data/lib/hello_sign/resource/resource_array.rb +7 -10
  24. data/lib/hello_sign/resource/signature_request.rb +6 -9
  25. data/lib/hello_sign/resource/team.rb +3 -6
  26. data/lib/hello_sign/resource/template.rb +5 -8
  27. data/lib/hello_sign/resource/template_draft.rb +4 -7
  28. data/lib/hello_sign/resource/unclaimed_draft.rb +5 -10
  29. data/lib/hello_sign/version.rb +1 -3
  30. data/spec/fixtures/api_app.json +10 -10
  31. data/spec/fixtures/bulk_send_job.json +88 -0
  32. data/spec/fixtures/bulk_send_jobs.json +22 -0
  33. data/spec/hello_sign/api/account_spec.rb +1 -1
  34. data/spec/hello_sign/api/bulk_send_job_spec.rb +53 -0
  35. data/spec/hello_sign_spec.rb +2 -4
  36. data/spec/spec_helper.rb +0 -2
  37. metadata +11 -3
@@ -1,4 +1,3 @@
1
- #
2
1
  # The MIT License (MIT)
3
2
  #
4
3
  # Copyright (C) 2014 hellosign.com
@@ -20,7 +19,6 @@
20
19
  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
21
  # SOFTWARE.
23
- #
24
22
 
25
23
  require 'faraday'
26
24
  require 'multi_json'
@@ -32,13 +30,10 @@ require 'hello_sign/api'
32
30
  require 'logger'
33
31
 
34
32
  module HelloSign
35
- #
33
+
36
34
  # You'll need the HelloSign::Client to do just about everything, from creating
37
35
  # signatures to updating account information.
38
36
  #
39
- # @example
40
- # client = HelloSign::Client.new :email_address => "me@example.com", :password => "mypassword"
41
- #
42
37
  # @author [hellosign]
43
38
  class Client
44
39
  include Api::Account
@@ -49,6 +44,7 @@ module HelloSign
49
44
  include Api::Embedded
50
45
  include Api::OAuth
51
46
  include Api::ApiApp
47
+ include Api::BulkSendJob
52
48
 
53
49
  attr_accessor :end_point, :oauth_end_point, :api_version, :user_agent, :client_id, :client_secret, :email_address, :password, :api_key, :auth_token, :logging, :log_level, :proxy_uri, :proxy_user, :proxy_pass, :timeout
54
50
 
@@ -67,13 +63,18 @@ module HelloSign
67
63
  503 => Error::ServiceUnavailable
68
64
  }
69
65
 
70
- #
71
66
  # Initiates a new HelloSign Client
72
-
73
67
  # @option opts [String] email_address The account's email address. (optional)
74
68
  # @option opts [String] password The account's password, if authenticating with an email_address. (optional)
75
69
  # @option opts [String] api_key The account's API key.
70
+ #
76
71
  # @return [HelloSign::Client] a new HelloSign::Client
72
+ #
73
+ # @example Authenticating with username and password
74
+ # client = HelloSign::Client.new email_address: 'me@example.com', password: 'mypassword'
75
+ #
76
+ # @example Authenticating with API key
77
+ # client = HelloSign::Client.new api_key: '1234567890123456789012345678901234567890123456789012345678901234'
77
78
  def initialize(opts={})
78
79
  options = HelloSign.options.merge(opts)
79
80
  HelloSign::Configuration::VALID_OPTIONS_KEYS.each do |key|
@@ -81,11 +82,9 @@ module HelloSign
81
82
  end
82
83
  end
83
84
 
84
- #
85
85
  # Makes an HTTP GET request
86
- # @param path [String] Relative path of the request.
86
+ # @param path [String] Relative path of the request.
87
87
  # @option options [Hash] params Params of the URL.
88
- #
89
88
  def get(path, options={})
90
89
  response = request(path, :get, options)
91
90
  validate response
@@ -93,12 +92,10 @@ module HelloSign
93
92
  data = { headers: response.headers, body: parsed_response }
94
93
  end
95
94
 
96
- #
97
95
  # Makes an HTTP POST request
98
- # @param path [String] Relative path of the request.
96
+ # @param path [String] Relative path of the request.
99
97
  # @option options [Hash] params Params of the URL.
100
98
  # @option options [Hash] body Body of the request.
101
- #
102
99
  def post(path, options={})
103
100
  response = request(path, :post, options)
104
101
  validate response
@@ -106,12 +103,10 @@ module HelloSign
106
103
  data = { headers: response.headers, body: parsed_response }
107
104
  end
108
105
 
109
- #
110
106
  # Makes an HTTP PUT request
111
- # @param path [String] Relative path of the request.
107
+ # @param path [String] Relative path of the request.
112
108
  # @option options [Hash] params Params of the URL.
113
109
  # @option options [Hash] body Body of the request.
114
- #
115
110
  def put(path, options={})
116
111
  response = request(path, :put, options)
117
112
  validate response
@@ -119,11 +114,9 @@ module HelloSign
119
114
  data = { headers: response.headers, body: parsed_response }
120
115
  end
121
116
 
122
- #
123
- # Make an HTTP DELETE request
124
- # @param path [String] Relative path of the request.
117
+ # Makes an HTTP DELETE request
118
+ # @param path [String] Relative path of the request.
125
119
  # @option options [Hash] Params of the URL.
126
- #
127
120
  def delete(path, options={})
128
121
  response = request(path, :delete, options)
129
122
  validate response
@@ -277,7 +270,11 @@ module HelloSign
277
270
  end
278
271
 
279
272
  def prepare_signers(opts)
280
- prepare opts, :signers
273
+ if opts[:signers]
274
+ prepare opts, :signers
275
+ elsif opts[:signer_group]
276
+ prepare_signer_group opts, :signer_group
277
+ end
281
278
  end
282
279
 
283
280
  def prepare_ccs(opts)
@@ -292,6 +289,10 @@ module HelloSign
292
289
  prepare opts, :signer_roles
293
290
  end
294
291
 
292
+ def prepare_attachments(opts)
293
+ prepare opts, :attachments
294
+ end
295
+
295
296
  def prepare_form_fields(opts)
296
297
  if (opts[:form_fields_per_document] and opts[:form_fields_per_document].is_a? Array)
297
298
  opts[:form_fields_per_document] = MultiJson.dump(opts[:form_fields_per_document])
@@ -313,6 +314,18 @@ module HelloSign
313
314
  # ignore if it's already a string, or not present
314
315
  end
315
316
 
317
+ def prepare_bulk_signers(opts)
318
+ if opts[:signer_file]
319
+ file = opts[:signer_file]
320
+ mime_type = MIMEfromIO file
321
+ opts[:signer_file] = Faraday::UploadIO.new(file, mime_type)
322
+ elsif opts[:signer_list]
323
+ opts[:signer_list] = MultiJson.dump(opts[:signer_list])
324
+ else
325
+ raise HelloSign::Error::NotSupportedType.new "Upload a CSV file or JSON list of signers"
326
+ end
327
+ end
328
+
316
329
  def prepare(opts, key)
317
330
  return unless opts[key]
318
331
  opts[key].each_with_index do |value, index|
@@ -329,5 +342,28 @@ module HelloSign
329
342
  end
330
343
  opts.delete(key)
331
344
  end
345
+
346
+ def prepare_signer_group(opts, key)
347
+ opts[key].each_with_index do |value, index|
348
+ if value[:role]
349
+ group_index_or_role = value[:role]
350
+ else
351
+ group_index_or_role = index
352
+ end
353
+
354
+ opts[:"signers[#{group_index_or_role}][group]"] = value[:group_name]
355
+ opts[key] = value[:signers]
356
+ prepare_signers_for_group(value[:signers], group_index_or_role, opts)
357
+ end
358
+ opts.delete(key)
359
+ end
360
+
361
+ def prepare_signers_for_group(signers, group_index_or_role, opts)
362
+ signers.each_with_index do |signer, index|
363
+ signer.each do |param, data|
364
+ opts[:"signers[#{group_index_or_role}][#{index}][#{param}]"] = data
365
+ end
366
+ end
367
+ end
332
368
  end
333
369
  end
@@ -1,4 +1,3 @@
1
- #
2
1
  # The MIT License (MIT)
3
2
  #
4
3
  # Copyright (C) 2014 hellosign.com
@@ -20,21 +19,18 @@
20
19
  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
21
  # SOFTWARE.
23
- #
24
22
 
25
23
  module HelloSign
26
- #
27
- # Define config attributes and default values for HelloSign module
24
+
25
+ # Defines config attributes and default values for HelloSign module
28
26
  #
29
27
  # @author [hellosign]
30
- #
31
28
  module Configuration
32
29
  DEFAULT_ENDPOINT = 'https://api.hellosign.com'
33
30
  DEFAULT_API_VERSION = '/v3'
34
31
  DEFAULT_OAUTH_ENDPOINT = 'https://app.hellosign.com'
35
32
  VALID_OPTIONS_KEYS = [:end_point, :oauth_end_point, :api_version, :user_agent, :client_id, :client_secret, :email_address, :password, :api_key, :auth_token, :log_level, :logging, :proxy_uri, :proxy_user, :proxy_pass, :timeout]
36
33
 
37
-
38
34
  DEFAULT_USER_AGENT = "hellosign-ruby-sdk/" + HelloSign::VERSION
39
35
 
40
36
  attr_accessor *VALID_OPTIONS_KEYS
@@ -42,7 +38,7 @@ module HelloSign
42
38
  # Sets all configuration options to their default values
43
39
  # when this module is extended.
44
40
  #
45
- # @param base [Object] new module or class extend thid module
41
+ # @param base [Object] New module or class extends this module
46
42
  def self.extended(base)
47
43
  base.reset
48
44
  end
@@ -1,4 +1,3 @@
1
- #
2
1
  # The MIT License (MIT)
3
2
  #
4
3
  # Copyright (C) 2014 hellosign.com
@@ -20,10 +19,10 @@
20
19
  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
21
  # SOFTWARE.
23
- #
24
22
 
25
23
  module HelloSign
26
24
  module Error
25
+
27
26
  # Custom error class for rescuing from all HelloSign errors.
28
27
  class Error < StandardError;
29
28
  attr_accessor :request_uri, :response_body, :response_status
@@ -43,7 +42,7 @@ module HelloSign
43
42
  end
44
43
  end
45
44
 
46
- # Raise when attributes are missing.
45
+ # Raised when attributes are missing.
47
46
  class MissingAttributes < Error; end
48
47
 
49
48
  # Raised when API endpoint credentials not configured.
@@ -1,4 +1,3 @@
1
- #
2
1
  # The MIT License (MIT)
3
2
  #
4
3
  # Copyright (C) 2014 hellosign.com
@@ -20,7 +19,6 @@
20
19
  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
21
  # SOFTWARE.
23
- #
24
22
 
25
23
  require 'hello_sign/resource/base_resource'
26
24
  require 'hello_sign/resource/resource_array'
@@ -32,3 +30,4 @@ require 'hello_sign/resource/signature_request'
32
30
  require 'hello_sign/resource/team'
33
31
  require 'hello_sign/resource/unclaimed_draft'
34
32
  require 'hello_sign/resource/api_app'
33
+ require 'hello_sign/resource/bulk_send_job'
@@ -1,4 +1,3 @@
1
- #
2
1
  # The MIT License (MIT)
3
2
  #
4
3
  # Copyright (C) 2014 hellosign.com
@@ -20,24 +19,22 @@
20
19
  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
21
  # SOFTWARE.
23
- #
24
22
 
25
23
  module HelloSign
26
24
  module Resource
27
- #
28
25
  # Contains information about an Account and its settings.
29
26
  # Take a look at our API Documentation on the Account resource (https://app.hellosign.com/api/reference#Account)
30
27
  # for more information about this.
31
28
  #
32
29
  # @author [hellosign]
33
- #
30
+
34
31
  class Account < BaseResource
35
- #
32
+
36
33
  # Creates a new Account from a hash. If key defined then account data with be the value of hash[key], otherwise the hash itself.
37
34
  # @param hash [Hash] Account's data
38
35
  # @param key [String] (account) key of the hash, point to where Account data is. If nil, then the hash itself.
39
36
  #
40
- # @return [HelloSign::Resource:Account] an Account resource
37
+ # @return [HelloSign::Resource::Account] an Account
41
38
  def initialize(hash, key='account')
42
39
  super
43
40
  end
@@ -1,4 +1,3 @@
1
- #
2
1
  # The MIT License (MIT)
3
2
  #
4
3
  # Copyright (C) 2015 hellosign.com
@@ -20,24 +19,22 @@
20
19
  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
21
  # SOFTWARE.
23
- #
24
22
 
25
23
  module HelloSign
26
24
  module Resource
27
- #
28
25
  # Contains information about the ApiApp resource.
29
26
  # Take a look at our API Documentation for ApiApps (https://app.hellosign.com/api/reference#ApiApp)
30
27
  # for more information about this.
31
28
  #
32
29
  # @author [hellosign]
33
- #
30
+
34
31
  class ApiApp < BaseResource
35
- #
32
+
36
33
  # Creates a new ApiApp from a hash. If a key is defined then ApiApp data with be the value of hash[key], otherwise the hash itself.
37
34
  # @param hash [Hash] ApiApp data
38
35
  # @param key [String] (api_app) key of the hash, point to where ApiApp data is. If nil, then the hash itself.
39
36
  #
40
- # @return [HelloSign::Resource:ApiApp] an ApiApp resource
37
+ # @return [HelloSign::Resource::ApiApp] an ApiApp
41
38
  def initialize(hash, key='api_app')
42
39
  super
43
40
  end
@@ -1,4 +1,3 @@
1
- #
2
1
  # The MIT License (MIT)
3
2
  #
4
3
  # Copyright (C) 2014 hellosign.com
@@ -20,20 +19,18 @@
20
19
  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
21
  # SOFTWARE.
23
- #
24
22
 
25
23
  module HelloSign
26
24
  module Resource
27
- #
28
25
  # Stores the value of a hash. Use missing_method to create method to access it like an object
29
26
  #
30
27
  # @author [hellosign]
31
- #
28
+
32
29
  class BaseResource
33
30
 
34
31
  attr_reader :data, :raw_data, :warnings, :headers
35
- #
36
- # recursively convert hash data into BaseResource.
32
+
33
+ # Converts hash data recursively into BaseResource.
37
34
  #
38
35
  # @param hash [Hash] Data of the resource
39
36
  # @param key [String] (nil) Key of the hash, point to where resource data is. If nil, then the hash itself.
@@ -58,15 +55,14 @@ module HelloSign
58
55
  end
59
56
  end
60
57
 
61
- #
62
- # Magic method, give class dynamic methods based on hash keys.
58
+ # Magic method, gives class dynamic methods based on hash keys.
63
59
  # If initialized hash has a key which matches the method name, return value of that key.
64
60
  # Otherwise, return nil.
65
61
  #
66
62
  # @param method [Symbol] Method's name
67
63
  #
68
64
  # @example
69
- # resource = BaseResource.new :email_address => "me@example.com"
65
+ # resource = BaseResource.new email_address: "me@example.com"
70
66
  # resource.email_address => "me@example.com"
71
67
  # resource.not_in_hash_keys => nil
72
68
  def method_missing(method)
@@ -0,0 +1,43 @@
1
+ # The MIT License (MIT)
2
+ #
3
+ # Copyright (C) 2014 hellosign.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.
22
+
23
+ module HelloSign
24
+ module Resource
25
+ # Contains information about a BulkSendJob.
26
+ # Take a look at our API Documentation on BulkSendJobs (https://app.hellosign.com/api/reference#BulkSendJob)
27
+ # for more information about this.
28
+ #
29
+ # @author [hellosign]
30
+
31
+ class BulkSendJob < BaseResource
32
+
33
+ # Creates a new BulkSendJob from a hash. If a key is defined then account data with be the value of hash[key], otherwise the hash itself.
34
+ # @param hash [Hash] BulkSendJob's data
35
+ # @param key [String] (bulk_send_job) Key of the hash, point to where BulkSendJob data is. If nil, then the hash itself.
36
+ #
37
+ # @return [HelloSign::Resource::BulkSendJob] a BulkSendJob
38
+ def initialize(hash, key='bulk_send_job')
39
+ super
40
+ end
41
+ end
42
+ end
43
+ end
@@ -1,4 +1,3 @@
1
- #
2
1
  # The MIT License (MIT)
3
2
  #
4
3
  # Copyright (C) 2014 hellosign.com
@@ -20,24 +19,22 @@
20
19
  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
21
  # SOFTWARE.
23
- #
24
22
 
25
23
  module HelloSign
26
24
  module Resource
27
- #
28
- # An object that contains necessary information to set up Embedded signing.
25
+ # Contains information about Embedded workflows.
29
26
  # Take a look at our Embedded Signing Walkthrough (https://app.hellosign.com/api/embeddedSigningWalkthrough)
30
27
  # for more information about this.
31
28
  #
32
29
  # @author [hellosign]
33
- #
30
+
34
31
  class Embedded < BaseResource
32
+
33
+ # Creates a new Embedded resource from a hash. If a key is defined then embedded data with be the value of hash[key], otherwise the hash itself.
34
+ # @param hash [Hash] Embedded's data
35
+ # @param key [String] (embedded) Key of the hash, point to where Embedded data is. If nil, then the hash itself.
35
36
  #
36
- # create a new Embedded resource from a hash. If a key is defined then embedded data with be the value of hash[key], otherwise the hash itself.
37
- # @param hash [Hash] Embedded's data
38
- # @param key [String] (embedded) Key of the hash, point to where Embedded data is. If nil, then the hash itself.
39
- #
40
- # @return [HelloSign::Resource:Embedded] an Embedded resource
37
+ # @return [HelloSign::Resource::Embedded] an Embedded resource
41
38
  def initialize(hash, key='embedded')
42
39
  super
43
40
  end