class SynapseClient::APIResource

Attributes

id[RW]

Public Class Methods

api_resource_name() click to toggle source
# File lib/synapse_client/api_resource.rb, line 11
def self.api_resource_name
  class_name.downcase
end
class_name() click to toggle source
# File lib/synapse_client/api_resource.rb, line 7
def self.class_name
  self.name.split('::').last
end
retrieve(id, opts={}) click to toggle source
# File lib/synapse_client/api_resource.rb, line 42
def self.retrieve(id, opts={})
  opts.merge!(:id => id)
  instance = self.new(opts)
  instance.refresh(retrieve_endpoint)
  instance
end
url() click to toggle source
# File lib/synapse_client/api_resource.rb, line 24
def self.url
  if self == APIResource
    raise NotImplementedError.new('APIResource is an abstract class.  You should perform actions on its subclasses (Customer, Bank Account, Order, etc.)')
  end
  "/api/v2/#{CGI.escape( api_resource_name )}/"
end

Public Instance Methods

refresh(endpoint="") click to toggle source
# File lib/synapse_client/api_resource.rb, line 35
def refresh(endpoint="")
  response = SynapseClient.request(:post, url + endpoint, retrieve_params)

  return response unless response.successful?
  update_attributes(response.data[self.class.class_name.downcase])
end
successful?() click to toggle source
# File lib/synapse_client/api_resource.rb, line 50
def successful?
  true
end
to_hash() click to toggle source
# File lib/synapse_client/api_resource.rb, line 15
def to_hash
  hash = {}
  instance_variables.each do |var|
    value = instance_variable_get(var)
    hash[var[1..-1].to_sym] = value if value
  end
  hash
end
url() click to toggle source
# File lib/synapse_client/api_resource.rb, line 31
def url
  self.class.url
end