class Rhc::Rest::Client

Public Class Methods

new(end_point, username, password) click to toggle source
# File lib/rhc-rest/client.rb, line 7
def initialize(end_point, username, password)
  logger.debug "Connecting to #{end_point}" if @mydebug
  credentials = Base64.encode64("#{username}:#{password}")
  @@headers["Authorization"] = "Basic #{credentials}"
  #first get the API
  RestClient.proxy = ENV['http_proxy']
  request = RestClient::Request.new(:url => end_point, :method => :get, :headers => @@headers)
  begin
    response = request.execute
    result = JSON.parse(response)
    @links = send(request)
  rescue RestClient::ExceptionWithResponse => e
      logger.error "Failed to get API #{e.response}"
  rescue Exception => e
    raise ResourceAccessException.new("Resource could not be accessed:#{e.message}")
  end
end

Public Instance Methods

add_domain(id) click to toggle source

Add Domain

# File lib/rhc-rest/client.rb, line 26
def add_domain(id)
  logger.debug "Adding domain #{id}" if @mydebug
  url = @links['ADD_DOMAIN']['href']
  method =  @links['ADD_DOMAIN']['method']
  payload = {:id => id}
  request = RestClient::Request.new(:url => url, :method => method, :headers => @@headers, :payload => payload)
  return send(request)
end
cartridges() click to toggle source

Get all Cartridge

# File lib/rhc-rest/client.rb, line 73
def cartridges
  logger.debug "Getting all cartridges" if @mydebug
  url = @links['LIST_CARTRIDGES']['href']
  method =  @links['LIST_CARTRIDGES']['method']
  request = RestClient::Request.new(:url => url, :method => method, :headers => @@headers)
  return send(request)
end
close() click to toggle source
Alias for: logout
domains() click to toggle source

Get all Domain

# File lib/rhc-rest/client.rb, line 36
def domains
  logger.debug "Getting all domains" if @mydebug
  url = @links['LIST_DOMAINS']['href']
  method =  @links['LIST_DOMAINS']['method']
  request = RestClient::Request.new(:url => url, :method => method, :headers => @@headers)
  return send(request)
end
find_application(name) click to toggle source

Find Application by name

# File lib/rhc-rest/client.rb, line 58
def find_application(name)
  logger.debug "Finding application #{name}" if @mydebug
  filtered = Array.new
  domains.each do |domain|
  #TODO do a regex caomparison
    domain.applications.each do |app|
      if app.name == name
      filtered.push(app)
      end
    end
  end
  return filtered
end
find_cartridge(name) click to toggle source

Find Cartridge by name

# File lib/rhc-rest/client.rb, line 82
def find_cartridge(name)
  logger.debug "Finding cartridge #{name}" if @mydebug
  filtered = Array.new
  cartridges.each do |cart|
  #TODO do a regex caomparison
    if cart.name == name
    filtered.push(cart)
    end
  end
  return filtered
end
find_domain(id) click to toggle source

Find Domain by namesapce

# File lib/rhc-rest/client.rb, line 45
def find_domain(id)
  logger.debug "Finding domain #{id}" if @mydebug
  filtered = Array.new
  domains.each do |domain|
  #TODO do a regex caomparison
    if domain.id == id
    filtered.push(domain)
    end
  end
  return filtered
end
find_key(name) click to toggle source

find Key by name

# File lib/rhc-rest/client.rb, line 103
def find_key(name)
  logger.debug "Finding key #{name}" if @mydebug
  filtered = Array.new
  user.keys.each do |key|
  #TODO do a regex caomparison
    if key.name == name
    filtered.push(key)
    end
  end
  return filtered
end
logout() click to toggle source
# File lib/rhc-rest/client.rb, line 115
def logout
  #TODO logout
  logger.debug "Logout/Close client" if @mydebug
end
Also aliased as: close
user() click to toggle source

Get User info

# File lib/rhc-rest/client.rb, line 95
def user
  url = @links['GET_USER']['href']
  method =  @links['GET_USER']['method']
  request = RestClient::Request.new(:url => url, :method => method, :headers => @@headers)
  return send(request)
end