hellosign-api 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +15 -0
  5. data/CONTRIBUTING.md +42 -0
  6. data/Gemfile +13 -0
  7. data/Guardfile +14 -0
  8. data/LICENSE +21 -0
  9. data/README.md +112 -0
  10. data/Rakefile +16 -0
  11. data/hellosign-api.gemspec +54 -0
  12. data/lib/hello_sign/.error.rb.swp +0 -0
  13. data/lib/hello_sign/api/account.rb +78 -0
  14. data/lib/hello_sign/api/api_app.rb +121 -0
  15. data/lib/hello_sign/api/bulk_send_job.rb +62 -0
  16. data/lib/hello_sign/api/embedded.rb +68 -0
  17. data/lib/hello_sign/api/oauth.rb +95 -0
  18. data/lib/hello_sign/api/signature_request.rb +691 -0
  19. data/lib/hello_sign/api/team.rb +107 -0
  20. data/lib/hello_sign/api/template.rb +227 -0
  21. data/lib/hello_sign/api/unclaimed_draft.rb +328 -0
  22. data/lib/hello_sign/api.rb +31 -0
  23. data/lib/hello_sign/client.rb +372 -0
  24. data/lib/hello_sign/configuration.rb +78 -0
  25. data/lib/hello_sign/error.rb +99 -0
  26. data/lib/hello_sign/resource/account.rb +43 -0
  27. data/lib/hello_sign/resource/api_app.rb +43 -0
  28. data/lib/hello_sign/resource/base_resource.rb +73 -0
  29. data/lib/hello_sign/resource/bulk_send_job.rb +43 -0
  30. data/lib/hello_sign/resource/embedded.rb +43 -0
  31. data/lib/hello_sign/resource/resource_array.rb +56 -0
  32. data/lib/hello_sign/resource/signature_request.rb +43 -0
  33. data/lib/hello_sign/resource/team.rb +43 -0
  34. data/lib/hello_sign/resource/template.rb +43 -0
  35. data/lib/hello_sign/resource/template_draft.rb +44 -0
  36. data/lib/hello_sign/resource/unclaimed_draft.rb +44 -0
  37. data/lib/hello_sign/resource.rb +33 -0
  38. data/lib/hello_sign/version.rb +25 -0
  39. data/lib/hello_sign.rb +50 -0
  40. data/lib/hellosign-ruby-sdk.rb +4 -0
  41. data/spec/fixtures/account.json +15 -0
  42. data/spec/fixtures/api_app.json +16 -0
  43. data/spec/fixtures/api_apps.json +43 -0
  44. data/spec/fixtures/bulk_send_job.json +88 -0
  45. data/spec/fixtures/bulk_send_jobs.json +22 -0
  46. data/spec/fixtures/embedded.json +6 -0
  47. data/spec/fixtures/empty.pdf +0 -0
  48. data/spec/fixtures/error.json +6 -0
  49. data/spec/fixtures/file.json +0 -0
  50. data/spec/fixtures/headers.json +18 -0
  51. data/spec/fixtures/nda.pdf +0 -0
  52. data/spec/fixtures/signature_request.json +45 -0
  53. data/spec/fixtures/signature_requests.json +44 -0
  54. data/spec/fixtures/team.json +15 -0
  55. data/spec/fixtures/template.json +53 -0
  56. data/spec/fixtures/templates.json +59 -0
  57. data/spec/fixtures/token.json +14 -0
  58. data/spec/fixtures/unclaimed_draft.json +6 -0
  59. data/spec/hello_sign/.error_spec.rb.swp +0 -0
  60. data/spec/hello_sign/api/account_spec.rb +42 -0
  61. data/spec/hello_sign/api/api_app_spec.rb +104 -0
  62. data/spec/hello_sign/api/bulk_send_job_spec.rb +53 -0
  63. data/spec/hello_sign/api/embedded_spec.rb +23 -0
  64. data/spec/hello_sign/api/oauth_spec.rb +27 -0
  65. data/spec/hello_sign/api/signature_request_spec.rb +268 -0
  66. data/spec/hello_sign/api/team_spec.rb +101 -0
  67. data/spec/hello_sign/api/template_spec.rb +172 -0
  68. data/spec/hello_sign/api/unclaimed_draft_spec.rb +145 -0
  69. data/spec/hello_sign/client_spec.rb +191 -0
  70. data/spec/hello_sign/error_spec.rb +10 -0
  71. data/spec/hello_sign/resource/base_resource_spec.rb +53 -0
  72. data/spec/hello_sign_spec.rb +57 -0
  73. data/spec/scenarios/uploads_spec.rb +19 -0
  74. data/spec/spec_helper.rb +104 -0
  75. metadata +261 -0
@@ -0,0 +1,31 @@
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
+ require 'hello_sign/api/account'
24
+ require 'hello_sign/api/embedded'
25
+ require 'hello_sign/api/template'
26
+ require 'hello_sign/api/signature_request'
27
+ require 'hello_sign/api/team'
28
+ require 'hello_sign/api/unclaimed_draft'
29
+ require 'hello_sign/api/oauth'
30
+ require 'hello_sign/api/api_app'
31
+ require 'hello_sign/api/bulk_send_job'
@@ -0,0 +1,372 @@
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
+ require 'faraday'
24
+ require 'faraday/multipart'
25
+ require 'multi_json'
26
+ require 'mime/types'
27
+ require 'hello_sign/error'
28
+ require 'hello_sign/configuration'
29
+ require 'hello_sign/resource'
30
+ require 'hello_sign/api'
31
+ require 'logger'
32
+
33
+ module HelloSign
34
+
35
+ # You'll need the HelloSign::Client to do just about everything, from creating
36
+ # signatures to updating account information.
37
+ #
38
+ # @author [hellosign]
39
+ class Client
40
+ include Api::Account
41
+ include Api::SignatureRequest
42
+ include Api::Template
43
+ include Api::Team
44
+ include Api::UnclaimedDraft
45
+ include Api::Embedded
46
+ include Api::OAuth
47
+ include Api::ApiApp
48
+ include Api::BulkSendJob
49
+
50
+ 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
51
+
52
+ ERRORS = {
53
+ 400 => Error::BadRequest,
54
+ 401 => Error::Unauthorized,
55
+ 402 => Error::PaidApiPlanRequired,
56
+ 403 => Error::Forbidden,
57
+ 404 => Error::NotFound,
58
+ 405 => Error::MethodNotAllowed,
59
+ 409 => Error::Conflict,
60
+ 410 => Error::Gone,
61
+ 429 => Error::ExceededRate,
62
+ 500 => Error::InternalServerError,
63
+ 502 => Error::BadGateway,
64
+ 503 => Error::ServiceUnavailable
65
+ }
66
+
67
+ # Initiates a new HelloSign Client
68
+ # @option opts [String] email_address The account's email address. (optional)
69
+ # @option opts [String] password The account's password, if authenticating with an email_address. (optional)
70
+ # @option opts [String] api_key The account's API key.
71
+ #
72
+ # @return [HelloSign::Client] a new HelloSign::Client
73
+ #
74
+ # @example Authenticating with username and password
75
+ # client = HelloSign::Client.new email_address: 'me@example.com', password: 'mypassword'
76
+ #
77
+ # @example Authenticating with API key
78
+ # client = HelloSign::Client.new api_key: '1234567890123456789012345678901234567890123456789012345678901234'
79
+ def initialize(opts={})
80
+ options = HelloSign.options.merge(opts)
81
+ HelloSign::Configuration::VALID_OPTIONS_KEYS.each do |key|
82
+ self.send("#{key}=", options[key])
83
+ end
84
+ end
85
+
86
+ # Makes an HTTP GET request
87
+ # @param path [String] Relative path of the request.
88
+ # @option options [Hash] params Params of the URL.
89
+ def get(path, options={})
90
+ response = request(path, :get, options)
91
+ validate response
92
+ parsed_response = parse response
93
+ data = { headers: response.headers, body: parsed_response }
94
+ end
95
+
96
+ # Makes an HTTP POST request
97
+ # @param path [String] Relative path of the request.
98
+ # @option options [Hash] params Params of the URL.
99
+ # @option options [Hash] body Body of the request.
100
+ def post(path, options={})
101
+ response = request(path, :post, options)
102
+ validate response
103
+ parsed_response = parse response
104
+ data = { headers: response.headers, body: parsed_response }
105
+ end
106
+
107
+ # Makes an HTTP PUT request
108
+ # @param path [String] Relative path of the request.
109
+ # @option options [Hash] params Params of the URL.
110
+ # @option options [Hash] body Body of the request.
111
+ def put(path, options={})
112
+ response = request(path, :put, options)
113
+ validate response
114
+ responsed_response = parse response
115
+ data = { headers: response.headers, body: parsed_response }
116
+ end
117
+
118
+ # Makes an HTTP DELETE request
119
+ # @param path [String] Relative path of the request.
120
+ # @option options [Hash] Params of the URL.
121
+ def delete(path, options={})
122
+ response = request(path, :delete, options)
123
+ validate response
124
+ parsed_response = parse response
125
+ data = { headers: response.headers, body: parsed_response }
126
+ end
127
+
128
+ private
129
+
130
+ def request(path, method, options={})
131
+ make_connection(options).send method do |request|
132
+ if options[:oauth_request]
133
+ request.url path, options[:params]
134
+ else
135
+ request.url "#{api_version}#{path}", options[:params]
136
+ end
137
+ request.body = options[:body]
138
+ end
139
+ end
140
+
141
+ def make_connection options
142
+ url = options[:oauth_request] ? oauth_end_point : end_point
143
+
144
+ if @logging
145
+ logger = Logger.new(STDOUT)
146
+ logger.level = @log_level
147
+ end
148
+
149
+ connection = Faraday.new(:url => url, :headers => { user_agent: user_agent }) do |faraday|
150
+ faraday.request :multipart
151
+ faraday.request :url_encoded
152
+ faraday.response :logger, logger if @logging
153
+ faraday.adapter :net_http
154
+ faraday.options[:timeout] = timeout if timeout
155
+ end
156
+
157
+ if options[:no_auth]
158
+ elsif auth_token
159
+ connection.authorization :Bearer, auth_token
160
+ elsif api_key
161
+ connection.basic_auth api_key, ''
162
+ elsif email_address
163
+ connection.basic_auth email_address, password
164
+ else
165
+ end
166
+ if proxy_uri
167
+ connection.options.proxy = {
168
+ :uri => proxy_uri.nil? ? nil : URI(proxy_uri),
169
+ :user => proxy_user,
170
+ :password => proxy_pass
171
+ }
172
+ end
173
+ connection
174
+ end
175
+
176
+ def validate(response)
177
+ if response.status >= 400
178
+ error_class = ERRORS[response.status] || HelloSign::Error::UnknownError
179
+ error = error_class.new(response.status, response.body, response.to_hash[:url].to_s)
180
+ raise error
181
+ end
182
+ end
183
+
184
+ def parse(response)
185
+ if response['content-type'] == 'application/pdf'
186
+ response.body
187
+ elsif response['content-type'] == 'application/zip'
188
+ response.body
189
+ elsif response.body.strip.empty?
190
+ {}
191
+ else
192
+ MultiJson.load response.body.strip
193
+ end
194
+ end
195
+
196
+ def MIMEfromName(name)
197
+ parts = name.split('.')
198
+ # defaults to pdf if no extension provided
199
+ if parts.length < 2
200
+ return 'application/pdf'
201
+ end
202
+ extension = parts[-1]
203
+ types = MIME::Types.type_for(extension)
204
+ types[0]
205
+ end
206
+
207
+ def MIMEfromIO(file)
208
+ begin
209
+ path = File.path file
210
+ MIMEfromName path
211
+ # in case of error in type detection, return default type
212
+ rescue
213
+ return 'application/pdf'
214
+ end
215
+ end
216
+
217
+ def prepare_files(opts)
218
+ if opts[:files]
219
+ opts[:files].each_with_index do |file, index|
220
+ if file.is_a? String
221
+ if File.file?(file)
222
+ mime_type = MIMEfromName file
223
+ opts[:"file[#{index}]"] = Faraday::UploadIO.new(file, mime_type)
224
+ else
225
+ raise HelloSign::Error::FileNotFound.new "#{file} was not found on the filesystem"
226
+ end
227
+ elsif file.is_a? File
228
+ mime_type = MIMEfromIO file
229
+ opts[:"file[#{index}]"] = Faraday::UploadIO.new(file, mime_type)
230
+ elsif file.is_a? StringIO
231
+ opts[:"file[#{index}]"] = Faraday::UploadIO.new(file, 'application/pdf')
232
+ elsif defined? ActionDispatch::Http::UploadedFile
233
+ if file.is_a? ActionDispatch::Http::UploadedFile
234
+ mime_type = MIMEfromIO file
235
+ opts[:"file[#{index}]"] = UploadIO.new(file.tempfile, mime_type, file.original_filename)
236
+ end
237
+ else
238
+ raise HelloSign::Error::NotSupportedType.new "#{file.class} is not a supported. Must be a string or ActionDispatch::Http::UploadedFile"
239
+ end
240
+ end
241
+ opts.delete(:files)
242
+ elsif opts[:file_urls]
243
+ opts[:file_urls].each_with_index do |file, index|
244
+ opts[:"file_url[#{index}]"] = file
245
+ end
246
+ opts.delete(:file_urls)
247
+ end
248
+ end
249
+
250
+ # Takes options given to an API endpoint as a hash, plus an array of parameters (as symbols), and creates a
251
+ # query string out of any listed parameters present (that also have values)
252
+
253
+ def create_query_string(opts, parameterList)
254
+ result = ""
255
+ is_first = true
256
+ parameterList.each do |param|
257
+ if (opts.has_key?(param) && opts[param])
258
+ if (!is_first)
259
+ result += "&"
260
+ end
261
+ is_first = false
262
+ result += "#{param}=#{opts[param]}"
263
+ end
264
+ end
265
+ if (result.length > 0)
266
+ result = "?" + result
267
+ end
268
+ result
269
+ end
270
+
271
+ def create_search_string(raw_string)
272
+ raw_string.tr(" ", "+")
273
+ end
274
+
275
+ def prepare_signers(opts)
276
+ if opts[:signers]
277
+ prepare opts, :signers
278
+ elsif opts[:signer_group]
279
+ prepare_signer_group opts, :signer_group
280
+ end
281
+ end
282
+
283
+ def prepare_ccs(opts)
284
+ prepare opts, :ccs
285
+ end
286
+
287
+ def prepare_templates(opts)
288
+ prepare opts, :template_ids
289
+ end
290
+
291
+ def prepare_signer_roles(opts)
292
+ prepare opts, :signer_roles
293
+ end
294
+
295
+ def prepare_attachments(opts)
296
+ prepare opts, :attachments
297
+ end
298
+
299
+ def prepare_form_fields(opts)
300
+ if (opts[:form_fields_per_document] and opts[:form_fields_per_document].is_a? Array)
301
+ opts[:form_fields_per_document] = MultiJson.dump(opts[:form_fields_per_document])
302
+ end
303
+ # ignore if it's already a string, or not present
304
+ end
305
+
306
+ def prepare_custom_fields(opts)
307
+ if (opts[:custom_fields] and opts[:custom_fields].is_a? Array)
308
+ opts[:custom_fields] = MultiJson.dump(opts[:custom_fields])
309
+ end
310
+ # ignore if it's already a string, or not present
311
+ end
312
+
313
+ def prepare_merge_fields(opts)
314
+ if (opts[:merge_fields] and opts[:merge_fields].is_a? Array)
315
+ opts[:merge_fields] = MultiJson.dump(opts[:merge_fields])
316
+ end
317
+ # ignore if it's already a string, or not present
318
+ end
319
+
320
+ def prepare_bulk_signers(opts)
321
+ if opts[:signer_file]
322
+ file = opts[:signer_file]
323
+ mime_type = MIMEfromIO file
324
+ opts[:signer_file] = Faraday::UploadIO.new(file, mime_type)
325
+ elsif opts[:signer_list]
326
+ opts[:signer_list] = MultiJson.dump(opts[:signer_list])
327
+ else
328
+ raise HelloSign::Error::NotSupportedType.new "Upload a CSV file or JSON list of signers"
329
+ end
330
+ end
331
+
332
+ def prepare(opts, key)
333
+ return unless opts[key]
334
+ opts[key].each_with_index do |value, index|
335
+ if value.is_a? String
336
+ opts[:"#{key}[#{index}]"] = value
337
+ else
338
+ if value[:role]
339
+ opts[:"#{key}[#{value[:role]}]"] = value
340
+ value.delete(:role)
341
+ else
342
+ opts[:"#{key}[#{index}]"] = value
343
+ end
344
+ end
345
+ end
346
+ opts.delete(key)
347
+ end
348
+
349
+ def prepare_signer_group(opts, key)
350
+ opts[key].each_with_index do |value, index|
351
+ if value[:role]
352
+ group_index_or_role = value[:role]
353
+ else
354
+ group_index_or_role = index
355
+ end
356
+
357
+ opts[:"signers[#{group_index_or_role}][group]"] = value[:group_name]
358
+ opts[key] = value[:signers]
359
+ prepare_signers_for_group(value[:signers], group_index_or_role, opts)
360
+ end
361
+ opts.delete(key)
362
+ end
363
+
364
+ def prepare_signers_for_group(signers, group_index_or_role, opts)
365
+ signers.each_with_index do |signer, index|
366
+ signer.each do |param, data|
367
+ opts[:"signers[#{group_index_or_role}][#{index}][#{param}]"] = data
368
+ end
369
+ end
370
+ end
371
+ end
372
+ end
@@ -0,0 +1,78 @@
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
+
25
+ # Defines config attributes and default values for HelloSign module
26
+ #
27
+ # @author [hellosign]
28
+ module Configuration
29
+ DEFAULT_ENDPOINT = 'https://api.hellosign.com'
30
+ DEFAULT_API_VERSION = '/v3'
31
+ DEFAULT_OAUTH_ENDPOINT = 'https://app.hellosign.com'
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]
33
+
34
+ DEFAULT_USER_AGENT = "hellosign-ruby-sdk/" + HelloSign::VERSION
35
+
36
+ attr_accessor *VALID_OPTIONS_KEYS
37
+
38
+ # Sets all configuration options to their default values
39
+ # when this module is extended.
40
+ #
41
+ # @param base [Object] New module or class extends this module
42
+ def self.extended(base)
43
+ base.reset
44
+ end
45
+
46
+ # Convenience method to allow configuration options to be set in a block.
47
+ def configure
48
+ yield self
49
+ end
50
+
51
+ # Creates a hash of options
52
+ def options
53
+ VALID_OPTIONS_KEYS.inject({}) do |option, key|
54
+ option.merge!(key => send(key))
55
+ end
56
+ end
57
+
58
+ # Resets all configuration options to the defaults.
59
+ def reset
60
+ self.email_address = nil
61
+ self.client_id = nil
62
+ self.client_secret = nil
63
+ self.auth_token = nil
64
+ self.password = nil
65
+ self.api_key = nil
66
+ self.end_point = DEFAULT_ENDPOINT
67
+ self.oauth_end_point = DEFAULT_OAUTH_ENDPOINT
68
+ self.api_version = DEFAULT_API_VERSION
69
+ self.user_agent = DEFAULT_USER_AGENT
70
+ self.log_level = 3
71
+ self.logging = true
72
+ self.proxy_uri = nil
73
+ self.proxy_user = nil
74
+ self.proxy_pass = nil
75
+ self.timeout = nil
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,99 @@
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 Error
25
+
26
+ # Custom error class for rescuing from all HelloSign errors.
27
+ class Error < StandardError;
28
+ attr_accessor :request_uri, :response_body, :response_status
29
+
30
+ def initialize(response_status, response_body = nil, request_uri = nil)
31
+ @request_uri = request_uri
32
+ @response_body = response_body
33
+ @response_status = response_status
34
+ super(human_readable_message)
35
+ end
36
+
37
+ private
38
+ def human_readable_message
39
+ "Server responded with code #{@response_status}\n" \
40
+ "Request URI: #{@request_uri}\n"\
41
+ "Message: #{@response_body}"
42
+ end
43
+ end
44
+
45
+ # Raised when attributes are missing.
46
+ class MissingAttributes < Error; end
47
+
48
+ # Raised when API endpoint credentials not configured.
49
+ class MissingCredentials < Error; end
50
+
51
+ # Raised when impossible to parse response body.
52
+ class Parsing < Error; end
53
+
54
+ # Raised when API endpoint returns the HTTP status code 400.
55
+ class BadRequest < Error; end
56
+
57
+ # Raised when API endpoint returns the HTTP status code 401.
58
+ class Unauthorized < Error; end
59
+
60
+ # Raised when API endpoint returns the HTTP status code 402.
61
+ class PaidApiPlanRequired < Error; end
62
+
63
+ # Raised when API endpoint returns the HTTP status code 403.
64
+ class Forbidden < Error; end
65
+
66
+ # Raised when API endpoint returns the HTTP status code 404.
67
+ class NotFound < Error; end
68
+
69
+ # Raised when API endpoint returns the HTTP status code 405.
70
+ class MethodNotAllowed < Error; end
71
+
72
+ # Raised when API endpoint returns the HTTP status code 409.
73
+ class Conflict < Error; end
74
+
75
+ # Raised when API endpoint returns the HTTP status code 410.
76
+ class Gone < Error; end
77
+
78
+ # Raised when API endpoint returns the HTTP status code 500.
79
+ class InternalServerError < Error; end
80
+
81
+ # Raised when API endpoint returns the HTTP status code 429.
82
+ class ExceededRate < Error; end
83
+
84
+ # Raised when API endpoint returns the HTTP status code 502.
85
+ class BadGateway < Error; end
86
+
87
+ # Raised when API endpoint returns the HTTP status code 503.
88
+ class ServiceUnavailable < Error; end
89
+
90
+ # Raised when API endpoint returns the HTTP status code 503.
91
+ class NotSupportedType < Error; end
92
+
93
+ # Raised when a file attempted to be sent in a request doesn't exist
94
+ class FileNotFound < Error; end
95
+
96
+ # Raised when API endpoint returns error which is not defined in sdk.
97
+ class UnknownError < Error; end
98
+ end
99
+ end
@@ -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 an Account and its settings.
26
+ # Take a look at our API Documentation on the Account resource (https://app.hellosign.com/api/reference#Account)
27
+ # for more information about this.
28
+ #
29
+ # @author [hellosign]
30
+
31
+ class Account < BaseResource
32
+
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.
34
+ # @param hash [Hash] Account's data
35
+ # @param key [String] (account) key of the hash, point to where Account data is. If nil, then the hash itself.
36
+ #
37
+ # @return [HelloSign::Resource::Account] an Account
38
+ def initialize(hash, key='account')
39
+ super
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,43 @@
1
+ # The MIT License (MIT)
2
+ #
3
+ # Copyright (C) 2015 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 the ApiApp resource.
26
+ # Take a look at our API Documentation for ApiApps (https://app.hellosign.com/api/reference#ApiApp)
27
+ # for more information about this.
28
+ #
29
+ # @author [hellosign]
30
+
31
+ class ApiApp < BaseResource
32
+
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.
34
+ # @param hash [Hash] ApiApp data
35
+ # @param key [String] (api_app) key of the hash, point to where ApiApp data is. If nil, then the hash itself.
36
+ #
37
+ # @return [HelloSign::Resource::ApiApp] an ApiApp
38
+ def initialize(hash, key='api_app')
39
+ super
40
+ end
41
+ end
42
+ end
43
+ end