Class: Amiando::Resource

Inherits:
Object
  • Object
show all
Includes:
Attributes, Autorun
Defined in:
lib/amiando/resource.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Attributes

#[], #id, included, #method_missing, #respond_to?, #type

Methods included from Autorun

included

Constructor Details

#initialize(attributes = nil) ⇒ Resource

Returns a new instance of Resource.


72
73
74
# File 'lib/amiando/resource.rb', line 72

def initialize(attributes = nil)
  set_attributes(attributes)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Amiando::Attributes

Instance Attribute Details

#requestObject

Returns the value of attribute request


6
7
8
# File 'lib/amiando/resource.rb', line 6

def request
  @request
end

#responseObject

Returns the value of attribute response


6
7
8
# File 'lib/amiando/resource.rb', line 6

def response
  @response
end

#successObject (readonly)

Returns the value of attribute success


7
8
9
# File 'lib/amiando/resource.rb', line 7

def success
  @success
end

Class Method Details

.method_missing(method_name, *args, &block) ⇒ Object


12
13
14
15
16
17
18
19
20
# File 'lib/amiando/resource.rb', line 12

def method_missing(method_name, *args, &block)
  if match = /sync_(.*)/.match(method_name.to_s)
    res = self.send(match[1], *args, &block)
    Amiando.run
    res
  else
    super
  end
end

Instance Method Details

#==(resource) ⇒ Object


93
94
95
# File 'lib/amiando/resource.rb', line 93

def ==(resource)
  id == resource.id
end

#extract_attributes_from(response_body, key) ⇒ Object


85
86
87
88
89
90
91
# File 'lib/amiando/resource.rb', line 85

def extract_attributes_from(response_body, key)
  @attributes = {}

  set_attributes(response_body[key])

  @success = response_body['success']
end

#populate(reponse_body) ⇒ Object


76
77
78
# File 'lib/amiando/resource.rb', line 76

def populate(reponse_body)
  raise Error::NotImplemented.new("populate method not implemented for #{self.class}")
end

#populate_create(response_body) ⇒ Object


80
81
82
83
# File 'lib/amiando/resource.rb', line 80

def populate_create(response_body)
  @attributes = {:id => response_body['id'], :errors => response_body['errors']}
  @success    = response_body['success']
end