Class: Kentaa::Api::Resources::Resource
- Inherits:
-
Base
- Object
- Base
- Kentaa::Api::Resources::Resource
show all
- Defined in:
- lib/kentaa/api/resources/resource.rb
Direct Known Subclasses
Action, Activity, Avatar, Company, Donation, DonationForm, ManualDonation, NewsletterSubscription, Order, Payment, Performance, PerformancePhoto, Project, RecurringDonor, Segment, Site, Team, User
Instance Attribute Summary collapse
Attributes inherited from Base
#config, #endpoint_path, #options, #resource_class
Instance Method Summary
collapse
Methods inherited from Base
attribute_key, #loaded?
Constructor Details
#initialize(config, id: nil, data: nil, 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, id: nil, data: nil, options: {})
super(config, options)
if data
@data = data || {}
@id = @data.fetch(:id) if @data.key?(:id)
elsif id
@id = 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
#create(attributes) ⇒ Object
29
30
31
|
# File 'lib/kentaa/api/resources/resource.rb', line 29
def create(attributes)
save(attributes)
end
|
#created_at ⇒ Object
50
51
52
|
# File 'lib/kentaa/api/resources/resource.rb', line 50
def created_at
Time.parse(data[:created_at]) if data[:created_at]
end
|
#delete ⇒ Object
44
45
46
47
48
|
# File 'lib/kentaa/api/resources/resource.rb', line 44
def delete
delete_resource
nil
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
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/kentaa/api/resources/resource.rb', line 33
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
54
55
56
|
# File 'lib/kentaa/api/resources/resource.rb', line 54
def updated_at
Time.parse(data[:updated_at]) if data[:updated_at]
end
|