class RHC::Rest::Base

Attributes

client[R]

Public Class Methods

new(attrs=nil, client=nil) click to toggle source
# File lib/rhc/rest/base.rb, line 9
def initialize(attrs=nil, client=nil)
  @attributes = (attrs || {}).stringify_keys!
  @attributes['messages'] ||= []
  @client = client
end

Public Instance Methods

add_message(msg) click to toggle source
# File lib/rhc/rest/base.rb, line 15
def add_message(msg)
  messages << msg
end
rest_method(link_name, payload={}, options={}) click to toggle source
# File lib/rhc/rest/base.rb, line 19
def rest_method(link_name, payload={}, options={})
  link = links[link_name.to_s]
  raise "No link defined for #{link_name}" unless link
  url = link['href']
  url = url.gsub(%r:\w+/) { |s| options[:params][s] } if options[:params]
  method = options[:method] || link['method']

  client.request(options.merge({
    :url => url,
    :method => method,
    :payload => payload,
  }))
end
supports?(sym) click to toggle source
# File lib/rhc/rest/base.rb, line 37
def supports?(sym)
  links.has_key?(sym.to_s) || links.has_key?(sym.to_s.upcase)
end

Protected Instance Methods

debug(msg, obj=nil) click to toggle source
# File lib/rhc/rest/base.rb, line 44
def debug(msg, obj=nil)
  client.debug("#{msg}#{obj ? " #{obj}" : ''}") if client && client.debug?
end
debug?() click to toggle source
# File lib/rhc/rest/base.rb, line 48
def debug?
  client && client.debug?
end