vaulted_billing 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,16 @@ require 'uri'
4
4
  module VaultedBilling
5
5
  module HttpsInterface
6
6
 
7
+ HTTP_ERRORS = [
8
+ Timeout::Error,
9
+ Errno::EINVAL,
10
+ Errno::ECONNRESET,
11
+ EOFError,
12
+ Net::HTTPBadResponse,
13
+ Net::HTTPHeaderSyntaxError,
14
+ Net::ProtocolError
15
+ ] unless defined?(HTTP_ERRORS)
16
+
7
17
  class PostResponse
8
18
  attr_accessor :code
9
19
  attr_accessor :message
@@ -12,11 +22,13 @@ module VaultedBilling
12
22
  attr_accessor :raw_response
13
23
 
14
24
  def initialize(http_response)
15
- self.raw_response = http_response
16
- self.code = http_response.code
17
- self.message = http_response.message
18
- self.body = http_response.body
19
- self.success = ((http_response.code =~ /^2\d{2}/) == 0)
25
+ if http_response
26
+ self.raw_response = http_response
27
+ # self.code = http_response.code
28
+ # self.message = http_response.message
29
+ self.body = http_response.body
30
+ self.success = ((http_response.code =~ /^2\d{2}/) == 0)
31
+ end
20
32
  end
21
33
 
22
34
  alias :success? :success
@@ -62,9 +74,17 @@ module VaultedBilling
62
74
  end
63
75
 
64
76
  before_post(data)
65
- response = response.request(request)
66
- PostResponse.new(response).tap do |post_response|
67
- after_post(post_response)
77
+
78
+ begin
79
+ PostResponse.new(response.request(request)).tap do |post_response|
80
+ after_post(post_response)
81
+ end
82
+ rescue *HTTP_ERRORS
83
+ PostResponse.new(nil).tap do |post_response|
84
+ post_response.success = false
85
+ post_response.message = "%s - %s" % [$!.class.name, $!.message]
86
+ after_post(post_response)
87
+ end
68
88
  end
69
89
  end
70
90
  protected :post_data
@@ -1,3 +1,3 @@
1
1
  module VaultedBilling
2
- Version = '0.0.0'
2
+ Version = '0.0.1'
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 0
9
- version: 0.0.0
8
+ - 1
9
+ version: 0.0.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Nathaniel Bibler