module Stingray::ServiceInterface

Public Class Methods

new(args={}) click to toggle source
# File lib/stingray/service_interface.rb, line 4
def initialize(args={})
  # Iterate over the existing config, if one exists, and set instance variables for the current object
  config=Stingray.config
  config.instance_variables.each do |var| 
    instance_variable_set("#{var}",config.instance_variable_get("#{var}"))
  end
  # Allow override of individual variables
  args.each do |key,val| 
    self.class.__send__(:attr_accessor,"#{key}")
    instance_variable_set("@#{key}",val)
  end

end

Public Instance Methods

get_endpoint(endpoint='') click to toggle source

Parse out the endpoint

# File lib/stingray/service_interface.rb, line 44
def get_endpoint(endpoint='')
  r=self.get_rest(endpoint)
  actions={}
  response=Map.new(JSON.parse(r))
  if response.respond_to?(:children)
    response.children.map{|k| actions[k.values.first]=k.values.last} unless error
    actions
  else 
    response
  end
end
rest() click to toggle source

Default REST object

# File lib/stingray/service_interface.rb, line 39
def rest
  @rest||=RestClient::Resource.new(URI.escape(@url),:user => @user, :password => @password)
end

Private Instance Methods

raise_error(e) click to toggle source
# File lib/stingray/service_interface.rb, line 58
def raise_error(e)
  if e.is_a? RestClient::ResourceNotFound
    raise NotFoundError.new(e)
  else
    raise Error.new(e)
  end
end