hello_sign 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,12 @@
1
+ require 'hello_sign/version'
1
2
  require 'hello_sign/response'
2
3
  require 'faraday'
3
4
  require 'faraday_middleware'
4
5
 
5
6
  module HelloSign
6
7
  class Connection
7
- API_ENDPOINT = 'https://api.hellosign.com'
8
- API_VERSION = '3'
8
+ API_ENDPOINT = 'https://api.hellosign.com'.freeze
9
+ API_VERSION = '3'.freeze
9
10
 
10
11
  attr_reader :auth_configuration
11
12
 
@@ -2,6 +2,31 @@ module HelloSign
2
2
  class Error < StandardError
3
3
  attr_reader :message, :status_code
4
4
 
5
+ def self.from_error_name(error_name)
6
+ case error_name
7
+ when 'bad_request'
8
+ BadRequest
9
+ when 'unauthorized'
10
+ Unauthorized
11
+ when 'forbidden'
12
+ Forbidden
13
+ when 'not_found'
14
+ NotFound
15
+ when 'unknown'
16
+ Unknown
17
+ when 'team_invite_failed'
18
+ TeamInviteFailed
19
+ when 'invalid_recipient'
20
+ InvalidRecipient
21
+ when 'convert_failed'
22
+ ConvertFailed
23
+ when 'signature_request_cancel_failed'
24
+ SignatureRequestCancelFailed
25
+ else
26
+ Error
27
+ end
28
+ end
29
+
5
30
  def initialize(message = nil, status_code = nil)
6
31
  @message, @status_code = message, status_code
7
32
  end
@@ -1,46 +1,19 @@
1
- require 'hello_sign/error'
2
-
3
1
  require 'faraday'
2
+ require 'hello_sign/error'
4
3
 
5
4
  module HelloSign
6
5
  module Middleware
7
6
  class RaiseError < Faraday::Response::Middleware
8
7
 
9
8
  def on_complete(env)
10
- body = env[:body] or return
11
-
12
- return unless body.is_a?(Hash)
9
+ body = env[:body] and body.is_a?(Hash) or return
13
10
 
14
11
  error = body[:error] and begin
15
- exception = begin
16
- case error[:error_name]
17
- when 'bad_request'
18
- HelloSign::Error::BadRequest
19
- when 'unauthorized'
20
- HelloSign::Error::Unauthorized
21
- when 'forbidden'
22
- HelloSign::Error::Forbidden
23
- when 'not_found'
24
- HelloSign::Error::NotFound
25
- when 'unknown'
26
- HelloSign::Error::Unknown
27
- when 'team_invite_failed'
28
- HelloSign::Error::TeamInviteFailed
29
- when 'invalid_recipient'
30
- HelloSign::Error::InvalidRecipient
31
- when 'convert_failed'
32
- HelloSign::Error::ConvertFailed
33
- when 'signature_request_cancel_failed'
34
- HelloSign::Error::SignatureRequestCancelFailed
35
- else
36
- HelloSign::Error
37
- end
38
- end
39
-
12
+ exception = Error.from_error_name(error[:error_name])
40
13
  message = error[:error_msg]
41
14
  status_code = env[:response][:status]
42
15
 
43
- raise exception.new(message, status_code)
16
+ fail exception.new(message, status_code)
44
17
  end
45
18
  end
46
19
 
@@ -1,14 +1,18 @@
1
1
  module HelloSign
2
2
  module Parameters
3
3
  class ReusableFormSignatureRequest
4
- attr_accessor :reusable_form_id, :title, :subject, :message, :test_mode
5
- private :reusable_form_id, :title, :subject, :message, :test_mode
4
+ attr_accessor :test_mode, :reusable_form_id, :title, :subject, :message
5
+ private :test_mode, :reusable_form_id, :title, :subject, :message
6
6
 
7
7
  attr_writer :ccs, :signers, :custom_fields
8
8
 
9
+ def initialize
10
+ @test_mode, @ccs, @signers, @custom_fields = 0, nil, nil, nil
11
+ end
12
+
9
13
  def formatted
10
14
  {
11
- test_mode: test_mode || 0,
15
+ test_mode: test_mode,
12
16
  reusable_form_id: reusable_form_id,
13
17
  title: title,
14
18
  subject: subject,
@@ -7,7 +7,11 @@ module HelloSign
7
7
  attr_accessor :title, :subject, :message, :ccs, :test_mode
8
8
  private :title, :subject, :message, :ccs, :test_mode
9
9
 
10
- attr_writer :signers, :files, :form_fields_per_document, :test_mode
10
+ attr_writer :signers, :files, :form_fields_per_document
11
+
12
+ def initialize
13
+ @signers, @files, @form_fields_per_document = nil, nil, nil
14
+ end
11
15
 
12
16
  def formatted
13
17
  {
@@ -24,11 +24,11 @@ module HelloSign
24
24
  end
25
25
 
26
26
  def add_member(params = {})
27
- client.post("/team/add_member", body: params)
27
+ client.post('/team/add_member', body: params)
28
28
  end
29
29
 
30
30
  def remove_member(params = {})
31
- client.post("/team/remove_member", body: params)
31
+ client.post('/team/remove_member', body: params)
32
32
  end
33
33
 
34
34
  end
@@ -1,3 +1,3 @@
1
1
  module HelloSign
2
- VERSION = '1.3.0'
2
+ VERSION = '1.3.1'
3
3
  end
@@ -51,10 +51,6 @@ describe HelloSign::Client do
51
51
  end
52
52
 
53
53
  context "when a hash is passed to the constructor" do
54
- subject(:hs_client) do
55
- HelloSign::Client.new(email_address: email_address, password: password)
56
- end
57
-
58
54
  it "raises an exception if an email address is not provided" do
59
55
  expect { HelloSign::Client.new(password: 'space') }.to(
60
56
  raise_error ArgumentError
@@ -2,6 +2,39 @@ require 'helper'
2
2
  require 'hello_sign/error'
3
3
 
4
4
  describe HelloSign::Error do
5
+ describe ".from_error_name" do
6
+ %w(
7
+ bad_request
8
+ unauthorized
9
+ forbidden
10
+ not_found
11
+ unknown
12
+ team_invite_failed
13
+ invalid_recipient
14
+ convert_failed
15
+ signature_request_cancel_failed
16
+ ).each do |error_name|
17
+ context "when the error name is #{error_name}" do
18
+ it "returns the proper exception" do
19
+ expect(HelloSign::Error.from_error_name(error_name)).to(
20
+ be(
21
+ HelloSign::Error.const_get(
22
+ error_name.split('_').map(&:capitalize).join
23
+ )
24
+ )
25
+ )
26
+ end
27
+ end
28
+ end
29
+
30
+ context "when the error name is unknown" do
31
+ it "returns a generic exception" do
32
+ expect(HelloSign::Error.from_error_name('no_such_error'))
33
+ .to be HelloSign::Error
34
+ end
35
+ end
36
+ end
37
+
5
38
  specify do
6
39
  expect { raise HelloSign::Error }.to(
7
40
  raise_error StandardError
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.3.0
4
+ version: 1.3.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-10-11 00:00:00.000000000 Z
12
+ date: 2014-01-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -182,15 +182,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
182
182
  - - ! '>='
183
183
  - !ruby/object:Gem::Version
184
184
  version: '0'
185
+ segments:
186
+ - 0
187
+ hash: 772753378671627303
185
188
  required_rubygems_version: !ruby/object:Gem::Requirement
186
189
  none: false
187
190
  requirements:
188
191
  - - ! '>='
189
192
  - !ruby/object:Gem::Version
190
193
  version: '0'
194
+ segments:
195
+ - 0
196
+ hash: 772753378671627303
191
197
  requirements: []
192
198
  rubyforge_project:
193
- rubygems_version: 1.8.25
199
+ rubygems_version: 1.8.23
194
200
  signing_key:
195
201
  specification_version: 3
196
202
  summary: A Ruby interface to the HelloSign API
@@ -224,4 +230,3 @@ test_files:
224
230
  - spec/unit/proxy/team_spec.rb
225
231
  - spec/unit/proxy/unclaimed_draft_spec.rb
226
232
  - spec/unit/upload_io_spec.rb
227
- has_rdoc: