module Vultrlife::Agent

Constants

API_HOST

Public Class Methods

http_get(endpoint, params={}) click to toggle source

GET

# File lib/vultrlife/agent.rb, line 10
def self.http_get(endpoint, params={})
  response = ''

  uri = URI.parse("#{API_HOST}#{endpoint}")
  https = Net::HTTP.new(uri.host, 443)
  https.use_ssl = true
  https.start{|https|
    response = https.get(uri.path + '?'+ query(params))
  }

  if response.body.to_s.empty?
    ''
  else
    JSON.parse(response.body)
  end
end
http_post(endpoint, body) click to toggle source

POST

# File lib/vultrlife/agent.rb, line 65
def self.http_post(endpoint, body)
  response = ''

  api_key = body.delete(:api_key)

  uri = URI.parse("#{API_HOST}#{endpoint}")
  https = Net::HTTP.new(uri.host, 443)
  https.use_ssl = true
  https.start{|https|
    response = https.post("#{uri.path}?api_key=#{api_key}",query(body))
  }

  if response.body.to_s.empty?
    ''
  else
    JSON.parse(response.body)
  end
end
os_list() click to toggle source
# File lib/vultrlife/agent.rb, line 41
def self.os_list
  #/v1/os/list
  #GET - public

  self.http_get('/v1/os/list')
end
plans_list() click to toggle source
# File lib/vultrlife/agent.rb, line 27
def self.plans_list
  #/v1/plans/list
  #GET - public

  self.http_get('/v1/plans/list')
end
query(option) click to toggle source

helper

# File lib/vultrlife/agent.rb, line 100
def self.query(option)
  return '' if option.empty?
  option.map{|e| e.join '='}.join('&')
end
regions_availability(dcid) click to toggle source
# File lib/vultrlife/agent.rb, line 48
def self.regions_availability(dcid)
  #/v1/regions/availability
  #GET - public

  self.http_get('/v1/regions/availability', DCID: dcid)
  .map(&:to_s)
end
regions_list() click to toggle source
# File lib/vultrlife/agent.rb, line 34
def self.regions_list
  #/v1/regions/list
  #GET - public

  self.http_get('/v1/regions/list')
end
server_create(body) click to toggle source
# File lib/vultrlife/agent.rb, line 84
def self.server_create(body)
  #/v1/server/create
  #POST - account

  self.http_post('/v1/server/create', body)
end
server_destroy(body) click to toggle source
# File lib/vultrlife/agent.rb, line 91
def self.server_destroy(body)
  #/v1/server/destroy
  #POST - account

  self.http_post('/v1/server/destroy', body)
end
server_list(api_key) click to toggle source
# File lib/vultrlife/agent.rb, line 56
def self.server_list(api_key)
  #/v1/server/list
  #GET - account

  self.http_get('/v1/server/list', api_key: api_key)
end