class Proxy::Ipam::ApiResource

Class to handle authentication and HTTP transactions with External IPAM providers

Public Class Methods

new(params = {}) click to toggle source
# 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

Public Instance Methods

delete(path) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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