hello_sign 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/hello_sign.rb +29 -5
- data/lib/hello_sign/client.rb +13 -38
- data/lib/hello_sign/connection.rb +53 -0
- data/lib/hello_sign/error.rb +13 -9
- data/lib/hello_sign/middleware/parse_json.rb +22 -0
- data/lib/hello_sign/middleware/raise_error.rb +2 -0
- data/lib/hello_sign/parameters/reusable_form_signature_request.rb +27 -14
- data/lib/hello_sign/parameters/signature_request.rb +29 -21
- data/lib/hello_sign/parameters/unclaimed_draft.rb +8 -5
- data/lib/hello_sign/proxy/signature_request.rb +30 -18
- data/lib/hello_sign/version.rb +1 -1
- data/spec/helper.rb +0 -6
- data/spec/integration/hello_sign_spec.rb +7 -1
- data/spec/integration/helper.rb +17 -4
- data/spec/shared_examples/proxy.rb +58 -15
- data/spec/unit/client_spec.rb +42 -27
- data/spec/unit/connection_spec.rb +38 -0
- data/spec/unit/error_spec.rb +65 -13
- data/spec/unit/hello_sign_spec.rb +66 -23
- data/spec/unit/middleware/parse_json_spec.rb +38 -0
- data/spec/unit/middleware/raise_error_spec.rb +36 -23
- data/spec/unit/parameters/reusable_form_signature_request_spec.rb +74 -37
- data/spec/unit/parameters/signature_request_spec.rb +11 -5
- data/spec/unit/parameters/unclaimed_draft_spec.rb +14 -6
- data/spec/unit/proxy/account_spec.rb +17 -9
- data/spec/unit/proxy/reusable_form_spec.rb +31 -14
- data/spec/unit/proxy/settings_spec.rb +11 -4
- data/spec/unit/proxy/signature_request_spec.rb +74 -38
- data/spec/unit/proxy/team_spec.rb +39 -20
- data/spec/unit/proxy/unclaimed_draft_spec.rb +25 -6
- data/spec/unit/upload_io_spec.rb +69 -27
- metadata +20 -40
@@ -5,11 +5,14 @@ describe HelloSign::Proxy::SignatureRequest do
|
|
5
5
|
let(:client) { double('client') }
|
6
6
|
let(:request_id) { 'request_id' }
|
7
7
|
let(:api_response) { double('API response') }
|
8
|
-
|
8
|
+
|
9
|
+
subject(:sr_proxy) do
|
10
|
+
HelloSign::Proxy::SignatureRequest.new(client, request_id)
|
11
|
+
end
|
9
12
|
|
10
13
|
before do
|
11
|
-
client.
|
12
|
-
client.
|
14
|
+
allow(client).to receive(:get).and_return(api_response)
|
15
|
+
allow(client).to receive(:post).and_return(api_response)
|
13
16
|
end
|
14
17
|
|
15
18
|
describe "#deliver" do
|
@@ -17,80 +20,103 @@ describe HelloSign::Proxy::SignatureRequest do
|
|
17
20
|
let(:request_parameters) { double('request parameters') }
|
18
21
|
|
19
22
|
before do
|
20
|
-
request_parameters.
|
21
|
-
request_parameters
|
22
|
-
|
23
|
+
allow(request_parameters).to receive(:foo=)
|
24
|
+
allow(request_parameters).to(
|
25
|
+
receive(:formatted).and_return(formatted_request_body)
|
26
|
+
)
|
27
|
+
allow(HelloSign::Parameters::SignatureRequest).to(
|
28
|
+
receive(:new).and_return(request_parameters)
|
29
|
+
)
|
30
|
+
|
31
|
+
@response = sr_proxy.deliver { |params| params.foo = 'bar' }
|
23
32
|
end
|
24
33
|
|
25
34
|
it "yields the request parameters to the block" do
|
26
|
-
request_parameters.
|
27
|
-
sr_proxy.deliver { |params| params.foo = 'bar' }
|
35
|
+
expect(request_parameters).to have_received(:foo=).with('bar')
|
28
36
|
end
|
29
37
|
|
30
38
|
it "sends a signature request" do
|
31
|
-
client.
|
32
|
-
|
39
|
+
expect(client).to have_received(:post).with(
|
40
|
+
'/signature_request/send',
|
41
|
+
body: formatted_request_body
|
42
|
+
)
|
33
43
|
end
|
34
44
|
|
35
45
|
it "returns the response" do
|
36
|
-
expect(
|
46
|
+
expect(@response).to eq api_response
|
37
47
|
end
|
38
48
|
|
39
49
|
context "when a reusable form is specified" do
|
40
50
|
before do
|
41
|
-
request_parameters.
|
42
|
-
HelloSign::Parameters::ReusableFormSignatureRequest
|
51
|
+
allow(request_parameters).to receive(:reusable_form_id=)
|
52
|
+
allow(HelloSign::Parameters::ReusableFormSignatureRequest).to(
|
53
|
+
receive(:new).and_return(request_parameters)
|
54
|
+
)
|
55
|
+
|
56
|
+
@response = sr_proxy.deliver(form: 'form_id') { }
|
43
57
|
end
|
44
58
|
|
45
59
|
it "sets the reusable form ID in the request parameters" do
|
46
|
-
request_parameters
|
47
|
-
|
60
|
+
expect(request_parameters).to(
|
61
|
+
have_received(:reusable_form_id=).with('form_id')
|
62
|
+
)
|
48
63
|
end
|
49
64
|
|
50
65
|
it "sends a reusable form signature request" do
|
51
|
-
client.
|
52
|
-
|
66
|
+
expect(client).to have_received(:post).with(
|
67
|
+
'/signature_request/send_with_reusable_form',
|
68
|
+
body: formatted_request_body
|
69
|
+
)
|
53
70
|
end
|
54
71
|
|
55
72
|
it "returns the response" do
|
56
|
-
expect(
|
73
|
+
expect(@response).to eq api_response
|
57
74
|
end
|
58
75
|
end
|
59
76
|
end
|
60
77
|
|
61
78
|
describe "#status" do
|
79
|
+
before { @response = sr_proxy.status }
|
80
|
+
|
62
81
|
it "fetches the signature request status" do
|
63
|
-
client.
|
64
|
-
|
82
|
+
expect(client).to have_received(:get).with(
|
83
|
+
"/signature_request/#{request_id}"
|
84
|
+
)
|
65
85
|
end
|
66
86
|
|
67
87
|
it "returns the response" do
|
68
|
-
expect(
|
88
|
+
expect(@response).to eq api_response
|
69
89
|
end
|
70
90
|
end
|
71
91
|
|
72
92
|
describe "#list" do
|
73
93
|
context "when called without a page number" do
|
94
|
+
before { @response = sr_proxy.list }
|
95
|
+
|
74
96
|
it "fetches the first page of signature requests" do
|
75
|
-
client.
|
76
|
-
|
97
|
+
expect(client).to have_received(:get).with(
|
98
|
+
'/signature_request/list',
|
99
|
+
params: {page: 1}
|
100
|
+
)
|
77
101
|
end
|
78
102
|
|
79
103
|
it "returns the response" do
|
80
|
-
|
81
|
-
expect(sr_proxy.list).to eq api_response
|
104
|
+
expect(@response).to eq api_response
|
82
105
|
end
|
83
106
|
end
|
84
107
|
|
85
108
|
context "when called with a page number" do
|
109
|
+
before { @response = sr_proxy.list(page: 10) }
|
110
|
+
|
86
111
|
it "fetches a list of signature requests from the specified page" do
|
87
|
-
client.
|
88
|
-
|
112
|
+
expect(client).to have_received(:get).with(
|
113
|
+
'/signature_request/list',
|
114
|
+
params: {page: 10}
|
115
|
+
)
|
89
116
|
end
|
90
117
|
|
91
118
|
it "returns the response" do
|
92
|
-
|
93
|
-
expect(sr_proxy.list(page: 10)).to eq api_response
|
119
|
+
expect(@response).to eq api_response
|
94
120
|
end
|
95
121
|
end
|
96
122
|
end
|
@@ -98,35 +124,45 @@ describe HelloSign::Proxy::SignatureRequest do
|
|
98
124
|
describe "#remind" do
|
99
125
|
let(:email) { 'john@johnson.com' }
|
100
126
|
|
127
|
+
before { @response = sr_proxy.remind(email: email) }
|
128
|
+
|
101
129
|
it "sends a signature request reminder" do
|
102
|
-
client.
|
103
|
-
|
130
|
+
expect(client).to have_received(:post).with(
|
131
|
+
"/signature_request/remind/#{request_id}",
|
132
|
+
body: {email_address: email}
|
133
|
+
)
|
104
134
|
end
|
105
135
|
|
106
136
|
it "returns the response" do
|
107
|
-
expect(
|
137
|
+
expect(@response).to eq api_response
|
108
138
|
end
|
109
139
|
end
|
110
140
|
|
111
141
|
describe "#cancel" do
|
142
|
+
before { @response = sr_proxy.cancel }
|
143
|
+
|
112
144
|
it "cancels a signature request" do
|
113
|
-
client.
|
114
|
-
|
145
|
+
expect(client).to have_received(:post).with(
|
146
|
+
"/signature_request/cancel/#{request_id}"
|
147
|
+
)
|
115
148
|
end
|
116
149
|
|
117
150
|
it "returns the response" do
|
118
|
-
expect(
|
151
|
+
expect(@response).to eq api_response
|
119
152
|
end
|
120
153
|
end
|
121
154
|
|
122
155
|
describe "#final_copy" do
|
156
|
+
before { @response = sr_proxy.final_copy }
|
157
|
+
|
123
158
|
it "fetches a final copy of the signature request" do
|
124
|
-
client.
|
125
|
-
|
159
|
+
expect(client).to have_received(:get).with(
|
160
|
+
"/signature_request/final_copy/#{request_id}"
|
161
|
+
)
|
126
162
|
end
|
127
163
|
|
128
164
|
it "returns the response" do
|
129
|
-
expect(
|
165
|
+
expect(@response).to eq api_response
|
130
166
|
end
|
131
167
|
end
|
132
168
|
end
|
@@ -4,84 +4,103 @@ require 'hello_sign/proxy/team'
|
|
4
4
|
describe HelloSign::Proxy::Team do
|
5
5
|
let(:client) { double('client') }
|
6
6
|
let(:api_response) { double('API response') }
|
7
|
+
|
7
8
|
subject(:team_proxy) { HelloSign::Proxy::Team.new(client) }
|
8
9
|
|
9
10
|
before do
|
10
|
-
client.
|
11
|
-
client.
|
11
|
+
allow(client).to receive(:get).and_return(api_response)
|
12
|
+
allow(client).to receive(:post).and_return(api_response)
|
12
13
|
end
|
13
14
|
|
14
15
|
describe "#create" do
|
15
16
|
let(:name) { 'The Browncoats' }
|
16
17
|
|
18
|
+
before { @response = team_proxy.create(name: name) }
|
19
|
+
|
17
20
|
it "sends a request to create a team" do
|
18
|
-
client.
|
19
|
-
|
21
|
+
expect(client).to have_received(:post).with(
|
22
|
+
'/team/create',
|
23
|
+
body: {name: name}
|
24
|
+
)
|
20
25
|
end
|
21
26
|
|
22
27
|
it "returns the API response" do
|
23
|
-
expect(
|
28
|
+
expect(@response).to eq api_response
|
24
29
|
end
|
25
30
|
end
|
26
31
|
|
27
32
|
describe "#show" do
|
33
|
+
before { @response = team_proxy.show }
|
34
|
+
|
28
35
|
it "sends a request to fetch the team information" do
|
29
|
-
client.
|
30
|
-
team_proxy.show
|
36
|
+
expect(client).to have_received(:get).with('/team')
|
31
37
|
end
|
32
38
|
|
33
39
|
it "returns the API response" do
|
34
|
-
expect(
|
40
|
+
expect(@response).to eq api_response
|
35
41
|
end
|
36
42
|
end
|
37
43
|
|
38
44
|
describe "#update" do
|
39
45
|
let(:new_name) { 'The Bluecoats' }
|
40
46
|
|
47
|
+
before { @response = team_proxy.update(name: new_name) }
|
48
|
+
|
41
49
|
it "sends a request to update the team information" do
|
42
|
-
client.
|
43
|
-
|
50
|
+
expect(client).to have_received(:post).with(
|
51
|
+
'/team',
|
52
|
+
body: {name: new_name}
|
53
|
+
)
|
44
54
|
end
|
45
55
|
|
46
56
|
it "returns the API response" do
|
47
|
-
expect(
|
57
|
+
expect(@response).to eq api_response
|
48
58
|
end
|
49
59
|
end
|
50
60
|
|
51
61
|
describe "#destroy" do
|
62
|
+
before { @response = team_proxy.destroy }
|
63
|
+
|
52
64
|
it "sends a request to destroy the team" do
|
53
|
-
client.
|
54
|
-
team_proxy.destroy
|
65
|
+
expect(client).to have_received(:post).with('/team/destroy')
|
55
66
|
end
|
56
67
|
|
57
68
|
it "returns the API response" do
|
58
|
-
expect(
|
69
|
+
expect(@response).to eq api_response
|
59
70
|
end
|
60
71
|
end
|
61
72
|
|
62
73
|
describe "#add_member" do
|
63
74
|
let(:email_address) { 'john@johnson.com' }
|
64
75
|
|
76
|
+
before { @response = team_proxy.add_member(email_address: email_address) }
|
77
|
+
|
65
78
|
it "sends a request to add the member to the team" do
|
66
|
-
client.
|
67
|
-
|
79
|
+
expect(client).to have_received(:post).with(
|
80
|
+
'/team/add_member',
|
81
|
+
body: {email_address: email_address}
|
82
|
+
)
|
68
83
|
end
|
69
84
|
|
70
85
|
it "returns the API response" do
|
71
|
-
expect(
|
86
|
+
expect(@response).to eq api_response
|
72
87
|
end
|
73
88
|
end
|
74
89
|
|
75
90
|
describe "#remove_member" do
|
76
91
|
let(:email_address) { 'john@johnson.com' }
|
77
92
|
|
93
|
+
before { @response = team_proxy.remove_member(email_address: email_address) }
|
94
|
+
|
78
95
|
it "sends a request to remove the member from the team" do
|
79
|
-
client.
|
80
|
-
|
96
|
+
expect(client).to have_received(:post).with(
|
97
|
+
'/team/remove_member',
|
98
|
+
body: {email_address: email_address}
|
99
|
+
)
|
81
100
|
end
|
82
101
|
|
83
102
|
it "returns the API response" do
|
84
|
-
expect(
|
103
|
+
expect(@response).to eq api_response
|
85
104
|
end
|
86
105
|
end
|
87
106
|
end
|
@@ -4,21 +4,40 @@ require 'hello_sign/proxy/unclaimed_draft'
|
|
4
4
|
describe HelloSign::Proxy::UnclaimedDraft do
|
5
5
|
let(:client) { double('client') }
|
6
6
|
let(:api_response) { double('API response') }
|
7
|
+
|
7
8
|
subject(:ud_proxy) { HelloSign::Proxy::UnclaimedDraft.new(client) }
|
8
9
|
|
10
|
+
before { allow(client).to receive(:post).and_return(api_response) }
|
11
|
+
|
9
12
|
describe "#create" do
|
10
13
|
let(:formatted_request_body) { double('formatted request body') }
|
11
14
|
let(:draft_parameters) { double('draft parameters') }
|
12
15
|
|
13
16
|
before do
|
14
|
-
HelloSign::Parameters::UnclaimedDraft
|
15
|
-
|
16
|
-
|
17
|
-
|
17
|
+
allow(HelloSign::Parameters::UnclaimedDraft).to(
|
18
|
+
receive(:new).and_return(draft_parameters)
|
19
|
+
)
|
20
|
+
allow(draft_parameters).to(
|
21
|
+
receive(:formatted).and_return(formatted_request_body)
|
22
|
+
)
|
23
|
+
allow(draft_parameters).to receive(:foo=)
|
24
|
+
|
25
|
+
@response = ud_proxy.create { |params| params.foo = 'bar' }
|
26
|
+
end
|
27
|
+
|
28
|
+
it "yields the request parameters to the block" do
|
29
|
+
expect(draft_parameters).to have_received(:foo=).with('bar')
|
30
|
+
end
|
31
|
+
|
32
|
+
it "sends an unclaimed draft creation request" do
|
33
|
+
expect(client).to have_received(:post).with(
|
34
|
+
'/unclaimed_draft/create',
|
35
|
+
body: formatted_request_body
|
36
|
+
)
|
18
37
|
end
|
19
38
|
|
20
|
-
it "
|
21
|
-
expect(
|
39
|
+
it "returns the response" do
|
40
|
+
expect(@response).to eq api_response
|
22
41
|
end
|
23
42
|
end
|
24
43
|
end
|
data/spec/unit/upload_io_spec.rb
CHANGED
@@ -5,53 +5,95 @@ describe HelloSign::File do
|
|
5
5
|
let(:attachment) { double('attachment') }
|
6
6
|
let(:io_object) { double('IO object') }
|
7
7
|
|
8
|
-
|
9
|
-
Faraday::UploadIO.
|
8
|
+
context "#attachment" do
|
9
|
+
before { allow(Faraday::UploadIO).to receive(:new).and_return(attachment) }
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
it "returns the attachment" do
|
12
|
+
expect(HelloSign::File.new(filename: 'test.txt').attachment).to(
|
13
|
+
eq attachment
|
14
|
+
)
|
15
|
+
end
|
13
16
|
|
14
|
-
|
15
|
-
|
16
|
-
Faraday::UploadIO.should_receive(:new).with('test.txt', 'text/plain')
|
17
|
+
context "when called with a file with a .txt extension" do
|
18
|
+
before { HelloSign::File.new(filename: 'test.txt').attachment }
|
17
19
|
|
18
|
-
|
20
|
+
it "creates an attachment with a text/plain MIME type" do
|
21
|
+
expect(Faraday::UploadIO).to(
|
22
|
+
have_received(:new).with('test.txt', 'text/plain')
|
23
|
+
)
|
24
|
+
end
|
19
25
|
end
|
20
26
|
|
21
|
-
|
22
|
-
|
27
|
+
context "when called with a file with an unknown extension" do
|
28
|
+
before { HelloSign::File.new(filename: 'test.foo').attachment }
|
23
29
|
|
24
|
-
|
30
|
+
it "creates an attachment with a text/plain MIME type" do
|
31
|
+
expect(Faraday::UploadIO).to(
|
32
|
+
have_received(:new).with('test.foo', 'text/plain')
|
33
|
+
)
|
34
|
+
end
|
25
35
|
end
|
26
36
|
|
27
|
-
|
28
|
-
|
37
|
+
context "when called with a specified MIME type" do
|
38
|
+
before do
|
39
|
+
HelloSign::File.new(filename: 'test.baz', mime: 'fake/mime').attachment
|
40
|
+
end
|
29
41
|
|
30
|
-
|
42
|
+
it "creates an attachment with the specified MIME type" do
|
43
|
+
expect(Faraday::UploadIO).to(
|
44
|
+
have_received(:new).with('test.baz', 'fake/mime')
|
45
|
+
)
|
46
|
+
end
|
31
47
|
end
|
32
48
|
|
33
|
-
|
34
|
-
|
49
|
+
context "when called with an IO object" do
|
50
|
+
before { HelloSign::File.new(io: io_object).attachment }
|
35
51
|
|
36
|
-
|
52
|
+
it "creates an attachment with a text/plain MIME type" do
|
53
|
+
expect(Faraday::UploadIO).to(
|
54
|
+
have_received(:new).with(io_object, 'text/plain')
|
55
|
+
)
|
56
|
+
end
|
37
57
|
end
|
38
58
|
|
39
|
-
|
40
|
-
|
59
|
+
context "when called with an IO and a specified MIME type" do
|
60
|
+
before do
|
61
|
+
HelloSign::File.new(io: io_object, mime: 'fake/mime').attachment
|
62
|
+
end
|
41
63
|
|
42
|
-
|
64
|
+
it "creates an attachment with the specified MIME type" do
|
65
|
+
expect(Faraday::UploadIO).to(
|
66
|
+
have_received(:new).with(io_object, 'fake/mime')
|
67
|
+
)
|
68
|
+
end
|
43
69
|
end
|
44
70
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
71
|
+
context "when called with a filename, IO object, and MIME type" do
|
72
|
+
before do
|
73
|
+
HelloSign::File.new(
|
74
|
+
filename: 'test.foo',
|
75
|
+
io: io_object,
|
76
|
+
mime: 'fake/mime'
|
77
|
+
).attachment
|
78
|
+
end
|
79
|
+
|
80
|
+
it "creates an attachment with the specified information" do
|
81
|
+
expect(Faraday::UploadIO).to(
|
82
|
+
have_received(:new).with(io_object, 'fake/mime', 'test.foo')
|
83
|
+
)
|
84
|
+
end
|
49
85
|
end
|
50
86
|
|
51
|
-
|
52
|
-
|
87
|
+
context "when called with a filename and IO object" do
|
88
|
+
before do
|
89
|
+
HelloSign::File.new(filename: 'test.foo', io: io_object).attachment
|
90
|
+
end
|
53
91
|
|
54
|
-
|
92
|
+
it "creates an attachment with a text/plain MIME type" do
|
93
|
+
expect(Faraday::UploadIO).to(
|
94
|
+
have_received(:new).with(io_object, 'text/plain', 'test.foo')
|
95
|
+
)
|
96
|
+
end
|
55
97
|
end
|
56
98
|
end
|
57
99
|
end
|