hello_sign 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. data/lib/hello_sign.rb +15 -21
  2. data/lib/hello_sign/client.rb +4 -0
  3. data/lib/hello_sign/parameters/unclaimed_draft.rb +27 -0
  4. data/lib/hello_sign/proxy.rb +56 -0
  5. data/lib/hello_sign/proxy/account.rb +35 -0
  6. data/lib/hello_sign/proxy/reusable_form.rb +41 -0
  7. data/lib/hello_sign/proxy/settings.rb +22 -0
  8. data/lib/hello_sign/proxy/signature_request.rb +72 -0
  9. data/lib/hello_sign/proxy/team.rb +49 -0
  10. data/lib/hello_sign/proxy/unclaimed_draft.rb +29 -0
  11. data/lib/hello_sign/version.rb +1 -1
  12. data/spec/integration/account_spec.rb +0 -1
  13. data/spec/integration/signature_request_spec.rb +2 -2
  14. data/spec/integration/unclaimed_draft_spec.rb +23 -0
  15. data/spec/shared_examples/proxy.rb +49 -0
  16. data/spec/unit/client_spec.rb +6 -12
  17. data/spec/unit/hello_sign_spec.rb +21 -39
  18. data/spec/unit/parameters/unclaimed_draft_spec.rb +25 -0
  19. data/spec/unit/{account_proxy_spec.rb → proxy/account_spec.rb} +4 -8
  20. data/spec/unit/{reusable_form_proxy_spec.rb → proxy/reusable_form_spec.rb} +3 -3
  21. data/spec/unit/{settings_proxy_spec.rb → proxy/settings_spec.rb} +3 -3
  22. data/spec/unit/proxy/signature_request_spec.rb +149 -0
  23. data/spec/unit/{team_proxy_spec.rb → proxy/team_spec.rb} +3 -3
  24. data/spec/unit/proxy/unclaimed_draft_spec.rb +32 -0
  25. metadata +29 -18
  26. data/lib/hello_sign/account_proxy.rb +0 -33
  27. data/lib/hello_sign/reusable_form_proxy.rb +0 -43
  28. data/lib/hello_sign/settings_proxy.rb +0 -20
  29. data/lib/hello_sign/signature_request_proxy.rb +0 -60
  30. data/lib/hello_sign/team_proxy.rb +0 -47
  31. data/spec/unit/signature_request_proxy_spec.rb +0 -126
@@ -1,33 +0,0 @@
1
- require 'hello_sign/settings_proxy'
2
-
3
- module HelloSign
4
- class AccountProxy
5
- attr_reader :client
6
- attr_writer :settings_proxy_source
7
-
8
- def initialize(client)
9
- @client = client
10
- end
11
-
12
- def create(credentials)
13
- email = credentials.fetch(:email)
14
- password = credentials.fetch(:password)
15
-
16
- client.post('/account/create',
17
- :body => {:email_address => email, :password => password},
18
- :auth_not_required => true
19
- )
20
- end
21
-
22
- def settings
23
- settings_proxy_source.new(client)
24
- end
25
-
26
- private
27
-
28
- def settings_proxy_source
29
- @settings_proxy_source || SettingsProxy
30
- end
31
-
32
- end
33
- end
@@ -1,43 +0,0 @@
1
- module HelloSign
2
- class ReusableFormProxy
3
- attr_reader :client
4
-
5
- def initialize(client)
6
- @client = client
7
- end
8
-
9
- def list(params = {})
10
- params = {:page => 1}.merge(params)
11
- client.get('/reusable_form/list', :params => params)
12
- end
13
-
14
- def show(form_id)
15
- client.get("/reusable_form/#{form_id}")
16
- end
17
-
18
- def grant_access(form_id, params = {})
19
- body = if email = params[:email]
20
- {:email_address => email}
21
- elsif account_id = params[:account_id]
22
- {:account_id => account_id}
23
- else
24
- raise ArgumentError, 'An email address or account ID must be provided.'
25
- end
26
-
27
- client.post("/reusable_form/add_user/#{form_id}", :body => body)
28
- end
29
-
30
- def revoke_access(form_id, params = {})
31
- body = if email = params[:email]
32
- {:email_address => email}
33
- elsif account_id = params[:account_id]
34
- {:account_id => account_id}
35
- else
36
- raise ArgumentError, 'An email address or account ID must be provided.'
37
- end
38
-
39
- client.post("/reusable_form/remove_user/#{form_id}", :body => body)
40
- end
41
-
42
- end
43
- end
@@ -1,20 +0,0 @@
1
- require 'hello_sign/client'
2
-
3
- module HelloSign
4
- class SettingsProxy
5
- attr_reader :client
6
-
7
- def initialize(client)
8
- @client = client
9
- end
10
-
11
- def show
12
- client.get('/account')
13
- end
14
-
15
- def update(attributes)
16
- client.post('/account', :body => attributes)
17
- end
18
-
19
- end
20
- end
@@ -1,60 +0,0 @@
1
- require 'hello_sign/parameters/signature_request'
2
- require 'hello_sign/parameters/reusable_form_signature_request'
3
-
4
- module HelloSign
5
- class SignatureRequestProxy
6
- attr_reader :client
7
- attr_writer :request_parameters, :reusable_form_request_parameters
8
-
9
- def initialize(client)
10
- @client = client
11
- end
12
-
13
- def send(params = {})
14
- if form_id = params[:form]
15
- reusable_form_request_parameters.reusable_form_id = form_id
16
- yield reusable_form_request_parameters
17
- client.post(
18
- '/signature_request/send_with_reusable_form',
19
- :body => reusable_form_request_parameters.formatted
20
- )
21
- else
22
- yield request_parameters
23
- client.post('/signature_request/send', :body => request_parameters.formatted)
24
- end
25
- end
26
-
27
- def status(request_id)
28
- client.get("/signature_request/#{request_id}")
29
- end
30
-
31
- def list(params = {})
32
- params = {:page => 1}.merge(params)
33
- client.get('/signature_request/list', :params => params)
34
- end
35
-
36
- def remind(request_id, parameters = {})
37
- email = parameters.fetch(:email)
38
- client.post("/signature_request/remind/#{request_id}", :body => {:email_address => email})
39
- end
40
-
41
- def cancel(request_id)
42
- client.post("/signature_request/cancel/#{request_id}")
43
- end
44
-
45
- def final_copy(request_id)
46
- client.get("/signature_request/final_copy/#{request_id}")
47
- end
48
-
49
- private
50
-
51
- def request_parameters
52
- @request_parameters ||= Parameters::SignatureRequest.new
53
- end
54
-
55
- def reusable_form_request_parameters
56
- @reusable_form_request_parameters ||= Parameters::ReusableFormSignatureRequest.new
57
- end
58
-
59
- end
60
- end
@@ -1,47 +0,0 @@
1
- module HelloSign
2
- class TeamProxy
3
- attr_reader :client
4
-
5
- def initialize(client)
6
- @client = client
7
- end
8
-
9
- def create(params)
10
- name = params.fetch(:name)
11
- client.post('/team/create', :body => {:name => name})
12
- end
13
-
14
- def show
15
- client.get('/team')
16
- end
17
-
18
- def update(attributes)
19
- client.post('/team', :body => attributes)
20
- end
21
-
22
- def destroy
23
- client.post('/team/destroy')
24
- end
25
-
26
- def add_member(params)
27
- client.post("/team/add_member", :body => body_by_identifier(params))
28
- end
29
-
30
- def remove_member(params)
31
- client.post("/team/remove_member", :body => body_by_identifier(params))
32
- end
33
-
34
- private
35
-
36
- def body_by_identifier(params)
37
- if email = params[:email]
38
- {:email_address => email}
39
- elsif account_id = params[:account_id]
40
- {:account_id => account_id}
41
- else
42
- raise ArgumentError, 'An email address or account ID must be provided.'
43
- end
44
- end
45
-
46
- end
47
- end
@@ -1,126 +0,0 @@
1
- require 'helper'
2
- require 'hello_sign/signature_request_proxy'
3
-
4
- describe HelloSign::SignatureRequestProxy do
5
- let(:client) { double('client') }
6
- let(:request_id) { 'request_id' }
7
- let(:api_response) { double('API response') }
8
- subject(:sr_proxy) { HelloSign::SignatureRequestProxy.new(client) }
9
-
10
- describe "#client" do
11
- it "returns the client" do
12
- expect(sr_proxy.client).to be client
13
- end
14
- end
15
-
16
- describe "#send" do
17
- let(:formatted_request_body) { double('formatted request body') }
18
- let(:request_parameters) { double('request parameters') }
19
-
20
- context "when a reusable form is not specified" do
21
- before do
22
- sr_proxy.request_parameters = request_parameters
23
- request_parameters.stub(:formatted).and_return(formatted_request_body)
24
- request_parameters.should_receive(:foo=).with('bar')
25
- client.should_receive(:post)
26
- .with('/signature_request/send', :body => formatted_request_body)
27
- .and_return(api_response)
28
- end
29
-
30
- it "sends a signature request creation request and returns the result" do
31
- expect(sr_proxy.send { |params| params.foo = 'bar' }).to eq api_response
32
- end
33
- end
34
-
35
- context "when a reusable form is specified" do
36
- before do
37
- sr_proxy.reusable_form_request_parameters = request_parameters
38
- request_parameters.stub(:formatted).and_return(formatted_request_body)
39
- request_parameters.should_receive(:reusable_form_id=).with('form_id')
40
- request_parameters.should_receive(:foo=).with('bar')
41
- client.should_receive(:post)
42
- .with('/signature_request/send_with_reusable_form', :body => formatted_request_body)
43
- .and_return(api_response)
44
- end
45
-
46
- it "sends a signature request using a reusable form and returns the result" do
47
- expect(sr_proxy.send(:form => 'form_id') { |params| params.foo = 'bar' }).to eq api_response
48
- end
49
- end
50
- end
51
-
52
- describe "#status" do
53
- before { client.should_receive(:get).with('/signature_request/request_id').and_return(api_response) }
54
-
55
- it "fetches the signature request status and returns the result" do
56
- expect(sr_proxy.status(request_id)).to eq api_response
57
- end
58
- end
59
-
60
- describe "#list" do
61
- context "when called without options" do
62
- before { client.should_receive(:get).with('/signature_request/list', :params => {:page => 1}).and_return(api_response) }
63
-
64
- it "fetches the first page of signature requests and returns the result" do
65
- expect(sr_proxy.list).to eq api_response
66
- end
67
- end
68
-
69
- context "when called with a page number" do
70
- before { client.should_receive(:get).with('/signature_request/list', :params => {:page => 10}).and_return(api_response) }
71
-
72
- it "fetches a list of signature requests for the passed page number and returns the result" do
73
- expect(sr_proxy.list(:page => 10)).to eq api_response
74
- end
75
- end
76
- end
77
-
78
- describe "#remind" do
79
- let(:email) { 'john@johnson.com' }
80
-
81
- before { client.stub(:post).and_return(api_response) }
82
-
83
- context "when called with the proper parameters" do
84
- it "sends a signature request reminder to the email address" do
85
- client.should_receive(:post).with('/signature_request/remind/request_id', :body => {:email_address => email})
86
- sr_proxy.remind(request_id, :email => email)
87
- end
88
-
89
- it "returns the API response" do
90
- expect(sr_proxy.remind(request_id, :email => email)).to eq api_response
91
- end
92
- end
93
-
94
- context "when called without proper parameters" do
95
- it "raises an exception" do
96
- expect { sr_proxy.remind(request_id) }.to raise_error
97
- end
98
- end
99
- end
100
-
101
- describe "#cancel" do
102
- before { client.stub(:post).and_return(api_response) }
103
-
104
- it "sends a signature request cancellation" do
105
- client.should_receive(:post).with('/signature_request/cancel/request_id')
106
- sr_proxy.cancel(request_id)
107
- end
108
-
109
- it "returns the API response" do
110
- expect(sr_proxy.cancel(request_id)).to eq api_response
111
- end
112
- end
113
-
114
- describe "#final_copy" do
115
- before { client.stub(:get).and_return(api_response) }
116
-
117
- it "sends a request to fetch a final copy of the signature request" do
118
- client.should_receive(:get).with('/signature_request/final_copy/request_id')
119
- sr_proxy.final_copy(request_id)
120
- end
121
-
122
- it "returns the API response" do
123
- expect(sr_proxy.final_copy(request_id)).to eq api_response
124
- end
125
- end
126
- end