killbill-client 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Gemfile +3 -0
- data/README.md +18 -0
- data/Rakefile +26 -0
- data/killbill_client.gemspec +44 -0
- data/lib/killbill_client.rb +93 -0
- data/lib/killbill_client/api/api.rb +85 -0
- data/lib/killbill_client/api/errors.rb +175 -0
- data/lib/killbill_client/api/net_http_adapter.rb +131 -0
- data/lib/killbill_client/models/account.rb +36 -0
- data/lib/killbill_client/models/gen/account_attributes.rb +51 -0
- data/lib/killbill_client/models/gen/account_attributes_simple.rb +33 -0
- data/lib/killbill_client/models/gen/account_attributes_with_balance.rb +52 -0
- data/lib/killbill_client/models/gen/account_attributes_with_balance_and_c_b_a.rb +53 -0
- data/lib/killbill_client/models/gen/account_email_attributes.rb +33 -0
- data/lib/killbill_client/models/gen/account_timeline_attributes.rb +35 -0
- data/lib/killbill_client/models/gen/analytics_sanity_attributes.rb +36 -0
- data/lib/killbill_client/models/gen/audit_log_attributes.rb +37 -0
- data/lib/killbill_client/models/gen/bundle_attributes_no_subscriptions.rb +36 -0
- data/lib/killbill_client/models/gen/bundle_attributes_simple.rb +34 -0
- data/lib/killbill_client/models/gen/bundle_attributes_with_subscriptions.rb +35 -0
- data/lib/killbill_client/models/gen/bundle_timeline_attributes.rb +36 -0
- data/lib/killbill_client/models/gen/business_account_attributes.rb +41 -0
- data/lib/killbill_client/models/gen/business_field_attributes.rb +35 -0
- data/lib/killbill_client/models/gen/business_invoice_attributes.rb +43 -0
- data/lib/killbill_client/models/gen/business_invoice_item_attributes.rb +46 -0
- data/lib/killbill_client/models/gen/business_invoice_payment_attributes.rb +50 -0
- data/lib/killbill_client/models/gen/business_overdue_status_attributes.rb +37 -0
- data/lib/killbill_client/models/gen/business_snapshot_attributes.rb +38 -0
- data/lib/killbill_client/models/gen/business_subscription_transition_attributes.rb +64 -0
- data/lib/killbill_client/models/gen/business_tag_attributes.rb +34 -0
- data/lib/killbill_client/models/gen/catalog_attributes_simple.rb +33 -0
- data/lib/killbill_client/models/gen/chargeback_attributes.rb +37 -0
- data/lib/killbill_client/models/gen/chargeback_collection_attributes.rb +33 -0
- data/lib/killbill_client/models/gen/credit_attributes.rb +39 -0
- data/lib/killbill_client/models/gen/credit_collection_attributes.rb +33 -0
- data/lib/killbill_client/models/gen/custom_field_attributes.rb +33 -0
- data/lib/killbill_client/models/gen/invoice_attributes_simple.rb +42 -0
- data/lib/killbill_client/models/gen/invoice_attributes_with_bundle_keys.rb +44 -0
- data/lib/killbill_client/models/gen/invoice_attributes_with_items.rb +43 -0
- data/lib/killbill_client/models/gen/invoice_email_attributes.rb +33 -0
- data/lib/killbill_client/models/gen/invoice_item_attributes_simple.rb +45 -0
- data/lib/killbill_client/models/gen/notification_attributes.rb +35 -0
- data/lib/killbill_client/models/gen/overdue_state_attributes.rb +38 -0
- data/lib/killbill_client/models/gen/payment_attributes_simple.rb +47 -0
- data/lib/killbill_client/models/gen/payment_attributes_with_bundle_keys.rb +50 -0
- data/lib/killbill_client/models/gen/payment_method_attributes.rb +36 -0
- data/lib/killbill_client/models/gen/payment_method_plugin_detail_attributes.rb +46 -0
- data/lib/killbill_client/models/gen/payment_method_properties.rb +34 -0
- data/lib/killbill_client/models/gen/phase_attributes.rb +33 -0
- data/lib/killbill_client/models/gen/plan_attributes.rb +33 -0
- data/lib/killbill_client/models/gen/plan_detail_attributes.rb +36 -0
- data/lib/killbill_client/models/gen/product_attributes.rb +36 -0
- data/lib/killbill_client/models/gen/refund_attributes.rb +40 -0
- data/lib/killbill_client/models/gen/require_gen.rb +80 -0
- data/lib/killbill_client/models/gen/subscription_attributes_no_events.rb +41 -0
- data/lib/killbill_client/models/gen/subscription_attributes_simple.rb +33 -0
- data/lib/killbill_client/models/gen/subscription_attributes_with_events.rb +36 -0
- data/lib/killbill_client/models/gen/subscription_deleted_event_attributes.rb +40 -0
- data/lib/killbill_client/models/gen/subscription_new_event_attributes.rb +38 -0
- data/lib/killbill_client/models/gen/subscription_read_event_attributes.rb +40 -0
- data/lib/killbill_client/models/gen/tag_attributes.rb +34 -0
- data/lib/killbill_client/models/gen/tag_definition_attributes.rb +36 -0
- data/lib/killbill_client/models/gen/tenant_attributes.rb +35 -0
- data/lib/killbill_client/models/gen/tenant_key_attributes.rb +33 -0
- data/lib/killbill_client/models/gen/time_series_data_attributes.rb +33 -0
- data/lib/killbill_client/models/invoice.rb +7 -0
- data/lib/killbill_client/models/invoice_item.rb +17 -0
- data/lib/killbill_client/models/models.rb +15 -0
- data/lib/killbill_client/models/payment.rb +6 -0
- data/lib/killbill_client/models/payment_method.rb +92 -0
- data/lib/killbill_client/models/resource.rb +125 -0
- data/lib/killbill_client/models/tag_definition.rb +6 -0
- data/lib/killbill_client/utils.rb +30 -0
- data/lib/killbill_client/version.rb +18 -0
- data/lib/rails/generators/killbill_client/config_generator.rb +17 -0
- data/lib/rails/killbill_client.rb +7 -0
- data/spec/killbill_client/remote/api_spec.rb +10 -0
- data/spec/killbill_client/remote/model_spec.rb +77 -0
- data/spec/spec_helper.rb +31 -0
- metadata +165 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/killbill/killbill-client-ruby.png)](https://travis-ci.org/killbill/killbill-client-ruby)
|
2
|
+
[![Code Climate](https://codeclimate.com/github/killbill/killbill-client-ruby.png)](https://codeclimate.com/github/killbill/killbill-client-ruby)
|
3
|
+
|
4
|
+
killbill-client-ruby
|
5
|
+
====================
|
6
|
+
|
7
|
+
Kill Bill ruby library.
|
8
|
+
|
9
|
+
Tests
|
10
|
+
-----
|
11
|
+
|
12
|
+
To run the integration tests:
|
13
|
+
|
14
|
+
```
|
15
|
+
rake test:remote:spec
|
16
|
+
```
|
17
|
+
|
18
|
+
You need to set in spec/spec_helper.rb the url of your instance, e.g. `KillBillClient.url = 'http://127.0.0.1:8080'`.
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
|
3
|
+
# Install tasks to build and release the plugin
|
4
|
+
require 'bundler/setup'
|
5
|
+
Bundler::GemHelper.install_tasks
|
6
|
+
|
7
|
+
# Install test tasks
|
8
|
+
require 'rspec/core/rake_task'
|
9
|
+
namespace :test do
|
10
|
+
desc 'Run RSpec tests'
|
11
|
+
RSpec::Core::RakeTask.new do |task|
|
12
|
+
task.name = 'spec'
|
13
|
+
task.pattern = './spec/*/*_spec.rb'
|
14
|
+
end
|
15
|
+
|
16
|
+
namespace :remote do
|
17
|
+
desc 'Run RSpec remote tests'
|
18
|
+
RSpec::Core::RakeTask.new do |task|
|
19
|
+
task.name = 'spec'
|
20
|
+
task.pattern = './spec/*/remote/*_spec.rb'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Run tests by default
|
26
|
+
task :default => 'test:spec'
|
@@ -0,0 +1,44 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2010-2013 Ning, Inc.
|
3
|
+
#
|
4
|
+
# Ning licenses this file to you under the Apache License, version 2.0
|
5
|
+
# (the "License"); you may not use this file except in compliance with the
|
6
|
+
# License. You may obtain a copy of the License at:
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
13
|
+
# License for the specific language governing permissions and limitations
|
14
|
+
# under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
18
|
+
require 'killbill_client/version'
|
19
|
+
|
20
|
+
Gem::Specification.new do |s|
|
21
|
+
s.name = 'killbill-client'
|
22
|
+
s.version = KillBillClient::Version.to_s
|
23
|
+
s.summary = 'Kill Bill client library.'
|
24
|
+
s.description = 'An API client library for Kill Bill.'
|
25
|
+
|
26
|
+
s.required_ruby_version = '>= 1.8.6'
|
27
|
+
|
28
|
+
s.license = 'Apache License (2.0)'
|
29
|
+
|
30
|
+
s.author = 'Killbill core team'
|
31
|
+
s.email = 'killbilling-users@googlegroups.com'
|
32
|
+
s.homepage = 'http://www.killbilling.org'
|
33
|
+
|
34
|
+
s.files = `git ls-files`.split("\n")
|
35
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
36
|
+
s.bindir = 'bin'
|
37
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
|
40
|
+
s.rdoc_options << '--exclude' << '.'
|
41
|
+
|
42
|
+
s.add_development_dependency 'rake', '>= 10.0.0'
|
43
|
+
s.add_development_dependency 'rspec', '~> 2.12.0'
|
44
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2011-2013 Ning, Inc.
|
3
|
+
#
|
4
|
+
# Ning licenses this file to you under the Apache License, version 2.0
|
5
|
+
# (the "License"); you may not use this file except in compliance with the
|
6
|
+
# License. You may obtain a copy of the License at:
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
13
|
+
# License for the specific language governing permissions and limitations
|
14
|
+
# under the License.
|
15
|
+
|
16
|
+
# KillBillClient is a Ruby client for Kill Bill's REST API.
|
17
|
+
module KillBillClient
|
18
|
+
# The exception class from which all KillBill exceptions inherit.
|
19
|
+
class Error < StandardError
|
20
|
+
def set_message(message)
|
21
|
+
@message = message
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [String]
|
25
|
+
def to_s
|
26
|
+
defined? @message and @message or super
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# This exception is raised if KillBill has not been configured.
|
31
|
+
class ConfigurationError < Error
|
32
|
+
end
|
33
|
+
|
34
|
+
class << self
|
35
|
+
# @return [String] A host.
|
36
|
+
def url
|
37
|
+
defined? @url and @url or raise(
|
38
|
+
ConfigurationError, 'KillBillClient.url not configured'
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
attr_writer :url
|
43
|
+
|
44
|
+
# Tenant key/password. Optional.
|
45
|
+
attr_accessor :api_key
|
46
|
+
attr_accessor :api_secret
|
47
|
+
|
48
|
+
# @return [String, nil] A default currency.
|
49
|
+
def default_currency
|
50
|
+
return @default_currency if defined? @default_currency
|
51
|
+
@default_currency = 'USD'
|
52
|
+
end
|
53
|
+
|
54
|
+
attr_writer :default_currency
|
55
|
+
|
56
|
+
# Assigns a logger to log requests/responses and more.
|
57
|
+
#
|
58
|
+
# @return [Logger, nil]
|
59
|
+
# @example
|
60
|
+
# require 'logger'
|
61
|
+
# KillBill.logger = Logger.new STDOUT
|
62
|
+
# @example Rails applications automatically log to the Rails log:
|
63
|
+
# KillBill.logger = Rails.logger
|
64
|
+
# @example Turn off logging entirely:
|
65
|
+
# KillBill.logger = nil # Or KillBill.logger = Logger.new nil
|
66
|
+
attr_accessor :logger
|
67
|
+
|
68
|
+
# Convenience logging method includes a Logger#progname dynamically.
|
69
|
+
# @return [true, nil]
|
70
|
+
def log(level, message)
|
71
|
+
logger.send(level, name) { message }
|
72
|
+
end
|
73
|
+
|
74
|
+
if RUBY_VERSION <= '1.9.0'
|
75
|
+
def const_defined?(sym, inherit = false)
|
76
|
+
raise ArgumentError, 'inherit must be false' if inherit
|
77
|
+
super sym
|
78
|
+
end
|
79
|
+
|
80
|
+
def const_get(sym, inherit = false)
|
81
|
+
raise ArgumentError, 'inherit must be false' if inherit
|
82
|
+
super sym
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
require 'killbill_client/api/api'
|
88
|
+
require 'killbill_client/models/models'
|
89
|
+
require 'killbill_client/utils'
|
90
|
+
require 'killbill_client/version'
|
91
|
+
end
|
92
|
+
|
93
|
+
require 'rails/killbill_client' if defined? Rails::Railtie
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module KillBillClient
|
2
|
+
# The API class handles all requests to the Kill Bill API. While most of its
|
3
|
+
# functionality is leveraged by the Resource class, it can be used directly,
|
4
|
+
# as well.
|
5
|
+
#
|
6
|
+
# Requests are made with methods named after the four main HTTP verbs
|
7
|
+
# recognized by the Kill Bill API.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# KillBillClient::API.get 'accounts' # => #<Net::HTTPOK ...>
|
11
|
+
# KillBillClient::API.post 'accounts', json_body # => #<Net::HTTPCreated ...>
|
12
|
+
# KillBillClient::API.put 'accounts/1', json_body # => #<Net::HTTPOK ...>
|
13
|
+
# KillBillClient::API.delete 'accounts/1' # => #<Net::HTTPNoContent ...>
|
14
|
+
class API
|
15
|
+
require 'killbill_client/api/errors'
|
16
|
+
|
17
|
+
class << self
|
18
|
+
# Additional HTTP headers sent with each API call
|
19
|
+
# @return [Hash{String => String}]
|
20
|
+
def headers
|
21
|
+
@headers ||= {'Accept' => accept, 'User-Agent' => user_agent}
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [String, nil] Accept-Language header value
|
25
|
+
def accept_language
|
26
|
+
headers['Accept-Language']
|
27
|
+
end
|
28
|
+
|
29
|
+
# @param [String] language Accept-Language header value
|
30
|
+
def accept_language=(language)
|
31
|
+
headers['Accept-Language'] = language
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [Net::HTTPOK, Net::HTTPResponse]
|
35
|
+
# @raise [ResponseError] With a non-2xx status code.
|
36
|
+
def head(uri, params = {}, options = {})
|
37
|
+
request :head, uri, {:params => params}.merge(options)
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [Net::HTTPOK, Net::HTTPResponse]
|
41
|
+
# @raise [ResponseError] With a non-2xx status code.
|
42
|
+
def get(uri, params = {}, options = {})
|
43
|
+
request :get, uri, {:params => params}.merge(options)
|
44
|
+
end
|
45
|
+
|
46
|
+
# @return [Net::HTTPCreated, Net::HTTPResponse]
|
47
|
+
# @raise [ResponseError] With a non-2xx status code.
|
48
|
+
def post(uri, body = nil, params = {}, options = {})
|
49
|
+
request :post, uri, {:body => body.to_s}.merge({:params => params}).merge(options)
|
50
|
+
end
|
51
|
+
|
52
|
+
# @return [Net::HTTPOK, Net::HTTPResponse]
|
53
|
+
# @raise [ResponseError] With a non-2xx status code.
|
54
|
+
def put(uri, body = nil, params = {}, options = {})
|
55
|
+
request :put, uri, {:body => body.to_s}.merge({:params => params}).merge(options)
|
56
|
+
end
|
57
|
+
|
58
|
+
# @return [Net::HTTPNoContent, Net::HTTPResponse]
|
59
|
+
# @raise [ResponseError] With a non-2xx status code.
|
60
|
+
def delete(uri, params = {}, options = {})
|
61
|
+
request :delete, uri, {:params => params}.merge(options)
|
62
|
+
end
|
63
|
+
|
64
|
+
# @return [URI::Generic]
|
65
|
+
def base_uri
|
66
|
+
URI.parse(KillBillClient.url)
|
67
|
+
end
|
68
|
+
|
69
|
+
# @return [String]
|
70
|
+
def user_agent
|
71
|
+
"killbill/#{Version}; #{RUBY_DESCRIPTION}"
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def accept
|
77
|
+
'application/json'
|
78
|
+
end
|
79
|
+
|
80
|
+
alias content_type accept
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
require 'killbill_client/api/net_http_adapter'
|
@@ -0,0 +1,175 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
3
|
+
module KillBillClient
|
4
|
+
class API
|
5
|
+
# The superclass to all errors that occur when making an API request.
|
6
|
+
class ResponseError < Error
|
7
|
+
attr_reader :request
|
8
|
+
attr_reader :response
|
9
|
+
|
10
|
+
def initialize(request, response)
|
11
|
+
@request, @response = request, response
|
12
|
+
end
|
13
|
+
|
14
|
+
def code
|
15
|
+
response.code.to_i if response and response.code
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_s
|
19
|
+
if description
|
20
|
+
return CGI.unescapeHTML description
|
21
|
+
end
|
22
|
+
|
23
|
+
return super unless code
|
24
|
+
'%d %s (%s %s)' % [
|
25
|
+
code, http_error, request.method, API.base_uri + request.path
|
26
|
+
]
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def description
|
32
|
+
@response.body.strip if @response.body
|
33
|
+
end
|
34
|
+
|
35
|
+
def http_error
|
36
|
+
Utils.demodulize self.class.name.gsub(/([a-z])([A-Z])/, '\1 \2')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# === 3xx Redirection
|
41
|
+
#
|
42
|
+
# Not an error, per se, but should result in one in the normal course of
|
43
|
+
# API interaction.
|
44
|
+
class Redirection < ResponseError
|
45
|
+
end
|
46
|
+
|
47
|
+
# === 304 Not Modified
|
48
|
+
#
|
49
|
+
# Raised when a request is made with an ETag.
|
50
|
+
class NotModified < ResponseError
|
51
|
+
end
|
52
|
+
|
53
|
+
# === 4xx Client Error
|
54
|
+
#
|
55
|
+
# The superclass to all client errors (responses with status code 4xx).
|
56
|
+
class ClientError < ResponseError
|
57
|
+
end
|
58
|
+
|
59
|
+
# === 400 Bad Request
|
60
|
+
#
|
61
|
+
# The request was invalid or could not be understood by the server.
|
62
|
+
# Resubmitting the request will likely result in the same error.
|
63
|
+
class BadRequest < ClientError
|
64
|
+
end
|
65
|
+
|
66
|
+
# === 401 Unauthorized
|
67
|
+
#
|
68
|
+
# The API key is missing or invalid for the given request.
|
69
|
+
class Unauthorized < ClientError
|
70
|
+
end
|
71
|
+
|
72
|
+
# === 403 Forbidden
|
73
|
+
#
|
74
|
+
# The login is attempting to perform an action it does not have privileges
|
75
|
+
# to access. The login credentials are correct.
|
76
|
+
class Forbidden < ClientError
|
77
|
+
end
|
78
|
+
|
79
|
+
# === 404 Not Found
|
80
|
+
#
|
81
|
+
# The resource was not found. This may be returned if the given account
|
82
|
+
# code or subscription plan does not exist. The response body will explain
|
83
|
+
# which resource was not found.
|
84
|
+
class NotFound < ClientError
|
85
|
+
end
|
86
|
+
|
87
|
+
# === 405 Method Not Allowed
|
88
|
+
#
|
89
|
+
# A method was attempted where it is not allowed.
|
90
|
+
#
|
91
|
+
# If this is raised, there may be a bug with the client library or with
|
92
|
+
# the server. Please contact skillbilling-users@googlegroups.com or
|
93
|
+
# {file a bug}[https://github.com/killbill/killbill-client-ruby/issues].
|
94
|
+
class MethodNotAllowed < ClientError
|
95
|
+
end
|
96
|
+
|
97
|
+
# === 406 Not Acceptable
|
98
|
+
#
|
99
|
+
# The request content type was not acceptable.
|
100
|
+
#
|
101
|
+
# If this is raised, there may be a bug with the client library or with
|
102
|
+
# the server. Please contact killbilling-users@googlegroups.com or
|
103
|
+
# {file a bug}[https://github.com/killbill/killbill-client-ruby/issues].
|
104
|
+
class NotAcceptable < ClientError
|
105
|
+
end
|
106
|
+
|
107
|
+
# === 415 Unsupported Media Type
|
108
|
+
#
|
109
|
+
# The request body was not recognized as XML.
|
110
|
+
#
|
111
|
+
# If this is raised, there may be a bug with the client library or with
|
112
|
+
# the server. Please contact killbilling-users@googlegroups.com or
|
113
|
+
# {file a bug}[https://github.com/killbill/killbill-client-ruby/issues].
|
114
|
+
class UnsupportedMediaType < ClientError
|
115
|
+
end
|
116
|
+
|
117
|
+
# === 422 Unprocessable Entity
|
118
|
+
#
|
119
|
+
# Could not process a POST or PUT request because the request is invalid.
|
120
|
+
# See the response body for more details.
|
121
|
+
class UnprocessableEntity < ClientError
|
122
|
+
end
|
123
|
+
|
124
|
+
# === 5xx Server Error
|
125
|
+
#
|
126
|
+
# The superclass to all server errors (responses with status code 5xx).
|
127
|
+
class ServerError < ResponseError
|
128
|
+
end
|
129
|
+
|
130
|
+
# === 500 Internal Server Error
|
131
|
+
#
|
132
|
+
# The server encountered an error while processing your request and failed.
|
133
|
+
class InternalServerError < ServerError
|
134
|
+
end
|
135
|
+
|
136
|
+
# === 502 Gateway Error
|
137
|
+
#
|
138
|
+
# The load balancer or web server had trouble connecting to Killbill.
|
139
|
+
# Please try the request again.
|
140
|
+
class GatewayError < ServerError
|
141
|
+
end
|
142
|
+
|
143
|
+
# === 503 Service Unavailable
|
144
|
+
#
|
145
|
+
# The service is temporarily unavailable. Please try the request again.
|
146
|
+
class ServiceUnavailable < ServerError
|
147
|
+
end
|
148
|
+
|
149
|
+
# Error mapping by status code.
|
150
|
+
ERRORS = Hash.new { |hash, code|
|
151
|
+
unless hash.key? code
|
152
|
+
case code
|
153
|
+
when 400...500 then
|
154
|
+
ClientError
|
155
|
+
when 500...600 then
|
156
|
+
ServerError
|
157
|
+
else
|
158
|
+
ResponseError
|
159
|
+
end
|
160
|
+
end
|
161
|
+
}.update(
|
162
|
+
304 => NotModified,
|
163
|
+
400 => BadRequest,
|
164
|
+
401 => Unauthorized,
|
165
|
+
403 => Forbidden,
|
166
|
+
404 => NotFound,
|
167
|
+
406 => NotAcceptable,
|
168
|
+
415 => UnsupportedMediaType,
|
169
|
+
422 => UnprocessableEntity,
|
170
|
+
500 => InternalServerError,
|
171
|
+
502 => GatewayError,
|
172
|
+
503 => ServiceUnavailable
|
173
|
+
).freeze
|
174
|
+
end
|
175
|
+
end
|