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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 110fedfb4c7cae791aba433214d0f8d5ce08c322
4
- data.tar.gz: fc4acd0b415091216c3d83291cbea330cc5f7619
3
+ metadata.gz: 2ac4d832ff168090c18ef76f0454c0f74917cca4
4
+ data.tar.gz: e4a6826d457f078a188fdd0628c37db49cef27dc
5
5
  SHA512:
6
- metadata.gz: ec0bb6d4d38e029afd787bd7e115d27e1c486d1fa13ae4af5f8ee0ff8e87e96fbc9b58bae272decb58c27a9638b88015513ae0a832137be7be3b791fac625a9d
7
- data.tar.gz: d6ad87477c2c50e44a9df3b7ae3417729d8da78832b97e6d20815d98b9583bacadda9e7cbd694994cbe569762290711c537ac6d7e9f09797989d852e5d0682af
6
+ metadata.gz: 06dbb02d3ea0e8fcfe8cf8fecc8fac3ac7c9baac4a084de8bf21a87d63b47282a4fdebac85393e840d14c65408e04ddd5595d7659db552b974916ddcd1dac5e6
7
+ data.tar.gz: 0549855a16c9189e7bd44d4a1e604c93f8713708ca43a175cd1cea85920d78ebbb913af16093d402cc82f6a56d2e5ce904d619c6e644ff280e1aee9d1b87064a
data/.travis.yml CHANGED
@@ -1,10 +1,9 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 1.9.3
5
- - 2.0.0
4
+ - 2.0
6
5
  - 2.1
7
- - 2.2
6
+ - 2.2
8
7
 
9
8
  sudo: false
10
9
 
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', '~> 1.8.0'
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
@@ -24,7 +24,7 @@ gem 'invoiced'
24
24
 
25
25
  ## Requirements
26
26
 
27
- - Ruby 1.9.3+
27
+ - Ruby 2.0+
28
28
  - rest_client, json, and active_support gems
29
29
 
30
30
  ## Usage
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', '~> 1.8.0')
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
 
@@ -1,3 +1,3 @@
1
1
  module Invoiced
2
- VERSION = '0.10.0'
2
+ VERSION = '0.11.0'
3
3
  end
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
- rescue_api_error(e.response)
94
+ handle_api_error(e.response)
90
95
  else
91
- rescue_rest_client_error(e)
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 rescue_api_error(response)
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 rescue_rest_client_error(error)
132
- raise ApiConnectionError.new("There was an error connecting to Invoiced.")
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 request exception" do
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.10.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-05-17 00:00:00.000000000 Z
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: 1.8.0
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: 1.8.0
26
+ version: 2.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: json
29
29
  requirement: !ruby/object:Gem::Requirement