Class: ButterCMS::ButterResource
- Inherits:
-
Object
- Object
- ButterCMS::ButterResource
show all
- Defined in:
- lib/buttercms/butter_resource.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ButterResource.
5
6
7
8
9
10
11
|
# File 'lib/buttercms/butter_resource.rb', line 5
def initialize(json)
@json = json
@data = HashToObject.convert(json["data"])
@meta = HashToObject.convert(json["meta"]) if json["meta"]
define_attribute_methods(@data)
end
|
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
3
4
5
|
# File 'lib/buttercms/butter_resource.rb', line 3
def data
@data
end
|
Returns the value of attribute meta.
3
4
5
|
# File 'lib/buttercms/butter_resource.rb', line 3
def meta
@meta
end
|
Class Method Details
.all(options = {}) ⇒ Object
46
47
48
49
50
|
# File 'lib/buttercms/butter_resource.rb', line 46
def self.all(options = {})
response = ButterCMS.request(self.endpoint, options)
self.create_collection(response)
end
|
.create(options = {}) ⇒ Object
58
59
60
61
62
63
|
# File 'lib/buttercms/butter_resource.rb', line 58
def self.create(options = {})
options[:method] = 'Post'
response = ButterCMS.write_request(self.endpoint, options)
self.create_object(response)
end
|
.endpoint(id = nil) ⇒ Object
30
31
32
33
34
|
# File 'lib/buttercms/butter_resource.rb', line 30
def self.endpoint(id = nil)
resource_path + (id ? "#{id}/" : '')
end
|
.find(id, options = {}) ⇒ Object
52
53
54
55
56
|
# File 'lib/buttercms/butter_resource.rb', line 52
def self.find(id, options = {})
response = ButterCMS.request(self.endpoint(id), options)
self.create_object(response)
end
|
.patch_endpoint(id) ⇒ Object
36
37
38
39
40
|
# File 'lib/buttercms/butter_resource.rb', line 36
def self.patch_endpoint(id)
resource_path + "*/#{id}/"
end
|
.resource_path ⇒ Object
42
43
44
|
# File 'lib/buttercms/butter_resource.rb', line 42
def self.resource_path
raise "resource_path must be set"
end
|
.update(id, options = {}) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/buttercms/butter_resource.rb', line 65
def self.update(id, options = {})
options[:method] = 'Patch'
_endpoint = if resource_path.include?("/pages/")
self.patch_endpoint(id)
else
self.endpoint(id)
end
response = ButterCMS.write_request(_endpoint, options)
self.create_object(response)
end
|
Instance Method Details
#inspect ⇒ Object
25
26
27
28
|
# File 'lib/buttercms/butter_resource.rb', line 25
def inspect
id_string = (self.respond_to?(:id) && !self.id.nil?) ? " id=#{self.id}" : ""
"#<#{self.class}:0x#{self.object_id.to_s(16)}#{id_string}> JSON: " + JSON.pretty_generate(@json)
end
|
#marshal_dump ⇒ Object
13
14
15
|
# File 'lib/buttercms/butter_resource.rb', line 13
def marshal_dump
{ json: @json, data: @data, meta: @meta }
end
|
#marshal_load(dump) ⇒ Object
17
18
19
20
21
22
23
|
# File 'lib/buttercms/butter_resource.rb', line 17
def marshal_load(dump)
@json = dump[:json]
@data = dump[:data]
@meta = dump[:meta]
define_attribute_methods(@data)
end
|