class Keystone::V2_0::Manager::Base

Attributes

auth_url[RW]
token[RW]
url_endpoint[RW]

Public Class Methods

new(auth_url, url_endpoint) click to toggle source
# File lib/keystone/v2_0/manager/base.rb, line 11
def initialize(auth_url, url_endpoint)
  self.auth_url     = auth_url
  self.url_endpoint = url_endpoint
end

Protected Instance Methods

create(payload) click to toggle source
# File lib/keystone/v2_0/manager/base.rb, line 39
def create(payload)
  options                           = {}
  options[:url]                     = "#{self.auth_url.sub(/\/$/, '')}/#{self.url_endpoint}"
  options[:method]                  = :post
  options[:headers]                 = {}
  options[:headers]["X-Auth-Token"] = self.token
  options[:headers]["User-Agent"]   = "keystone-client"
  options[:headers]["Accept"]       = "application/json"
  options[:headers]["Content-Type"] = "application/json"
  options[:payload]                 = payload

  # provide a block to ensure the response is parseable rather than
  # having RestClient throw an exception
  RestClient::Request.execute(options) do |response, request, result|
    if response and response.code == 200
      return JSON.parse(response.body)
    else
      return nil
    end
  end
end
list() click to toggle source
# File lib/keystone/v2_0/manager/base.rb, line 18
def list
  options                           = {}
  options[:url]                     = "#{self.auth_url.sub(/\/$/, '')}/#{self.url_endpoint}"
  options[:method]                  = :get
  options[:headers]                 = {}
  options[:headers]["X-Auth-Token"] = self.token
  options[:headers]["User-Agent"]   = "keystone-client"
  options[:headers]["Accept"]       = "application/json"
  options[:headers]["Content-Type"] = "application/json"

  # provide a block to ensure the response is parseable rather than
  # having RestClient throw an exception
  RestClient::Request.execute(options) do |response, request, result|
    if response and response.code == 200
      return JSON.parse(response.body)
    else
      return nil
    end
  end
end