Class: Kong::Client
Instance Attribute Summary collapse
-
#default_headers ⇒ Object
Returns the value of attribute default_headers.
-
#http_client ⇒ Object
readonly
Returns the value of attribute http_client.
Class Method Summary collapse
Instance Method Summary collapse
-
#api_url ⇒ String
Kong Admin API URL.
- #api_url=(url) ⇒ Object
-
#delete(path, body = nil, params = {}, headers = {}) ⇒ Hash
Delete request.
-
#get(path, params = nil, headers = {}) ⇒ Hash
Get request.
-
#initialize ⇒ Client
constructor
Initialize api client.
-
#patch(path, obj, params = {}, headers = {}) ⇒ Hash
Put request.
-
#post(path, obj, params = {}, headers = {}) ⇒ Hash
Post request.
-
#put(path, obj, params = {}, headers = {}) ⇒ Hash
Put request.
Constructor Details
#initialize ⇒ Client
Initialize api client
15 16 17 18 19 20 |
# File 'lib/kong/client.rb', line 15 def initialize Excon.defaults[:ssl_verify_peer] = false if ignore_ssl_errors? @api_url = api_url @http_client = Excon.new(@api_url, omit_default_port: true) @default_headers = { 'Accept' => 'application/json' } end |
Instance Attribute Details
#default_headers ⇒ Object
Returns the value of attribute default_headers.
10 11 12 |
# File 'lib/kong/client.rb', line 10 def default_headers @default_headers end |
#http_client ⇒ Object (readonly)
Returns the value of attribute http_client.
11 12 13 |
# File 'lib/kong/client.rb', line 11 def http_client @http_client end |
Class Method Details
.api_url ⇒ Object
22 23 24 |
# File 'lib/kong/client.rb', line 22 def self.api_url self.instance.api_url end |
.api_url=(url) ⇒ Object
26 27 28 |
# File 'lib/kong/client.rb', line 26 def self.api_url=(url) self.instance.api_url = url end |
Instance Method Details
#api_url ⇒ String
Kong Admin API URL
33 34 35 |
# File 'lib/kong/client.rb', line 33 def api_url @api_url ||= ENV['KONG_URI'] || 'http://localhost:8001' end |
#api_url=(url) ⇒ Object
37 38 39 |
# File 'lib/kong/client.rb', line 37 def api_url=(url) @api_url = url end |
#delete(path, body = nil, params = {}, headers = {}) ⇒ Hash
Delete request
140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/kong/client.rb', line 140 def delete(path, body = nil, params = {}, headers = {}) request_headers = request_headers(headers) = { path: path, headers: request_headers, body: encode_body(body, request_headers['Content-Type']), query: encode_params(params) } response = http_client.delete() unless response.status == 204 handle_error_response(response) end end |
#get(path, params = nil, headers = {}) ⇒ Hash
Get request
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/kong/client.rb', line 48 def get(path, params = nil, headers = {}) response = http_client.get( path: path, query: encode_params(params), headers: request_headers(headers) ) if response.status == 200 parse_response(response) else handle_error_response(response) end end |
#patch(path, obj, params = {}, headers = {}) ⇒ Hash
Put request
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/kong/client.rb', line 91 def patch(path, obj, params = {}, headers = {}) request_headers = request_headers(headers) = { path: path, headers: request_headers, body: encode_body(obj, request_headers['Content-Type']), query: encode_params(params) } response = http_client.patch() if [200, 201].include?(response.status) parse_response(response) else handle_error_response(response) end end |
#post(path, obj, params = {}, headers = {}) ⇒ Hash
Post request
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/kong/client.rb', line 68 def post(path, obj, params = {}, headers = {}) request_headers = request_headers(headers) = { path: path, headers: request_headers, body: encode_body(obj, request_headers['Content-Type']), query: encode_params(params) } response = http_client.post() if [200, 201].include?(response.status) parse_response(response) else handle_error_response(response) end end |
#put(path, obj, params = {}, headers = {}) ⇒ Hash
Put request
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/kong/client.rb', line 116 def put(path, obj, params = {}, headers = {}) request_headers = request_headers(headers) = { path: path, headers: request_headers, body: encode_body(obj, request_headers['Content-Type']), query: encode_params(params) } response = http_client.put() if [200, 201].include?(response.status) parse_response(response) else handle_error_response(response) end end |