invoiced 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +2 -3
- data/Gemfile +1 -1
- data/README.md +1 -1
- data/invoiced.gemspec +1 -1
- data/lib/invoiced/version.rb +1 -1
- data/lib/invoiced.rb +24 -6
- data/test/invoiced/invoiced_test.rb +41 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ac4d832ff168090c18ef76f0454c0f74917cca4
|
4
|
+
data.tar.gz: e4a6826d457f078a188fdd0628c37db49cef27dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06dbb02d3ea0e8fcfe8cf8fecc8fac3ac7c9baac4a084de8bf21a87d63b47282a4fdebac85393e840d14c65408e04ddd5595d7659db552b974916ddcd1dac5e6
|
7
|
+
data.tar.gz: 0549855a16c9189e7bd44d4a1e604c93f8713708ca43a175cd1cea85920d78ebbb913af16093d402cc82f6a56d2e5ce904d619c6e644ff280e1aee9d1b87064a
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -2,7 +2,7 @@ source "https://rubygems.org"
|
|
2
2
|
gemspec
|
3
3
|
|
4
4
|
gem 'json', '~> 1.8.3'
|
5
|
-
gem 'rest-client', '~>
|
5
|
+
gem 'rest-client', '~> 2.0.0'
|
6
6
|
gem 'activesupport', '~> 4.2.3'
|
7
7
|
gem 'coveralls', :require => false, :group => :test
|
8
8
|
gem 'simplecov', '~> 0.10.0', :require => false, :group => :test
|
data/README.md
CHANGED
data/invoiced.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.homepage = 'https://invoiced.com/docs/dev'
|
15
15
|
s.required_ruby_version = '>= 1.9.3'
|
16
16
|
|
17
|
-
s.add_dependency('rest-client', '~>
|
17
|
+
s.add_dependency('rest-client', '~> 2.0.0')
|
18
18
|
s.add_dependency('json', '~> 1.8.3')
|
19
19
|
s.add_dependency('activesupport', '~> 4.2.3')
|
20
20
|
|
data/lib/invoiced/version.rb
CHANGED
data/lib/invoiced.rb
CHANGED
@@ -38,6 +38,9 @@ module Invoiced
|
|
38
38
|
ApiBase = 'https://api.invoiced.com'
|
39
39
|
ApiBaseSandbox = 'https://api.sandbox.invoiced.com'
|
40
40
|
|
41
|
+
OpenTimeout = 30
|
42
|
+
ReadTimeout = 80
|
43
|
+
|
41
44
|
attr_reader :api_key, :api_url, :sandbox
|
42
45
|
attr_reader :CatalogItem, :CreditNote, :Customer, :Estimate, :Event, :File, :Invoice, :Plan, :Subscription, :Transaction
|
43
46
|
|
@@ -82,13 +85,15 @@ module Invoiced
|
|
82
85
|
:content_type => "application/json",
|
83
86
|
:user_agent => "Invoiced Ruby/#{Invoiced::VERSION}"
|
84
87
|
},
|
85
|
-
:payload => payload
|
88
|
+
:payload => payload,
|
89
|
+
:open_timeout => OpenTimeout,
|
90
|
+
:timeout => ReadTimeout
|
86
91
|
)
|
87
92
|
rescue RestClient::Exception => e
|
88
93
|
if e.response
|
89
|
-
|
94
|
+
handle_api_error(e.response)
|
90
95
|
else
|
91
|
-
|
96
|
+
handle_network_error(e)
|
92
97
|
end
|
93
98
|
end
|
94
99
|
|
@@ -111,7 +116,7 @@ module Invoiced
|
|
111
116
|
}
|
112
117
|
end
|
113
118
|
|
114
|
-
def
|
119
|
+
def handle_api_error(response)
|
115
120
|
begin
|
116
121
|
error = JSON.parse(response.body)
|
117
122
|
rescue JSON::ParserError
|
@@ -128,8 +133,21 @@ module Invoiced
|
|
128
133
|
end
|
129
134
|
end
|
130
135
|
|
131
|
-
def
|
132
|
-
|
136
|
+
def handle_network_error(error)
|
137
|
+
case error
|
138
|
+
when RestClient::Exceptions::OpenTimeout
|
139
|
+
message = "Timeed out while connecting to Invoiced. Please check your internet connection or status.invoiced.com for service outages."
|
140
|
+
when RestClient::Exceptions::ReadTimeout
|
141
|
+
message = "The request timed out reading data from the server."
|
142
|
+
when RestClient::ServerBrokeConnection
|
143
|
+
message = "Connection with the server was broken while receiving the response."
|
144
|
+
when RestClient::SSLCertificateNotVerified
|
145
|
+
message = "Failed to verify the Invoiced SSL certificate. Please verify that you have a recent version of OpenSSL installed."
|
146
|
+
else
|
147
|
+
message = "There was an error connecting to Invoiced: #{error.message}"
|
148
|
+
end
|
149
|
+
|
150
|
+
raise ApiConnectionError.new(message)
|
133
151
|
end
|
134
152
|
|
135
153
|
def authentication_error(error, response)
|
@@ -93,7 +93,7 @@ module Invoiced
|
|
93
93
|
assert_equal(expectedResponse, response)
|
94
94
|
end
|
95
95
|
|
96
|
-
should "handle a
|
96
|
+
should "handle a generic network error" do
|
97
97
|
RestClient::Request.any_instance.expects(:execute).raises(RestClient::Exception.new)
|
98
98
|
|
99
99
|
client = Invoiced::Client.new('test')
|
@@ -103,6 +103,46 @@ module Invoiced
|
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
106
|
+
should "handle an invalid SSL certificate" do
|
107
|
+
RestClient::Request.any_instance.expects(:execute).raises(RestClient::SSLCertificateNotVerified.new('invalid ssl cert'))
|
108
|
+
|
109
|
+
client = Invoiced::Client.new('test')
|
110
|
+
|
111
|
+
assert_raise Invoiced::ApiConnectionError do
|
112
|
+
client.request("POST", "/invoices")
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
should "handle a connection timeout" do
|
117
|
+
RestClient::Request.any_instance.expects(:execute).raises(RestClient::Exceptions::OpenTimeout.new)
|
118
|
+
|
119
|
+
client = Invoiced::Client.new('test')
|
120
|
+
|
121
|
+
assert_raise Invoiced::ApiConnectionError do
|
122
|
+
client.request("POST", "/invoices")
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
should "handle a read timeout" do
|
127
|
+
RestClient::Request.any_instance.expects(:execute).raises(RestClient::Exceptions::ReadTimeout.new)
|
128
|
+
|
129
|
+
client = Invoiced::Client.new('test')
|
130
|
+
|
131
|
+
assert_raise Invoiced::ApiConnectionError do
|
132
|
+
client.request("POST", "/invoices")
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
should "handle an unfinished request" do
|
137
|
+
RestClient::Request.any_instance.expects(:execute).raises(RestClient::ServerBrokeConnection.new)
|
138
|
+
|
139
|
+
client = Invoiced::Client.new('test')
|
140
|
+
|
141
|
+
assert_raise Invoiced::ApiConnectionError do
|
142
|
+
client.request("POST", "/invoices")
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
106
146
|
should "handle an invalid request error" do
|
107
147
|
mockResponse = mock('RestClient::Response')
|
108
148
|
mockResponse.stubs(:code).returns(400)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: invoiced
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jared King
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: json
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|