Class: Kong::Client
Class Attribute Summary collapse
-
.http_client ⇒ Object
Returns the value of attribute http_client.
Instance Attribute Summary collapse
-
#default_headers ⇒ Object
Returns the value of attribute default_headers.
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.
- #http_client ⇒ Object
-
#initialize ⇒ Client
constructor
Initialize api client.
-
#patch(path, obj, params = {}, headers = {}) ⇒ Hash
Patch request.
-
#post(path, obj, params = {}, headers = {}) ⇒ Hash
Post request.
-
#put(path, obj, params = {}, headers = {}) ⇒ Hash
Put request.
Constructor Details
#initialize ⇒ Client
Initialize api client
18 19 20 21 22 23 |
# File 'lib/kong/client.rb', line 18 def initialize Excon.defaults[:ssl_verify_peer] = false if ignore_ssl_errors? @api_url = api_url self.class.http_client = Excon.new(@api_url, omit_default_port: true) @default_headers = { 'Accept' => 'application/json' } end |
Class Attribute Details
.http_client ⇒ Object
Returns the value of attribute http_client.
9 10 11 |
# File 'lib/kong/client.rb', line 9 def http_client @http_client end |
Instance Attribute Details
#default_headers ⇒ Object
Returns the value of attribute default_headers.
14 15 16 |
# File 'lib/kong/client.rb', line 14 def default_headers @default_headers end |
Class Method Details
.api_url ⇒ Object
25 26 27 |
# File 'lib/kong/client.rb', line 25 def self.api_url @api_url || ENV['KONG_URI'] || 'http://localhost:8001' end |
.api_url=(url) ⇒ Object
29 30 31 32 |
# File 'lib/kong/client.rb', line 29 def self.api_url=(url) @api_url = url @http_client = Excon.new(self.api_url, omit_default_port: true) end |
Instance Method Details
#api_url ⇒ String
Kong Admin API URL
41 42 43 |
# File 'lib/kong/client.rb', line 41 def api_url self.class.api_url end |
#api_url=(url) ⇒ Object
45 46 47 |
# File 'lib/kong/client.rb', line 45 def api_url=(url) @api_url = url end |
#delete(path, body = nil, params = {}, headers = {}) ⇒ Hash
Delete request
146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/kong/client.rb', line 146 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
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/kong/client.rb', line 55 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 |
#http_client ⇒ Object
34 35 36 |
# File 'lib/kong/client.rb', line 34 def http_client self.class.http_client end |
#patch(path, obj, params = {}, headers = {}) ⇒ Hash
Patch request
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/kong/client.rb', line 98 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
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/kong/client.rb', line 75 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
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/kong/client.rb', line 122 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 |