hello_sign 0.0.5 → 0.1.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.
@@ -1,8 +1,9 @@
1
- require 'hello_sign/settings'
1
+ require 'hello_sign/settings_proxy'
2
2
 
3
3
  module HelloSign
4
4
  class AccountProxy
5
5
  attr_reader :client
6
+ attr_writer :settings_proxy_source
6
7
 
7
8
  def initialize(client)
8
9
  @client = client
@@ -12,25 +13,20 @@ module HelloSign
12
13
  email = credentials.fetch(:email)
13
14
  password = credentials.fetch(:password)
14
15
 
15
- create_account(email, password)
16
-
17
- true
16
+ client.post('/account/create',
17
+ :body => {:email_address => email, :password => password},
18
+ :unauthenticated => true
19
+ )
18
20
  end
19
21
 
20
22
  def settings
21
- settings = client.get('/account')
22
-
23
- Settings.new(settings, client)
23
+ settings_proxy_source.new(client)
24
24
  end
25
25
 
26
26
  private
27
27
 
28
- def create_account(email, password)
29
- client.post(
30
- '/account/create',
31
- :body => {:email_address => email, :password => password},
32
- :unauthenticated => true
33
- )
28
+ def settings_proxy_source
29
+ @settings_proxy_source || SettingsProxy
34
30
  end
35
31
 
36
32
  end
@@ -27,8 +27,9 @@ module HelloSign
27
27
  def request(method, path, options)
28
28
  connection = options[:unauthenticated] ? unauth_connection : auth_connection
29
29
  request = connection.send(method) do |request|
30
- request.path = "#{API_VERSION}#{path}"
31
- request.body = options[:body]
30
+ request.path = "#{API_VERSION}#{path}"
31
+ request.params = options[:params] if options[:params]
32
+ request.body = options[:body]
32
33
  end
33
34
 
34
35
  request.body
@@ -0,0 +1,41 @@
1
+ module HelloSign
2
+ module Parameters
3
+ class ReusableFormSignatureRequest
4
+ attr_accessor :reusable_form_id, :title, :subject, :message
5
+ attr_writer :ccs, :signers, :custom_fields
6
+
7
+ def ccs
8
+ @ccs.inject({}) do |parameter, cc|
9
+ parameter[cc[:role]] = {:email_address => cc[:email]}
10
+ parameter
11
+ end
12
+ end
13
+
14
+ def signers
15
+ @signers.inject({}) do |parameter, signer|
16
+ parameter[signer[:role]] = {:name => signer[:name], :email_address => signer[:email]}
17
+ parameter
18
+ end
19
+ end
20
+
21
+ def custom_fields
22
+ @custom_fields.inject({}) do |parameter, custom_field|
23
+ parameter[custom_field[:name]] = custom_field[:value]
24
+ parameter
25
+ end
26
+ end
27
+
28
+ def formatted
29
+ {
30
+ :reusable_form_id => reusable_form_id,
31
+ :title => title,
32
+ :subject => subject,
33
+ :message => message,
34
+ :ccs => ccs,
35
+ :signers => signers,
36
+ :custom_fields => custom_fields
37
+ }
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,47 @@
1
+ require 'faraday/upload_io'
2
+
3
+ module HelloSign
4
+ module Parameters
5
+ class SignatureRequest
6
+ attr_accessor :title, :subject, :message, :ccs
7
+ attr_writer :signers, :files
8
+
9
+ def signers
10
+ @signers.each_with_index.inject({}) do |parameter, (signer, index)|
11
+ signer = {
12
+ :name => signer[:name],
13
+ :email_address => signer[:email],
14
+ :order => index
15
+ }
16
+ parameter[index] = signer
17
+ parameter
18
+ end
19
+ end
20
+
21
+ def files
22
+ @files.each_with_index.inject({}) do |parameter, (file, index)|
23
+ parameter[index + 1] = upload_io.new(file[:io], file[:mime], file[:name])
24
+ parameter
25
+ end
26
+ end
27
+
28
+ def formatted
29
+ {
30
+ :title => title,
31
+ :subject => subject,
32
+ :message => message,
33
+ :cc_email_addresses => ccs,
34
+ :signers => signers,
35
+ :file => files
36
+ }
37
+ end
38
+
39
+ private
40
+
41
+ def upload_io
42
+ Faraday::UploadIO
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,20 @@
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,27 +1,59 @@
1
- require 'hello_sign/signature_request_parameters'
1
+ require 'hello_sign/parameters/signature_request'
2
+ require 'hello_sign/parameters/reusable_form_signature_request'
2
3
 
3
4
  module HelloSign
4
5
  class SignatureRequestProxy
5
6
  attr_reader :client
6
- attr_writer :request_parameters
7
+ attr_writer :request_parameters, :reusable_form_request_parameters
7
8
 
8
9
  def initialize(client)
9
10
  @client = client
10
11
  end
11
12
 
12
- def create(raw_parameters)
13
- raw_parameters.call(request_parameters)
14
- client.post('/signature_request/send', :body => request_parameters.formatted)
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
15
25
  end
16
26
 
17
27
  def status(request_id)
18
28
  client.get("/signature_request/#{request_id}")
19
29
  end
20
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
+
21
49
  private
22
50
 
23
51
  def request_parameters
24
- @request_parameters ||= SignatureRequestParameters.new
52
+ @request_parameters ||= Parameters::SignatureRequest.new
53
+ end
54
+
55
+ def reusable_form_request_parameters
56
+ @reusable_form_request_parameters ||= Parameters::ReusableFormSignatureRequest.new
25
57
  end
26
58
 
27
59
  end
@@ -1,3 +1,3 @@
1
1
  module HelloSign
2
- VERSION = '0.0.5'
2
+ VERSION = '0.1.0'
3
3
  end
data/lib/hello_sign.rb CHANGED
@@ -11,12 +11,8 @@ module HelloSign
11
11
  AccountProxy.new(client)
12
12
  end
13
13
 
14
- def signature_request(request_id = nil, &parameters)
15
- if request_id
16
- SignatureRequestProxy.new(client).status(request_id)
17
- else
18
- SignatureRequestProxy.new(client).create(parameters)
19
- end
14
+ def signature_request
15
+ SignatureRequestProxy.new(client)
20
16
  end
21
17
 
22
18
  def client
@@ -27,5 +23,11 @@ module HelloSign
27
23
  yield(self)
28
24
  end
29
25
 
26
+ private
27
+
28
+ def signature_request_proxy
29
+ SignatureRequestProxy.new(client)
30
+ end
31
+
30
32
  end
31
33
  end
@@ -18,7 +18,7 @@ describe HelloSign do
18
18
  context "when accessing an account's settings" do
19
19
  before do
20
20
  stub_get_with_auth('/account')
21
- @settings = HelloSign.account.settings
21
+ HelloSign.account.settings.show
22
22
  end
23
23
 
24
24
  it "fetches the account's settings from the HelloSign API" do
@@ -28,7 +28,6 @@ describe HelloSign do
28
28
 
29
29
  context "when updating an account's settings" do
30
30
  before do
31
- stub_get_with_auth('/account')
32
31
  stub_post_with_auth('/account')
33
32
  HelloSign.account.settings.update(:callback_url => 'http://callmemaybe.com')
34
33
  end
@@ -2,42 +2,136 @@ require 'integration/helper'
2
2
 
3
3
  describe HelloSign do
4
4
  context "when sending a signature request" do
5
- let(:text_file_io) { File.new('spec/fixtures/test.txt') }
6
- let(:image_io) { File.new('spec/fixtures/test.jpg') }
5
+ context "when not using a reusable form" do
6
+ let(:text_file_io) { File.new('spec/fixtures/test.txt') }
7
+ let(:image_io) { File.new('spec/fixtures/test.jpg') }
7
8
 
8
- before do
9
- stub_post_with_auth('/signature_request/send')
10
- request = HelloSign.signature_request do |request|
11
- request.title = 'Lease'
12
- request.subject = 'Sign this'
13
- request.message = 'You must sign this.'
14
- request.ccs = ['lawyer@lawfirm.com', 'spouse@family.com']
15
- request.signers = [
16
- {:name => 'Jack', :email => 'jack@hill.com'},
17
- {:name => 'Jill', :email => 'jill@hill.com'}
18
- ]
19
- request.files = [
20
- {:name => 'test.txt', :io => text_file_io, :mime => 'text/plain'},
21
- {:name => 'test.jpg', :io => image_io, :mime => 'image/jpeg'}
22
- ]
9
+ before do
10
+ stub_post_with_auth('/signature_request/send')
11
+ HelloSign.signature_request.send do |request|
12
+ request.title = 'Lease'
13
+ request.subject = 'Sign this'
14
+ request.message = 'You must sign this.'
15
+ request.ccs = ['lawyer@lawfirm.com', 'spouse@family.com']
16
+ request.signers = [
17
+ {:name => 'Jack', :email => 'jack@hill.com'},
18
+ {:name => 'Jill', :email => 'jill@hill.com'}
19
+ ]
20
+ request.files = [
21
+ {:name => 'test.txt', :io => text_file_io, :mime => 'text/plain'},
22
+ {:name => 'test.jpg', :io => image_io, :mime => 'image/jpeg'}
23
+ ]
24
+ end
25
+ end
26
+
27
+ it "sends a signature request to the HelloSign API" do
28
+ expect(a_post_with_auth('/signature_request/send')
29
+ .with(:headers => {'Content-Type' => /multipart\/form-data/}, :body => /This is a test upload file\./)
30
+ ).to have_been_made
23
31
  end
24
32
  end
25
33
 
26
- it "sends a signature request to the HelloSign API" do
27
- expect(a_post_with_auth('/signature_request/send')
28
- .with(:headers => {'Content-Type' => /multipart\/form-data/}, :body => /This is a test upload file\./)
29
- ).to have_been_made
34
+ context "when using a reusable form" do
35
+ before do
36
+ stub_post_with_auth('/signature_request/send_with_reusable_form')
37
+ HelloSign.signature_request.send(:form => 'form_id') do |request|
38
+ request.title = 'Lease'
39
+ request.subject = 'Sign this'
40
+ request.message = 'You must sign this.'
41
+ request.ccs = [
42
+ {:email => 'lawyer@lawfirm.com', :role => 'lawyer'},
43
+ {:email => 'accountant@llc.com', :role => 'accountant'}
44
+ ]
45
+ request.signers = [
46
+ {:name => 'Jack', :email => 'jack@hill.com', :role => 'consultant'},
47
+ {:name => 'Jill', :email => 'jill@hill.com', :role => 'client'}
48
+ ]
49
+ request.custom_fields = [
50
+ {:name => 'cost', :value => '$20,000'},
51
+ {:name => 'time', :value => 'two weeks'}
52
+ ]
53
+ end
54
+ end
55
+
56
+ it "sends a signature request using a reusable form to the HelloSign API" do
57
+ expect(a_post_with_auth('/signature_request/send_with_reusable_form')
58
+ .with(:body => {
59
+ :reusable_form_id => 'form_id',
60
+ :title => 'Lease',
61
+ :subject => 'Sign this',
62
+ :message => 'You must sign this.',
63
+ :ccs => {
64
+ 'lawyer' => {:email_address => 'lawyer@lawfirm.com'},
65
+ 'accountant' => {:email_address => 'accountant@llc.com'}
66
+ },
67
+ :signers => {
68
+ 'consultant' => {:name => 'Jack', :email_address => 'jack@hill.com'},
69
+ 'client' => {:name => 'Jill', :email_address => 'jill@hill.com'}
70
+ },
71
+ :custom_fields => {
72
+ 'cost' => '$20,000',
73
+ 'time' => 'two weeks'
74
+ }
75
+ })
76
+ ).to have_been_made
77
+ end
30
78
  end
31
79
  end
32
80
 
33
81
  context "when fetching a signature request" do
34
82
  before do
35
83
  stub_get_with_auth('/signature_request/request_id')
36
- HelloSign.signature_request('request_id')
84
+ HelloSign.signature_request.status('request_id')
37
85
  end
38
86
 
39
87
  it "fetches the signature request information from the HelloSign API" do
40
88
  expect(a_get_with_auth('/signature_request/request_id')).to have_been_made
41
89
  end
42
90
  end
91
+
92
+ context "when getting a list of signature requests" do
93
+ before do
94
+ stub_get_with_auth('/signature_request/list?page=1')
95
+ HelloSign.signature_request.list
96
+ end
97
+
98
+ it "fetches a list of signature requests from the HelloSign API" do
99
+ expect(a_get_with_auth('/signature_request/list?page=1')).to have_been_made
100
+ end
101
+ end
102
+
103
+ context "when sending a signature request reminder" do
104
+ before do
105
+ stub_post_with_auth('/signature_request/remind/request_id')
106
+ HelloSign.signature_request.remind('request_id', :email => 'john@johnson.com')
107
+ end
108
+
109
+ it "sends a reminder request to the HelloSign API" do
110
+ expect(a_post_with_auth('/signature_request/remind/request_id')
111
+ .with(:body => {:email_address => 'john@johnson.com'})
112
+ ).to have_been_made
113
+ end
114
+ end
115
+
116
+ context "when canceling a signature request" do
117
+ before do
118
+ stub_post_with_auth('/signature_request/cancel/request_id')
119
+ HelloSign.signature_request.cancel('request_id')
120
+ end
121
+
122
+ it "sends a signature request cancellation to the HelloSign API" do
123
+ expect(a_post_with_auth('/signature_request/cancel/request_id')).to have_been_made
124
+ end
125
+ end
126
+
127
+ context "when fetching a final copy of a signature request" do
128
+ before do
129
+ stub_get_with_auth('/signature_request/final_copy/request_id')
130
+ HelloSign.signature_request.final_copy('request_id')
131
+ end
132
+
133
+ it "fetches a final copy of the signature request from the HelloSign API" do
134
+ expect(a_get_with_auth('/signature_request/final_copy/request_id')).to have_been_made
135
+ end
136
+ end
43
137
  end
@@ -13,7 +13,9 @@ describe HelloSign::AccountProxy do
13
13
 
14
14
  describe "#create" do
15
15
  context "when passed the proper parameters" do
16
- before { client.stub(:post) }
16
+ let(:api_response) { double('API response') }
17
+
18
+ before { client.stub(:post).and_return(api_response) }
17
19
 
18
20
  it "sends an account creation request" do
19
21
  client.should_receive(:post)
@@ -25,8 +27,8 @@ describe HelloSign::AccountProxy do
25
27
  account_proxy.create(:email => 'david@bowman.com', :password => 'space')
26
28
  end
27
29
 
28
- it "returns true" do
29
- expect(account_proxy.create(:email => 'david@bowman.com', :password => 'space')). to be true
30
+ it "returns the API response" do
31
+ expect(account_proxy.create(:email => 'david@bowman.com', :password => 'space')). to eq api_response
30
32
  end
31
33
  end
32
34
 
@@ -38,22 +40,16 @@ describe HelloSign::AccountProxy do
38
40
  end
39
41
 
40
42
  describe "#settings" do
41
- let(:settings) { double('settings') }
42
-
43
- before { client.stub(:get).and_return(settings) }
44
-
45
- it "sends a request to fetch the account's settings" do
46
- client.should_receive(:get).with('/account')
47
- account_proxy.settings
48
- end
43
+ let(:settings_proxy_source) { double('settings proxy source') }
44
+ let(:settings_proxy) { double('settings proxy') }
49
45
 
50
- it "creates an account object" do
51
- HelloSign::Settings.should_receive(:new).with(settings, client)
52
- account_proxy.settings
46
+ before do
47
+ account_proxy.settings_proxy_source = settings_proxy_source
48
+ settings_proxy_source.should_receive(:new).with(client).and_return(settings_proxy)
53
49
  end
54
50
 
55
- it "returns an account object" do
56
- expect(account_proxy.settings).to be_a HelloSign::Settings
51
+ it "returns a signature request proxy" do
52
+ expect(account_proxy.settings).to be settings_proxy
57
53
  end
58
54
  end
59
55
  end
@@ -9,25 +9,8 @@ describe HelloSign do
9
9
  end
10
10
 
11
11
  describe "::signature_request" do
12
- let(:sr_proxy) { mock }
13
- let(:request_result) { stub }
14
-
15
- before { HelloSign::SignatureRequestProxy.stub(:new).and_return(sr_proxy) }
16
-
17
- context "when called without passing a request ID" do
18
- before { sr_proxy.should_receive(:create).and_return(request_result) }
19
-
20
- it "calls #create on the signature request proxy and returns the result" do
21
- expect(HelloSign.signature_request).to eq request_result
22
- end
23
- end
24
-
25
- context "when called with a signature ID" do
26
- before { sr_proxy.should_receive(:status).with('request_id').and_return(request_result) }
27
-
28
- it "calls #status on the signature request proxy and returns the result " do
29
- expect(HelloSign.signature_request('request_id')).to eq request_result
30
- end
12
+ it "returns a signature request proxy" do
13
+ expect(HelloSign.signature_request).to be_a HelloSign::SignatureRequestProxy
31
14
  end
32
15
  end
33
16
 
@@ -0,0 +1,51 @@
1
+ require 'helper'
2
+ require 'hello_sign/parameters/reusable_form_signature_request'
3
+
4
+ describe HelloSign::Parameters::ReusableFormSignatureRequest do
5
+ describe "#formatted" do
6
+ let(:request_parameters) { HelloSign::Parameters::ReusableFormSignatureRequest.new }
7
+ let(:expected) do
8
+ {
9
+ :reusable_form_id => 'form_id',
10
+ :title => 'Lease',
11
+ :subject => 'Sign this',
12
+ :message => 'You must sign this.',
13
+ :ccs => {
14
+ 'lawyer' => {:email_address => 'lawyer@lawfirm.com'},
15
+ 'accountant' => {:email_address => 'accountant@llc.com'}
16
+ },
17
+ :signers => {
18
+ 'consultant' => {:name => 'Jack', :email_address => 'jack@hill.com'},
19
+ 'client' => {:name => 'Jill', :email_address => 'jill@hill.com'}
20
+ },
21
+ :custom_fields => {
22
+ 'cost' => '$20,000',
23
+ 'time' => 'two weeks'
24
+ }
25
+ }
26
+ end
27
+
28
+ before do
29
+ request_parameters.reusable_form_id = 'form_id'
30
+ request_parameters.title = 'Lease'
31
+ request_parameters.subject = 'Sign this'
32
+ request_parameters.message = 'You must sign this.'
33
+ request_parameters.ccs = [
34
+ {:email => 'lawyer@lawfirm.com', :role => 'lawyer'},
35
+ {:email => 'accountant@llc.com', :role => 'accountant'}
36
+ ]
37
+ request_parameters.signers = [
38
+ {:name => 'Jack', :email => 'jack@hill.com', :role => 'consultant'},
39
+ {:name => 'Jill', :email => 'jill@hill.com', :role => 'client'}
40
+ ]
41
+ request_parameters.custom_fields = [
42
+ {:name => 'cost', :value => '$20,000'},
43
+ {:name => 'time', :value => 'two weeks'}
44
+ ]
45
+ end
46
+
47
+ it "returns formatted parameters" do
48
+ expect(request_parameters.formatted).to eq expected
49
+ end
50
+ end
51
+ end
@@ -1,32 +1,17 @@
1
1
  require 'helper'
2
- require 'hello_sign/signature_request_parameters'
2
+ require 'hello_sign/parameters/signature_request'
3
3
 
4
- describe HelloSign::SignatureRequestParameters do
4
+ describe HelloSign::Parameters::SignatureRequest do
5
5
  describe "#formatted" do
6
- before do
7
- Faraday::UploadIO.should_receive(:new).with('text file IO object', 'text/plain', 'test.txt').and_return(text_file = stub)
8
- Faraday::UploadIO.should_receive(:new).with('image file IO object', 'image/jpeg', 'test.jpg').and_return(image_file = stub)
9
-
10
- @request_parameters = HelloSign::SignatureRequestParameters.new
11
-
12
- @request_parameters.title = 'Lease'
13
- @request_parameters.subject = 'Sign this'
14
- @request_parameters.message = 'You must sign this.'
15
- @request_parameters.ccs = ['lawyer@lawfirm.com', 'spouse@family.com']
16
- @request_parameters.signers = [
17
- {:name => 'Jack', :email => 'jack@hill.com'},
18
- {:name => 'Jill', :email => 'jill@hill.com'}
19
- ]
20
- @request_parameters.files = [
21
- {:name => 'test.txt', :io => 'text file IO object', :mime => 'text/plain'},
22
- {:name => 'test.jpg', :io => 'image file IO object', :mime => 'image/jpeg'}
23
- ]
24
-
25
- @expected = {
6
+ let(:request_parameters) { HelloSign::Parameters::SignatureRequest.new }
7
+ let(:text_file) { double('text file') }
8
+ let(:image_file) { double('image file') }
9
+ let(:expected) do
10
+ {
26
11
  :title => 'Lease',
27
12
  :subject =>'Sign this',
28
13
  :message =>'You must sign this.',
29
- :cc_email_addresses => ['lawyer@lawfirm.com', 'spouse@family.com'],
14
+ :cc_email_addresses => ['lawyer@lawfirm.com', 'spouse@family.com'], # BUGBUG: should have explicit indexes
30
15
  :signers => {
31
16
  0 => {:name => 'Jack', :email_address => 'jack@hill.com', :order => 0},
32
17
  1 => {:name => 'Jill', :email_address => 'jill@hill.com', :order => 1}
@@ -35,8 +20,26 @@ describe HelloSign::SignatureRequestParameters do
35
20
  }
36
21
  end
37
22
 
23
+ before do
24
+ Faraday::UploadIO.should_receive(:new).with('text file IO object', 'text/plain', 'test.txt').and_return(text_file)
25
+ Faraday::UploadIO.should_receive(:new).with('image file IO object', 'image/jpeg', 'test.jpg').and_return(image_file)
26
+
27
+ request_parameters.title = 'Lease'
28
+ request_parameters.subject = 'Sign this'
29
+ request_parameters.message = 'You must sign this.'
30
+ request_parameters.ccs = ['lawyer@lawfirm.com', 'spouse@family.com']
31
+ request_parameters.signers = [
32
+ {:name => 'Jack', :email => 'jack@hill.com'},
33
+ {:name => 'Jill', :email => 'jill@hill.com'}
34
+ ]
35
+ request_parameters.files = [
36
+ {:name => 'test.txt', :io => 'text file IO object', :mime => 'text/plain'},
37
+ {:name => 'test.jpg', :io => 'image file IO object', :mime => 'image/jpeg'}
38
+ ]
39
+ end
40
+
38
41
  it "returns formatted parameters" do
39
- expect(@request_parameters.formatted).to eq @expected
42
+ expect(request_parameters.formatted).to eq expected
40
43
  end
41
44
  end
42
45
  end
@@ -0,0 +1,29 @@
1
+ require 'helper'
2
+ require 'hello_sign/settings_proxy'
3
+
4
+ describe HelloSign::SettingsProxy do
5
+ let(:client) { double('client') }
6
+ subject(:settings) { HelloSign::SettingsProxy.new(client) }
7
+
8
+ describe "#client" do
9
+ it "returns the client" do
10
+ expect(settings.client).to eq client
11
+ end
12
+ end
13
+
14
+ describe "#update" do
15
+ let(:callback_url) { 'http://www.callmemaybe.com' }
16
+ let(:api_response) { double('API response') }
17
+
18
+ before { client.stub(:post).and_return(api_response) }
19
+
20
+ it "sends a request to update the account's settings" do
21
+ client.should_receive(:post).with('/account', :body => {:callback_url => callback_url})
22
+ settings.update(:callback_url => callback_url)
23
+ end
24
+
25
+ it "returns the API response" do
26
+ expect(settings.update(:callback_url => callback_url)).to be api_response
27
+ end
28
+ end
29
+ end
@@ -2,8 +2,9 @@ require 'helper'
2
2
  require 'hello_sign/signature_request_proxy'
3
3
 
4
4
  describe HelloSign::SignatureRequestProxy do
5
- let(:client) { mock }
6
- let(:api_response) { stub }
5
+ let(:client) { double('client') }
6
+ let(:request_id) { 'request_id' }
7
+ let(:api_response) { double('API response') }
7
8
  subject(:sr_proxy) { HelloSign::SignatureRequestProxy.new(client) }
8
9
 
9
10
  describe "#client" do
@@ -12,34 +13,114 @@ describe HelloSign::SignatureRequestProxy do
12
13
  end
13
14
  end
14
15
 
15
- describe "#create" do
16
- let(:formatted_request_body) { stub }
17
- let(:raw_parameters) { Proc.new { |params| params.foo = 'bar' } }
18
- let(:request_parameters) { mock }
16
+ describe "#send" do
17
+ let(:formatted_request_body) { double('formatted request body') }
18
+ let(:request_parameters) { double('request parameters') }
19
19
 
20
- before do
21
- sr_proxy.request_parameters = request_parameters
22
- request_parameters.stub(:formatted).and_return(formatted_request_body)
23
- request_parameters.should_receive(:foo=).with('bar')
24
- client.should_receive(:post)
25
- .with('/signature_request/send', :body => formatted_request_body)
26
- .and_return(api_response)
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
27
33
  end
28
34
 
29
- it "sends a signature request creation request and returns the result" do
30
- expect(sr_proxy.create(raw_parameters)).to eq api_response
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
31
49
  end
32
50
  end
33
51
 
34
52
  describe "#status" do
35
- let(:request_id) { 'request_id' }
36
-
37
- before do
38
- client.should_receive(:get).with('/signature_request/request_id').and_return(api_response)
39
- end
53
+ before { client.should_receive(:get).with('/signature_request/request_id').and_return(api_response) }
40
54
 
41
55
  it "fetches the signature request status and returns the result" do
42
56
  expect(sr_proxy.status(request_id)).to eq api_response
43
57
  end
44
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
45
126
  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.0.5
4
+ version: 0.1.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-27 00:00:00.000000000 Z
12
+ date: 2013-01-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -84,8 +84,9 @@ extra_rdoc_files: []
84
84
  files:
85
85
  - lib/hello_sign/account_proxy.rb
86
86
  - lib/hello_sign/client.rb
87
- - lib/hello_sign/settings.rb
88
- - lib/hello_sign/signature_request_parameters.rb
87
+ - lib/hello_sign/parameters/reusable_form_signature_request.rb
88
+ - lib/hello_sign/parameters/signature_request.rb
89
+ - lib/hello_sign/settings_proxy.rb
89
90
  - lib/hello_sign/signature_request_proxy.rb
90
91
  - lib/hello_sign/version.rb
91
92
  - lib/hello_sign.rb
@@ -100,8 +101,9 @@ files:
100
101
  - spec/unit/account_proxy_spec.rb
101
102
  - spec/unit/client_spec.rb
102
103
  - spec/unit/hello_sign_spec.rb
103
- - spec/unit/settings_spec.rb
104
- - spec/unit/signature_request_parameters_spec.rb
104
+ - spec/unit/parameters/reusable_form_signature_request_spec.rb
105
+ - spec/unit/parameters/signature_request_spec.rb
106
+ - spec/unit/settings_proxy_spec.rb
105
107
  - spec/unit/signature_request_proxy_spec.rb
106
108
  homepage: http://www.github.com/craiglittle/hello_sign
107
109
  licenses: []
@@ -139,6 +141,7 @@ test_files:
139
141
  - spec/unit/account_proxy_spec.rb
140
142
  - spec/unit/client_spec.rb
141
143
  - spec/unit/hello_sign_spec.rb
142
- - spec/unit/settings_spec.rb
143
- - spec/unit/signature_request_parameters_spec.rb
144
+ - spec/unit/parameters/reusable_form_signature_request_spec.rb
145
+ - spec/unit/parameters/signature_request_spec.rb
146
+ - spec/unit/settings_proxy_spec.rb
144
147
  - spec/unit/signature_request_proxy_spec.rb
@@ -1,19 +0,0 @@
1
- require 'hello_sign/client'
2
-
3
- module HelloSign
4
- class Settings
5
- attr_reader :attributes, :client
6
-
7
- def initialize(attributes, client)
8
- @attributes = attributes
9
- @client = client
10
- end
11
-
12
- def update(attributes)
13
- client.post('/account', :body => attributes)
14
-
15
- true
16
- end
17
-
18
- end
19
- end
@@ -1,45 +0,0 @@
1
- require 'faraday/upload_io'
2
-
3
- module HelloSign
4
- class SignatureRequestParameters
5
- attr_accessor :title, :subject, :message, :ccs
6
- attr_writer :signers, :files
7
-
8
- def signers
9
- @signers.each_with_index.inject({}) do |parameter, (signer, index)|
10
- signer = {
11
- :name => signer[:name],
12
- :email_address => signer[:email],
13
- :order => index
14
- }
15
- parameter[index] = signer
16
- parameter
17
- end
18
- end
19
-
20
- def files
21
- @files.each_with_index.inject({}) do |parameter, (file, index)|
22
- parameter[index + 1] = upload_io.new(file[:io], file[:mime], file[:name])
23
- parameter
24
- end
25
- end
26
-
27
- def formatted
28
- {
29
- :title => title,
30
- :subject => subject,
31
- :message => message,
32
- :cc_email_addresses => ccs,
33
- :signers => signers,
34
- :file => files
35
- }
36
- end
37
-
38
- private
39
-
40
- def upload_io
41
- Faraday::UploadIO
42
- end
43
-
44
- end
45
- end
@@ -1,36 +0,0 @@
1
- require 'helper'
2
- require 'hello_sign/settings'
3
-
4
- describe HelloSign::Settings do
5
- let(:attributes) { double('attributes') }
6
- let(:client) { double('client') }
7
- subject(:settings) { HelloSign::Settings.new(attributes, client) }
8
-
9
- describe "#attributes" do
10
- it "returns the attributes" do
11
- expect(settings.attributes).to eq attributes
12
- end
13
- end
14
-
15
- describe "#client" do
16
- it "returns the client" do
17
- expect(settings.client).to eq client
18
- end
19
- end
20
-
21
- describe "#update" do
22
- let(:callback_url) { 'http://www.callmemaybe.com' }
23
-
24
- before { client.stub(:post) }
25
-
26
- it "sends a request to update the account's settings" do
27
- client.should_receive(:post)
28
- .with('/account', :body => {:callback_url => callback_url})
29
- settings.update(:callback_url => callback_url)
30
- end
31
-
32
- it "returns true" do
33
- expect(settings.update(:callback_url => callback_url)).to be true
34
- end
35
- end
36
- end