hello_sign 0.1.0 → 0.2.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 +0 -1
- data/lib/hello_sign/reusable_form_proxy.rb +43 -0
- data/lib/hello_sign/version.rb +1 -1
- data/lib/hello_sign.rb +5 -6
- data/spec/integration/reusable_form_spec.rb +51 -0
- data/spec/unit/hello_sign_spec.rb +6 -0
- data/spec/unit/reusable_form_proxy_spec.rb +111 -0
- metadata +6 -1
data/lib/hello_sign/client.rb
CHANGED
@@ -0,0 +1,43 @@
|
|
1
|
+
module HelloSign
|
2
|
+
class ReusableFormProxy
|
3
|
+
attr_reader :client
|
4
|
+
|
5
|
+
def initialize(client)
|
6
|
+
@client = client
|
7
|
+
end
|
8
|
+
|
9
|
+
def list(params = {})
|
10
|
+
params = {:page => 1}.merge(params)
|
11
|
+
client.get('/reusable_form/list', :params => params)
|
12
|
+
end
|
13
|
+
|
14
|
+
def show(form_id)
|
15
|
+
client.get("/reusable_form/#{form_id}")
|
16
|
+
end
|
17
|
+
|
18
|
+
def grant_access(form_id, params = {})
|
19
|
+
body = if email = params[:email]
|
20
|
+
{:email_address => email}
|
21
|
+
elsif account_id = params[:account_id]
|
22
|
+
{:account_id => account_id}
|
23
|
+
else
|
24
|
+
raise ArgumentError, 'An email address or account ID must be provided.'
|
25
|
+
end
|
26
|
+
|
27
|
+
client.post("/reusable_form/add_user/#{form_id}", :body => body)
|
28
|
+
end
|
29
|
+
|
30
|
+
def revoke_access(form_id, params = {})
|
31
|
+
body = if email = params[:email]
|
32
|
+
{:email_address => email}
|
33
|
+
elsif account_id = params[:account_id]
|
34
|
+
{:account_id => account_id}
|
35
|
+
else
|
36
|
+
raise ArgumentError, 'An email address or account ID must be provided.'
|
37
|
+
end
|
38
|
+
|
39
|
+
client.post("/reusable_form/remove_user/#{form_id}", :body => body)
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
data/lib/hello_sign/version.rb
CHANGED
data/lib/hello_sign.rb
CHANGED
@@ -2,6 +2,7 @@ require 'hello_sign/version'
|
|
2
2
|
require 'hello_sign/client'
|
3
3
|
require 'hello_sign/account_proxy'
|
4
4
|
require 'hello_sign/signature_request_proxy'
|
5
|
+
require 'hello_sign/reusable_form_proxy'
|
5
6
|
|
6
7
|
module HelloSign
|
7
8
|
class << self
|
@@ -15,6 +16,10 @@ module HelloSign
|
|
15
16
|
SignatureRequestProxy.new(client)
|
16
17
|
end
|
17
18
|
|
19
|
+
def reusable_form
|
20
|
+
ReusableFormProxy.new(client)
|
21
|
+
end
|
22
|
+
|
18
23
|
def client
|
19
24
|
@client ||= Client.new(email, password)
|
20
25
|
end
|
@@ -23,11 +28,5 @@ module HelloSign
|
|
23
28
|
yield(self)
|
24
29
|
end
|
25
30
|
|
26
|
-
private
|
27
|
-
|
28
|
-
def signature_request_proxy
|
29
|
-
SignatureRequestProxy.new(client)
|
30
|
-
end
|
31
|
-
|
32
31
|
end
|
33
32
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'integration/helper'
|
2
|
+
|
3
|
+
describe HelloSign do
|
4
|
+
context "when getting a list of reusable forms" do
|
5
|
+
before do
|
6
|
+
stub_get_with_auth('/reusable_form/list?page=1')
|
7
|
+
HelloSign.reusable_form.list
|
8
|
+
end
|
9
|
+
|
10
|
+
it "fetches a list of reusable forms from the HelloSign API" do
|
11
|
+
expect(a_get_with_auth('/reusable_form/list?page=1')).to have_been_made
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "when fetching information about a reusable form" do
|
16
|
+
before do
|
17
|
+
stub_get_with_auth('/reusable_form/form_id')
|
18
|
+
HelloSign.reusable_form.show('form_id')
|
19
|
+
end
|
20
|
+
|
21
|
+
it "fetches the reusable form information from the HelloSign API" do
|
22
|
+
expect(a_get_with_auth('/reusable_form/form_id')).to have_been_made
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "when giving a user access to a reusable form" do
|
27
|
+
before do
|
28
|
+
stub_post_with_auth('/reusable_form/add_user/form_id')
|
29
|
+
HelloSign.reusable_form.grant_access('form_id', :email => 'john@johnson.com')
|
30
|
+
end
|
31
|
+
|
32
|
+
it "sends a request to grant form access to the HelloSign API" do
|
33
|
+
expect(a_post_with_auth('/reusable_form/add_user/form_id')
|
34
|
+
.with(:body => {:email_address => 'john@johnson.com'})
|
35
|
+
).to have_been_made
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "when taking away a user's access to a reusable form" do
|
40
|
+
before do
|
41
|
+
stub_post_with_auth('/reusable_form/remove_user/form_id')
|
42
|
+
HelloSign.reusable_form.revoke_access('form_id', :email => 'john@johnson.com')
|
43
|
+
end
|
44
|
+
|
45
|
+
it "sends a request to grant form access to the HelloSign API" do
|
46
|
+
expect(a_post_with_auth('/reusable_form/remove_user/form_id')
|
47
|
+
.with(:body => {:email_address => 'john@johnson.com'})
|
48
|
+
).to have_been_made
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -14,6 +14,12 @@ describe HelloSign do
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
describe "::reusable_form" do
|
18
|
+
it "returns a reusable form proxy" do
|
19
|
+
expect(HelloSign.reusable_form).to be_a HelloSign::ReusableFormProxy
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
17
23
|
describe "::client" do
|
18
24
|
context "when it has not previously been called" do
|
19
25
|
it "returns a new client" do
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'hello_sign/reusable_form_proxy'
|
3
|
+
|
4
|
+
describe HelloSign::ReusableFormProxy do
|
5
|
+
let(:client) { double('client') }
|
6
|
+
let(:api_response) { double('API response') }
|
7
|
+
let(:form_id) { 'form_id' }
|
8
|
+
subject(:rf_proxy) { HelloSign::ReusableFormProxy.new(client) }
|
9
|
+
|
10
|
+
describe "#client" do
|
11
|
+
it "returns the client" do
|
12
|
+
expect(rf_proxy.client).to be client
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#list" do
|
17
|
+
context "when called without options" do
|
18
|
+
before { client.should_receive(:get).with('/reusable_form/list', :params => {:page => 1}).and_return(api_response) }
|
19
|
+
|
20
|
+
it "fetches the first page of reusable forms and returns the result" do
|
21
|
+
expect(rf_proxy.list).to eq api_response
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "when called with a page number" do
|
26
|
+
before { client.should_receive(:get).with('/reusable_form/list', :params => {:page => 10}).and_return(api_response) }
|
27
|
+
|
28
|
+
it "fetches a list of reusable forms for the passed page number and returns the result" do
|
29
|
+
expect(rf_proxy.list(:page => 10)).to eq api_response
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#show" do
|
35
|
+
before { client.should_receive(:get).with('/reusable_form/form_id').and_return(api_response) }
|
36
|
+
|
37
|
+
it "fetches the reusable form details and returns the result" do
|
38
|
+
expect(rf_proxy.show(form_id)).to eq api_response
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#grant_access" do
|
43
|
+
let(:email) { 'john@johnson.com' }
|
44
|
+
let(:account_id) { '15' }
|
45
|
+
|
46
|
+
before { client.stub(:post).and_return(api_response) }
|
47
|
+
|
48
|
+
context "when called with an email address" do
|
49
|
+
it "grants access to account tied to the email address" do
|
50
|
+
client.should_receive(:post).with('/reusable_form/add_user/form_id', :body => {:email_address => email})
|
51
|
+
rf_proxy.grant_access(form_id, :email => email)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "returns the API response" do
|
55
|
+
expect(rf_proxy.grant_access(form_id, :email => email)).to eq api_response
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "when called with an account ID" do
|
60
|
+
it "grants access to account tied to the account ID" do
|
61
|
+
client.should_receive(:post).with('/reusable_form/add_user/form_id', :body => {:account_id => account_id})
|
62
|
+
rf_proxy.grant_access(form_id, :account_id => account_id)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "returns the API response" do
|
66
|
+
expect(rf_proxy.grant_access(form_id, :account_id => account_id)).to eq api_response
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "when called without proper parameters" do
|
71
|
+
it "raises an argument error exception" do
|
72
|
+
expect { rf_proxy.grant_access(form_id) }.to raise_error ArgumentError
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "#revoke_access" do
|
78
|
+
let(:email) { 'john@johnson.com' }
|
79
|
+
let(:account_id) { '15' }
|
80
|
+
|
81
|
+
before { client.stub(:post).and_return(api_response) }
|
82
|
+
|
83
|
+
context "when called with an email address" do
|
84
|
+
it "revokes access to account tied to the email address" do
|
85
|
+
client.should_receive(:post).with('/reusable_form/remove_user/form_id', :body => {:email_address => email})
|
86
|
+
rf_proxy.revoke_access(form_id, :email => email)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "returns the API response" do
|
90
|
+
expect(rf_proxy.revoke_access(form_id, :email => email)).to eq api_response
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context "when called with an account ID" do
|
95
|
+
it "revokes access to account tied to the account ID" do
|
96
|
+
client.should_receive(:post).with('/reusable_form/remove_user/form_id', :body => {:account_id => account_id})
|
97
|
+
rf_proxy.revoke_access(form_id, :account_id => account_id)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "returns the API response" do
|
101
|
+
expect(rf_proxy.revoke_access(form_id, :account_id => account_id)).to eq api_response
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "when called without proper parameters" do
|
106
|
+
it "raises an argument error exception" do
|
107
|
+
expect { rf_proxy.revoke_access(form_id) }.to raise_error ArgumentError
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
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.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- lib/hello_sign/client.rb
|
87
87
|
- lib/hello_sign/parameters/reusable_form_signature_request.rb
|
88
88
|
- lib/hello_sign/parameters/signature_request.rb
|
89
|
+
- lib/hello_sign/reusable_form_proxy.rb
|
89
90
|
- lib/hello_sign/settings_proxy.rb
|
90
91
|
- lib/hello_sign/signature_request_proxy.rb
|
91
92
|
- lib/hello_sign/version.rb
|
@@ -97,12 +98,14 @@ files:
|
|
97
98
|
- spec/integration/account_spec.rb
|
98
99
|
- spec/integration/hello_sign_spec.rb
|
99
100
|
- spec/integration/helper.rb
|
101
|
+
- spec/integration/reusable_form_spec.rb
|
100
102
|
- spec/integration/signature_request_spec.rb
|
101
103
|
- spec/unit/account_proxy_spec.rb
|
102
104
|
- spec/unit/client_spec.rb
|
103
105
|
- spec/unit/hello_sign_spec.rb
|
104
106
|
- spec/unit/parameters/reusable_form_signature_request_spec.rb
|
105
107
|
- spec/unit/parameters/signature_request_spec.rb
|
108
|
+
- spec/unit/reusable_form_proxy_spec.rb
|
106
109
|
- spec/unit/settings_proxy_spec.rb
|
107
110
|
- spec/unit/signature_request_proxy_spec.rb
|
108
111
|
homepage: http://www.github.com/craiglittle/hello_sign
|
@@ -137,11 +140,13 @@ test_files:
|
|
137
140
|
- spec/integration/account_spec.rb
|
138
141
|
- spec/integration/hello_sign_spec.rb
|
139
142
|
- spec/integration/helper.rb
|
143
|
+
- spec/integration/reusable_form_spec.rb
|
140
144
|
- spec/integration/signature_request_spec.rb
|
141
145
|
- spec/unit/account_proxy_spec.rb
|
142
146
|
- spec/unit/client_spec.rb
|
143
147
|
- spec/unit/hello_sign_spec.rb
|
144
148
|
- spec/unit/parameters/reusable_form_signature_request_spec.rb
|
145
149
|
- spec/unit/parameters/signature_request_spec.rb
|
150
|
+
- spec/unit/reusable_form_proxy_spec.rb
|
146
151
|
- spec/unit/settings_proxy_spec.rb
|
147
152
|
- spec/unit/signature_request_proxy_spec.rb
|