hello_sign 0.3.0 → 0.4.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.
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
@@ -1,37 +1,31 @@
1
- require 'hello_sign/version'
2
1
  require 'hello_sign/client'
3
- require 'hello_sign/account_proxy'
4
- require 'hello_sign/signature_request_proxy'
5
- require 'hello_sign/reusable_form_proxy'
6
- require 'hello_sign/team_proxy'
2
+ require 'hello_sign/version'
3
+
4
+ require 'forwardable'
7
5
 
8
6
  module HelloSign
9
7
  class << self
10
- attr_accessor :email, :password
11
-
12
- def account
13
- AccountProxy.new(client)
14
- end
15
-
16
- def signature_request
17
- SignatureRequestProxy.new(client)
18
- end
8
+ extend Forwardable
19
9
 
20
- def reusable_form
21
- ReusableFormProxy.new(client)
22
- end
10
+ attr_accessor :email, :password
23
11
 
24
- def team
25
- TeamProxy.new(client)
26
- end
12
+ delegate [:account, :signature_request, :reusable_form, :team,
13
+ :unclaimed_draft] => :client
27
14
 
28
15
  def client
29
- @client ||= Client.new(email, password)
16
+ @client = Client.new(email, password) unless credentials_match?
17
+ @client
30
18
  end
31
19
 
32
20
  def configure
33
21
  yield(self)
34
22
  end
35
23
 
24
+ private
25
+
26
+ def credentials_match?
27
+ @client && [@client.email, @client.password].hash == [email, password].hash
28
+ end
29
+
36
30
  end
37
31
  end
@@ -1,8 +1,12 @@
1
+ require 'hello_sign/proxy'
2
+
1
3
  require 'faraday'
2
4
  require 'faraday_middleware-multi_json'
3
5
 
4
6
  module HelloSign
5
7
  class Client
8
+ include HelloSign::Proxy
9
+
6
10
  API_ENDPOINT = 'https://api.hellosign.com'
7
11
  API_VERSION = '/v3'
8
12
 
@@ -0,0 +1,27 @@
1
+ require 'faraday/upload_io'
2
+
3
+ module HelloSign
4
+ module Parameters
5
+ class UnclaimedDraft
6
+ attr_writer :files
7
+
8
+ def files
9
+ @files.each_with_index.inject({}) do |parameter, (file, index)|
10
+ parameter[index] = upload_io.new(file[:io], file[:mime], file[:name])
11
+ parameter
12
+ end
13
+ end
14
+
15
+ def formatted
16
+ {:file => files}
17
+ end
18
+
19
+ private
20
+
21
+ def upload_io
22
+ Faraday::UploadIO
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,56 @@
1
+ require 'hello_sign/proxy/account'
2
+ require 'hello_sign/proxy/signature_request'
3
+ require 'hello_sign/proxy/reusable_form'
4
+ require 'hello_sign/proxy/team'
5
+ require 'hello_sign/proxy/unclaimed_draft'
6
+
7
+ module HelloSign
8
+ module Proxy
9
+ attr_writer :account_proxy_source, :signature_request_proxy_source,
10
+ :reusable_form_proxy_source, :team_proxy_source,
11
+ :unclaimed_draft_proxy_source
12
+
13
+ def account
14
+ account_proxy_source.new(self)
15
+ end
16
+
17
+ def signature_request
18
+ signature_request_proxy_source.new(self)
19
+ end
20
+
21
+ def reusable_form
22
+ reusable_form_proxy_source.new(self)
23
+ end
24
+
25
+ def team
26
+ team_proxy_source.new(self)
27
+ end
28
+
29
+ def unclaimed_draft
30
+ unclaimed_draft_proxy_source.new(self)
31
+ end
32
+
33
+ private
34
+
35
+ def account_proxy_source
36
+ @account_proxy_source || HelloSign::Proxy::Account
37
+ end
38
+
39
+ def signature_request_proxy_source
40
+ @signature_request_proxy_source || HelloSign::Proxy::SignatureRequest
41
+ end
42
+
43
+ def reusable_form_proxy_source
44
+ @reusable_form_proxy_source || HelloSign::Proxy::ReusableForm
45
+ end
46
+
47
+ def team_proxy_source
48
+ @team_proxy_source || HelloSign::Proxy::Team
49
+ end
50
+
51
+ def unclaimed_draft_proxy_source
52
+ @unclaimed_draft_proxy_source || HelloSign::Proxy::UnclaimedDraft
53
+ end
54
+
55
+ end
56
+ end
@@ -0,0 +1,35 @@
1
+ require 'hello_sign/proxy/settings'
2
+
3
+ module HelloSign
4
+ module Proxy
5
+ class Account
6
+ attr_reader :client
7
+ attr_writer :settings_proxy_source
8
+
9
+ def initialize(client)
10
+ @client = client
11
+ end
12
+
13
+ def create(credentials)
14
+ email = credentials.fetch(:email)
15
+ password = credentials.fetch(:password)
16
+
17
+ client.post('/account/create',
18
+ :body => {:email_address => email, :password => password},
19
+ :auth_not_required => true
20
+ )
21
+ end
22
+
23
+ def settings
24
+ settings_proxy_source.new(client)
25
+ end
26
+
27
+ private
28
+
29
+ def settings_proxy_source
30
+ @settings_proxy_source || HelloSign::Proxy::Settings
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,41 @@
1
+ module HelloSign
2
+ module Proxy
3
+ class ReusableForm
4
+ attr_reader :client
5
+
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ def list(params = {})
11
+ params = {:page => 1}.merge(params)
12
+ client.get('/reusable_form/list', :params => params)
13
+ end
14
+
15
+ def show(form_id)
16
+ client.get("/reusable_form/#{form_id}")
17
+ end
18
+
19
+ def grant_access(form_id, params = {})
20
+ client.post("/reusable_form/add_user/#{form_id}", :body => body(params))
21
+ end
22
+
23
+ def revoke_access(form_id, params = {})
24
+ client.post("/reusable_form/remove_user/#{form_id}", :body => body(params))
25
+ end
26
+
27
+ private
28
+
29
+ def body(params)
30
+ if email = params[:email]
31
+ {:email_address => email}
32
+ elsif account_id = params[:account_id]
33
+ {:account_id => account_id}
34
+ else
35
+ raise ArgumentError, 'An email address or account ID must be provided.'
36
+ end
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,22 @@
1
+ require 'hello_sign/client'
2
+
3
+ module HelloSign
4
+ module Proxy
5
+ class Settings
6
+ attr_reader :client
7
+
8
+ def initialize(client)
9
+ @client = client
10
+ end
11
+
12
+ def show
13
+ client.get('/account')
14
+ end
15
+
16
+ def update(attributes)
17
+ client.post('/account', :body => attributes)
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,72 @@
1
+ require 'hello_sign/parameters/signature_request'
2
+ require 'hello_sign/parameters/reusable_form_signature_request'
3
+
4
+ module HelloSign
5
+ module Proxy
6
+ class SignatureRequest
7
+ attr_reader :client
8
+ attr_writer :request_parameters, :reusable_form_request_parameters
9
+
10
+ def initialize(client)
11
+ @client = client
12
+ end
13
+
14
+ def deliver(params = {})
15
+ if form_id = params[:form]
16
+ reusable_form_request_parameters.reusable_form_id = form_id
17
+ yield reusable_form_request_parameters
18
+
19
+ client.post(
20
+ '/signature_request/send_with_reusable_form',
21
+ :body => reusable_form_request_parameters.formatted
22
+ )
23
+ else
24
+ yield request_parameters
25
+
26
+ client.post(
27
+ '/signature_request/send',
28
+ :body => request_parameters.formatted
29
+ )
30
+ end
31
+ end
32
+
33
+ def status(request_id)
34
+ client.get("/signature_request/#{request_id}")
35
+ end
36
+
37
+ def list(params = {})
38
+ params = {:page => 1}.merge(params)
39
+
40
+ client.get('/signature_request/list', :params => params)
41
+ end
42
+
43
+ def remind(request_id, params = {})
44
+ email = params.fetch(:email) { raise ArgumentError, 'An email address must be provided.' }
45
+
46
+ client.post(
47
+ "/signature_request/remind/#{request_id}",
48
+ :body => {:email_address => email}
49
+ )
50
+ end
51
+
52
+ def cancel(request_id)
53
+ client.post("/signature_request/cancel/#{request_id}")
54
+ end
55
+
56
+ def final_copy(request_id)
57
+ client.get("/signature_request/final_copy/#{request_id}")
58
+ end
59
+
60
+ private
61
+
62
+ def request_parameters
63
+ @request_parameters ||= Parameters::SignatureRequest.new
64
+ end
65
+
66
+ def reusable_form_request_parameters
67
+ @reusable_form_request_parameters ||= Parameters::ReusableFormSignatureRequest.new
68
+ end
69
+
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,49 @@
1
+ module HelloSign
2
+ module Proxy
3
+ class Team
4
+ attr_reader :client
5
+
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ def create(params)
11
+ name = params.fetch(:name)
12
+ client.post('/team/create', :body => {:name => name})
13
+ end
14
+
15
+ def show
16
+ client.get('/team')
17
+ end
18
+
19
+ def update(attributes)
20
+ client.post('/team', :body => attributes)
21
+ end
22
+
23
+ def destroy
24
+ client.post('/team/destroy')
25
+ end
26
+
27
+ def add_member(params)
28
+ client.post("/team/add_member", :body => body_by_identifier(params))
29
+ end
30
+
31
+ def remove_member(params)
32
+ client.post("/team/remove_member", :body => body_by_identifier(params))
33
+ end
34
+
35
+ private
36
+
37
+ def body_by_identifier(params)
38
+ if email = params[:email]
39
+ {:email_address => email}
40
+ elsif account_id = params[:account_id]
41
+ {:account_id => account_id}
42
+ else
43
+ raise ArgumentError, 'An email address or account ID must be provided.'
44
+ end
45
+ end
46
+
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,29 @@
1
+ require 'hello_sign/parameters/unclaimed_draft'
2
+
3
+ module HelloSign
4
+ module Proxy
5
+ class UnclaimedDraft
6
+ attr_reader :client
7
+ attr_writer :draft_parameters
8
+
9
+ def initialize(client)
10
+ @client = client
11
+ end
12
+
13
+ def create
14
+ yield draft_parameters
15
+ client.post(
16
+ '/unclaimed_draft/create',
17
+ :body => draft_parameters.formatted
18
+ )
19
+ end
20
+
21
+ private
22
+
23
+ def draft_parameters
24
+ @draft_parameters ||= Parameters::UnclaimedDraft.new
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -1,3 +1,3 @@
1
1
  module HelloSign
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -1,6 +1,5 @@
1
1
  require 'integration/helper'
2
2
 
3
-
4
3
  describe HelloSign do
5
4
  context "when creating an account" do
6
5
  before do
@@ -8,7 +8,7 @@ describe HelloSign do
8
8
 
9
9
  before do
10
10
  stub_post_with_auth('/signature_request/send')
11
- HelloSign.signature_request.send do |request|
11
+ HelloSign.signature_request.deliver do |request|
12
12
  request.title = 'Lease'
13
13
  request.subject = 'Sign this'
14
14
  request.message = 'You must sign this.'
@@ -34,7 +34,7 @@ describe HelloSign do
34
34
  context "when using a reusable form" do
35
35
  before do
36
36
  stub_post_with_auth('/signature_request/send_with_reusable_form')
37
- HelloSign.signature_request.send(:form => 'form_id') do |request|
37
+ HelloSign.signature_request.deliver(:form => 'form_id') do |request|
38
38
  request.title = 'Lease'
39
39
  request.subject = 'Sign this'
40
40
  request.message = 'You must sign this.'
@@ -0,0 +1,23 @@
1
+ require 'integration/helper'
2
+
3
+ describe HelloSign do
4
+ context "creating an unclaimed draft" do
5
+ let(:text_io) { File.new('spec/fixtures/test.txt') }
6
+ let(:image_io) { File.new('spec/fixtures/test.jpg') }
7
+
8
+ before { stub_post_with_auth('/unclaimed_draft/create') }
9
+
10
+ example do
11
+ HelloSign.unclaimed_draft.create do |draft|
12
+ draft.files = [
13
+ {:name => 'test.txt', :io => text_io, :mime => 'text/plain'},
14
+ {:name => 'test.jpg', :io => image_io, :mime => 'image/jpeg'}
15
+ ]
16
+ end
17
+
18
+ expect(a_post_with_auth('/unclaimed_draft/create')
19
+ .with(:headers => {'Content-Type' => /multipart\/form-data/}, :body => /This is a test upload file\./)
20
+ ).to have_been_made
21
+ end
22
+ end
23
+ end