A Ruby interface to the HelloSign API.
gem install hello_sign
HelloSign uses the HTTP Basic Access Authentication scheme to authenticate API users.
To configure the client, simply execute the following with your credentials:
HelloSign.configure do |hs|
hs.email_address = 'david@bowman.com'
hs.password = 'hal_9000'
end
Those credentials will be used when making each request that requires authentication.
Applications that make requests on behalf of multiple HelloSign users should avoid global configuration. Instead, instantiate a client directly.
hello_sign = HelloSign::Client.new(email_address: 'david@bowman.com', password: 'hal_9000')
A client instantiated in this way responds to the same methods as the
HelloSign
constant.
All JSON-encoded responses from the HelloSign API are converted to a hash equivalent with symbols for keys before being returned.
HelloSign.account.create(email_address: 'david@bowman.com', password: 'hal_9000')
Authentication is not required to make this request.
HelloSign.account.settings.show
HelloSign.account.settings.update(callback_url: 'https://callmemaybe.com')
HelloSign.signature_request.deliver do |request|
request.title = 'Contract'
request.subject = 'Here is the contract for you to sign!'
request.message = 'You should definitely sign this.'
request.ccs = ['lawyer@lawfirm.com', 'spouse@family.com']
request.signers = [
{name: 'Jack', email_address: 'jack@hill.com'},
{name: 'Jill', email_address: 'jill@hill.com'}
]
request.files = [
{filename: 'path/to/contract.pdf'},
{filename: 'details.txt', io: text_file},
{filename: 'path/to/directions.txt', mime: 'text/xml'},
{io: image, mime: 'image/jpeg'}
]
end
There are a couple ways to specify a file when sending a signature request:
- Provide a path to the file's location on disk using
filename
. - Pass a Ruby IO object using
io
(e.g.text_file
andimage
above).
Other things to keep in mind:
- If a
filename
isn't provided, a generic one will be inferred. - If no
mime
key is specified, the MIME type will be inferred by the file extension. If a MIME type cannot be inferred, it will default totext/plain
. - When using any method of file specification, the MIME type can always be overriden using the
mime
key.
HelloSign.signature_request.deliver(form: 'form_id') do |request|
request.title = 'Contract'
request.subject = 'Here is the contract for you to sign!'
request.message = 'You should definitely sign this.'
request.ccs = [
{email_address: 'lawyer@lawfirm.com', role: 'lawyer'},
{email_address: 'accountant@llc.com', role: 'accountant'}
]
request.signers = [
{name: 'Jack', email_address: 'jack@hill.com', role: 'consultant'},
{name: 'Jill', email_address: 'jill@hill.com', role: 'client'}
]
request.custom_fields = [
{name: 'cost', value: '$20,000'},
{name: 'time', value: 'two weeks'}
]
end
HelloSign.signature_request('abc123').status
HelloSign.signature_request.list
HelloSign.signature_request.list(page: 5)
Defaults to page one when no page number is provided.
HelloSign.signature_request('abc123').remind(email_address: 'bob@smith.com')
HelloSign.signature_request('abc123').cancel
HelloSign.signature_request('abc123').final_copy
HelloSign.reusable_form.list
HelloSign.reusable_form.list(page: 5)
Defaults to page one when no page number is provided.
HelloSign.reusable_form('abc123').show
HelloSign.reusable_form('abc123').grant_access(email_address: 'bob@smith.com')
HelloSign.reusable_form('abc123').grant_access(account_id: '123456')
HelloSign.reusable_form('abc123').revoke_access(email_address: 'bob@smith.com')
HelloSign.reusable_form('abc123').revoke_access(account_id: '123456')
HelloSign.team.create(name: 'The Browncoats')
HelloSign.team.show
HelloSign.team.update(name: 'The Reavers')
HelloSign.team.destroy
HelloSign.team.add_member(email_address: 'new@person.com')
HelloSign.team.add_member(account_id: '123456')
HelloSign.team.remove_member(email_address: 'old@person.com')
HelloSign.team.remove_member(account_id: '123456')
HelloSign.unclaimed_draft.create do |draft|
draft.files = [
{filename: 'path/to/test.txt'},
{filename: 'test.jpg', io: image}
]
end
See the related notes on specifying files.
When an error is returned from the HelloSign API, an associated exception is raised.
This gem officially supports and is tested against the following Ruby interpreters:
- MRI 1.9.2
- MRI 1.9.3
- MRI 2.0.0
- JRuby in 1.9 mode
- Rubinius in 1.9 mode
Pull requests are welcome, but consider asking for a feature or bug fix first through the issue tracker. When contributing code, please squash sloppy commits aggressively and follow Tim Pope's guidelines for commit messages.
Copyright (c) 2013 Craig Little. See LICENSE for details.