hello_sign 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,6 +3,7 @@ require 'hello_sign/client'
3
3
  require 'hello_sign/account_proxy'
4
4
  require 'hello_sign/signature_request_proxy'
5
5
  require 'hello_sign/reusable_form_proxy'
6
+ require 'hello_sign/team_proxy'
6
7
 
7
8
  module HelloSign
8
9
  class << self
@@ -20,6 +21,10 @@ module HelloSign
20
21
  ReusableFormProxy.new(client)
21
22
  end
22
23
 
24
+ def team
25
+ TeamProxy.new(client)
26
+ end
27
+
23
28
  def client
24
29
  @client ||= Client.new(email, password)
25
30
  end
@@ -15,7 +15,7 @@ module HelloSign
15
15
 
16
16
  client.post('/account/create',
17
17
  :body => {:email_address => email, :password => password},
18
- :unauthenticated => true
18
+ :auth_not_required => true
19
19
  )
20
20
  end
21
21
 
@@ -7,7 +7,6 @@ module HelloSign
7
7
  API_VERSION = '/v3'
8
8
 
9
9
  attr_reader :email, :password
10
- attr_writer :connection
11
10
 
12
11
  def initialize(email, password)
13
12
  @email = email
@@ -25,29 +24,22 @@ module HelloSign
25
24
  private
26
25
 
27
26
  def request(method, path, options)
28
- connection = options[:unauthenticated] ? unauth_connection : auth_connection
29
- request = connection.send(method) do |request|
30
- request.path = "#{API_VERSION}#{path}"
31
- request.params = options[:params] if options[:params]
32
- request.body = options[:body]
33
- end
34
-
35
- request.body
27
+ base_connection do |connection|
28
+ connection.request :basic_auth, email, password unless options[:auth_not_required]
29
+ end.send(method) do |request|
30
+ request.url "#{API_VERSION}#{path}", options[:params]
31
+ request.body = options[:body]
32
+ end.body
36
33
  end
37
34
 
38
- def unauth_connection(&auth)
39
- Faraday.new(:url => API_ENDPOINT) do |faraday|
40
- auth.call(faraday) if block_given?
41
- faraday.request :multipart
42
- faraday.request :url_encoded
43
- faraday.response :multi_json, :symbolize_keys => true
44
- faraday.adapter Faraday.default_adapter
45
- end
46
- end
35
+ def base_connection
36
+ Faraday.new(:url => API_ENDPOINT) do |connection|
37
+ yield connection
47
38
 
48
- def auth_connection
49
- unauth_connection do |faraday|
50
- faraday.request :basic_auth, email, password
39
+ connection.request :multipart
40
+ connection.request :url_encoded
41
+ connection.response :multi_json, :symbolize_keys => true
42
+ connection.adapter :net_http
51
43
  end
52
44
  end
53
45
 
@@ -0,0 +1,47 @@
1
+ module HelloSign
2
+ class TeamProxy
3
+ attr_reader :client
4
+
5
+ def initialize(client)
6
+ @client = client
7
+ end
8
+
9
+ def create(params)
10
+ name = params.fetch(:name)
11
+ client.post('/team/create', :body => {:name => name})
12
+ end
13
+
14
+ def show
15
+ client.get('/team')
16
+ end
17
+
18
+ def update(attributes)
19
+ client.post('/team', :body => attributes)
20
+ end
21
+
22
+ def destroy
23
+ client.post('/team/destroy')
24
+ end
25
+
26
+ def add_member(params)
27
+ client.post("/team/add_member", :body => body_by_identifier(params))
28
+ end
29
+
30
+ def remove_member(params)
31
+ client.post("/team/remove_member", :body => body_by_identifier(params))
32
+ end
33
+
34
+ private
35
+
36
+ def body_by_identifier(params)
37
+ if email = params[:email]
38
+ {:email_address => email}
39
+ elsif account_id = params[:account_id]
40
+ {:account_id => account_id}
41
+ else
42
+ raise ArgumentError, 'An email address or account ID must be provided.'
43
+ end
44
+ end
45
+
46
+ end
47
+ end
@@ -1,3 +1,3 @@
1
1
  module HelloSign
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -1,11 +1,30 @@
1
1
  require 'integration/helper'
2
+ require 'json'
2
3
 
3
4
  describe HelloSign do
4
5
  context "when returning a response with a body" do
5
- before { stub_get('/json').to_return(:body => {:account_id => 1}.to_json) }
6
+ before { stub_get_with_auth('/json').to_return(:body => {:account_id => 1}.to_json) }
6
7
 
7
- it "renders it as JSON" do
8
- expect(HelloSign.client.get('/json', :unauthenticated => true)).to eq({:account_id => 1})
8
+ it "parses the body into a hash with symbols as keys" do
9
+ expect(HelloSign.client.get('/json')).to eq({:account_id => 1})
10
+ end
11
+ end
12
+
13
+ describe "#get" do
14
+ before { stub_get_with_auth('/resource') }
15
+
16
+ example do
17
+ HelloSign.client.get('/resource')
18
+ expect(a_get_with_auth('/resource')).to have_been_made
19
+ end
20
+ end
21
+
22
+ describe "#post" do
23
+ before { stub_post_with_auth('/resource') }
24
+
25
+ example do
26
+ HelloSign.client.post('/resource')
27
+ expect(a_post_with_auth('/resource')).to have_been_made
9
28
  end
10
29
  end
11
30
  end
@@ -31,7 +31,7 @@ describe HelloSign do
31
31
 
32
32
  it "sends a request to grant form access to the HelloSign API" do
33
33
  expect(a_post_with_auth('/reusable_form/add_user/form_id')
34
- .with(:body => {:email_address => 'john@johnson.com'})
34
+ .with(:email_address => 'john@johnson.com')
35
35
  ).to have_been_made
36
36
  end
37
37
  end
@@ -44,7 +44,7 @@ describe HelloSign do
44
44
 
45
45
  it "sends a request to grant form access to the HelloSign API" do
46
46
  expect(a_post_with_auth('/reusable_form/remove_user/form_id')
47
- .with(:body => {:email_address => 'john@johnson.com'})
47
+ .with(:email_address => 'john@johnson.com')
48
48
  ).to have_been_made
49
49
  end
50
50
  end
@@ -0,0 +1,73 @@
1
+ require 'integration/helper'
2
+
3
+ describe HelloSign do
4
+ context "creating a team" do
5
+ before { stub_post_with_auth('/team/create') }
6
+
7
+ example do
8
+ HelloSign.team.create(:name => 'The Browncoats')
9
+
10
+ expect(a_post_with_auth('/team/create')
11
+ .with(:body => {:name => 'The Browncoats'}))
12
+ .to have_been_made
13
+ end
14
+ end
15
+
16
+ context "fetching team information" do
17
+ before { stub_get_with_auth('/team') }
18
+
19
+ example do
20
+ HelloSign.team.show
21
+
22
+ expect(a_get_with_auth('/team'))
23
+ .to have_been_made
24
+ end
25
+ end
26
+
27
+ context "updating team information" do
28
+ before { stub_post_with_auth('/team') }
29
+
30
+ example do
31
+ HelloSign.team.update(:name => 'The Bluecoats')
32
+
33
+ expect(a_post_with_auth('/team')
34
+ .with(:name => 'The Bluecoats'))
35
+ .to have_been_made
36
+ end
37
+ end
38
+
39
+ context "destroying a team" do
40
+ before { stub_post_with_auth('/team/destroy') }
41
+
42
+ example do
43
+ HelloSign.team.destroy
44
+
45
+ expect(a_post_with_auth('/team/destroy'))
46
+ .to have_been_made
47
+ end
48
+ end
49
+
50
+ context "adding a member to a team" do
51
+ before { stub_post_with_auth('/team/add_member') }
52
+
53
+ example do
54
+ HelloSign.team.add_member(:email => 'bob@smith.com')
55
+
56
+ expect(a_post_with_auth('/team/add_member')
57
+ .with(:email => 'bob@smith.com'))
58
+ .to have_been_made
59
+ end
60
+ end
61
+
62
+ context "removing a member from a team" do
63
+ before { stub_post_with_auth('/team/remove_member') }
64
+
65
+ example do
66
+ HelloSign.team.remove_member(:email => 'bob@smith.com')
67
+
68
+ expect(a_post_with_auth('/team/remove_member')
69
+ .with(:email => 'bob@smith.com'))
70
+ .to have_been_made
71
+ end
72
+ end
73
+ end
@@ -22,7 +22,7 @@ describe HelloSign::AccountProxy do
22
22
  .with(
23
23
  '/account/create',
24
24
  :body => {:email_address => 'david@bowman.com', :password => 'space'},
25
- :unauthenticated => true
25
+ :auth_not_required => true
26
26
  )
27
27
  account_proxy.create(:email => 'david@bowman.com', :password => 'space')
28
28
  end
@@ -6,8 +6,6 @@ describe HelloSign::Client do
6
6
  let(:connection) { double('connection') }
7
7
  subject(:client) { HelloSign::Client.new('david@bowman.com', 'space') }
8
8
 
9
- before { client.connection = connection }
10
-
11
9
  describe "#email" do
12
10
  it "returns the email address" do
13
11
  expect(client.email).to eq 'david@bowman.com'
@@ -19,20 +17,4 @@ describe HelloSign::Client do
19
17
  expect(client.password).to eq 'space'
20
18
  end
21
19
  end
22
-
23
- describe "#get" do
24
- before { subject.should_receive(:request).with(:get, 'path', {:options => {}}) }
25
-
26
- it "makes a GET request" do
27
- subject.get('path', :options => {})
28
- end
29
- end
30
-
31
- describe "#post" do
32
- before { subject.should_receive(:request).with(:post, 'path', {:options => {}}) }
33
-
34
- it "makes a POST request" do
35
- subject.post('path', :options => {})
36
- end
37
- end
38
20
  end
@@ -20,6 +20,12 @@ describe HelloSign do
20
20
  end
21
21
  end
22
22
 
23
+ describe "::team" do
24
+ it "returns a team proxy" do
25
+ expect(HelloSign.team).to be_a HelloSign::TeamProxy
26
+ end
27
+ end
28
+
23
29
  describe "::client" do
24
30
  context "when it has not previously been called" do
25
31
  it "returns a new client" do
@@ -0,0 +1,141 @@
1
+ require 'helper'
2
+ require 'hello_sign/team_proxy'
3
+
4
+ describe HelloSign::TeamProxy do
5
+ let(:client) { double('client') }
6
+ let(:api_response) { double('API response') }
7
+ subject(:team_proxy) { HelloSign::TeamProxy.new(client) }
8
+
9
+ before do
10
+ client.stub(:get).and_return(api_response)
11
+ client.stub(:post).and_return(api_response)
12
+ end
13
+
14
+ describe "#client" do
15
+ it "returns the client" do
16
+ expect(team_proxy.client).to be client
17
+ end
18
+ end
19
+
20
+ describe "#create" do
21
+ let(:name) { 'The Browncoats' }
22
+
23
+ context "when called with the proper parameters" do
24
+ it "sends a team creation request" do
25
+ client.should_receive(:post).with('/team/create', :body => {:name => name})
26
+ team_proxy.create(:name => name)
27
+ end
28
+
29
+ it "returns the API response" do
30
+ expect(team_proxy.create(:name => name)).to eq api_response
31
+ end
32
+ end
33
+
34
+ context "when called without the proper parameters" do
35
+ it "raises an exception" do
36
+ expect { team_proxy.create }.to raise_error
37
+ end
38
+ end
39
+ end
40
+
41
+ describe "#show" do
42
+ it "fetches the team information" do
43
+ client.should_receive(:get).with('/team')
44
+ team_proxy.show
45
+ end
46
+
47
+ it "returns the API response" do
48
+ expect(team_proxy.show).to eq api_response
49
+ end
50
+ end
51
+
52
+ describe "#update" do
53
+ let(:new_name) { 'The Bluecoats' }
54
+
55
+ it "sends a team update request" do
56
+ client.should_receive(:post).with('/team', :body => {:name => new_name})
57
+ team_proxy.update(:name => new_name)
58
+ end
59
+
60
+ it "returns the API response" do
61
+ expect(team_proxy.update(:name => new_name)).to eq api_response
62
+ end
63
+ end
64
+
65
+ describe "#destroy" do
66
+ it "sends a team destroy request" do
67
+ client.should_receive(:post).with('/team/destroy')
68
+ team_proxy.destroy
69
+ end
70
+
71
+ it "returns the API response" do
72
+ expect(team_proxy.destroy).to eq api_response
73
+ end
74
+ end
75
+
76
+ describe "#add_member" do
77
+ let(:email) { 'john@johnson.com' }
78
+ let(:account_id) { '15' }
79
+
80
+ context "when called with an email address" do
81
+ it "adds the user with the email address to the team" do
82
+ client.should_receive(:post).with('/team/add_member', :body => {:email_address => email})
83
+ team_proxy.add_member(:email => email)
84
+ end
85
+
86
+ it "returns the API response" do
87
+ expect(team_proxy.add_member(:email => email)).to eq api_response
88
+ end
89
+ end
90
+
91
+ context "when called with an account ID" do
92
+ it "adds the user with the account ID to the team" do
93
+ client.should_receive(:post).with('/team/add_member', :body => {:account_id => account_id})
94
+ team_proxy.add_member(:account_id => account_id)
95
+ end
96
+
97
+ it "returns the API response" do
98
+ expect(team_proxy.add_member(:account_id => account_id)).to eq api_response
99
+ end
100
+ end
101
+
102
+ context "when called without proper parameters" do
103
+ it "raises an argument error exception" do
104
+ expect { team_proxy.add_member }.to raise_error ArgumentError
105
+ end
106
+ end
107
+ end
108
+
109
+ describe "#remove_member" do
110
+ let(:email) { 'john@johnson.com' }
111
+ let(:account_id) { '15' }
112
+
113
+ context "when called with an email address" do
114
+ it "removes the user with the email address from the team" do
115
+ client.should_receive(:post).with('/team/remove_member', :body => {:email_address => email})
116
+ team_proxy.remove_member(:email => email)
117
+ end
118
+
119
+ it "returns the API response" do
120
+ expect(team_proxy.remove_member(:email => email)).to eq api_response
121
+ end
122
+ end
123
+
124
+ context "when called with an account ID" do
125
+ it "removes the user with the account ID from the team" do
126
+ client.should_receive(:post).with('/team/remove_member', :body => {:account_id => account_id})
127
+ team_proxy.remove_member(:account_id => account_id)
128
+ end
129
+
130
+ it "returns the API response" do
131
+ expect(team_proxy.remove_member(:account_id => account_id)).to eq api_response
132
+ end
133
+ end
134
+
135
+ context "when called without proper parameters" do
136
+ it "raises an argument error exception" do
137
+ expect { team_proxy.remove_member }.to raise_error ArgumentError
138
+ end
139
+ end
140
+ end
141
+ 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.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-28 00:00:00.000000000 Z
12
+ date: 2013-01-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -89,6 +89,7 @@ files:
89
89
  - lib/hello_sign/reusable_form_proxy.rb
90
90
  - lib/hello_sign/settings_proxy.rb
91
91
  - lib/hello_sign/signature_request_proxy.rb
92
+ - lib/hello_sign/team_proxy.rb
92
93
  - lib/hello_sign/version.rb
93
94
  - lib/hello_sign.rb
94
95
  - spec/fixtures/test.jpg
@@ -100,6 +101,7 @@ files:
100
101
  - spec/integration/helper.rb
101
102
  - spec/integration/reusable_form_spec.rb
102
103
  - spec/integration/signature_request_spec.rb
104
+ - spec/integration/team_spec.rb
103
105
  - spec/unit/account_proxy_spec.rb
104
106
  - spec/unit/client_spec.rb
105
107
  - spec/unit/hello_sign_spec.rb
@@ -108,6 +110,7 @@ files:
108
110
  - spec/unit/reusable_form_proxy_spec.rb
109
111
  - spec/unit/settings_proxy_spec.rb
110
112
  - spec/unit/signature_request_proxy_spec.rb
113
+ - spec/unit/team_proxy_spec.rb
111
114
  homepage: http://www.github.com/craiglittle/hello_sign
112
115
  licenses: []
113
116
  post_install_message:
@@ -142,6 +145,7 @@ test_files:
142
145
  - spec/integration/helper.rb
143
146
  - spec/integration/reusable_form_spec.rb
144
147
  - spec/integration/signature_request_spec.rb
148
+ - spec/integration/team_spec.rb
145
149
  - spec/unit/account_proxy_spec.rb
146
150
  - spec/unit/client_spec.rb
147
151
  - spec/unit/hello_sign_spec.rb
@@ -150,3 +154,4 @@ test_files:
150
154
  - spec/unit/reusable_form_proxy_spec.rb
151
155
  - spec/unit/settings_proxy_spec.rb
152
156
  - spec/unit/signature_request_proxy_spec.rb
157
+ - spec/unit/team_proxy_spec.rb