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
@@ -0,0 +1,49 @@
1
+ shared_examples_for 'a proxy' do
2
+ let(:proxy_source) { double('proxy source') }
3
+ let(:proxy) { double('proxy') }
4
+
5
+ describe "#account" do
6
+ before { client.account_proxy_source = proxy_source }
7
+
8
+ it "returns an account proxy" do
9
+ proxy_source.should_receive(:new).with(client).and_return(proxy)
10
+ expect(client.account).to eq proxy
11
+ end
12
+ end
13
+
14
+ describe "#signature_request" do
15
+ before { client.signature_request_proxy_source = proxy_source }
16
+
17
+ it "returns an signature request proxy" do
18
+ proxy_source.should_receive(:new).with(client).and_return(proxy)
19
+ expect(client.signature_request).to eq proxy
20
+ end
21
+ end
22
+
23
+ describe "#reusable_form" do
24
+ before { client.reusable_form_proxy_source = proxy_source }
25
+
26
+ it "returns an reusable form proxy" do
27
+ proxy_source.should_receive(:new).with(client).and_return(proxy)
28
+ expect(client.reusable_form).to eq proxy
29
+ end
30
+ end
31
+
32
+ describe "#team" do
33
+ before { client.team_proxy_source = proxy_source }
34
+
35
+ it "returns an team proxy" do
36
+ proxy_source.should_receive(:new).with(client).and_return(proxy)
37
+ expect(client.team).to eq proxy
38
+ end
39
+ end
40
+
41
+ describe "#unclaimed_draft" do
42
+ before { client.unclaimed_draft_proxy_source = proxy_source }
43
+
44
+ it "returns an unclaimed draft proxy" do
45
+ proxy_source.should_receive(:new).with(client).and_return(proxy)
46
+ expect(client.unclaimed_draft).to eq proxy
47
+ end
48
+ end
49
+ end
@@ -1,20 +1,14 @@
1
1
  require 'helper'
2
- require 'json'
3
2
  require 'hello_sign/client'
3
+ require 'shared_examples/proxy'
4
4
 
5
5
  describe HelloSign::Client do
6
- let(:connection) { double('connection') }
7
- subject(:client) { HelloSign::Client.new('david@bowman.com', 'space') }
6
+ subject(:hs_client) { HelloSign::Client.new('david@bowman.com', 'space') }
8
7
 
9
- describe "#email" do
10
- it "returns the email address" do
11
- expect(client.email).to eq 'david@bowman.com'
12
- end
13
- end
8
+ its(:email) { should eq 'david@bowman.com' }
9
+ its(:password) { should eq 'space' }
14
10
 
15
- describe "#password" do
16
- it "returns the password" do
17
- expect(client.password).to eq 'space'
18
- end
11
+ it_behaves_like 'a proxy' do
12
+ let(:client) { hs_client }
19
13
  end
20
14
  end
@@ -2,29 +2,13 @@ require 'helper'
2
2
  require 'hello_sign'
3
3
 
4
4
  describe HelloSign do
5
- describe "::account" do
6
- it "returns an account proxy" do
7
- expect(HelloSign.account).to be_a HelloSign::AccountProxy
8
- end
9
- end
10
-
11
- describe "::signature_request" do
12
- it "returns a signature request proxy" do
13
- expect(HelloSign.signature_request).to be_a HelloSign::SignatureRequestProxy
14
- end
15
- end
16
-
17
- describe "::reusable_form" do
18
- it "returns a reusable form proxy" do
19
- expect(HelloSign.reusable_form).to be_a HelloSign::ReusableFormProxy
20
- end
5
+ before do
6
+ HelloSign.email = 'hal@jupiter.com'
7
+ HelloSign.password = 'human_domination'
21
8
  end
22
9
 
23
- describe "::team" do
24
- it "returns a team proxy" do
25
- expect(HelloSign.team).to be_a HelloSign::TeamProxy
26
- end
27
- end
10
+ its(:email) { should eq 'hal@jupiter.com' }
11
+ its(:password) { should eq 'human_domination' }
28
12
 
29
13
  describe "::client" do
30
14
  context "when it has not previously been called" do
@@ -34,9 +18,23 @@ describe HelloSign do
34
18
  end
35
19
 
36
20
  context "when it has previously been called" do
21
+ before { @client = HelloSign.client }
22
+
37
23
  it "returns the same client" do
38
- client = HelloSign.client
39
- expect(HelloSign.client).to be client
24
+ expect(HelloSign.client).to be @client
25
+ end
26
+
27
+ context "and the email and password changes" do
28
+ before do
29
+ HelloSign.email = 'bob@earth.com'
30
+ HelloSign.password = 'being_human'
31
+ end
32
+
33
+ it "creates a new client with the new credentials" do
34
+ expect(HelloSign.client).to_not be @client
35
+ expect(HelloSign.client.email).to eq 'bob@earth.com'
36
+ expect(HelloSign.client.password).to eq 'being_human'
37
+ end
40
38
  end
41
39
  end
42
40
  end
@@ -48,20 +46,4 @@ describe HelloSign do
48
46
  end
49
47
  end
50
48
  end
51
-
52
- describe "::email" do
53
- it "sets and returns the email address" do
54
- HelloSign.email = 'hal@jupiter.com'
55
-
56
- expect(HelloSign.email).to eq 'hal@jupiter.com'
57
- end
58
- end
59
-
60
- describe "::password" do
61
- it "sets and returns the password" do
62
- HelloSign.password = 'human_domination'
63
-
64
- expect(HelloSign.password).to eq 'human_domination'
65
- end
66
- end
67
49
  end
@@ -0,0 +1,25 @@
1
+ require 'helper'
2
+ require 'hello_sign/parameters/unclaimed_draft'
3
+
4
+ describe HelloSign::Parameters::UnclaimedDraft do
5
+ describe "#formatted" do
6
+ let(:draft_parameters) { HelloSign::Parameters::UnclaimedDraft.new }
7
+ let(:text_file) { double('text file') }
8
+ let(:image_file) { double('image file') }
9
+ let(:expected) { {:file => {0 => text_file, 1 => image_file}} }
10
+
11
+ before do
12
+ Faraday::UploadIO.should_receive(:new).with('text file IO object', 'text/plain', 'test.txt').and_return(text_file)
13
+ Faraday::UploadIO.should_receive(:new).with('image file IO object', 'image/jpeg', 'test.jpg').and_return(image_file)
14
+
15
+ draft_parameters.files = [
16
+ {:name => 'test.txt', :io => 'text file IO object', :mime => 'text/plain'},
17
+ {:name => 'test.jpg', :io => 'image file IO object', :mime => 'image/jpeg'}
18
+ ]
19
+ end
20
+
21
+ it "returns formatted parameters" do
22
+ expect(draft_parameters.formatted).to eq expected
23
+ end
24
+ end
25
+ end
@@ -1,15 +1,11 @@
1
1
  require 'helper'
2
- require 'hello_sign/account_proxy'
2
+ require 'hello_sign/proxy/account'
3
3
 
4
- describe HelloSign::AccountProxy do
4
+ describe HelloSign::Proxy::Account do
5
5
  let(:client) { double('client') }
6
- subject(:account_proxy) { HelloSign::AccountProxy.new(client) }
6
+ subject(:account_proxy) { HelloSign::Proxy::Account.new(client) }
7
7
 
8
- describe "#client" do
9
- it "returns the client" do
10
- expect(account_proxy.client).to be client
11
- end
12
- end
8
+ its(:client) { should eq client }
13
9
 
14
10
  describe "#create" do
15
11
  context "when passed the proper parameters" do
@@ -1,11 +1,11 @@
1
1
  require 'helper'
2
- require 'hello_sign/reusable_form_proxy'
2
+ require 'hello_sign/proxy/reusable_form'
3
3
 
4
- describe HelloSign::ReusableFormProxy do
4
+ describe HelloSign::Proxy::ReusableForm do
5
5
  let(:client) { double('client') }
6
6
  let(:api_response) { double('API response') }
7
7
  let(:form_id) { 'form_id' }
8
- subject(:rf_proxy) { HelloSign::ReusableFormProxy.new(client) }
8
+ subject(:rf_proxy) { HelloSign::Proxy::ReusableForm.new(client) }
9
9
 
10
10
  describe "#client" do
11
11
  it "returns the client" do
@@ -1,9 +1,9 @@
1
1
  require 'helper'
2
- require 'hello_sign/settings_proxy'
2
+ require 'hello_sign/proxy/settings'
3
3
 
4
- describe HelloSign::SettingsProxy do
4
+ describe HelloSign::Proxy::Settings do
5
5
  let(:client) { double('client') }
6
- subject(:settings) { HelloSign::SettingsProxy.new(client) }
6
+ subject(:settings) { HelloSign::Proxy::Settings.new(client) }
7
7
 
8
8
  describe "#client" do
9
9
  it "returns the client" do
@@ -0,0 +1,149 @@
1
+ require 'helper'
2
+ require 'hello_sign/proxy/signature_request'
3
+
4
+ describe HelloSign::Proxy::SignatureRequest do
5
+ let(:client) { double('client') }
6
+ let(:request_id) { 'request_id' }
7
+ let(:api_response) { double('API response') }
8
+ subject(:sr_proxy) { HelloSign::Proxy::SignatureRequest.new(client) }
9
+
10
+ its(:client) { should eq client }
11
+
12
+ describe "#deliver" do
13
+ let(:formatted_request_body) { double('formatted request body') }
14
+ let(:request_parameters) { double('request parameters') }
15
+
16
+ before do
17
+ request_parameters.stub(:foo=)
18
+ request_parameters.stub(:formatted).and_return(formatted_request_body)
19
+ sr_proxy.request_parameters = request_parameters
20
+
21
+ client.stub(:post).and_return(api_response)
22
+ end
23
+
24
+ it "yields the request parameters to the block" do
25
+ request_parameters.should_receive(:foo=).with('bar')
26
+ sr_proxy.deliver { |params| params.foo = 'bar' }
27
+ end
28
+
29
+ it "sends a signature request" do
30
+ client.should_receive(:post)
31
+ .with('/signature_request/send', :body => formatted_request_body)
32
+ sr_proxy.deliver { |params| params.foo = 'bar' }
33
+ end
34
+
35
+ it "returns the response" do
36
+ expect(sr_proxy.deliver {}).to eq api_response
37
+ end
38
+
39
+ context "when a reusable form is specified" do
40
+ before do
41
+ request_parameters.stub(:reusable_form_id=)
42
+ sr_proxy.reusable_form_request_parameters = request_parameters
43
+ end
44
+
45
+ it "sets the reusable form ID in the request parameters" do
46
+ request_parameters.should_receive(:reusable_form_id=).with('form_id')
47
+ sr_proxy.deliver(:form => 'form_id') {}
48
+ end
49
+
50
+ it "sends a reusable form signature request" do
51
+ client.should_receive(:post)
52
+ .with('/signature_request/send_with_reusable_form', :body => formatted_request_body)
53
+ sr_proxy.deliver(:form => 'form_id') {}
54
+ end
55
+
56
+ it "returns the response" do
57
+ expect(sr_proxy.deliver(:form => 'form_id') {}).to eq api_response
58
+ end
59
+ end
60
+ end
61
+
62
+ describe "#status" do
63
+ it "fetches the signature request status" do
64
+ client.should_receive(:get)
65
+ .with('/signature_request/request_id')
66
+ sr_proxy.status(request_id)
67
+ end
68
+
69
+ it "returns the response" do
70
+ client.stub(:get).and_return(api_response)
71
+ expect(sr_proxy.status(request_id)).to eq api_response
72
+ end
73
+ end
74
+
75
+ describe "#list" do
76
+ context "when called without a page number" do
77
+ it "fetches the first page of signature requests" do
78
+ client.should_receive(:get)
79
+ .with('/signature_request/list', :params => {:page => 1})
80
+ sr_proxy.list
81
+ end
82
+
83
+ it "returns the response" do
84
+ client.stub(:get).and_return(api_response)
85
+ expect(sr_proxy.list).to eq api_response
86
+ end
87
+ end
88
+
89
+ context "when called with a page number" do
90
+ it "fetches a list of signature requests from the specified page" do
91
+ client.should_receive(:get)
92
+ .with('/signature_request/list', :params => {:page => 10})
93
+ sr_proxy.list(:page => 10)
94
+ end
95
+
96
+ it "returns the response" do
97
+ client.stub(:get).and_return(api_response)
98
+ expect(sr_proxy.list(:page => 10)).to eq api_response
99
+ end
100
+ end
101
+ end
102
+
103
+ describe "#remind" do
104
+ let(:email) { 'john@johnson.com' }
105
+
106
+ it "sends a signature request reminder" do
107
+ client.should_receive(:post)
108
+ .with('/signature_request/remind/request_id', :body => {:email_address => email})
109
+ sr_proxy.remind(request_id, :email => email)
110
+ end
111
+
112
+ it "returns the response" do
113
+ client.stub(:post).and_return(api_response)
114
+ expect(sr_proxy.remind(request_id, :email => email)).to eq api_response
115
+ end
116
+
117
+ context "when called without an email address" do
118
+ it "raises an exception" do
119
+ expect { sr_proxy.remind(request_id) }.to raise_error ArgumentError
120
+ end
121
+ end
122
+ end
123
+
124
+ describe "#cancel" do
125
+ it "cancels a signature request" do
126
+ client.should_receive(:post)
127
+ .with('/signature_request/cancel/request_id')
128
+ sr_proxy.cancel(request_id)
129
+ end
130
+
131
+ it "returns the response" do
132
+ client.stub(:post).and_return(api_response)
133
+ expect(sr_proxy.cancel(request_id)).to eq api_response
134
+ end
135
+ end
136
+
137
+ describe "#final_copy" do
138
+ it "fetches a final copy of the signature request" do
139
+ client.should_receive(:get)
140
+ .with('/signature_request/final_copy/request_id')
141
+ sr_proxy.final_copy(request_id)
142
+ end
143
+
144
+ it "returns the response" do
145
+ client.stub(:get).and_return(api_response)
146
+ expect(sr_proxy.final_copy(request_id)).to eq api_response
147
+ end
148
+ end
149
+ end
@@ -1,10 +1,10 @@
1
1
  require 'helper'
2
- require 'hello_sign/team_proxy'
2
+ require 'hello_sign/proxy/team'
3
3
 
4
- describe HelloSign::TeamProxy do
4
+ describe HelloSign::Proxy::Team do
5
5
  let(:client) { double('client') }
6
6
  let(:api_response) { double('API response') }
7
- subject(:team_proxy) { HelloSign::TeamProxy.new(client) }
7
+ subject(:team_proxy) { HelloSign::Proxy::Team.new(client) }
8
8
 
9
9
  before do
10
10
  client.stub(:get).and_return(api_response)
@@ -0,0 +1,32 @@
1
+ require 'helper'
2
+ require 'hello_sign/proxy/unclaimed_draft'
3
+
4
+ describe HelloSign::Proxy::UnclaimedDraft do
5
+ let(:client) { double('client') }
6
+ let(:api_response) { double('API response') }
7
+ subject(:ud_proxy) { HelloSign::Proxy::UnclaimedDraft.new(client) }
8
+
9
+ describe "#client" do
10
+ it "returns the client" do
11
+ expect(ud_proxy.client).to be client
12
+ end
13
+ end
14
+
15
+ describe "#create" do
16
+ let(:formatted_request_body) { double('formatted request body') }
17
+ let(:draft_parameters) { double('draft parameters') }
18
+
19
+ before do
20
+ ud_proxy.draft_parameters = draft_parameters
21
+ draft_parameters.stub(:formatted).and_return(formatted_request_body)
22
+ draft_parameters.should_receive(:foo=).with('bar')
23
+ client.should_receive(:post)
24
+ .with('/unclaimed_draft/create', :body => formatted_request_body)
25
+ .and_return(api_response)
26
+ end
27
+
28
+ it "sends a unclaimed draft creation request and returns the result" do
29
+ expect(ud_proxy.create { |params| params.foo = 'bar' }).to eq api_response
30
+ end
31
+ end
32
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hello_sign
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-30 00:00:00.000000000 Z
12
+ date: 2013-02-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -82,14 +82,17 @@ executables: []
82
82
  extensions: []
83
83
  extra_rdoc_files: []
84
84
  files:
85
- - lib/hello_sign/account_proxy.rb
86
85
  - lib/hello_sign/client.rb
87
86
  - lib/hello_sign/parameters/reusable_form_signature_request.rb
88
87
  - lib/hello_sign/parameters/signature_request.rb
89
- - lib/hello_sign/reusable_form_proxy.rb
90
- - lib/hello_sign/settings_proxy.rb
91
- - lib/hello_sign/signature_request_proxy.rb
92
- - lib/hello_sign/team_proxy.rb
88
+ - lib/hello_sign/parameters/unclaimed_draft.rb
89
+ - lib/hello_sign/proxy/account.rb
90
+ - lib/hello_sign/proxy/reusable_form.rb
91
+ - lib/hello_sign/proxy/settings.rb
92
+ - lib/hello_sign/proxy/signature_request.rb
93
+ - lib/hello_sign/proxy/team.rb
94
+ - lib/hello_sign/proxy/unclaimed_draft.rb
95
+ - lib/hello_sign/proxy.rb
93
96
  - lib/hello_sign/version.rb
94
97
  - lib/hello_sign.rb
95
98
  - spec/fixtures/test.jpg
@@ -102,15 +105,19 @@ files:
102
105
  - spec/integration/reusable_form_spec.rb
103
106
  - spec/integration/signature_request_spec.rb
104
107
  - spec/integration/team_spec.rb
105
- - spec/unit/account_proxy_spec.rb
108
+ - spec/integration/unclaimed_draft_spec.rb
109
+ - spec/shared_examples/proxy.rb
106
110
  - spec/unit/client_spec.rb
107
111
  - spec/unit/hello_sign_spec.rb
108
112
  - spec/unit/parameters/reusable_form_signature_request_spec.rb
109
113
  - spec/unit/parameters/signature_request_spec.rb
110
- - spec/unit/reusable_form_proxy_spec.rb
111
- - spec/unit/settings_proxy_spec.rb
112
- - spec/unit/signature_request_proxy_spec.rb
113
- - spec/unit/team_proxy_spec.rb
114
+ - spec/unit/parameters/unclaimed_draft_spec.rb
115
+ - spec/unit/proxy/account_spec.rb
116
+ - spec/unit/proxy/reusable_form_spec.rb
117
+ - spec/unit/proxy/settings_spec.rb
118
+ - spec/unit/proxy/signature_request_spec.rb
119
+ - spec/unit/proxy/team_spec.rb
120
+ - spec/unit/proxy/unclaimed_draft_spec.rb
114
121
  homepage: http://www.github.com/craiglittle/hello_sign
115
122
  licenses: []
116
123
  post_install_message:
@@ -131,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
138
  version: '0'
132
139
  requirements: []
133
140
  rubyforge_project:
134
- rubygems_version: 1.8.24
141
+ rubygems_version: 1.8.23
135
142
  signing_key:
136
143
  specification_version: 3
137
144
  summary: A Ruby interface to the HelloSign API.
@@ -146,12 +153,16 @@ test_files:
146
153
  - spec/integration/reusable_form_spec.rb
147
154
  - spec/integration/signature_request_spec.rb
148
155
  - spec/integration/team_spec.rb
149
- - spec/unit/account_proxy_spec.rb
156
+ - spec/integration/unclaimed_draft_spec.rb
157
+ - spec/shared_examples/proxy.rb
150
158
  - spec/unit/client_spec.rb
151
159
  - spec/unit/hello_sign_spec.rb
152
160
  - spec/unit/parameters/reusable_form_signature_request_spec.rb
153
161
  - spec/unit/parameters/signature_request_spec.rb
154
- - spec/unit/reusable_form_proxy_spec.rb
155
- - spec/unit/settings_proxy_spec.rb
156
- - spec/unit/signature_request_proxy_spec.rb
157
- - spec/unit/team_proxy_spec.rb
162
+ - spec/unit/parameters/unclaimed_draft_spec.rb
163
+ - spec/unit/proxy/account_spec.rb
164
+ - spec/unit/proxy/reusable_form_spec.rb
165
+ - spec/unit/proxy/settings_spec.rb
166
+ - spec/unit/proxy/signature_request_spec.rb
167
+ - spec/unit/proxy/team_spec.rb
168
+ - spec/unit/proxy/unclaimed_draft_spec.rb