Class: Kentaa::Api::Resources::Resource
- Inherits:
-
Base
- Object
- Base
- Kentaa::Api::Resources::Resource
show all
- Defined in:
- lib/kentaa/api/resources/resource.rb
Instance Attribute Summary collapse
Attributes inherited from Base
#config, #options
Instance Method Summary
collapse
Methods inherited from Base
#loaded?
Constructor Details
#initialize(config, options = {}) ⇒ Resource
Returns a new instance of Resource.
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/kentaa/api/resources/resource.rb', line 11
def initialize(config, options = {})
super(config, options)
if options.key?(:data)
@data = options.delete(:data) || {}
@id = @data.fetch(:id) if @data.key?(:id)
elsif options.key?(:id)
@id = options.delete(:id)
end
end
|
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
9
10
11
|
# File 'lib/kentaa/api/resources/resource.rb', line 9
def id
@id
end
|
Instance Method Details
#created_at ⇒ Object
46
47
48
|
# File 'lib/kentaa/api/resources/resource.rb', line 46
def created_at
Time.parse(data[:created_at]) if data[:created_at]
end
|
#delete ⇒ Object
40
41
42
43
44
|
# File 'lib/kentaa/api/resources/resource.rb', line 40
def delete
delete_resource
self
end
|
#load ⇒ Object
22
23
24
25
26
27
|
# File 'lib/kentaa/api/resources/resource.rb', line 22
def load
super
@id = data.fetch(:id) if data.key?(:id)
self
end
|
#save(attributes) ⇒ Object
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/kentaa/api/resources/resource.rb', line 29
def save(attributes)
if id
@response = update_resource(attributes)
else
@response = create_resource(attributes)
@id = data.fetch(:id) if data.key?(:id)
end
self
end
|
#updated_at ⇒ Object
50
51
52
|
# File 'lib/kentaa/api/resources/resource.rb', line 50
def updated_at
Time.parse(data[:updated_at]) if data[:updated_at]
end
|