hellosign-ruby-sdk 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,56 @@
1
+ module HelloSign
2
+
3
+
4
+ #
5
+ # Define config attributes and default values for HelloSign module
6
+ #
7
+ # @author [hellosign]
8
+ #
9
+ module Configuration
10
+ DEFAULT_ENDPOINT = 'https://api.hellosign.com'
11
+ DEFAULT_API_VERSION = '/v3'
12
+ DEFAULT_OAUTH_ENDPOINT = "https://www.hellosign.com"
13
+ 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]
14
+
15
+
16
+ DEFAULT_USER_AGENT = "hellosign-ruby-sdk #{HelloSign::VERSION}"
17
+
18
+ attr_accessor *VALID_OPTIONS_KEYS
19
+
20
+ # Sets all configuration options to their default values
21
+ # when this module is extended.
22
+ #
23
+ # @param base [Object] new module or class extend thid module
24
+ def self.extended(base)
25
+ base.reset
26
+ end
27
+
28
+ # Convenience method to allow configuration options to be set in a block.
29
+ def configure
30
+ yield self
31
+ end
32
+
33
+ # Creates a hash of options
34
+ def options
35
+ VALID_OPTIONS_KEYS.inject({}) do |option, key|
36
+ option.merge!(key => send(key))
37
+ end
38
+ end
39
+
40
+ # Resets all configuration options to the defaults.
41
+ def reset
42
+ self.email_address = nil
43
+ self.client_id = nil
44
+ self.client_secret = nil
45
+ self.auth_token = nil
46
+ self.password = nil
47
+ self.api_key = nil
48
+ self.end_point = DEFAULT_ENDPOINT
49
+ self.oauth_end_point = DEFAULT_OAUTH_ENDPOINT
50
+ self.api_version = DEFAULT_API_VERSION
51
+ self.user_agent = DEFAULT_USER_AGENT
52
+ self.log_level = 3
53
+ self.logging = true
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,48 @@
1
+ module HelloSign
2
+ module Error
3
+ # Custom error class for rescuing from all HelloSign errors.
4
+ class Error < StandardError; end
5
+
6
+ # Raise when attributes are missing.
7
+ class MissingAttributes < Error; end
8
+
9
+ # Raised when API endpoint credentials not configured.
10
+ class MissingCredentials < Error; end
11
+
12
+ # Raised when impossible to parse response body.
13
+ class Parsing < Error; end
14
+
15
+ # Raised when API endpoint returns the HTTP status code 400.
16
+ class BadRequest < Error; end
17
+
18
+ # Raised when API endpoint returns the HTTP status code 401.
19
+ class Unauthorized < Error; end
20
+
21
+ # Raised when API endpoint returns the HTTP status code 403.
22
+ class Forbidden < Error; end
23
+
24
+ # Raised when API endpoint returns the HTTP status code 404.
25
+ class NotFound < Error; end
26
+
27
+ # Raised when API endpoint returns the HTTP status code 405.
28
+ class MethodNotAllowed < Error; end
29
+
30
+ # Raised when API endpoint returns the HTTP status code 409.
31
+ class Conflict < Error; end
32
+
33
+ # Raised when API endpoint returns the HTTP status code 410.
34
+ class Gone < Error; end
35
+
36
+ # Raised when API endpoint returns the HTTP status code 500.
37
+ class InternalServerError < Error; end
38
+
39
+ # Raised when API endpoint returns the HTTP status code 502.
40
+ class BadGateway < Error; end
41
+
42
+ # Raised when API endpoint returns the HTTP status code 503.
43
+ class ServiceUnavailable < Error; end
44
+
45
+ # Raised when API endpoint returns the HTTP status code 503.
46
+ class NotSupportedType < Error; end
47
+ end
48
+ end
@@ -0,0 +1,8 @@
1
+ require 'hello_sign/resource/base_resource'
2
+ require 'hello_sign/resource/resource_array'
3
+ require 'hello_sign/resource/account'
4
+ require 'hello_sign/resource/embedded'
5
+ require 'hello_sign/resource/template'
6
+ require 'hello_sign/resource/signature_request'
7
+ require 'hello_sign/resource/team'
8
+ require 'hello_sign/resource/unclaimed_draft'
@@ -0,0 +1,24 @@
1
+ module HelloSign
2
+ module Resource
3
+
4
+ #
5
+ # Contains information about an account and its settings.
6
+ # Take a look at our {https://www.hellosign.com/api/reference#Account account resource document}
7
+ # for more information about this.
8
+ #
9
+ # @author [hellosign]
10
+ #
11
+ class Account < BaseResource
12
+
13
+ #
14
+ # Create a new Account from a hash. If key defined then account data with be the value of hash[key], otherwise the hash itself
15
+ # @param hash [Hash] account's data
16
+ # @param key [String] (account) key of the hash, point to where account data is. If nil then the hash itself
17
+ #
18
+ # @return [HelloSign::Resource:Account] a Account resource
19
+ def initialize(hash, key='account')
20
+ super
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,60 @@
1
+ module HelloSign
2
+ module Resource
3
+
4
+ #
5
+ # Store the value of a hash. Use missing_method to create method to access it like an object
6
+ #
7
+ # @author [hellosign]
8
+ #
9
+ class BaseResource
10
+
11
+
12
+ #
13
+ # recursively convert hash data into BaseResource.
14
+ #
15
+ # @param hash [Hash] data of the resource
16
+ # @param key [String] (nil) key of the hash, point to where resource data is. If nil then the hash itself
17
+ #
18
+ # @return [HelloSign::Resource::BaseResource] a new BaseResource
19
+ def initialize(hash, key=nil)
20
+ @raw_data = key ? hash[key] : hash
21
+ @data = @raw_data.inject({}) do |data, (key,value)|
22
+ data[key.to_s] = if value.is_a? Hash
23
+ value = BaseResource.new(value)
24
+ elsif ((value.is_a? Array) && (value[0].is_a? Hash))
25
+ value = value.map {|v| BaseResource.new(v)}
26
+ else
27
+ value
28
+ end
29
+ data
30
+ end
31
+ end
32
+
33
+
34
+ #
35
+ # Magic method, give class dynamic methods based on hash keys.
36
+ #
37
+ # If initialized hash has a key which matches the method name, return value of that key.
38
+ #
39
+ # Otherwise, return nil
40
+ #
41
+ # @param method [Symbol] Method's name
42
+ #
43
+ # @example
44
+ # resource = BaseResource.new :email_address => "me@example.com"
45
+ # resource.email_address # => "me@example.com"
46
+ # resource.not_in_hash_keys # => nil
47
+ def method_missing(method)
48
+ @data.key?(method.to_s) ? @data[method.to_s] : nil
49
+ end
50
+
51
+ #
52
+ # raw response data from the server in json
53
+ #
54
+ # @return [type] [description]
55
+ def data
56
+ @raw_data
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,24 @@
1
+ module HelloSign
2
+ module Resource
3
+
4
+ #
5
+ # An object that contains necessary information to set up embedded signing.
6
+ # Take a look at our {https://www.hellosign.com/api/reference#Embedded account resource document}
7
+ # for more information about this.
8
+ #
9
+ # @author [hellosign]
10
+ #
11
+ class Embedded < BaseResource
12
+
13
+ #
14
+ # 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
15
+ # @param hash [Hash] embedded's data
16
+ # @param key [String] (embedded) key of the hash, point to where embedded data is. If nil then the hash itself
17
+ #
18
+ # @return [HelloSign::Resource:Embedded] a Embedded resource
19
+ def initialize(hash, key='embedded')
20
+ super
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,33 @@
1
+ require 'pry'
2
+ module HelloSign
3
+ module Resource
4
+
5
+ #
6
+ # Stores an array of HelloSign BaseResource with paging information
7
+ #
8
+ # @author [hellosign]
9
+ #
10
+ class ResourceArray < Array
11
+ attr_reader :page, :num_pages, :num_results, :page_size
12
+
13
+
14
+ #
15
+ # create a new ResourceArray from a hash
16
+ #
17
+ # @param hash [Hash] data of the array
18
+ # @param key [String] key of the hash, point to where resource array data is
19
+ # @param resource_class [Class] a Resource Class object inherited from BaseResource. Use the created array item from hash[key]
20
+ #
21
+ # @return [type] [description]
22
+ def initialize(hash, key, resource_class)
23
+ @page = hash['list_info']['page']
24
+ @num_pages = hash['list_info']['num_pages']
25
+ @num_results = hash['list_info']['num_results']
26
+ @page_size = hash['list_info']['page_size']
27
+ hash[key] && hash[key].each do |resouce|
28
+ self << resource_class.new(resouce, nil)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,25 @@
1
+ module HelloSign
2
+ module Resource
3
+
4
+ #
5
+ # Contains information regarding documents that need to be signed
6
+ # Take a look at our {https://www.hellosign.com/api/reference#SignatureRequest signature request resource document}
7
+ # for more information about this.
8
+ #
9
+ # @author [hellosign]
10
+ #
11
+ class SignatureRequest < BaseResource
12
+
13
+ #
14
+ # create a new SignatureRequest from a hash. If a key is defined then account data with be the value of hash[key], otherwise the hash itself
15
+ # @param hash [Hash] signature request's data
16
+ # @param key [String] (signature_request) key of the hash, point to where signature request data is. If nil then the hash itself
17
+ #
18
+ #
19
+ # @return [HelloSign::Resource::SignatureRequest] a SignatureRequest resource
20
+ def initialize(hash, key='signature_request')
21
+ super
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,24 @@
1
+ module HelloSign
2
+ module Resource
3
+
4
+ #
5
+ # Contains information about an team and its members.
6
+ # Take a look at our {https://www.hellosign.com/api/reference#Team team resource document}
7
+ # for more information about this.
8
+ #
9
+ # @author [hellosign]
10
+ #
11
+ class Team < BaseResource
12
+
13
+ #
14
+ # create a new Team from a hash. If a key is defined then team data with be the value of hash[key], otherwise the hash itself
15
+ # @param hash [Hash] team's data
16
+ # @param key [String] (team) key of the hash, point to where team data is. If nil then the hash itself
17
+ #
18
+ # @return [HelloSign::Resource:Team] a Team resource
19
+ def initialize(hash, key='team')
20
+ super
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ module HelloSign
2
+ module Resource
3
+
4
+ #
5
+ # Contains information about the templates you and your team have created
6
+ #
7
+ # Take a look at our {https://www.hellosign.com/api/reference#Template Template resource document}
8
+ # for more information about this.
9
+ #
10
+ # @author [hellosign]
11
+ #
12
+ class Template < BaseResource
13
+
14
+ #
15
+ # create a new Template from a hash. If a key is defined then template data will be the value of hash[key], otherwise the hash itself
16
+ # @param hash [Hash] template's data
17
+ # @param key [String] (template) key of the hash, point to where template data is. If nil then the hash itself
18
+ #
19
+ # @return [HelloSign::Resource:Team] a Team resource
20
+ def initialize(hash, key='template')
21
+ super
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ module HelloSign
2
+ module Resource
3
+
4
+ #
5
+ # A group of documents that a user can take ownership of by going to the claim URL
6
+ # Take a look at our {https://www.hellosign.com/api/reference#UnclaimedDraft unclaimed draft resource document}
7
+ # for more information about this.
8
+ #
9
+ # @author [hellosign]
10
+ #
11
+ class UnclaimedDraft < BaseResource
12
+
13
+ #
14
+ # create a new UnclaimedDraft from a hash. If a key is defined then unclaimed draft data with be the value of hash[key], otherwise the hash itself
15
+ # @param hash [Hash] unclaimed draft's data
16
+ # @param key [String] (unclaimed_draft) key of the hash, point to where unclaimed draft data is. If nil then the hash itself
17
+ #
18
+ # @return [HelloSign::Resource:Team] a Team resource
19
+ def initialize(hash, key='unclaimed_draft')
20
+ super
21
+ end
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module HelloSign
2
+ VERSION = "3.0.0"
3
+ end
@@ -0,0 +1 @@
1
+ {"account": {"account_id":"123456789", "email_address":"test@example.com", "is_paid_hs":false, "is_paid_hf":false, "quotas":{"templates_left":0, "documents_left":0, "api_signature_requests_left":0}, "callback_url":"https://example.com", "role_code":""}}
@@ -0,0 +1,6 @@
1
+ {
2
+ "embedded": {
3
+ "sign_url": "https://api.hellosign.com/editor/embeddedSign?signature_id=50e3542f738adfa7ddd4cbd4c00d2a8ab6e4194b&amp;token=b6b8e7deaf8f0b95c029dca049356d4a2cf9710a",
4
+ "expires_at": 1396469502
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "error": {
3
+ "error_msg": "Error Message",
4
+ "error_name": "Error Name"
5
+ }
6
+ }
File without changes
@@ -0,0 +1,2 @@
1
+ {"signature_request":{"signature_request_id":"1", "title":"title", "original_title":"original_title", "subject":"subject", "message":"message", "test_mode":false, "is_complete":true, "has_error":false, "custom_fields":[],
2
+ "response_data":[{"name":"name", "value":"value", "type":"signature", "api_id":"api_id", "signature_id":"signature_id"}], "signing_url":"https://example.com/signing_url", "signing_redirect_url":"https://example.com/signing_redirect_url", "final_copy_uri":"/v3/final_copy_url", "files_url":"https://example.com/file_url", "details_url":"https://example.com/details_url", "requester_email_address":"requester_email_address@example.com", "signatures":[{"signature_id":"signature_id", "has_pin":false, "signer_email_address":"signer_email_address@example.com", "signer_name":"signer_name", "order":1, "status_code":"signed", "signed_at":1393389891, "last_viewed_at":1393389853, "last_reminded_at":1393389852}], "cc_email_addresses":[]}}
@@ -0,0 +1,14 @@
1
+ {
2
+ "list_info": {
3
+ "page": 1,
4
+ "num_pages": 1,
5
+ "num_results": 1,
6
+ "page_size": 20
7
+ },
8
+ "signature_requests":[
9
+ {
10
+ "signature_request_id":"1", "title":"title", "original_title":"original_title", "subject":"subject", "message":"message", "test_mode":false, "is_complete":true, "has_error":false, "custom_fields":[],
11
+ "response_data":[{"name":"name", "value":"value", "type":"signature", "api_id":"api_id", "signature_id":"signature_id"}], "signing_url":"https://example.com/signing_url", "signing_redirect_url":"https://example.com/signing_redirect_url", "final_copy_uri":"/v3/final_copy_url", "files_url":"https://example.com/file_url", "details_url":"https://example.com/details_url", "requester_email_address":"requester_email_address@example.com", "signatures":[{"signature_id":"signature_id", "has_pin":false, "signer_email_address":"signer_email_address@example.com", "signer_name":"signer_name", "order":1, "status_code":"signed", "signed_at":1393389891, "last_viewed_at":1393389853, "last_reminded_at":1393389852}], "cc_email_addresses":[]
12
+ }
13
+ ]
14
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "team": {
3
+ "name": "Team HelloSign",
4
+ "accounts": [
5
+ {
6
+ "account_id": "5008b25c7f67153e57d5a357b1687968068fb465",
7
+ "email_address": "me@example.com",
8
+ "role_code": "a"
9
+ },
10
+ {
11
+ "account_id": "d3d3d7b98d80b67d07740df7cdfd1f49fa8e2b82",
12
+ "email_address": "teammate@example.com",
13
+ "role_code": "m"
14
+ }
15
+ ],
16
+ "invited_accounts": [
17
+ ]
18
+ }
19
+ }
@@ -0,0 +1 @@
1
+ {"template":{"template_id":"a364138e0d8ae6393aa425a8ec64715580f3748b","title":"bitcoin","message":"Hello, bitcoin pdf here","is_creator":true,"can_edit":true,"signer_roles":[{"name":"Client","order":null}],"cc_roles":[],"documents":[{"index":"0","name":"bitcoin.pdf","custom_fields":[],"form_fields":[{"name":"","type":"signature","signer":"1","x":501,"y":7498,"width":120,"height":30,"required":true,"api_id":"a1ca72_9"}]}],"custom_fields":[],"named_form_fields":[{"name":"","type":"signature","signer":"1","x":501,"y":7498,"width":120,"height":30,"required":true,"api_id":"a1ca72_9"}],"accounts":[{"account_id":"a82bbf8a2fb928f239e2bd59df50e23b82b3eedd","email_address":"testuser@example.com","is_paid_hs":false,"is_paid_hf":false,"quotas":{"templates_left":0,"documents_left":3,"api_signature_requests_left":0}}]}}
@@ -0,0 +1,11 @@
1
+ {
2
+ "list_info": {
3
+ "page": 1,
4
+ "num_pages": 1,
5
+ "num_results": 1,
6
+ "page_size": 20
7
+ },
8
+ "templates":[
9
+ {"template_id":"a364138e0d8ae6393aa425a8ec64715580f3748b","title":"bitcoin","message":"Hello, bitcoin pdf here","is_creator":true,"can_edit":true,"signer_roles":[{"name":"Client","order":null}],"cc_roles":[],"documents":[{"index":"0","name":"bitcoin.pdf","custom_fields":[],"form_fields":[{"name":"","type":"signature","signer":"1","x":501,"y":7498,"width":120,"height":30,"required":true,"api_id":"a1ca72_9"}]}],"custom_fields":[],"named_form_fields":[{"name":"","type":"signature","signer":"1","x":501,"y":7498,"width":120,"height":30,"required":true,"api_id":"a1ca72_9"}],"accounts":[{"account_id":"a82bbf8a2fb928f239e2bd59df50e23b82b3eedd","email_address":"testuser@example.com","is_paid_hs":false,"is_paid_hf":false,"quotas":{"templates_left":0,"documents_left":3,"api_signature_requests_left":0}}]}
10
+ ]
11
+ }