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
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
66
|
-
|
67
|
-
|
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
|