hello_sign 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,7 +13,7 @@ module HelloSign
13
13
  delegate [:account, :signature_request, :reusable_form, :team, :unclaimed_draft] => :client
14
14
 
15
15
  def client
16
- @client = client_source.new(email_address, password) unless credentials_match?
16
+ @client = HelloSign::Client.new(email_address, password) unless credentials_match?
17
17
  @client
18
18
  end
19
19
 
@@ -27,10 +27,6 @@ module HelloSign
27
27
  @client && [@client.email_address, @client.password].hash == [email_address, password].hash
28
28
  end
29
29
 
30
- def client_source
31
- @client_source || HelloSign::Client
32
- end
33
-
34
30
  Faraday.register_middleware :response, raise_error: HelloSign::Middleware::RaiseError
35
31
 
36
32
  end
@@ -42,7 +42,9 @@ module HelloSign
42
42
  end
43
43
 
44
44
  def base_connection
45
- Faraday.new(url: API_ENDPOINT) do |connection|
45
+ options = {url: API_ENDPOINT, headers: {user_agent: "hello_sign gem v#{HelloSign::VERSION}"}}
46
+
47
+ Faraday.new(options) do |connection|
46
48
  yield connection
47
49
 
48
50
  connection.request :multipart
@@ -0,0 +1,36 @@
1
+ require 'hello_sign/file/mime_types'
2
+ require 'faraday/upload_io'
3
+
4
+ module HelloSign
5
+ class File
6
+ DEFAULT_MIME_TYPE = MIME_TYPES.fetch('txt')
7
+
8
+ attr_reader :filename, :io_object, :mime_type
9
+
10
+ def initialize(file_data)
11
+ @filename = file_data[:filename]
12
+ @io_object = file_data[:io]
13
+ @mime_type = file_data[:mime]
14
+ end
15
+
16
+ def attachment
17
+ Faraday::UploadIO.new(*parameters)
18
+ end
19
+
20
+ private
21
+
22
+ def parameters
23
+ begin
24
+ io_object ? [io_object, mime_type, filename] : [filename, mime_type]
25
+ end.compact
26
+ end
27
+
28
+ def mime_type
29
+ @mime_type or begin
30
+ extension = (filename || '').split('.').last
31
+ MIME_TYPES.fetch(extension) { DEFAULT_MIME_TYPE }
32
+ end
33
+ end
34
+
35
+ end
36
+ end
@@ -1,8 +1,5 @@
1
- require 'faraday/upload_io'
2
- require 'hello_sign/error'
3
-
4
1
  module HelloSign
5
- class UploadIO
2
+ class File
6
3
  MIME_TYPES = {
7
4
  'doc' => 'application/msword',
8
5
  'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
@@ -20,37 +17,5 @@ module HelloSign
20
17
  'xls' => 'application/vnd.ms-excel',
21
18
  'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
22
19
  }
23
-
24
- attr_reader :filename, :io_object
25
-
26
- def initialize(file_data)
27
- @filename = file_data[:filename]
28
- @io_object = file_data[:io]
29
- @mime_type = file_data[:mime]
30
- end
31
-
32
- def upload
33
- file_converter_source.new(*parameters)
34
- end
35
-
36
- private
37
-
38
- def parameters
39
- begin
40
- io_object ? [io_object, mime_type, filename] : [filename, mime_type]
41
- end.compact
42
- end
43
-
44
- def mime_type
45
- @mime_type or begin
46
- extension = (filename || '').split('.').last
47
- MIME_TYPES.fetch(extension) { 'text/plain' }
48
- end
49
- end
50
-
51
- def file_converter_source
52
- @file_converter_source || Faraday::UploadIO
53
- end
54
-
55
20
  end
56
21
  end
@@ -1,10 +1,10 @@
1
- require 'hello_sign/upload_io'
1
+ require 'hello_sign/file'
2
2
 
3
3
  module HelloSign
4
4
  module Parameters
5
5
  class SignatureRequest
6
6
  attr_accessor :title, :subject, :message, :ccs
7
- attr_writer :signers, :files, :upload_io_source
7
+ attr_writer :signers, :files
8
8
 
9
9
  def signers
10
10
  (@signers || {}).each_with_index.inject({}) do |parameter, (signer, index)|
@@ -20,7 +20,7 @@ module HelloSign
20
20
 
21
21
  def files
22
22
  (@files || {}).each_with_index.inject({}) do |parameter, (file_data, index)|
23
- parameter[index + 1] = upload_io_source.new(file_data).upload
23
+ parameter[index + 1] = HelloSign::File.new(file_data).attachment
24
24
  parameter
25
25
  end
26
26
  end
@@ -36,12 +36,6 @@ module HelloSign
36
36
  }
37
37
  end
38
38
 
39
- private
40
-
41
- def upload_io_source
42
- @upload_io_source || HelloSign::UploadIO
43
- end
44
-
45
39
  end
46
40
  end
47
41
  end
@@ -1,9 +1,9 @@
1
- require 'hello_sign/upload_io'
1
+ require 'hello_sign/file'
2
2
 
3
3
  module HelloSign
4
4
  module Parameters
5
5
  class UnclaimedDraft
6
- attr_writer :files, :upload_io_source
6
+ attr_writer :files
7
7
 
8
8
  def formatted
9
9
  {file: files}
@@ -13,15 +13,11 @@ module HelloSign
13
13
 
14
14
  def files
15
15
  @files.each_with_index.inject({}) do |parameter, (file_data, index)|
16
- parameter[index] = upload_io_source.new(file_data).upload
16
+ parameter[index] = HelloSign::File.new(file_data).attachment
17
17
  parameter
18
18
  end
19
19
  end
20
20
 
21
- def upload_io_source
22
- @upload_io_source || HelloSign::UploadIO
23
- end
24
-
25
21
  end
26
22
  end
27
23
  end
@@ -6,50 +6,25 @@ require 'hello_sign/proxy/unclaimed_draft'
6
6
 
7
7
  module HelloSign
8
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
9
 
13
10
  def account
14
- account_proxy_source.new(self)
11
+ HelloSign::Proxy::Account.new(self)
15
12
  end
16
13
 
17
14
  def signature_request(request_id = nil)
18
- signature_request_proxy_source.new(self, request_id)
15
+ HelloSign::Proxy::SignatureRequest.new(self, request_id)
19
16
  end
20
17
 
21
18
  def reusable_form(form_id = nil)
22
- reusable_form_proxy_source.new(self, form_id)
19
+ HelloSign::Proxy::ReusableForm.new(self, form_id)
23
20
  end
24
21
 
25
22
  def team
26
- team_proxy_source.new(self)
23
+ HelloSign::Proxy::Team.new(self)
27
24
  end
28
25
 
29
26
  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
27
+ HelloSign::Proxy::UnclaimedDraft.new(self)
53
28
  end
54
29
 
55
30
  end
@@ -4,7 +4,6 @@ module HelloSign
4
4
  module Proxy
5
5
  class Account
6
6
  attr_reader :client
7
- attr_writer :settings_proxy_source
8
7
 
9
8
  def initialize(client)
10
9
  @client = client
@@ -15,13 +14,7 @@ module HelloSign
15
14
  end
16
15
 
17
16
  def settings
18
- settings_proxy_source.new(client)
19
- end
20
-
21
- private
22
-
23
- def settings_proxy_source
24
- @settings_proxy_source || HelloSign::Proxy::Settings
17
+ HelloSign::Proxy::Settings.new(client)
25
18
  end
26
19
 
27
20
  end
@@ -5,7 +5,6 @@ module HelloSign
5
5
  module Proxy
6
6
  class SignatureRequest
7
7
  attr_reader :client, :request_id
8
- attr_writer :request_parameters, :reusable_form_request_parameters
9
8
 
10
9
  def initialize(client, request_id)
11
10
  @client = client
@@ -4,7 +4,6 @@ module HelloSign
4
4
  module Proxy
5
5
  class UnclaimedDraft
6
6
  attr_reader :client
7
- attr_writer :draft_parameters
8
7
 
9
8
  def initialize(client)
10
9
  @client = client
@@ -1,3 +1,3 @@
1
1
  module HelloSign
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
@@ -17,6 +17,12 @@ describe HelloSign do
17
17
  HelloSign.client.get('/resource')
18
18
  expect(a_get_with_auth('/resource')).to have_been_made
19
19
  end
20
+
21
+ example do
22
+ HelloSign.client.get('/resource')
23
+ headers = {'User-Agent' => "hello_sign gem v#{HelloSign::VERSION}"}
24
+ expect(a_get_with_auth('/resource').with(headers: headers)).to have_been_made
25
+ end
20
26
  end
21
27
 
22
28
  describe "#post" do
@@ -1,58 +1,47 @@
1
1
  shared_examples_for 'a proxy' do
2
- let(:proxy_source) { double('proxy source') }
3
2
  let(:proxy) { double('proxy') }
4
3
 
5
4
  describe "#account" do
6
- before { client.account_proxy_source = proxy_source }
7
-
8
5
  it "returns an account proxy" do
9
- proxy_source.should_receive(:new).with(client).and_return(proxy)
6
+ HelloSign::Proxy::Account.should_receive(:new).with(client).and_return(proxy)
10
7
  expect(client.account).to eq proxy
11
8
  end
12
9
  end
13
10
 
14
11
  describe "#signature_request" do
15
- before { client.signature_request_proxy_source = proxy_source }
16
-
17
12
  it "returns a signature request proxy" do
18
- proxy_source.should_receive(:new).with(client, nil).and_return(proxy)
13
+ HelloSign::Proxy::SignatureRequest.should_receive(:new).with(client, nil).and_return(proxy)
19
14
  expect(client.signature_request).to eq proxy
20
15
  end
21
16
 
22
17
  it "passes on an optional signature request ID" do
23
- proxy_source.should_receive(:new).with(client, 'signature_request_id')
18
+ HelloSign::Proxy::SignatureRequest.should_receive(:new).with(client, 'signature_request_id')
24
19
  client.signature_request('signature_request_id')
25
20
  end
26
21
  end
27
22
 
28
23
  describe "#reusable_form" do
29
- before { client.reusable_form_proxy_source = proxy_source }
30
-
31
24
  it "returns a reusable form proxy" do
32
- proxy_source.should_receive(:new).with(client, nil).and_return(proxy)
25
+ HelloSign::Proxy::ReusableForm.should_receive(:new).with(client, nil).and_return(proxy)
33
26
  expect(client.reusable_form).to eq proxy
34
27
  end
35
28
 
36
29
  it "passes on an optional reusable form ID" do
37
- proxy_source.should_receive(:new).with(client, 'reusable_form_id')
30
+ HelloSign::Proxy::ReusableForm.should_receive(:new).with(client, 'reusable_form_id')
38
31
  client.reusable_form('reusable_form_id')
39
32
  end
40
33
  end
41
34
 
42
35
  describe "#team" do
43
- before { client.team_proxy_source = proxy_source }
44
-
45
36
  it "returns a team proxy" do
46
- proxy_source.should_receive(:new).with(client).and_return(proxy)
37
+ HelloSign::Proxy::Team.should_receive(:new).with(client).and_return(proxy)
47
38
  expect(client.team).to eq proxy
48
39
  end
49
40
  end
50
41
 
51
42
  describe "#unclaimed_draft" do
52
- before { client.unclaimed_draft_proxy_source = proxy_source }
53
-
54
43
  it "returns an unclaimed draft proxy" do
55
- proxy_source.should_receive(:new).with(client).and_return(proxy)
44
+ HelloSign::Proxy::UnclaimedDraft.should_receive(:new).with(client).and_return(proxy)
56
45
  expect(client.unclaimed_draft).to eq proxy
57
46
  end
58
47
  end
@@ -7,9 +7,6 @@ describe HelloSign::Client do
7
7
  let(:password) { double('password') }
8
8
  subject(:hs_client) { HelloSign::Client.new(email_address, password) }
9
9
 
10
- its(:email_address) { should eq email_address }
11
- its(:password) { should eq password }
12
-
13
10
  it_behaves_like 'a proxy' do
14
11
  let(:client) { hs_client }
15
12
  end
@@ -47,9 +44,6 @@ describe HelloSign::Client do
47
44
  context "when a hash is passed to the constructor" do
48
45
  subject(:hs_client) { HelloSign::Client.new(email_address: email_address, password: password) }
49
46
 
50
- its(:email_address) { should eq email_address }
51
- its(:password) { should eq password }
52
-
53
47
  it "raises an exception if an email address is not provided" do
54
48
  expect { HelloSign::Client.new(password: 'space') }.to raise_error ArgumentError
55
49
  end
@@ -10,24 +10,11 @@ describe HelloSign do
10
10
  HelloSign.password = password
11
11
  end
12
12
 
13
- its(:email_address) { should eq email_address }
14
- its(:password) { should eq password }
15
-
16
13
  describe "::client" do
17
- let(:client_source) { double('client_source') }
18
- let(:client) { double('client') }
19
-
20
- before do
21
- HelloSign._set_internal_collaborator(:client_source, client_source)
22
- client_source.stub(:new).and_return(client)
23
- end
24
-
25
- after { HelloSign.instance_variable_set(:@client, nil) }
26
-
27
- its(:client) { should be client }
14
+ let(:client) { double('client') }
28
15
 
29
16
  it "passes the credentials when creating the client" do
30
- client_source.should_receive(:new).with(email_address, password)
17
+ HelloSign::Client.should_receive(:new).with(email_address, password)
31
18
  HelloSign.client
32
19
  end
33
20
 
@@ -35,12 +22,14 @@ describe HelloSign do
35
22
  let(:new_client) { double('new client') }
36
23
 
37
24
  before do
38
- client_source.stub(:new).and_return(client, new_client)
25
+ HelloSign::Client.stub(:new).and_return(client, new_client)
39
26
  client.stub(:email_address).and_return(email_address)
40
27
  client.stub(:password).and_return(password)
41
28
  HelloSign.client
42
29
  end
43
30
 
31
+ after { HelloSign.instance_variable_set(:@client, nil) }
32
+
44
33
  its(:client) { should be client }
45
34
 
46
35
  context "and the credentials change" do
@@ -55,13 +44,9 @@ describe HelloSign do
55
44
  end
56
45
 
57
46
  context "when calling delegated methods" do
58
- let(:client_source) { double('client_source') }
59
47
  let(:client) { double('client') }
60
48
 
61
- before do
62
- HelloSign._set_internal_collaborator(:client_source, client_source)
63
- client_source.stub(:new).and_return(client)
64
- end
49
+ before { HelloSign::Client.stub(:new).and_return(client) }
65
50
 
66
51
  after { HelloSign.instance_variable_set(:@client, nil) }
67
52
 
@@ -4,19 +4,16 @@ require 'hello_sign/parameters/signature_request'
4
4
  describe HelloSign::Parameters::SignatureRequest do
5
5
  describe "#formatted" do
6
6
  let(:request_parameters) { HelloSign::Parameters::SignatureRequest.new }
7
- let(:upload_io_source) { double('upload IO source') }
8
7
  let(:text_file) { double('text file') }
9
8
  let(:image_file) { double('image file') }
10
9
 
11
- before { request_parameters.upload_io_source = upload_io_source }
12
-
13
10
  context "when all required arguments are set" do
14
11
  let(:expected) do
15
12
  {
16
13
  title: 'Lease',
17
14
  subject: 'Sign this',
18
15
  message: 'You must sign this.',
19
- cc_email_addresses: ['lawyer@lawfirm.com', 'spouse@family.com'], # BUGBUG: should have explicit indexes
16
+ cc_email_addresses: ['lawyer@lawfirm.com', 'spouse@family.com'],
20
17
  signers: {
21
18
  0 => {name: 'Jack', email_address: 'jack@hill.com', order: 0},
22
19
  1 => {name: 'Jill', email_address: 'jill@hill.com', order: 1}
@@ -41,9 +38,9 @@ describe HelloSign::Parameters::SignatureRequest do
41
38
  end
42
39
 
43
40
  it "returns formatted parameters" do
44
- upload_io_source.should_receive(:new).with(@file_data_1).and_return(text_file)
45
- upload_io_source.should_receive(:new).with(@file_data_2).and_return(image_file)
46
- [text_file, image_file].each { |file| file.should_receive(:upload).and_return(file) }
41
+ HelloSign::File.should_receive(:new).with(@file_data_1).and_return(text_file)
42
+ HelloSign::File.should_receive(:new).with(@file_data_2).and_return(image_file)
43
+ [text_file, image_file].each { |file| file.should_receive(:attachment).and_return(file) }
47
44
 
48
45
  expect(request_parameters.formatted).to eq expected
49
46
  end
@@ -4,11 +4,8 @@ require 'hello_sign/parameters/unclaimed_draft'
4
4
  require 'stringio'
5
5
 
6
6
  describe HelloSign::Parameters::UnclaimedDraft do
7
- let(:upload_io_source) { double('upload IO source') }
8
7
  subject(:draft_parameters) { HelloSign::Parameters::UnclaimedDraft.new }
9
8
 
10
- before { draft_parameters.upload_io_source = upload_io_source }
11
-
12
9
  describe "#formatted" do
13
10
  let(:text_file) { double('text file') }
14
11
  let(:image) { double('image') }
@@ -21,9 +18,9 @@ describe HelloSign::Parameters::UnclaimedDraft do
21
18
  end
22
19
 
23
20
  it "returns formatted parameters" do
24
- upload_io_source.should_receive(:new).with(@file_data_1).and_return(text_file)
25
- upload_io_source.should_receive(:new).with(@file_data_2).and_return(image)
26
- [text_file, image].each { |file| file.should_receive(:upload).and_return(file) }
21
+ HelloSign::File.should_receive(:new).with(@file_data_1).and_return(text_file)
22
+ HelloSign::File.should_receive(:new).with(@file_data_2).and_return(image)
23
+ [text_file, image].each { |file| file.should_receive(:attachment).and_return(file) }
27
24
 
28
25
  expect(draft_parameters.formatted).to eq({file: {0 => text_file, 1 => image}})
29
26
  end
@@ -6,10 +6,7 @@ describe HelloSign::Proxy::Account do
6
6
  let(:api_response) { double('API response') }
7
7
  subject(:account_proxy) { HelloSign::Proxy::Account.new(client) }
8
8
 
9
- its(:client) { should eq client }
10
-
11
9
  describe "#create" do
12
-
13
10
  let(:email_address) { 'david@bowman.com' }
14
11
  let(:password) { 'password' }
15
12
 
@@ -35,24 +32,14 @@ describe HelloSign::Proxy::Account do
35
32
  )
36
33
  ). to eq api_response
37
34
  end
38
-
39
35
  end
40
36
 
41
37
  describe "#settings" do
42
-
43
- let(:settings_proxy_source) { double('settings proxy source') }
44
38
  let(:settings_proxy) { double('settings proxy') }
45
39
 
46
- before do
47
- account_proxy.settings_proxy_source = settings_proxy_source
48
- end
49
-
50
40
  it "returns a signature request proxy" do
51
- settings_proxy_source.should_receive(:new)
52
- .with(client)
53
- .and_return(settings_proxy)
41
+ HelloSign::Proxy::Settings.should_receive(:new).with(client).and_return(settings_proxy)
54
42
  expect(account_proxy.settings).to be settings_proxy
55
43
  end
56
-
57
44
  end
58
45
  end
@@ -13,9 +13,6 @@ describe HelloSign::Proxy::ReusableForm do
13
13
  client.stub(:post).and_return(api_response)
14
14
  end
15
15
 
16
- its(:client) { should eq client }
17
- its(:form_id) { should eq form_id }
18
-
19
16
  describe "#list" do
20
17
  it "sends a request to fetch the list of reusable forms" do
21
18
  client.should_receive(:get).with('/reusable_form/list', params: {page: 10})
@@ -12,9 +12,6 @@ describe HelloSign::Proxy::SignatureRequest do
12
12
  client.stub(:post).and_return(api_response)
13
13
  end
14
14
 
15
- its(:client) { should eq client }
16
- its(:request_id) { should eq request_id }
17
-
18
15
  describe "#deliver" do
19
16
  let(:formatted_request_body) { double('formatted request body') }
20
17
  let(:request_parameters) { double('request parameters') }
@@ -22,7 +19,7 @@ describe HelloSign::Proxy::SignatureRequest do
22
19
  before do
23
20
  request_parameters.stub(:foo=)
24
21
  request_parameters.stub(:formatted).and_return(formatted_request_body)
25
- sr_proxy.request_parameters = request_parameters
22
+ HelloSign::Parameters::SignatureRequest.stub(:new).and_return(request_parameters)
26
23
  end
27
24
 
28
25
  it "yields the request parameters to the block" do
@@ -31,8 +28,7 @@ describe HelloSign::Proxy::SignatureRequest do
31
28
  end
32
29
 
33
30
  it "sends a signature request" do
34
- client.should_receive(:post)
35
- .with('/signature_request/send', body: formatted_request_body)
31
+ client.should_receive(:post).with('/signature_request/send', body: formatted_request_body)
36
32
  sr_proxy.deliver { |params| params.foo = 'bar' }
37
33
  end
38
34
 
@@ -43,7 +39,7 @@ describe HelloSign::Proxy::SignatureRequest do
43
39
  context "when a reusable form is specified" do
44
40
  before do
45
41
  request_parameters.stub(:reusable_form_id=)
46
- sr_proxy.reusable_form_request_parameters = request_parameters
42
+ HelloSign::Parameters::ReusableFormSignatureRequest.stub(:new).and_return(request_parameters)
47
43
  end
48
44
 
49
45
  it "sets the reusable form ID in the request parameters" do
@@ -52,8 +48,7 @@ describe HelloSign::Proxy::SignatureRequest do
52
48
  end
53
49
 
54
50
  it "sends a reusable form signature request" do
55
- client.should_receive(:post)
56
- .with('/signature_request/send_with_reusable_form', body: formatted_request_body)
51
+ client.should_receive(:post).with('/signature_request/send_with_reusable_form', body: formatted_request_body)
57
52
  sr_proxy.deliver(form: 'form_id') {}
58
53
  end
59
54
 
@@ -77,8 +72,7 @@ describe HelloSign::Proxy::SignatureRequest do
77
72
  describe "#list" do
78
73
  context "when called without a page number" do
79
74
  it "fetches the first page of signature requests" do
80
- client.should_receive(:get)
81
- .with('/signature_request/list', params: {page: 1})
75
+ client.should_receive(:get).with('/signature_request/list', params: {page: 1})
82
76
  sr_proxy.list
83
77
  end
84
78
 
@@ -90,8 +84,7 @@ describe HelloSign::Proxy::SignatureRequest do
90
84
 
91
85
  context "when called with a page number" do
92
86
  it "fetches a list of signature requests from the specified page" do
93
- client.should_receive(:get)
94
- .with('/signature_request/list', params: {page: 10})
87
+ client.should_receive(:get).with('/signature_request/list', params: {page: 10})
95
88
  sr_proxy.list(page: 10)
96
89
  end
97
90
 
@@ -106,8 +99,7 @@ describe HelloSign::Proxy::SignatureRequest do
106
99
  let(:email) { 'john@johnson.com' }
107
100
 
108
101
  it "sends a signature request reminder" do
109
- client.should_receive(:post)
110
- .with("/signature_request/remind/#{request_id}", body: {email_address: email})
102
+ client.should_receive(:post).with("/signature_request/remind/#{request_id}", body: {email_address: email})
111
103
  sr_proxy.remind(email: email)
112
104
  end
113
105
 
@@ -11,10 +11,7 @@ describe HelloSign::Proxy::Team do
11
11
  client.stub(:post).and_return(api_response)
12
12
  end
13
13
 
14
- its(:client) { should eq client }
15
-
16
14
  describe "#create" do
17
-
18
15
  let(:name) { 'The Browncoats' }
19
16
 
20
17
  it "sends a request to create a team" do
@@ -25,11 +22,9 @@ describe HelloSign::Proxy::Team do
25
22
  it "returns the API response" do
26
23
  expect(team_proxy.create(name: name)).to eq api_response
27
24
  end
28
-
29
25
  end
30
26
 
31
27
  describe "#show" do
32
-
33
28
  it "sends a request to fetch the team information" do
34
29
  client.should_receive(:get).with('/team')
35
30
  team_proxy.show
@@ -38,11 +33,9 @@ describe HelloSign::Proxy::Team do
38
33
  it "returns the API response" do
39
34
  expect(team_proxy.show).to eq api_response
40
35
  end
41
-
42
36
  end
43
37
 
44
38
  describe "#update" do
45
-
46
39
  let(:new_name) { 'The Bluecoats' }
47
40
 
48
41
  it "sends a request to update the team information" do
@@ -53,11 +46,9 @@ describe HelloSign::Proxy::Team do
53
46
  it "returns the API response" do
54
47
  expect(team_proxy.update(name: new_name)).to eq api_response
55
48
  end
56
-
57
49
  end
58
50
 
59
51
  describe "#destroy" do
60
-
61
52
  it "sends a request to destroy the team" do
62
53
  client.should_receive(:post).with('/team/destroy')
63
54
  team_proxy.destroy
@@ -66,11 +57,9 @@ describe HelloSign::Proxy::Team do
66
57
  it "returns the API response" do
67
58
  expect(team_proxy.destroy).to eq api_response
68
59
  end
69
-
70
60
  end
71
61
 
72
62
  describe "#add_member" do
73
-
74
63
  let(:email_address) { 'john@johnson.com' }
75
64
 
76
65
  it "sends a request to add the member to the team" do
@@ -81,11 +70,9 @@ describe HelloSign::Proxy::Team do
81
70
  it "returns the API response" do
82
71
  expect(team_proxy.add_member(email_address: email_address)).to eq api_response
83
72
  end
84
-
85
73
  end
86
74
 
87
75
  describe "#remove_member" do
88
-
89
76
  let(:email_address) { 'john@johnson.com' }
90
77
 
91
78
  it "sends a request to remove the member from the team" do
@@ -96,6 +83,5 @@ describe HelloSign::Proxy::Team do
96
83
  it "returns the API response" do
97
84
  expect(team_proxy.remove_member(email_address: email_address)).to eq api_response
98
85
  end
99
-
100
86
  end
101
87
  end
@@ -6,19 +6,15 @@ describe HelloSign::Proxy::UnclaimedDraft do
6
6
  let(:api_response) { double('API response') }
7
7
  subject(:ud_proxy) { HelloSign::Proxy::UnclaimedDraft.new(client) }
8
8
 
9
- its(:client) { should eq client }
10
-
11
9
  describe "#create" do
12
10
  let(:formatted_request_body) { double('formatted request body') }
13
11
  let(:draft_parameters) { double('draft parameters') }
14
12
 
15
13
  before do
16
- ud_proxy.draft_parameters = draft_parameters
14
+ HelloSign::Parameters::UnclaimedDraft.stub(:new).and_return(draft_parameters)
17
15
  draft_parameters.stub(:formatted).and_return(formatted_request_body)
18
16
  draft_parameters.should_receive(:foo=).with('bar')
19
- client.should_receive(:post)
20
- .with('/unclaimed_draft/create', body: formatted_request_body)
21
- .and_return(api_response)
17
+ client.should_receive(:post).with('/unclaimed_draft/create', body: formatted_request_body).and_return(api_response)
22
18
  end
23
19
 
24
20
  it "sends a unclaimed draft creation request and returns the result" do
@@ -1,60 +1,57 @@
1
1
  require 'helper'
2
- require 'hello_sign/upload_io'
2
+ require 'hello_sign/file'
3
3
 
4
- describe HelloSign::UploadIO do
5
- let(:upload_file) { double('upload file') }
6
- let(:io_object) { double('IO object') }
7
- let(:file_converter_source) { double('file converter source') }
4
+ describe HelloSign::File do
5
+ let(:attachment) { double('attachment') }
6
+ let(:io_object) { double('IO object') }
8
7
 
9
- before { HelloSign::UploadIO.any_instance.stub(:file_converter_source).and_return(file_converter_source) }
8
+ it "returns the attachment" do
9
+ Faraday::UploadIO.stub(:new).and_return(attachment)
10
10
 
11
- it "returns the upload file" do
12
- file_converter_source.stub(:new).and_return(upload_file)
13
-
14
- expect(HelloSign::UploadIO.new(filename: 'test.txt').upload).to eq upload_file
11
+ expect(HelloSign::File.new(filename: 'test.txt').attachment).to eq attachment
15
12
  end
16
13
 
17
14
  context "#upload" do
18
15
  specify do
19
- file_converter_source.should_receive(:new).with('test.txt', 'text/plain')
16
+ Faraday::UploadIO.should_receive(:new).with('test.txt', 'text/plain')
20
17
 
21
- HelloSign::UploadIO.new(filename: 'test.txt').upload
18
+ HelloSign::File.new(filename: 'test.txt').attachment
22
19
  end
23
20
 
24
21
  specify do
25
- file_converter_source.should_receive(:new).with('test.foo', 'text/plain')
22
+ Faraday::UploadIO.should_receive(:new).with('test.foo', 'text/plain')
26
23
 
27
- HelloSign::UploadIO.new(filename: 'test.foo').upload
24
+ HelloSign::File.new(filename: 'test.foo').attachment
28
25
  end
29
26
 
30
27
  specify do
31
- file_converter_source.should_receive(:new).with('test.baz', 'fake/mime')
28
+ Faraday::UploadIO.should_receive(:new).with('test.baz', 'fake/mime')
32
29
 
33
- HelloSign::UploadIO.new(filename: 'test.baz', mime: 'fake/mime').upload
30
+ HelloSign::File.new(filename: 'test.baz', mime: 'fake/mime').attachment
34
31
  end
35
32
 
36
33
  specify do
37
- file_converter_source.should_receive(:new).with(io_object, 'text/plain')
34
+ Faraday::UploadIO.should_receive(:new).with(io_object, 'text/plain')
38
35
 
39
- HelloSign::UploadIO.new(io: io_object).upload
36
+ HelloSign::File.new(io: io_object).attachment
40
37
  end
41
38
 
42
39
  specify do
43
- file_converter_source.should_receive(:new).with(io_object, 'fake/mime')
40
+ Faraday::UploadIO.should_receive(:new).with(io_object, 'fake/mime')
44
41
 
45
- HelloSign::UploadIO.new(io: io_object, mime: 'fake/mime').upload
42
+ HelloSign::File.new(io: io_object, mime: 'fake/mime').attachment
46
43
  end
47
44
 
48
45
  specify do
49
- file_converter_source.should_receive(:new).with(io_object, 'fake/mime', 'test.foo')
46
+ Faraday::UploadIO.should_receive(:new).with(io_object, 'fake/mime', 'test.foo')
50
47
 
51
- HelloSign::UploadIO.new(filename: 'test.foo', io: io_object, mime: 'fake/mime').upload
48
+ HelloSign::File.new(filename: 'test.foo', io: io_object, mime: 'fake/mime').attachment
52
49
  end
53
50
 
54
51
  specify do
55
- file_converter_source.should_receive(:new).with(io_object, 'text/plain', 'test.foo')
52
+ Faraday::UploadIO.should_receive(:new).with(io_object, 'text/plain', 'test.foo')
56
53
 
57
- HelloSign::UploadIO.new(filename: 'test.foo', io: io_object).upload
54
+ HelloSign::File.new(filename: 'test.foo', io: io_object).attachment
58
55
  end
59
56
  end
60
57
  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: 1.0.0
4
+ version: 1.0.1
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-03-17 00:00:00.000000000 Z
12
+ date: 2013-03-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -107,7 +107,7 @@ dependencies:
107
107
  - - ~>
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0.6'
110
- description: A Ruby interface to the HelloSign API.
110
+ description: A Ruby interface to the HelloSign API
111
111
  email:
112
112
  - craiglttl@gmail.com
113
113
  executables: []
@@ -116,6 +116,8 @@ extra_rdoc_files: []
116
116
  files:
117
117
  - lib/hello_sign/client.rb
118
118
  - lib/hello_sign/error.rb
119
+ - lib/hello_sign/file/mime_types.rb
120
+ - lib/hello_sign/file.rb
119
121
  - lib/hello_sign/middleware/raise_error.rb
120
122
  - lib/hello_sign/parameters/reusable_form_signature_request.rb
121
123
  - lib/hello_sign/parameters/signature_request.rb
@@ -127,7 +129,6 @@ files:
127
129
  - lib/hello_sign/proxy/team.rb
128
130
  - lib/hello_sign/proxy/unclaimed_draft.rb
129
131
  - lib/hello_sign/proxy.rb
130
- - lib/hello_sign/upload_io.rb
131
132
  - lib/hello_sign/version.rb
132
133
  - lib/hello_sign.rb
133
134
  - spec/fixtures/test.jpg
@@ -178,10 +179,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
179
  version: '0'
179
180
  requirements: []
180
181
  rubyforge_project:
181
- rubygems_version: 1.8.25
182
+ rubygems_version: 1.8.23
182
183
  signing_key:
183
184
  specification_version: 3
184
- summary: A Ruby interface to the HelloSign API.
185
+ summary: A Ruby interface to the HelloSign API
185
186
  test_files:
186
187
  - spec/fixtures/test.jpg
187
188
  - spec/fixtures/test.pdf