Class: Proxy::Ipam::ApiResource
- Inherits:
-
Object
- Object
- Proxy::Ipam::ApiResource
- Includes:
- IpamHelper, Log
- Defined in:
- lib/smart_proxy_ipam/api_resource.rb
Overview
Class to handle authentication and HTTP transactions with External IPAM providers
Constant Summary
Constants included from IpamHelper
IpamHelper::ERRORS, IpamHelper::MAX_IP_RETRIES
Instance Method Summary collapse
- #delete(path) ⇒ Object
- #get(path) ⇒ Object
-
#initialize(params = {}) ⇒ ApiResource
constructor
A new instance of ApiResource.
- #post(path, body = nil) ⇒ Object
Methods included from IpamHelper
#cache_next_ip, #find_new_ip, #get_request_group, #increment_ip, #provider, #usable_ip
Constructor Details
#initialize(params = {}) ⇒ ApiResource
Returns a new instance of ApiResource.
13 14 15 16 17 |
# File 'lib/smart_proxy_ipam/api_resource.rb', line 13 def initialize(params = {}) @api_base = params[:api_base] @token = params[:token] @auth_header = params[:auth_header] || 'Authorization' end |
Instance Method Details
#delete(path) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/smart_proxy_ipam/api_resource.rb', line 30 def delete(path) uri = URI(@api_base + path) request = Net::HTTP::Delete.new(uri) request[@auth_header] = @token request['Accept'] = 'application/json' Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http| http.request(request) end end |
#get(path) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/smart_proxy_ipam/api_resource.rb', line 19 def get(path) uri = URI(@api_base + path) request = Net::HTTP::Get.new(uri) request[@auth_header] = @token request['Accept'] = 'application/json' Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http| http.request(request) end end |
#post(path, body = nil) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/smart_proxy_ipam/api_resource.rb', line 41 def post(path, body = nil) uri = URI(@api_base + path) request = Net::HTTP::Post.new(uri) request.body = body request[@auth_header] = @token request['Accept'] = 'application/json' request['Content-Type'] = 'application/json' Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http| http.request(request) end end |