class Platform::Api::Proxy::Base

Attributes

instance[RW]

Public Class Methods

<=>(other) click to toggle source
# File lib/platform/api/proxy/base.rb, line 30
def self.<=>(other)
  api_version <=> other.api_version
end
api_version() click to toggle source
# File lib/platform/api/proxy/base.rb, line 34
def self.api_version
  @api_version ||= begin
    $1.to_i if name =~ /_(\d+)$/
  end
end
ensure_valid_class_name() click to toggle source
# File lib/platform/api/proxy/base.rb, line 44
def self.ensure_valid_class_name
  raise NameError.new("Proxy class name (#{name}) must end in _<version>") if api_version.nil?
end
instance_class() click to toggle source
# File lib/platform/api/proxy/base.rb, line 40
def self.instance_class
  @klass
end
new(instance) click to toggle source
# File lib/platform/api/proxy/base.rb, line 12
def initialize(instance)
  @instance = instance
end
proxy_for(klass) click to toggle source
# File lib/platform/api/proxy/base.rb, line 8
def self.proxy_for(klass)
  Proxy.add(klass, self)
end

Public Instance Methods

full_url(url) click to toggle source
# File lib/platform/api/proxy/base.rb, line 60
def full_url(url)
  return url if url.index('http')
  "http://#{Platform::Config.site_base_url}#{url}"
end
sanitize_api_hash(hash) click to toggle source
# File lib/platform/api/proxy/base.rb, line 52
def sanitize_api_hash(hash)
  hash.select{|key, value| !value.blank?}
end
to_api_hash(opts = {}) click to toggle source
# File lib/platform/api/proxy/base.rb, line 48
def to_api_hash(opts = {})
  raise NotImplementedError, 'Must be implemented in descendant class'
end
to_api_path(opts = {}) click to toggle source
# File lib/platform/api/proxy/base.rb, line 56
def to_api_path(opts = {})
  "#{Platform::Config.api_scheme}://#{Platform::Config.api_base_url}/#{instance.class.name.underscore}/#{instance.id}"
end
to_json(opts={}) click to toggle source
# File lib/platform/api/proxy/base.rb, line 20
def to_json(opts={})
  Api::AlreadyJsonedString.new(to_api_hash(opts).to_json(opts))
end
to_xml(opts={}) click to toggle source
# File lib/platform/api/proxy/base.rb, line 24
def to_xml(opts={})
  opts = opts.dup
  opts[:root] ||= instance.class.name.underscore.downcase
  to_api_hash(opts).to_xml(opts)
end
update_attributes!(attrs) click to toggle source
# File lib/platform/api/proxy/base.rb, line 16
def update_attributes!(attrs)
  instance.update_attributes!(attrs)
end