Class: KillBillClient::API
- Inherits:
-
Object
- Object
- KillBillClient::API
show all
- Extended by:
- Net::HTTPAdapter
- Defined in:
- lib/killbill_client/api/api.rb,
lib/killbill_client/api/errors.rb,
lib/killbill_client/api/net_http_adapter.rb
Overview
The API class handles all requests to the Kill Bill API. While most of its functionality is leveraged by the Resource class, it can be used directly, as well.
Requests are made with methods named after the four main HTTP verbs recognized by the Kill Bill API.
Defined Under Namespace
Modules: Net
Classes: BadRequest, ClientError, Forbidden, GatewayError, InternalServerError, MethodNotAllowed, NotAcceptable, NotFound, NotModified, Redirection, ResponseError, ServerError, ServiceUnavailable, Unauthorized, UnprocessableEntity, UnsupportedMediaType
Constant Summary
collapse
- ERRORS =
Error mapping by status code.
Hash.new { |hash, code|
unless hash.key? code
case code
when 400...500 then
ClientError
when 500...600 then
ServerError
else
ResponseError
end
end
}.update(
304 => NotModified,
400 => BadRequest,
401 => Unauthorized,
403 => Forbidden,
404 => NotFound,
406 => NotAcceptable,
415 => UnsupportedMediaType,
422 => UnprocessableEntity,
500 => InternalServerError,
502 => GatewayError,
503 => ServiceUnavailable
).freeze
Instance Attribute Summary
#net_http
Class Method Summary
collapse
-
.accept_language ⇒ String?
Accept-Language header value.
-
.accept_language=(language) ⇒ Object
-
.base_uri ⇒ URI::Generic
-
.delete(uri, body = nil, params = {}, options = {}) ⇒ Net::HTTPNoContent, Net::HTTPResponse
-
.get(uri, params = {}, options = {}) ⇒ Net::HTTPOK, Net::HTTPResponse
-
.head(uri, params = {}, options = {}) ⇒ Net::HTTPOK, Net::HTTPResponse
-
.headers ⇒ Hash{String => String}
Additional HTTP headers sent with each API call.
-
.post(uri, body = nil, params = {}, options = {}) ⇒ Net::HTTPCreated, Net::HTTPResponse
-
.put(uri, body = nil, params = {}, options = {}) ⇒ Net::HTTPOK, Net::HTTPResponse
-
.user_agent ⇒ String
Class Method Details
.accept_language ⇒ String?
Returns Accept-Language header value.
25
26
27
|
# File 'lib/killbill_client/api/api.rb', line 25
def accept_language
['Accept-Language']
end
|
.accept_language=(language) ⇒ Object
30
31
32
|
# File 'lib/killbill_client/api/api.rb', line 30
def accept_language=(language)
['Accept-Language'] = language
end
|
.base_uri ⇒ URI::Generic
65
66
67
|
# File 'lib/killbill_client/api/api.rb', line 65
def base_uri
URI.parse(KillBillClient.url)
end
|
.delete(uri, body = nil, params = {}, options = {}) ⇒ Net::HTTPNoContent, Net::HTTPResponse
60
61
62
|
# File 'lib/killbill_client/api/api.rb', line 60
def delete(uri, body = nil, params = {}, options = {})
request :delete, uri, {:body => body.to_s}.merge({:params => params}).merge(options)
end
|
.get(uri, params = {}, options = {}) ⇒ Net::HTTPOK, Net::HTTPResponse
42
43
44
|
# File 'lib/killbill_client/api/api.rb', line 42
def get(uri, params = {}, options = {})
request :get, uri, {:params => params}.merge(options)
end
|
.head(uri, params = {}, options = {}) ⇒ Net::HTTPOK, Net::HTTPResponse
36
37
38
|
# File 'lib/killbill_client/api/api.rb', line 36
def head(uri, params = {}, options = {})
request :head, uri, {:params => params}.merge(options)
end
|
Additional HTTP headers sent with each API call
20
21
22
|
# File 'lib/killbill_client/api/api.rb', line 20
def
@headers ||= {'Accept' => accept, 'User-Agent' => user_agent}
end
|
.post(uri, body = nil, params = {}, options = {}) ⇒ Net::HTTPCreated, Net::HTTPResponse
48
49
50
|
# File 'lib/killbill_client/api/api.rb', line 48
def post(uri, body = nil, params = {}, options = {})
request :post, uri, {:body => body.to_s}.merge({:params => params}).merge(options)
end
|
.put(uri, body = nil, params = {}, options = {}) ⇒ Net::HTTPOK, Net::HTTPResponse
54
55
56
|
# File 'lib/killbill_client/api/api.rb', line 54
def put(uri, body = nil, params = {}, options = {})
request :put, uri, {:body => body.to_s}.merge({:params => params}).merge(options)
end
|
.user_agent ⇒ String
70
71
72
|
# File 'lib/killbill_client/api/api.rb', line 70
def user_agent
"killbill/#{Version}; #{RUBY_DESCRIPTION}"
end
|