class OHResources

Attributes

conn[RW]
options[RW]

Public Class Methods

new(conn=OHConnection.connect, options={}) click to toggle source
# File lib/resources.rb, line 5
def initialize(conn=OHConnection.connect, options={})
  @conn = conn
  @options = options
end

Public Instance Methods

create(type, name, options={}) click to toggle source
# File lib/resources.rb, line 33
def create(type, name, options={})
  options = options.to_json
  resp = @conn.post "#{@@subject}/#{type.to_s}/#{__method__}", options
  return JSON.parse(resp.body)
end
destroy(type, resource) click to toggle source
# File lib/resources.rb, line 39
def destroy(type, resource)
  loc = "#{@@subject}/#{type.to_s}/#{resource.to_s}/#{__method__}"   
  resp = @conn.post loc
  return resp.status
end
info(*options) click to toggle source
# File lib/resources.rb, line 21
def info(*options)
  # add our subject, in this case "resources"
  loc = @@subject
  if ( options.size > 0)
    loc += "/#{options[0].to_s}/#{options[1]}"
  end
  # add the verb, which is the method name
  loc += "/#{__method__}"
  resp = @conn.get loc
  return JSON.parse(resp.body)
end
list(*type) click to toggle source
# File lib/resources.rb, line 10
def list(*type)
  # the __method__ instance var is the name of the method
  loc = @@subject
  if ( type.size > 0 )
    loc += "/#{type.first}"
  end
  loc += "/#{__method__}"   
  resp = @conn.get loc
  return JSON.parse(resp.body)
end
set(type, resource, options={}) click to toggle source
# File lib/resources.rb, line 45
def set(type, resource, options={})
  options = options.to_json
  loc = @@subject
  loc += "/#{type.to_s}/#{resource.to_s}/#{__method__}"   
  resp = @conn.post loc, options
  return JSON.parse(resp.body) 
end