hello_sign 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -36,10 +36,11 @@ module HelloSign
36
36
 
37
37
  def unauth_connection(&auth)
38
38
  Faraday.new(:url => API_ENDPOINT) do |faraday|
39
+ auth.call(faraday) if block_given?
40
+ faraday.request :multipart
39
41
  faraday.request :url_encoded
40
42
  faraday.response :logger
41
43
  faraday.response :multi_json, :symbolize_keys => true
42
- auth.call(faraday) if block_given?
43
44
  faraday.adapter Faraday.default_adapter
44
45
  end
45
46
  end
@@ -0,0 +1,45 @@
1
+ require 'faraday/upload_io'
2
+
3
+ module HelloSign
4
+ class SignatureRequestParameters
5
+ attr_accessor :title, :subject, :message, :ccs
6
+ attr_writer :signers, :files
7
+
8
+ def signers
9
+ @signers.each_with_index.inject({}) do |parameter, (signer, index)|
10
+ signer = {
11
+ :name => signer[:name],
12
+ :email_address => signer[:email],
13
+ :order => index
14
+ }
15
+ parameter[index] = signer
16
+ parameter
17
+ end
18
+ end
19
+
20
+ def files
21
+ @files.each_with_index.inject({}) do |parameter, (file, index)|
22
+ parameter[index + 1] = upload_io.new(file[:io], file[:mime], file[:name])
23
+ parameter
24
+ end
25
+ end
26
+
27
+ def formatted
28
+ {
29
+ :title => title,
30
+ :subject => subject,
31
+ :message => message,
32
+ :cc_email_addresses => ccs,
33
+ :signers => signers,
34
+ :file => files
35
+ }
36
+ end
37
+
38
+ private
39
+
40
+ def upload_io
41
+ Faraday::UploadIO
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,17 @@
1
+ require 'hello_sign/signature_request_parameters'
2
+
3
+ module HelloSign
4
+ class SignatureRequestProxy
5
+ attr_reader :client
6
+
7
+ def initialize(client)
8
+ @client = client
9
+ end
10
+
11
+ def create(raw_parameters)
12
+ raw_parameters.call(request_parameters = SignatureRequestParameters.new)
13
+ client.post('/signature_request/send', :body => request_parameters.formatted)
14
+ end
15
+
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module HelloSign
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
data/lib/hello_sign.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'hello_sign/version'
2
2
  require 'hello_sign/client'
3
3
  require 'hello_sign/account_proxy'
4
+ require 'hello_sign/signature_request_proxy'
4
5
 
5
6
  module HelloSign
6
7
  class << self
@@ -10,6 +11,10 @@ module HelloSign
10
11
  AccountProxy.new(client)
11
12
  end
12
13
 
14
+ def signature_request(&parameters)
15
+ SignatureRequestProxy.new(client).create(parameters)
16
+ end
17
+
13
18
  def client
14
19
  @client ||= Client.new(email, password)
15
20
  end
Binary file
Binary file
@@ -0,0 +1 @@
1
+ This is a test upload file.
@@ -1,5 +1,6 @@
1
1
  require 'integration/helper'
2
2
 
3
+
3
4
  describe HelloSign do
4
5
  context "when creating an account" do
5
6
  before do
@@ -0,0 +1,32 @@
1
+ require 'integration/helper'
2
+
3
+ describe HelloSign do
4
+ context "when sending a signature request" do
5
+ let(:text_file_io) { File.new('spec/fixtures/test.txt') }
6
+ let(:image_io) { File.new('spec/fixtures/test.jpg') }
7
+
8
+ before do
9
+ stub_post_with_auth('/signature_request/send')
10
+ request = HelloSign.signature_request do |request|
11
+ request.title = 'Lease'
12
+ request.subject = 'Sign this'
13
+ request.message = 'You must sign this.'
14
+ request.ccs = ['lawyer@lawfirm.com', 'spouse@family.com']
15
+ request.signers = [
16
+ {:name => 'Jack', :email => 'jack@hill.com'},
17
+ {:name => 'Jill', :email => 'jill@hill.com'}
18
+ ]
19
+ request.files = [
20
+ {:name => 'test.txt', :io => text_file_io, :mime => 'text/plain'},
21
+ {:name => 'test.jpg', :io => image_io, :mime => 'image/jpeg'}
22
+ ]
23
+ end
24
+ end
25
+
26
+ it "sends a signature request to the HelloSign API" do
27
+ expect(a_post_with_auth('/signature_request/send')
28
+ .with(:headers => {'Content-Type' => /multipart\/form-data/}, :body => /This is a test upload file\./)
29
+ ).to have_been_made
30
+ end
31
+ end
32
+ end
@@ -8,6 +8,19 @@ describe HelloSign do
8
8
  end
9
9
  end
10
10
 
11
+ describe "::signature_request" do
12
+ let(:sr_proxy) { double('signature_request_proxy') }
13
+
14
+ before do
15
+ HelloSign::SignatureRequestProxy.stub(:new).and_return(sr_proxy)
16
+ sr_proxy.should_receive(:create).and_return(@request_result = stub)
17
+ end
18
+
19
+ it "calls #create on the signature request proxy and returns the result" do
20
+ expect(HelloSign.signature_request).to eq @request_result
21
+ end
22
+ end
23
+
11
24
  describe "::client" do
12
25
  context "when it has not previously been called" do
13
26
  it "returns a new client" do
@@ -0,0 +1,42 @@
1
+ require 'helper'
2
+ require 'hello_sign/signature_request_parameters'
3
+
4
+ describe HelloSign::SignatureRequestParameters do
5
+ describe "#formatted" do
6
+ before do
7
+ Faraday::UploadIO.should_receive(:new).with('text file IO object', 'text/plain', 'test.txt').and_return(text_file = stub)
8
+ Faraday::UploadIO.should_receive(:new).with('image file IO object', 'image/jpeg', 'test.jpg').and_return(image_file = stub)
9
+
10
+ @request_parameters = HelloSign::SignatureRequestParameters.new
11
+
12
+ @request_parameters.title = 'Lease'
13
+ @request_parameters.subject = 'Sign this'
14
+ @request_parameters.message = 'You must sign this.'
15
+ @request_parameters.ccs = ['lawyer@lawfirm.com', 'spouse@family.com']
16
+ @request_parameters.signers = [
17
+ {:name => 'Jack', :email => 'jack@hill.com'},
18
+ {:name => 'Jill', :email => 'jill@hill.com'}
19
+ ]
20
+ @request_parameters.files = [
21
+ {:name => 'test.txt', :io => 'text file IO object', :mime => 'text/plain'},
22
+ {:name => 'test.jpg', :io => 'image file IO object', :mime => 'image/jpeg'}
23
+ ]
24
+
25
+ @expected = {
26
+ :title => 'Lease',
27
+ :subject =>'Sign this',
28
+ :message =>'You must sign this.',
29
+ :cc_email_addresses => ['lawyer@lawfirm.com', 'spouse@family.com'],
30
+ :signers => {
31
+ 0 => {:name => 'Jack', :email_address => 'jack@hill.com', :order => 0},
32
+ 1 => {:name => 'Jill', :email_address => 'jill@hill.com', :order => 1}
33
+ },
34
+ :file => {1 => text_file, 2 => image_file}
35
+ }
36
+ end
37
+
38
+ it "returns formatted parameters" do
39
+ expect(@request_parameters.formatted).to eq @expected
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,32 @@
1
+ require 'helper'
2
+ require 'hello_sign/signature_request_proxy'
3
+
4
+ describe HelloSign::SignatureRequestProxy do
5
+ let(:client) { double('client') }
6
+ subject(:sr_proxy) { HelloSign::SignatureRequestProxy.new(client) }
7
+
8
+ describe "#client" do
9
+ it "returns the client" do
10
+ expect(sr_proxy.client).to be client
11
+ end
12
+ end
13
+
14
+ describe "#create" do
15
+ let(:formatted_request_body) { stub }
16
+ let(:create_response) { stub }
17
+ let(:raw_parameters) { Proc.new { |params| params.foo = 'bar' } }
18
+
19
+ before do
20
+ HelloSign::SignatureRequestParameters.stub(:new).and_return(request_parameters = mock)
21
+ request_parameters.stub(:formatted).and_return(formatted_request_body)
22
+ request_parameters.should_receive(:foo=).with('bar')
23
+ client.should_receive(:post)
24
+ .with('/signature_request/send', :body => formatted_request_body)
25
+ .and_return(create_response)
26
+ end
27
+
28
+ it "sends a signature request creation request and returns the result" do
29
+ expect(sr_proxy.create(raw_parameters)).to eq create_response
30
+ end
31
+ end
32
+ 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.3
4
+ version: 0.0.4
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-20 00:00:00.000000000 Z
12
+ date: 2013-01-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -85,16 +85,24 @@ files:
85
85
  - lib/hello_sign/account_proxy.rb
86
86
  - lib/hello_sign/client.rb
87
87
  - lib/hello_sign/settings.rb
88
+ - lib/hello_sign/signature_request_parameters.rb
89
+ - lib/hello_sign/signature_request_proxy.rb
88
90
  - lib/hello_sign/version.rb
89
91
  - lib/hello_sign.rb
92
+ - spec/fixtures/test.jpg
93
+ - spec/fixtures/test.pdf
94
+ - spec/fixtures/test.txt
90
95
  - spec/helper.rb
91
96
  - spec/integration/account_spec.rb
92
97
  - spec/integration/hello_sign_spec.rb
93
98
  - spec/integration/helper.rb
99
+ - spec/integration/signature_request_spec.rb
94
100
  - spec/unit/account_proxy_spec.rb
95
101
  - spec/unit/client_spec.rb
96
102
  - spec/unit/hello_sign_spec.rb
97
103
  - spec/unit/settings_spec.rb
104
+ - spec/unit/signature_request_parameters_spec.rb
105
+ - spec/unit/signature_request_proxy_spec.rb
98
106
  homepage: http://www.github.com/craiglittle/hello_sign
99
107
  licenses: []
100
108
  post_install_message:
@@ -120,11 +128,17 @@ signing_key:
120
128
  specification_version: 3
121
129
  summary: A Ruby interface to the HelloSign API.
122
130
  test_files:
131
+ - spec/fixtures/test.jpg
132
+ - spec/fixtures/test.pdf
133
+ - spec/fixtures/test.txt
123
134
  - spec/helper.rb
124
135
  - spec/integration/account_spec.rb
125
136
  - spec/integration/hello_sign_spec.rb
126
137
  - spec/integration/helper.rb
138
+ - spec/integration/signature_request_spec.rb
127
139
  - spec/unit/account_proxy_spec.rb
128
140
  - spec/unit/client_spec.rb
129
141
  - spec/unit/hello_sign_spec.rb
130
142
  - spec/unit/settings_spec.rb
143
+ - spec/unit/signature_request_parameters_spec.rb
144
+ - spec/unit/signature_request_proxy_spec.rb