Class: Platform::Api::Proxy::Base
- Defined in:
- lib/platform/api/proxy/base.rb
Instance Attribute Summary collapse
-
#instance ⇒ Object
Returns the value of attribute instance.
Class Method Summary collapse
- .<=>(other) ⇒ Object
- .api_version ⇒ Object
- .ensure_valid_class_name ⇒ Object
- .instance_class ⇒ Object
- .proxy_for(klass) ⇒ Object
Instance Method Summary collapse
-
#initialize(instance) ⇒ Base
constructor
A new instance of Base.
- #to_api_hash(opts = {}) ⇒ Object
- #to_api_path(opts = {}) ⇒ Object
- #to_json(opts = {}) ⇒ Object
- #to_xml(opts = {}) ⇒ Object
- #update_attributes!(attrs) ⇒ Object
Constructor Details
#initialize(instance) ⇒ Base
Returns a new instance of Base.
14 15 16 |
# File 'lib/platform/api/proxy/base.rb', line 14 def initialize(instance) @instance = instance end |
Instance Attribute Details
#instance ⇒ Object
Returns the value of attribute instance.
8 9 10 |
# File 'lib/platform/api/proxy/base.rb', line 8 def instance @instance end |
Class Method Details
.<=>(other) ⇒ Object
32 33 34 |
# File 'lib/platform/api/proxy/base.rb', line 32 def self.<=>(other) api_version <=> other.api_version end |
.api_version ⇒ Object
36 37 38 39 40 |
# File 'lib/platform/api/proxy/base.rb', line 36 def self.api_version @api_version ||= begin $1.to_i if name =~ /_(\d+)$/ end end |
.ensure_valid_class_name ⇒ Object
46 47 48 |
# File 'lib/platform/api/proxy/base.rb', line 46 def self.ensure_valid_class_name raise NameError.new("Proxy class name (#{name}) must end in _<version>") if api_version.nil? end |
.instance_class ⇒ Object
42 43 44 |
# File 'lib/platform/api/proxy/base.rb', line 42 def self.instance_class @klass end |
Instance Method Details
#to_api_hash(opts = {}) ⇒ Object
50 51 52 |
# File 'lib/platform/api/proxy/base.rb', line 50 def to_api_hash(opts = {}) raise NotImplementedError, 'Must be implemented in descendant class' end |
#to_api_path(opts = {}) ⇒ Object
54 55 56 |
# File 'lib/platform/api/proxy/base.rb', line 54 def to_api_path(opts = {}) "#{Platform::Config.api_scheme}://#{Platform::Config.api_base_url}/#{instance.class.name.underscore}/#{instance.id}" end |
#to_json(opts = {}) ⇒ Object
22 23 24 |
# File 'lib/platform/api/proxy/base.rb', line 22 def to_json(opts={}) Api::AlreadyJsonedString.new(to_api_hash(opts).to_json(opts)) end |
#to_xml(opts = {}) ⇒ Object
26 27 28 29 30 |
# File 'lib/platform/api/proxy/base.rb', line 26 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) ⇒ Object
18 19 20 |
# File 'lib/platform/api/proxy/base.rb', line 18 def update_attributes!(attrs) instance.update_attributes!(attrs) end |