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,14 @@
1
+ {
2
+ "account": {
3
+ "account_id": "b4680b45053c7601ca1eee3b126eca6b2b0a0219",
4
+ "email_address": "jill@example.com",
5
+ "callback_url": null,
6
+ "role_code": null
7
+ },
8
+ "oauth_data": {
9
+ "access_token": "NWNiOTMxOGFkOGVjMDhhNTAxZN2NkNjgxMjMwOWJiYTEzZTBmZGUzMjMThhMzYyMzc=",
10
+ "token_type": "Bearer",
11
+ "refresh_token": "hNTI2MTFmM2VmZDQxZTZjOWRmZmFjZmVmMGMyNGFjMzI2MGI5YzgzNmE3",
12
+ "expires_in": 86400
13
+ }
14
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "unclaimed_draft": {
3
+ "claim_url": "https:\/\/www.hellosign.com\/send\/resendDocs?root_snapshot_guids[]=7f967b7d06e154394eab693febedf61e8ebe49eb&snapshot_access_guids[]=fb848631&root_snapshot_guids[]=7aedaf31e12edf9f2672a0b2ddf028aca670e101&snapshot_access_guids[]=f398ef87",
4
+ "signing_redirect_url" : null
5
+ }
6
+ }
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe HelloSign::Api::Account do
4
+ describe "#get_account" do
5
+ before do
6
+ stub_get("/account", 'account')
7
+ @account = HelloSign.get_account
8
+ end
9
+
10
+ it "should get the correct resource" do
11
+ expect(a_get("/account")).to have_been_made
12
+ end
13
+
14
+ it "should return current user account" do
15
+ expect(@account).to be_an HelloSign::Resource::Account
16
+ end
17
+ end
18
+
19
+
20
+
21
+ describe "#create_account" do
22
+ before do
23
+ stub_post("/account/create", "account")
24
+ @body = {:email_address => "test@example.com", :password => "secret"}
25
+ @account = HelloSign.create_account @body
26
+ end
27
+
28
+ it "should get the correct resource" do
29
+ expect(a_post("/account/create")).to have_been_made
30
+ end
31
+
32
+ it "should return information about a created account" do
33
+ expect(@account.email_address).to eql("test@example.com")
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe HelloSign::Api::Embedded do
4
+ describe "#get_embedded_sign_url" do
5
+ let(:signature_id){'50e3542f738adfa7ddd4cbd4c00d2a8ab6e4194b'}
6
+ before do
7
+ stub_get("/embedded/sign_url/#{signature_id}", 'embedded')
8
+ @embedded = HelloSign.get_embedded_sign_url :signature_id => signature_id
9
+ end
10
+
11
+ it "should get the correct resource" do
12
+ expect(a_get("/embedded/sign_url/#{signature_id}")).to have_been_made
13
+ end
14
+
15
+ it "should return a UnclaimedDraft" do
16
+ expect(@embedded).to be_an HelloSign::Resource::Embedded
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe HelloSign::Api::Account do
4
+
5
+ describe "#get_oauth_token" do
6
+ context "when successful request" do
7
+ before do
8
+ stub_post_oauth("/oauth/token", "token")
9
+ @oauth_info = HelloSign.get_oauth_token :state => 'state', :code => 'code'
10
+ end
11
+
12
+ it "should get the correct resource" do
13
+ expect(a_post_oauth("/oauth/token")).to have_been_made
14
+ end
15
+ end
16
+ end
17
+
18
+ describe "#refresh_oauth_token" do
19
+ before do
20
+ stub_post_oauth("/oauth/token", "token")
21
+ @oauth_info = HelloSign.refresh_oauth_token 'oauth_token'
22
+ end
23
+
24
+ it "should get the correct resource" do
25
+ expect(a_post_oauth("/oauth/token")).to have_been_made
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,126 @@
1
+ require 'spec_helper'
2
+
3
+ describe HelloSign::Api::SignatureRequest do
4
+ describe "#get_signature_request" do
5
+ before do
6
+ stub_get("/signature_request/1", 'signature_request')
7
+ @signature_request = HelloSign.get_signature_request :signature_request_id => 1
8
+ end
9
+
10
+ it "should get the correct resource" do
11
+ expect(a_get("/signature_request/1")).to have_been_made
12
+ end
13
+
14
+ it "should return a SignatureRequest" do
15
+ expect(@signature_request).to be_an HelloSign::Resource::SignatureRequest
16
+ end
17
+ end
18
+
19
+ describe "#get_signature_requests" do
20
+ before do
21
+ stub_get("/signature_request/list", 'signature_requests')
22
+ @signature_requests = HelloSign.get_signature_requests({})
23
+ end
24
+
25
+ it "should get the correct resource" do
26
+ expect(a_get("/signature_request/list")).to have_been_made
27
+ end
28
+
29
+ it "should return a SignatureRequestArray" do
30
+ expect(@signature_requests).to be_an HelloSign::Resource::ResourceArray
31
+ end
32
+
33
+ it "each of Array is an SignatureRequest" do
34
+ expect(@signature_requests[0]).to be_an HelloSign::Resource::SignatureRequest
35
+ end
36
+ end
37
+
38
+ describe "#send_signature_request" do
39
+ before do
40
+ stub_post("/signature_request/send", 'signature_request')
41
+ @signature_request = HelloSign.send_signature_request(
42
+ :files_url => ["http://hellosign.com/test.pdf"],
43
+ :signers => ["sss"]
44
+ )
45
+ end
46
+
47
+ it "should get the correct resource" do
48
+ expect(a_post("/signature_request/send")).to have_been_made
49
+ end
50
+
51
+ it "should return a SignatureRequest" do
52
+ expect(@signature_request).to be_an HelloSign::Resource::SignatureRequest
53
+ end
54
+ end
55
+
56
+ describe "#remind_signature_request" do
57
+ before do
58
+ stub_post("/signature_request/remind/1", 'signature_request')
59
+ @signature_request = HelloSign.remind_signature_request(:signature_request_id => 1)
60
+ end
61
+
62
+ it "should get the correct resource" do
63
+ expect(a_post("/signature_request/remind/1")).to have_been_made
64
+ end
65
+
66
+ it "should return a SignatureRequest" do
67
+ expect(@signature_request).to be_an HelloSign::Resource::SignatureRequest
68
+ end
69
+ end
70
+
71
+ describe "#cancel_signature_request" do
72
+ before do
73
+ stub_post("/signature_request/cancel/1", 'signature_request')
74
+ @signature_request = HelloSign.cancel_signature_request(:signature_request_id => 1)
75
+ end
76
+
77
+ it "should get the correct resource" do
78
+ expect(a_post("/signature_request/cancel/1")).to have_been_made
79
+ end
80
+ end
81
+
82
+ describe "#signature_request_files" do
83
+ before do
84
+ stub_get("/signature_request/files/1", 'file')
85
+ @files = HelloSign.signature_request_files(:signature_request_id => 1)
86
+ end
87
+
88
+ it "should get the correct resource" do
89
+ expect(a_get("/signature_request/files/1")).to have_been_made
90
+ end
91
+ end
92
+
93
+
94
+ describe "#send_signature_request_with_template" do
95
+ before do
96
+ stub_post("/signature_request/send_with_template", 'signature_request')
97
+ @signature_request = HelloSign.send_signature_request_with_template({})
98
+ end
99
+
100
+ it "should get the correct resource" do
101
+ expect(a_post("/signature_request/send_with_template")).to have_been_made
102
+ end
103
+ end
104
+
105
+ describe "#create_embedded_signature_request" do
106
+ before do
107
+ stub_post("/signature_request/create_embedded", 'signature_request')
108
+ @signature_request = HelloSign.create_embedded_signature_request({})
109
+ end
110
+
111
+ it "should get the correct resource" do
112
+ expect(a_post("/signature_request/create_embedded")).to have_been_made
113
+ end
114
+ end
115
+
116
+ describe "#create_embedded_signature_request_with_template" do
117
+ before do
118
+ stub_post("/signature_request/create_embedded_with_template", 'signature_request')
119
+ @signature_request = HelloSign.create_embedded_signature_request_with_template({})
120
+ end
121
+
122
+ it "should get the correct resource" do
123
+ expect(a_post("/signature_request/create_embedded_with_template")).to have_been_made
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,94 @@
1
+ require 'spec_helper'
2
+
3
+ describe HelloSign::Api::Team do
4
+ describe "#get_team" do
5
+ before do
6
+ stub_get("/team", 'team')
7
+ @team = HelloSign.get_team
8
+ end
9
+
10
+ it "should get the correct resource" do
11
+ expect(a_get("/team")).to have_been_made
12
+ end
13
+
14
+ it "should return user's team" do
15
+ expect(@team).to be_an HelloSign::Resource::Team
16
+ end
17
+ end
18
+
19
+
20
+
21
+ describe "#create_team" do
22
+ before do
23
+ stub_post("/team/create", "team")
24
+ @team = HelloSign.create_team :name => "Team HelloSign"
25
+ end
26
+
27
+ it "should get the correct resource" do
28
+ expect(a_post("/team/create")).to have_been_made
29
+ end
30
+
31
+ it "should return information about a created team" do
32
+ expect(@team.name).to eql("Team HelloSign")
33
+ end
34
+ end
35
+
36
+ describe "#update_team" do
37
+ before do
38
+ stub_post("/team", "team")
39
+ @team = HelloSign.update_team :name => "Team HelloSign"
40
+ end
41
+
42
+ it "should get the correct resource" do
43
+ expect(a_post("/team")).to have_been_made
44
+ end
45
+
46
+ it "should return information about a updated team" do
47
+ expect(@team.name).to eql("Team HelloSign")
48
+ end
49
+ end
50
+
51
+ describe "#destroy_team" do
52
+ before do
53
+ stub_post("/team/destroy", "team")
54
+ @team = HelloSign.destroy_team
55
+ end
56
+
57
+ it "should get the correct resource" do
58
+ expect(a_post("/team/destroy")).to have_been_made
59
+ end
60
+ end
61
+
62
+ describe "#destroy_team" do
63
+ before do
64
+ stub_post("/team/destroy", "team")
65
+ @team = HelloSign.destroy_team
66
+ end
67
+
68
+ it "should get the correct resource" do
69
+ expect(a_post("/team/destroy")).to have_been_made
70
+ end
71
+ end
72
+
73
+ describe "#add_member_to_team" do
74
+ before do
75
+ stub_post("/team/add_member", "team")
76
+ @team = HelloSign.add_member_to_team :email_address => "george@example.com"
77
+ end
78
+
79
+ it "should get the correct resource" do
80
+ expect(a_post("/team/add_member")).to have_been_made
81
+ end
82
+ end
83
+
84
+ describe "#remove_member_from_team" do
85
+ before do
86
+ stub_post("/team/remove_member", "team")
87
+ @team = HelloSign.remove_member_from_team :email_address => "george@example.com"
88
+ end
89
+
90
+ it "should get the correct resource" do
91
+ expect(a_post("/team/remove_member")).to have_been_made
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe HelloSign::Api::Template do
4
+ describe "#get_template" do
5
+ before do
6
+ stub_get("/template/1", 'template')
7
+ @template = HelloSign.get_template :template_id => 1
8
+ end
9
+
10
+ it "should get the correct resource" do
11
+ expect(a_get("/template/1")).to have_been_made
12
+ end
13
+
14
+ it "should return a Template" do
15
+ expect(@template).to be_an HelloSign::Resource::Template
16
+ end
17
+ end
18
+
19
+ describe "#get_templates" do
20
+ before do
21
+ stub_get("/template/list", 'templates')
22
+ @template = HelloSign.get_templates({})
23
+ end
24
+
25
+ it "should get the correct resource" do
26
+ expect(a_get("/template/list")).to have_been_made
27
+ end
28
+
29
+ it "should return a ResourceArray" do
30
+ expect(@template).to be_an HelloSign::Resource::ResourceArray
31
+ end
32
+
33
+ it "each of Array is an Template" do
34
+ expect(@template[0]).to be_an HelloSign::Resource::Template
35
+ end
36
+ end
37
+
38
+ describe "#add_user_to_template" do
39
+ before do
40
+ stub_post("/template/add_user/1", 'template')
41
+ @template = HelloSign.add_user_to_template :template_id => 1
42
+ end
43
+
44
+ it "should get the correct resource" do
45
+ expect(a_post("/template/add_user/1")).to have_been_made
46
+ end
47
+
48
+ it "should return a Template" do
49
+ expect(@template).to be_an HelloSign::Resource::Template
50
+ end
51
+ end
52
+
53
+ describe "#remove_user_from_template" do
54
+ before do
55
+ stub_post("/template/remove_user/1", 'template')
56
+ @template = HelloSign.remove_user_from_template :template_id => 1
57
+ end
58
+
59
+ it "should get the correct resource" do
60
+ expect(a_post("/template/remove_user/1")).to have_been_made
61
+ end
62
+
63
+ it "should return a Template" do
64
+ expect(@template).to be_an HelloSign::Resource::Template
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe HelloSign::Api::UnclaimedDraft do
4
+ describe "#create_unclaimed_draft" do
5
+ context "send_document" do
6
+ before do
7
+ stub_post("/unclaimed_draft/create", 'unclaimed_draft')
8
+ @unclaimed_draft = HelloSign.create_unclaimed_draft({:type => 'send_document'})
9
+ end
10
+
11
+ it "should get the correct resource" do
12
+ expect(a_post("/unclaimed_draft/create")).to have_been_made
13
+ end
14
+
15
+ it "should return a UnclaimedDraft" do
16
+ expect(@unclaimed_draft).to be_an HelloSign::Resource::UnclaimedDraft
17
+ end
18
+ end
19
+
20
+ context "request_signature" do
21
+ before do
22
+ stub_post("/unclaimed_draft/create", 'unclaimed_draft')
23
+ @unclaimed_draft = HelloSign.create_unclaimed_draft({:type => 'request_signature'})
24
+ end
25
+
26
+ it "should get the correct resource" do
27
+ expect(a_post("/unclaimed_draft/create")).to have_been_made
28
+ end
29
+
30
+ it "should return a UnclaimedDraft" do
31
+ expect(@unclaimed_draft).to be_an HelloSign::Resource::UnclaimedDraft
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,132 @@
1
+ require 'spec_helper'
2
+
3
+ describe HelloSign::Client do
4
+ describe "#initialize" do
5
+ context "with default values" do
6
+ subject(:client){HelloSign::Client.new}
7
+ HelloSign::Configuration::VALID_OPTIONS_KEYS.each do |key|
8
+ it "should set #{key}" do
9
+ expect(client.send(key)).to eql(HelloSign.send(key))
10
+ end
11
+ end
12
+ end
13
+
14
+ context "with custom values" do
15
+ let(:custom_client){
16
+ {
17
+ :email_address => "email_address",
18
+ :password => "password",
19
+ :api_key => "api_key",
20
+ :user_agent => "user_agent",
21
+ :end_point => "end_point",
22
+ :oauth_end_point => "oauth_end_point",
23
+ :api_version => "api_version",
24
+ :client_id => "client_id",
25
+ :client_secret => "client_secret",
26
+ :auth_token => "auth_token",
27
+ :log_level => 5,
28
+ :logging => false
29
+ }
30
+ }
31
+ subject(:client){ HelloSign::Client.new custom_client}
32
+ HelloSign::Configuration::VALID_OPTIONS_KEYS.each do |key|
33
+ it "should set #{key}" do
34
+ expect(client.send(key)).to eql(custom_client[key])
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ describe "#request" do
41
+ context "when response status >= 400" do
42
+ HelloSign::Client::ERRORS.keys.each do |key|
43
+ it "raise #{HelloSign::Client::ERRORS[key].to_s} when response status #{key}" do
44
+
45
+ # raise when post
46
+ stub_post("/account/create", 'error', key)
47
+ expect {
48
+ HelloSign.create_account :email_address => "test@example.com", :password => "password"
49
+ }.to raise_error(HelloSign::Client::ERRORS[key])
50
+
51
+ # raise when get
52
+ stub_get("/account", 'error', key)
53
+ expect {
54
+ HelloSign.get_account
55
+ }.to raise_error(HelloSign::Client::ERRORS[key])
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ describe "prepare" do
62
+ context "signers" do
63
+ describe "is an array" do
64
+ before do
65
+ stub_post("/signature_request/send", 'signature_request')
66
+ end
67
+
68
+ it "work correctly" do
69
+ expect(lambda{HelloSign.send_signature_request(
70
+ :files_url => ["http://hellosign.com/test.pdf"],
71
+ :signers => ["sss"]
72
+ )}).not_to raise_error
73
+ end
74
+ end
75
+
76
+ describe "is an Hash" do
77
+ before do
78
+ stub_post("/signature_request/send", 'signature_request')
79
+ end
80
+
81
+ it "work correctly" do
82
+ expect(lambda{HelloSign.send_signature_request(
83
+ :files_url => ["http://hellosign.com/test.pdf"],
84
+ :signers => [{
85
+ :email_address => 'jack@example.com',
86
+ :name => 'Jack',
87
+ :order => 0
88
+ },{
89
+ :email_address => 'jill@example.com',
90
+ :name => 'Jill',
91
+ :order => 1
92
+ }]
93
+ )}).not_to raise_error
94
+ end
95
+ end
96
+ end
97
+
98
+ context "ccs" do
99
+ describe "is an array" do
100
+ before do
101
+ stub_post("/signature_request/send_with_template", 'signature_request')
102
+ end
103
+
104
+ it "work correctly" do
105
+ expect(lambda{HelloSign.send_signature_request_with_template(
106
+ :ccs => ["sss"]
107
+ )}).not_to raise_error
108
+ end
109
+ end
110
+
111
+ describe "is an Hash" do
112
+ before do
113
+ stub_post("/signature_request/send_with_template", 'signature_request')
114
+ end
115
+
116
+ it "work correctly" do
117
+ expect(lambda{HelloSign.send_signature_request_with_template(
118
+ :ccs => [{
119
+ :email_address => 'jack@example.com',
120
+ :name => 'Jack',
121
+ :role => 'Manager'
122
+ },{
123
+ :email_address => 'jill@example.com',
124
+ :name => 'Jill',
125
+ :role => "Client"
126
+ }]
127
+ )}).not_to raise_error
128
+ end
129
+ end
130
+ end
131
+ end
132
+ end