hello_sign 0.0.2 → 0.0.3

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.
@@ -7,7 +7,7 @@ module HelloSign
7
7
  attr_accessor :email, :password
8
8
 
9
9
  def account
10
- AccountProxy.new
10
+ AccountProxy.new(client)
11
11
  end
12
12
 
13
13
  def client
@@ -1,7 +1,12 @@
1
- require 'hello_sign/account'
1
+ require 'hello_sign/settings'
2
2
 
3
3
  module HelloSign
4
4
  class AccountProxy
5
+ attr_reader :client
6
+
7
+ def initialize(client)
8
+ @client = client
9
+ end
5
10
 
6
11
  def create(credentials)
7
12
  email = credentials.fetch(:email)
@@ -9,17 +14,23 @@ module HelloSign
9
14
 
10
15
  create_account(email, password)
11
16
 
12
- Account.new(email, password)
17
+ true
13
18
  end
14
19
 
15
- private
20
+ def settings
21
+ settings = client.get('/account')
16
22
 
17
- def create_account(email, password)
18
- client.post('/v3/account/create', {:email_address => email, :password => password})
23
+ Settings.new(settings, client)
19
24
  end
20
25
 
21
- def client
22
- HelloSign.client
26
+ private
27
+
28
+ def create_account(email, password)
29
+ client.post(
30
+ '/account/create',
31
+ :body => {:email_address => email, :password => password},
32
+ :unauthenticated => true
33
+ )
23
34
  end
24
35
 
25
36
  end
@@ -1,26 +1,54 @@
1
1
  require 'faraday'
2
+ require 'faraday_middleware-multi_json'
2
3
 
3
4
  module HelloSign
4
5
  class Client
6
+ API_ENDPOINT = 'https://api.hellosign.com'
7
+ API_VERSION = '/v3'
8
+
5
9
  attr_reader :email, :password
10
+ attr_writer :connection
6
11
 
7
12
  def initialize(email, password)
8
13
  @email = email
9
14
  @password = password
10
15
  end
11
16
 
12
- def post(path, body)
13
- connection.post(path, body)
17
+ def get(path, options = {})
18
+ request(:get, path, options)
19
+ end
20
+
21
+ def post(path, options = {})
22
+ request(:post, path, options)
14
23
  end
15
24
 
16
25
  private
17
26
 
18
- def connection
19
- @connection ||= Faraday.new(:url => 'https://api.hellosign.com') do |faraday|
20
- faraday.request :url_encoded
27
+ 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.body = options[:body]
32
+ end
33
+
34
+ request.body
35
+ end
36
+
37
+ def unauth_connection(&auth)
38
+ Faraday.new(:url => API_ENDPOINT) do |faraday|
39
+ faraday.request :url_encoded
40
+ faraday.response :logger
41
+ faraday.response :multi_json, :symbolize_keys => true
42
+ auth.call(faraday) if block_given?
21
43
  faraday.adapter Faraday.default_adapter
22
44
  end
23
45
  end
24
46
 
47
+ def auth_connection
48
+ unauth_connection do |faraday|
49
+ faraday.request :basic_auth, email, password
50
+ end
51
+ end
52
+
25
53
  end
26
54
  end
@@ -0,0 +1,19 @@
1
+ require 'hello_sign/client'
2
+
3
+ module HelloSign
4
+ class Settings
5
+ attr_reader :attributes, :client
6
+
7
+ def initialize(attributes, client)
8
+ @attributes = attributes
9
+ @client = client
10
+ end
11
+
12
+ def update(attributes)
13
+ client.post('/account', :body => attributes)
14
+
15
+ true
16
+ end
17
+
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module HelloSign
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
@@ -1,5 +1,3 @@
1
- require 'hello_sign'
2
-
3
1
  RSpec.configure do |config|
4
2
  config.expect_with :rspec do |c|
5
3
  c.syntax = :expect
@@ -7,5 +5,4 @@ RSpec.configure do |config|
7
5
 
8
6
  config.color_enabled = true
9
7
  config.tty = true
10
- config.formatter = :documentation
11
8
  end
@@ -3,14 +3,39 @@ require 'integration/helper'
3
3
  describe HelloSign do
4
4
  context "when creating an account" do
5
5
  before do
6
- stub_request(:post, 'https://api.hellosign.com/v3/account/create')
6
+ stub_post('/account/create')
7
7
  HelloSign.account.create(:email => 'david@bowman.com', :password => 'foobar')
8
8
  end
9
9
 
10
10
  it "sends an account creation request to the HelloSign API" do
11
- expect(a_request(:post, 'https://api.hellosign.com/v3/account/create')
11
+ expect(a_post('/account/create')
12
12
  .with(:body => {:email_address => 'david@bowman.com', :password => 'foobar'}))
13
13
  .to have_been_made
14
14
  end
15
15
  end
16
+
17
+ context "when accessing an account's settings" do
18
+ before do
19
+ stub_get_with_auth('/account')
20
+ @settings = HelloSign.account.settings
21
+ end
22
+
23
+ it "fetches the account's settings from the HelloSign API" do
24
+ expect(a_get_with_auth('/account')).to have_been_made
25
+ end
26
+ end
27
+
28
+ context "when updating an account's settings" do
29
+ before do
30
+ stub_get_with_auth('/account')
31
+ stub_post_with_auth('/account')
32
+ HelloSign.account.settings.update(:callback_url => 'http://callmemaybe.com')
33
+ end
34
+
35
+ it "sends an update account request to the HelloSign API" do
36
+ expect(a_post_with_auth('/account')
37
+ .with(:body => {:callback_url => 'http://callmemaybe.com'}))
38
+ .to have_been_made
39
+ end
40
+ end
16
41
  end
@@ -0,0 +1,11 @@
1
+ require 'integration/helper'
2
+
3
+ describe HelloSign do
4
+ context "when returning a response with a body" do
5
+ before { stub_get('/json').to_return(:body => {:account_id => 1}.to_json) }
6
+
7
+ it "renders it as JSON" do
8
+ expect(HelloSign.client.get('/json', :unauthenticated => true)).to eq({:account_id => 1})
9
+ end
10
+ end
11
+ end
@@ -1,2 +1,41 @@
1
1
  require 'helper'
2
+ require 'hello_sign'
2
3
  require 'webmock/rspec'
4
+ require 'json'
5
+
6
+ HelloSign.configure do |hs|
7
+ hs.email = 'david@bowman.com'
8
+ hs.password = 'foobar'
9
+ end
10
+
11
+ def stub_get(path)
12
+ stub_request(:get, "https://api.hellosign.com/v3#{path}")
13
+ end
14
+
15
+ def stub_post(path)
16
+ stub_request(:post, "https://api.hellosign.com/v3#{path}")
17
+ end
18
+
19
+ def stub_get_with_auth(path)
20
+ stub_request(:get, "https://david@bowman.com:foobar@api.hellosign.com/v3#{path}")
21
+ end
22
+
23
+ def stub_post_with_auth(path)
24
+ stub_request(:post, "https://david@bowman.com:foobar@api.hellosign.com/v3#{path}")
25
+ end
26
+
27
+ def a_get(path)
28
+ a_request(:get, "https://api.hellosign.com/v3#{path}")
29
+ end
30
+
31
+ def a_post(path)
32
+ a_request(:post, "https://api.hellosign.com/v3#{path}")
33
+ end
34
+
35
+ def a_get_with_auth(path)
36
+ a_request(:get, "https://david@bowman.com:foobar@api.hellosign.com/v3#{path}")
37
+ end
38
+
39
+ def a_post_with_auth(path)
40
+ a_request(:post, "https://david@bowman.com:foobar@api.hellosign.com/v3#{path}")
41
+ end
@@ -0,0 +1,59 @@
1
+ require 'helper'
2
+ require 'hello_sign/account_proxy'
3
+
4
+ describe HelloSign::AccountProxy do
5
+ let(:client) { double('client') }
6
+ subject(:account_proxy) { HelloSign::AccountProxy.new(client) }
7
+
8
+ describe "#client" do
9
+ it "returns the client" do
10
+ expect(account_proxy.client).to be client
11
+ end
12
+ end
13
+
14
+ describe "#create" do
15
+ context "when passed the proper parameters" do
16
+ before { client.stub(:post) }
17
+
18
+ it "sends an account creation request" do
19
+ client.should_receive(:post)
20
+ .with(
21
+ '/account/create',
22
+ :body => {:email_address => 'david@bowman.com', :password => 'space'},
23
+ :unauthenticated => true
24
+ )
25
+ account_proxy.create(:email => 'david@bowman.com', :password => 'space')
26
+ end
27
+
28
+ it "returns true" do
29
+ expect(account_proxy.create(:email => 'david@bowman.com', :password => 'space')). to be true
30
+ end
31
+ end
32
+
33
+ context "when not passed the proper parameters" do
34
+ it "raises an exception" do
35
+ expect { account_proxy.create(:email => 'david@bowman.com') }.to raise_error
36
+ end
37
+ end
38
+ end
39
+
40
+ describe "#settings" do
41
+ let(:settings) { double('settings') }
42
+
43
+ before { client.stub(:get).and_return(settings) }
44
+
45
+ it "sends a request to fetch the account's settings" do
46
+ client.should_receive(:get).with('/account')
47
+ account_proxy.settings
48
+ end
49
+
50
+ it "creates an account object" do
51
+ HelloSign::Settings.should_receive(:new).with(settings, client)
52
+ account_proxy.settings
53
+ end
54
+
55
+ it "returns an account object" do
56
+ expect(account_proxy.settings).to be_a HelloSign::Settings
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,38 @@
1
+ require 'helper'
2
+ require 'json'
3
+ require 'hello_sign/client'
4
+
5
+ describe HelloSign::Client do
6
+ let(:connection) { double('connection') }
7
+ subject(:client) { HelloSign::Client.new('david@bowman.com', 'space') }
8
+
9
+ before { client.connection = connection }
10
+
11
+ describe "#email" do
12
+ it "returns the email address" do
13
+ expect(client.email).to eq 'david@bowman.com'
14
+ end
15
+ end
16
+
17
+ describe "#password" do
18
+ it "returns the password" do
19
+ expect(client.password).to eq 'space'
20
+ end
21
+ 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
+ end
@@ -1,4 +1,5 @@
1
1
  require 'helper'
2
+ require 'hello_sign'
2
3
 
3
4
  describe HelloSign do
4
5
  describe "::account" do
@@ -6,4 +7,43 @@ describe HelloSign do
6
7
  expect(HelloSign.account).to be_a HelloSign::AccountProxy
7
8
  end
8
9
  end
10
+
11
+ describe "::client" do
12
+ context "when it has not previously been called" do
13
+ it "returns a new client" do
14
+ expect(HelloSign.client).to be_a HelloSign::Client
15
+ end
16
+ end
17
+
18
+ context "when it has previously been called" do
19
+ it "returns the same client" do
20
+ client = HelloSign.client
21
+ expect(HelloSign.client).to be client
22
+ end
23
+ end
24
+ end
25
+
26
+ describe "::configure" do
27
+ it "yields itself to the block" do
28
+ HelloSign.configure do |hs|
29
+ expect(hs).to be HelloSign
30
+ end
31
+ end
32
+ end
33
+
34
+ describe "::email" do
35
+ it "sets and returns the email address" do
36
+ HelloSign.email = 'hal@jupiter.com'
37
+
38
+ expect(HelloSign.email).to eq 'hal@jupiter.com'
39
+ end
40
+ end
41
+
42
+ describe "::password" do
43
+ it "sets and returns the password" do
44
+ HelloSign.password = 'human_domination'
45
+
46
+ expect(HelloSign.password).to eq 'human_domination'
47
+ end
48
+ end
9
49
  end
@@ -0,0 +1,36 @@
1
+ require 'helper'
2
+ require 'hello_sign/settings'
3
+
4
+ describe HelloSign::Settings do
5
+ let(:attributes) { double('attributes') }
6
+ let(:client) { double('client') }
7
+ subject(:settings) { HelloSign::Settings.new(attributes, client) }
8
+
9
+ describe "#attributes" do
10
+ it "returns the attributes" do
11
+ expect(settings.attributes).to eq attributes
12
+ end
13
+ end
14
+
15
+ describe "#client" do
16
+ it "returns the client" do
17
+ expect(settings.client).to eq client
18
+ end
19
+ end
20
+
21
+ describe "#update" do
22
+ let(:callback_url) { 'http://www.callmemaybe.com' }
23
+
24
+ before { client.stub(:post) }
25
+
26
+ it "sends a request to update the account's settings" do
27
+ client.should_receive(:post)
28
+ .with('/account', :body => {:callback_url => callback_url})
29
+ settings.update(:callback_url => callback_url)
30
+ end
31
+
32
+ it "returns true" do
33
+ expect(settings.update(:callback_url => callback_url)).to be true
34
+ end
35
+ end
36
+ 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.0.2
4
+ version: 0.0.3
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-19 00:00:00.000000000 Z
12
+ date: 2013-01-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
29
  version: 0.8.4
30
+ - !ruby/object:Gem::Dependency
31
+ name: faraday_middleware-multi_json
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.0.5
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.0.5
30
46
  - !ruby/object:Gem::Dependency
31
47
  name: rspec
32
48
  requirement: !ruby/object:Gem::Requirement
@@ -66,16 +82,19 @@ executables: []
66
82
  extensions: []
67
83
  extra_rdoc_files: []
68
84
  files:
69
- - lib/hello_sign/account.rb
70
85
  - lib/hello_sign/account_proxy.rb
71
86
  - lib/hello_sign/client.rb
87
+ - lib/hello_sign/settings.rb
72
88
  - lib/hello_sign/version.rb
73
89
  - lib/hello_sign.rb
74
90
  - spec/helper.rb
75
91
  - spec/integration/account_spec.rb
92
+ - spec/integration/hello_sign_spec.rb
76
93
  - spec/integration/helper.rb
77
- - spec/unit/account_spec.rb
94
+ - spec/unit/account_proxy_spec.rb
95
+ - spec/unit/client_spec.rb
78
96
  - spec/unit/hello_sign_spec.rb
97
+ - spec/unit/settings_spec.rb
79
98
  homepage: http://www.github.com/craiglittle/hello_sign
80
99
  licenses: []
81
100
  post_install_message:
@@ -103,6 +122,9 @@ summary: A Ruby interface to the HelloSign API.
103
122
  test_files:
104
123
  - spec/helper.rb
105
124
  - spec/integration/account_spec.rb
125
+ - spec/integration/hello_sign_spec.rb
106
126
  - spec/integration/helper.rb
107
- - spec/unit/account_spec.rb
127
+ - spec/unit/account_proxy_spec.rb
128
+ - spec/unit/client_spec.rb
108
129
  - spec/unit/hello_sign_spec.rb
130
+ - spec/unit/settings_spec.rb
@@ -1,13 +0,0 @@
1
- require 'hello_sign/client'
2
-
3
- module HelloSign
4
- class Account
5
- attr_reader :email, :password
6
-
7
- def initialize(email, password)
8
- @email = email
9
- @password = password
10
- end
11
-
12
- end
13
- end
@@ -1,7 +0,0 @@
1
- require 'helper'
2
-
3
- describe HelloSign::Account do
4
- describe "#create" do
5
-
6
- end
7
- end