module RHC::Rest::ApiMethods

These are methods that belong to the API object but are callable from the client for convenience.

Public Instance Methods

add_authorization(options={}) click to toggle source
# File lib/rhc/rest/client.rb, line 161
def add_authorization(options={})
  raise AuthorizationsNotSupported unless supports_sessions?
  api.rest_method('ADD_AUTHORIZATION', options, options)
end
add_domain(id) click to toggle source
# File lib/rhc/rest/client.rb, line 18
def add_domain(id)
  debug "Adding domain #{id}"
  @domains = nil
  api.rest_method "ADD_DOMAIN", :id => id
end
add_key(name, key, content) click to toggle source
# File lib/rhc/rest/client.rb, line 44
def add_key(name, key, content)
  debug "Adding key #{key} for #{user.login}"
  user.add_key name, key, content
end
authorization_scope_list() click to toggle source
# File lib/rhc/rest/client.rb, line 176
def authorization_scope_list
  raise AuthorizationsNotSupported unless supports_sessions?
  link = api.links['ADD_AUTHORIZATION']
  scope = link['optional_params'].find{ |h| h['name'] == 'scope' }
  scope['description'].scan(%r(?!\n)\*(.*?)\n(.*?)(?:\n|\Z)/).inject([]) do |h, (a, b)|
    h << [a.strip, b.strip] if a.present? && b.present?
    h
  end
end
authorizations() click to toggle source
# File lib/rhc/rest/client.rb, line 142
def authorizations
  raise AuthorizationsNotSupported unless supports_sessions?
  api.rest_method 'LIST_AUTHORIZATIONS'
end
cartridges() click to toggle source
# File lib/rhc/rest/client.rb, line 29
def cartridges
  debug "Getting all cartridges"
  @cartridges ||= api.rest_method("LIST_CARTRIDGES", nil, :lazy_auth => true)
end
close() click to toggle source
Alias for: logout
delete_authorization(token) click to toggle source
# File lib/rhc/rest/client.rb, line 171
def delete_authorization(token)
  raise AuthorizationsNotSupported unless supports_sessions?
  api.rest_method('SHOW_AUTHORIZATION', nil, {:method => :delete, :params => {':id' => token}})
end
delete_authorizations() click to toggle source
# File lib/rhc/rest/client.rb, line 166
def delete_authorizations
  raise AuthorizationsNotSupported unless supports_sessions?
  api.rest_method('LIST_AUTHORIZATIONS', nil, {:method => :delete})
end
delete_key(name) click to toggle source
# File lib/rhc/rest/client.rb, line 49
def delete_key(name)
  debug "Deleting key '#{name}'"
  key = find_key(name)
  key.destroy
end
domains() click to toggle source
# File lib/rhc/rest/client.rb, line 24
def domains
  debug "Getting all domains"
  @domains ||= api.rest_method "LIST_DOMAINS"
end
find_application(domain, application, options={}) click to toggle source
# File lib/rhc/rest/client.rb, line 63
def find_application(domain, application, options={})
  response = request({
    :url => link_show_application_by_domain_name(domain, application),
    :method => "GET",
    :payload => options
  })
end
find_application_aliases(domain, application, options={}) click to toggle source
# File lib/rhc/rest/client.rb, line 79
def find_application_aliases(domain, application, options={})
  response = request({
    :url => link_show_application_by_domain_name(domain, application, "aliases"),
    :method => "GET",
    :payload => options
  })
end
find_application_gear_groups(domain, application, options={}) click to toggle source
# File lib/rhc/rest/client.rb, line 71
def find_application_gear_groups(domain, application, options={})
  response = request({
    :url => link_show_application_by_domain_name(domain, application, "gear_groups"),
    :method => "GET",
    :payload => options
  })
end
find_cartridges(name) click to toggle source

Find Cartridge by name or regex

# File lib/rhc/rest/client.rb, line 97
def find_cartridges(name)
  debug "Finding cartridge #{name}"
  if name.is_a?(Hash)
    regex = name[:regex]
    type = name[:type]
    name = name[:name]
  end

  filtered = Array.new
  cartridges.each do |cart|
    if regex
      filtered.push(cart) if cart.name.match(regex) and (type.nil? or cart.type == type)
    else
      filtered.push(cart) if (name.nil? or cart.name == name) and (type.nil? or cart.type == type)
    end
  end
  return filtered
end
find_domain(id) click to toggle source

Find Domain by namesapce

# File lib/rhc/rest/client.rb, line 56
def find_domain(id)
  debug "Finding domain #{id}"
  domains.each { |domain| return domain if domain.id == id }

  raise DomainNotFoundException.new("Domain #{id} not found")
end
find_key(name) click to toggle source

find Key by name

# File lib/rhc/rest/client.rb, line 117
def find_key(name)
  debug "Finding key #{name}"
  user.find_key(name) or raise RHC::KeyNotFoundException.new("Key #{name} does not exist")
end
logout() click to toggle source
# File lib/rhc/rest/client.rb, line 186
def logout
  #TODO logout
  debug "Logout/Close client"
end
Also aliased as: close
new_session(options={}) click to toggle source

Returns nil if creating sessions is not supported, raises on error, otherwise returns an Authorization object.

# File lib/rhc/rest/client.rb, line 151
def new_session(options={})
  if supports_sessions?
    api.rest_method('ADD_AUTHORIZATION', {
      :scope => 'session',
      :note => "RHC/#{RHC::VERSION::STRING} (from #{Socket.gethostname rescue 'unknown'} on #{RUBY_PLATFORM})",
      :reuse => true
    }, options)
  end
end
sshkeys() click to toggle source
# File lib/rhc/rest/client.rb, line 39
def sshkeys
  debug "Finding all keys for #{user.login}"
  user.keys
end
supports_sessions?() click to toggle source
# File lib/rhc/rest/client.rb, line 138
def supports_sessions?
  api.supports? 'ADD_AUTHORIZATION'
end
user() click to toggle source
# File lib/rhc/rest/client.rb, line 34
def user
  debug "Getting user info"
  @user ||= api.rest_method "GET_USER"
end