class Rhc::Rest::Client

Public Class Methods

new(end_point, username, password) click to toggle source
# File lib/rhc-rest/client.rb, line 26
def initialize(end_point, username, password)
  @@end_point = end_point
  @username = username
  @password = password
  request = RestClient::Request.new(:url => @@end_point + "/api", :method => :get, :headers => @@headers, :username => @username, :password => password)
  begin
    begin
      response = request.execute
      result = JSON.parse(response)
      @links = send(request)
    rescue RestClient::ExceptionWithResponse => e
      puts e.response
    end
  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 45
def add_domain(id)
  logger.debug "Adding domain #{id}"
  url = @@end_point + @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 92
def cartridges
  logger.debug "Getting all cartridges"
  url = @@end_point + @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 55
def domains
  logger.debug "Getting all domains"
  url = @@end_point + @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 77
def find_application(name)
  ogger.debug "Finding application #{name}"
  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 101
def find_cartridge(name)
  logger.debug "Finding cartridge #{name}"
  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 64
def find_domain(id)
  logger.debug "Finding domain #{id}"
  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 122
def find_key(name)
  logger.debug "Finding key #{name}"
  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 134
def logout
  #TODO logout
  logger.debug "Logout/Close client"
end
Also aliased as: close
user() click to toggle source

Get User info

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