hello_sign 0.6.0 → 1.0.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.
- data/lib/hello_sign/client.rb +2 -2
- data/lib/hello_sign/parameters/reusable_form_signature_request.rb +9 -9
- data/lib/hello_sign/parameters/signature_request.rb +15 -15
- data/lib/hello_sign/parameters/unclaimed_draft.rb +7 -7
- data/lib/hello_sign/proxy/account.rb +1 -1
- data/lib/hello_sign/proxy/reusable_form.rb +10 -9
- data/lib/hello_sign/proxy/settings.rb +1 -1
- data/lib/hello_sign/proxy/signature_request.rb +13 -12
- data/lib/hello_sign/proxy/team.rb +4 -4
- data/lib/hello_sign/proxy/unclaimed_draft.rb +1 -1
- data/lib/hello_sign/proxy.rb +4 -4
- data/lib/hello_sign/upload_io.rb +56 -0
- data/lib/hello_sign/version.rb +1 -1
- data/lib/hello_sign.rb +1 -1
- data/spec/helper.rb +0 -2
- data/spec/integration/account_spec.rb +4 -4
- data/spec/integration/hello_sign_spec.rb +2 -2
- data/spec/integration/helper.rb +6 -1
- data/spec/integration/reusable_form_spec.rb +16 -20
- data/spec/integration/signature_request_spec.rb +52 -57
- data/spec/integration/team_spec.rb +8 -8
- data/spec/integration/unclaimed_draft_spec.rb +3 -3
- data/spec/shared_examples/proxy.rb +15 -5
- data/spec/unit/client_spec.rb +3 -3
- data/spec/unit/middleware/raise_error_spec.rb +1 -1
- data/spec/unit/parameters/reusable_form_signature_request_spec.rb +17 -17
- data/spec/unit/parameters/signature_request_spec.rb +25 -20
- data/spec/unit/parameters/unclaimed_draft_spec.rb +12 -11
- data/spec/unit/proxy/account_spec.rb +6 -6
- data/spec/unit/proxy/reusable_form_spec.rb +13 -12
- data/spec/unit/proxy/settings_spec.rb +3 -3
- data/spec/unit/proxy/signature_request_spec.rb +29 -32
- data/spec/unit/proxy/team_spec.rb +12 -12
- data/spec/unit/proxy/unclaimed_draft_spec.rb +1 -1
- data/spec/unit/upload_io_spec.rb +60 -0
- metadata +19 -15
data/lib/hello_sign/client.rb
CHANGED
@@ -42,13 +42,13 @@ module HelloSign
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def base_connection
|
45
|
-
Faraday.new(:
|
45
|
+
Faraday.new(url: API_ENDPOINT) do |connection|
|
46
46
|
yield connection
|
47
47
|
|
48
48
|
connection.request :multipart
|
49
49
|
connection.request :url_encoded
|
50
50
|
connection.response :raise_error
|
51
|
-
connection.response :multi_json, :
|
51
|
+
connection.response :multi_json, symbolize_keys: true
|
52
52
|
connection.adapter :net_http
|
53
53
|
end
|
54
54
|
end
|
@@ -5,13 +5,13 @@ module HelloSign
|
|
5
5
|
|
6
6
|
def formatted
|
7
7
|
{
|
8
|
-
:
|
9
|
-
:
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
8
|
+
reusable_form_id: reusable_form_id,
|
9
|
+
title: title,
|
10
|
+
subject: subject,
|
11
|
+
message: message,
|
12
|
+
ccs: ccs,
|
13
|
+
signers: signers,
|
14
|
+
custom_fields: custom_fields
|
15
15
|
}
|
16
16
|
end
|
17
17
|
|
@@ -21,14 +21,14 @@ module HelloSign
|
|
21
21
|
|
22
22
|
def ccs
|
23
23
|
@ccs.inject({}) do |parameter, cc|
|
24
|
-
parameter[cc[:role]] = {:
|
24
|
+
parameter[cc[:role]] = {email_address: cc[:email_address]}
|
25
25
|
parameter
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
def signers
|
30
30
|
@signers.inject({}) do |parameter, signer|
|
31
|
-
parameter[signer[:role]] = {:
|
31
|
+
parameter[signer[:role]] = {name: signer[:name], email_address: signer[:email_address]}
|
32
32
|
parameter
|
33
33
|
end
|
34
34
|
end
|
@@ -1,17 +1,17 @@
|
|
1
|
-
require '
|
1
|
+
require 'hello_sign/upload_io'
|
2
2
|
|
3
3
|
module HelloSign
|
4
4
|
module Parameters
|
5
5
|
class SignatureRequest
|
6
6
|
attr_accessor :title, :subject, :message, :ccs
|
7
|
-
attr_writer :signers, :files
|
7
|
+
attr_writer :signers, :files, :upload_io_source
|
8
8
|
|
9
9
|
def signers
|
10
10
|
(@signers || {}).each_with_index.inject({}) do |parameter, (signer, index)|
|
11
11
|
signer = {
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
12
|
+
name: signer[:name],
|
13
|
+
email_address: signer[:email_address],
|
14
|
+
order: index
|
15
15
|
}
|
16
16
|
parameter[index] = signer
|
17
17
|
parameter
|
@@ -19,27 +19,27 @@ module HelloSign
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def files
|
22
|
-
(@files || {}).each_with_index.inject({}) do |parameter, (
|
23
|
-
parameter[index + 1] =
|
22
|
+
(@files || {}).each_with_index.inject({}) do |parameter, (file_data, index)|
|
23
|
+
parameter[index + 1] = upload_io_source.new(file_data).upload
|
24
24
|
parameter
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
def formatted
|
29
29
|
{
|
30
|
-
:
|
31
|
-
:
|
32
|
-
:
|
33
|
-
:
|
34
|
-
:
|
35
|
-
:
|
30
|
+
title: title,
|
31
|
+
subject: subject,
|
32
|
+
message: message,
|
33
|
+
cc_email_addresses: ccs,
|
34
|
+
signers: signers,
|
35
|
+
file: files
|
36
36
|
}
|
37
37
|
end
|
38
38
|
|
39
39
|
private
|
40
40
|
|
41
|
-
def
|
42
|
-
|
41
|
+
def upload_io_source
|
42
|
+
@upload_io_source || HelloSign::UploadIO
|
43
43
|
end
|
44
44
|
|
45
45
|
end
|
@@ -1,25 +1,25 @@
|
|
1
|
-
require '
|
1
|
+
require 'hello_sign/upload_io'
|
2
2
|
|
3
3
|
module HelloSign
|
4
4
|
module Parameters
|
5
5
|
class UnclaimedDraft
|
6
|
-
attr_writer :files
|
6
|
+
attr_writer :files, :upload_io_source
|
7
7
|
|
8
8
|
def formatted
|
9
|
-
{:
|
9
|
+
{file: files}
|
10
10
|
end
|
11
11
|
|
12
12
|
private
|
13
13
|
|
14
14
|
def files
|
15
|
-
@files.each_with_index.inject({}) do |parameter, (
|
16
|
-
parameter[index] =
|
15
|
+
@files.each_with_index.inject({}) do |parameter, (file_data, index)|
|
16
|
+
parameter[index] = upload_io_source.new(file_data).upload
|
17
17
|
parameter
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
22
|
-
|
21
|
+
def upload_io_source
|
22
|
+
@upload_io_source || HelloSign::UploadIO
|
23
23
|
end
|
24
24
|
|
25
25
|
end
|
@@ -1,26 +1,27 @@
|
|
1
1
|
module HelloSign
|
2
2
|
module Proxy
|
3
3
|
class ReusableForm
|
4
|
-
attr_reader :client
|
4
|
+
attr_reader :client, :form_id
|
5
5
|
|
6
|
-
def initialize(client)
|
7
|
-
@client
|
6
|
+
def initialize(client, form_id)
|
7
|
+
@client = client
|
8
|
+
@form_id = form_id
|
8
9
|
end
|
9
10
|
|
10
11
|
def list(params = {})
|
11
|
-
client.get('/reusable_form/list', :
|
12
|
+
client.get('/reusable_form/list', params: params)
|
12
13
|
end
|
13
14
|
|
14
|
-
def show
|
15
|
+
def show
|
15
16
|
client.get("/reusable_form/#{form_id}")
|
16
17
|
end
|
17
18
|
|
18
|
-
def grant_access(
|
19
|
-
client.post("/reusable_form/add_user/#{form_id}", :
|
19
|
+
def grant_access(params = {})
|
20
|
+
client.post("/reusable_form/add_user/#{form_id}", body: params)
|
20
21
|
end
|
21
22
|
|
22
|
-
def revoke_access(
|
23
|
-
client.post("/reusable_form/remove_user/#{form_id}", :
|
23
|
+
def revoke_access(params = {})
|
24
|
+
client.post("/reusable_form/remove_user/#{form_id}", body: params)
|
24
25
|
end
|
25
26
|
|
26
27
|
end
|
@@ -4,11 +4,12 @@ require 'hello_sign/parameters/reusable_form_signature_request'
|
|
4
4
|
module HelloSign
|
5
5
|
module Proxy
|
6
6
|
class SignatureRequest
|
7
|
-
attr_reader :client
|
7
|
+
attr_reader :client, :request_id
|
8
8
|
attr_writer :request_parameters, :reusable_form_request_parameters
|
9
9
|
|
10
|
-
def initialize(client)
|
10
|
+
def initialize(client, request_id)
|
11
11
|
@client = client
|
12
|
+
@request_id = request_id
|
12
13
|
end
|
13
14
|
|
14
15
|
def deliver(params = {})
|
@@ -18,36 +19,36 @@ module HelloSign
|
|
18
19
|
|
19
20
|
client.post(
|
20
21
|
'/signature_request/send_with_reusable_form',
|
21
|
-
:
|
22
|
+
body: reusable_form_request_parameters.formatted
|
22
23
|
)
|
23
24
|
else
|
24
25
|
yield request_parameters
|
25
26
|
|
26
|
-
client.post('/signature_request/send', :
|
27
|
+
client.post('/signature_request/send', body: request_parameters.formatted)
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
30
|
-
def status
|
31
|
+
def status
|
31
32
|
client.get("/signature_request/#{request_id}")
|
32
33
|
end
|
33
34
|
|
34
35
|
def list(params = {})
|
35
|
-
params = {:
|
36
|
+
params = {page: 1}.merge(params)
|
36
37
|
|
37
|
-
client.get('/signature_request/list', :
|
38
|
+
client.get('/signature_request/list', params: params)
|
38
39
|
end
|
39
40
|
|
40
|
-
def remind(
|
41
|
-
params = {:
|
41
|
+
def remind(params = {})
|
42
|
+
params = {email_address: params.delete(:email)}.merge(params)
|
42
43
|
|
43
|
-
client.post("/signature_request/remind/#{request_id}", :
|
44
|
+
client.post("/signature_request/remind/#{request_id}", body: params)
|
44
45
|
end
|
45
46
|
|
46
|
-
def cancel
|
47
|
+
def cancel
|
47
48
|
client.post("/signature_request/cancel/#{request_id}")
|
48
49
|
end
|
49
50
|
|
50
|
-
def final_copy
|
51
|
+
def final_copy
|
51
52
|
client.get("/signature_request/final_copy/#{request_id}")
|
52
53
|
end
|
53
54
|
|
@@ -8,7 +8,7 @@ module HelloSign
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def create(params = {})
|
11
|
-
client.post('/team/create', :
|
11
|
+
client.post('/team/create', body: params)
|
12
12
|
end
|
13
13
|
|
14
14
|
def show
|
@@ -16,7 +16,7 @@ module HelloSign
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def update(params = {})
|
19
|
-
client.post('/team', :
|
19
|
+
client.post('/team', body: params)
|
20
20
|
end
|
21
21
|
|
22
22
|
def destroy
|
@@ -24,11 +24,11 @@ module HelloSign
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def add_member(params = {})
|
27
|
-
client.post("/team/add_member", :
|
27
|
+
client.post("/team/add_member", body: params)
|
28
28
|
end
|
29
29
|
|
30
30
|
def remove_member(params = {})
|
31
|
-
client.post("/team/remove_member", :
|
31
|
+
client.post("/team/remove_member", body: params)
|
32
32
|
end
|
33
33
|
|
34
34
|
end
|
data/lib/hello_sign/proxy.rb
CHANGED
@@ -14,12 +14,12 @@ module HelloSign
|
|
14
14
|
account_proxy_source.new(self)
|
15
15
|
end
|
16
16
|
|
17
|
-
def signature_request
|
18
|
-
signature_request_proxy_source.new(self)
|
17
|
+
def signature_request(request_id = nil)
|
18
|
+
signature_request_proxy_source.new(self, request_id)
|
19
19
|
end
|
20
20
|
|
21
|
-
def reusable_form
|
22
|
-
reusable_form_proxy_source.new(self)
|
21
|
+
def reusable_form(form_id = nil)
|
22
|
+
reusable_form_proxy_source.new(self, form_id)
|
23
23
|
end
|
24
24
|
|
25
25
|
def team
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'faraday/upload_io'
|
2
|
+
require 'hello_sign/error'
|
3
|
+
|
4
|
+
module HelloSign
|
5
|
+
class UploadIO
|
6
|
+
MIME_TYPES = {
|
7
|
+
'doc' => 'application/msword',
|
8
|
+
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
9
|
+
'gif' => 'image/gif',
|
10
|
+
'jpg' => 'image/jpeg',
|
11
|
+
'jpeg' => 'image/jpeg',
|
12
|
+
'pdf' => 'application/pdf',
|
13
|
+
'png' => 'image/png',
|
14
|
+
'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
|
15
|
+
'ppt' => 'application/vnd.ms-powerpoint',
|
16
|
+
'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
17
|
+
'tif' => 'image/tiff',
|
18
|
+
'tiff' => 'image/tiff',
|
19
|
+
'txt' => 'text/plain',
|
20
|
+
'xls' => 'application/vnd.ms-excel',
|
21
|
+
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
22
|
+
}
|
23
|
+
|
24
|
+
attr_reader :filename, :io_object
|
25
|
+
|
26
|
+
def initialize(file_data)
|
27
|
+
@filename = file_data[:filename]
|
28
|
+
@io_object = file_data[:io]
|
29
|
+
@mime_type = file_data[:mime]
|
30
|
+
end
|
31
|
+
|
32
|
+
def upload
|
33
|
+
file_converter_source.new(*parameters)
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def parameters
|
39
|
+
begin
|
40
|
+
io_object ? [io_object, mime_type, filename] : [filename, mime_type]
|
41
|
+
end.compact
|
42
|
+
end
|
43
|
+
|
44
|
+
def mime_type
|
45
|
+
@mime_type or begin
|
46
|
+
extension = (filename || '').split('.').last
|
47
|
+
MIME_TYPES.fetch(extension) { 'text/plain' }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def file_converter_source
|
52
|
+
@file_converter_source || Faraday::UploadIO
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
data/lib/hello_sign/version.rb
CHANGED
data/lib/hello_sign.rb
CHANGED
@@ -31,7 +31,7 @@ module HelloSign
|
|
31
31
|
@client_source || HelloSign::Client
|
32
32
|
end
|
33
33
|
|
34
|
-
Faraday.register_middleware :response, :
|
34
|
+
Faraday.register_middleware :response, raise_error: HelloSign::Middleware::RaiseError
|
35
35
|
|
36
36
|
end
|
37
37
|
end
|
data/spec/helper.rb
CHANGED
@@ -5,10 +5,10 @@ describe HelloSign do
|
|
5
5
|
before { stub_post('/account/create') }
|
6
6
|
|
7
7
|
it "sends an account creation request to the HelloSign API" do
|
8
|
-
HelloSign.account.create(:
|
8
|
+
HelloSign.account.create(email_address: 'david@bowman.com', password: 'foobar')
|
9
9
|
|
10
10
|
expect(a_post('/account/create')
|
11
|
-
.with(:
|
11
|
+
.with(body: {email_address: 'david@bowman.com', password: 'foobar'}))
|
12
12
|
.to have_been_made
|
13
13
|
end
|
14
14
|
end
|
@@ -27,10 +27,10 @@ describe HelloSign do
|
|
27
27
|
before { stub_post_with_auth('/account') }
|
28
28
|
|
29
29
|
it "sends an update account request to the HelloSign API" do
|
30
|
-
HelloSign.account.settings.update(:
|
30
|
+
HelloSign.account.settings.update(callback_url: 'http://callmemaybe.com')
|
31
31
|
|
32
32
|
expect(a_post_with_auth('/account')
|
33
|
-
.with(:
|
33
|
+
.with(body: {callback_url: 'http://callmemaybe.com'}))
|
34
34
|
.to have_been_made
|
35
35
|
end
|
36
36
|
end
|
@@ -3,10 +3,10 @@ require 'json'
|
|
3
3
|
|
4
4
|
describe HelloSign do
|
5
5
|
context "when returning a response with a body" do
|
6
|
-
before { stub_get_with_auth('/json').to_return(:
|
6
|
+
before { stub_get_with_auth('/json').to_return(body: {account_id: 1}.to_json) }
|
7
7
|
|
8
8
|
it "parses the body into a hash with symbols as keys" do
|
9
|
-
expect(HelloSign.client.get('/json')).to eq({:
|
9
|
+
expect(HelloSign.client.get('/json')).to eq({account_id: 1})
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
data/spec/integration/helper.rb
CHANGED
@@ -3,6 +3,11 @@ require 'hello_sign'
|
|
3
3
|
require 'webmock/rspec'
|
4
4
|
require 'json'
|
5
5
|
|
6
|
+
if ENV['CI']
|
7
|
+
require 'coveralls'
|
8
|
+
Coveralls.wear!
|
9
|
+
end
|
10
|
+
|
6
11
|
HelloSign.configure do |hs|
|
7
12
|
hs.email_address = 'david@bowman.com'
|
8
13
|
hs.password = 'foobar'
|
@@ -25,7 +30,7 @@ def stub_post_with_auth(path)
|
|
25
30
|
end
|
26
31
|
|
27
32
|
def stub_request_with_error(error)
|
28
|
-
stub_request(:any, /api\.hellosign\.com/).to_return(:
|
33
|
+
stub_request(:any, /api\.hellosign\.com/).to_return(body: {error: {error_name: error}})
|
29
34
|
end
|
30
35
|
|
31
36
|
def a_get(path)
|
@@ -2,49 +2,45 @@ require 'integration/helper'
|
|
2
2
|
|
3
3
|
describe HelloSign do
|
4
4
|
context "when getting a list of reusable forms" do
|
5
|
-
before
|
6
|
-
stub_get_with_auth('/reusable_form/list')
|
7
|
-
HelloSign.reusable_form.list
|
8
|
-
end
|
5
|
+
before { stub_get_with_auth('/reusable_form/list') }
|
9
6
|
|
10
7
|
it "fetches a list of reusable forms from the HelloSign API" do
|
8
|
+
HelloSign.reusable_form.list
|
9
|
+
|
11
10
|
expect(a_get_with_auth('/reusable_form/list')).to have_been_made
|
12
11
|
end
|
13
12
|
end
|
14
13
|
|
15
14
|
context "when fetching information about a reusable form" do
|
16
|
-
before
|
17
|
-
stub_get_with_auth('/reusable_form/form_id')
|
18
|
-
HelloSign.reusable_form.show('form_id')
|
19
|
-
end
|
15
|
+
before { stub_get_with_auth('/reusable_form/form_id') }
|
20
16
|
|
21
17
|
it "fetches the reusable form information from the HelloSign API" do
|
18
|
+
HelloSign.reusable_form('form_id').show
|
19
|
+
|
22
20
|
expect(a_get_with_auth('/reusable_form/form_id')).to have_been_made
|
23
21
|
end
|
24
22
|
end
|
25
23
|
|
26
|
-
context "when
|
27
|
-
before
|
28
|
-
stub_post_with_auth('/reusable_form/add_user/form_id')
|
29
|
-
HelloSign.reusable_form.grant_access('form_id', :email_address => 'john@johnson.com')
|
30
|
-
end
|
24
|
+
context "when granting user access to a reusable form" do
|
25
|
+
before { stub_post_with_auth('/reusable_form/add_user/form_id') }
|
31
26
|
|
32
27
|
it "sends a request to grant form access to the HelloSign API" do
|
28
|
+
HelloSign.reusable_form('form_id').grant_access(email_address: 'john@johnson.com')
|
29
|
+
|
33
30
|
expect(a_post_with_auth('/reusable_form/add_user/form_id')
|
34
|
-
.with(:
|
31
|
+
.with(email_address: 'john@johnson.com')
|
35
32
|
).to have_been_made
|
36
33
|
end
|
37
34
|
end
|
38
35
|
|
39
|
-
context "when
|
40
|
-
before
|
41
|
-
stub_post_with_auth('/reusable_form/remove_user/form_id')
|
42
|
-
HelloSign.reusable_form.revoke_access('form_id', :email_address => 'john@johnson.com')
|
43
|
-
end
|
36
|
+
context "when revoking user access to a reusable form" do
|
37
|
+
before { stub_post_with_auth('/reusable_form/remove_user/form_id') }
|
44
38
|
|
45
39
|
it "sends a request to grant form access to the HelloSign API" do
|
40
|
+
HelloSign.reusable_form('form_id').revoke_access(email_address: 'john@johnson.com')
|
41
|
+
|
46
42
|
expect(a_post_with_auth('/reusable_form/remove_user/form_id')
|
47
|
-
.with(:
|
43
|
+
.with(email_address: 'john@johnson.com')
|
48
44
|
).to have_been_made
|
49
45
|
end
|
50
46
|
end
|