Class: Manifestly::Entity::ChildEndpoint
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Endpoint
#client, client, #create, #endpoint_target, endpoint_target, #save, #singular_endpoint_target, singular_endpoint_target
Methods inherited from Base
attr_accessor, attr_reader, attributes, #attributes, #attributes=, invalid_class_method, invalid_method, #to_h
Constructor Details
#initialize(parent, data = {}) ⇒ ChildEndpoint
Returns a new instance of ChildEndpoint.
88
89
90
91
92
93
|
# File 'lib/manifestly/entity/endpoint.rb', line 88
def initialize(parent, data = {})
raise "invalid #{parent_class}" unless parent.is_a?(parent_class)
@parent = parent
super(data)
end
|
Class Method Details
.get(id, parent) ⇒ Object
109
110
111
112
113
|
# File 'lib/manifestly/entity/endpoint.rb', line 109
def self.get(id, parent)
response = client.get("#{location(parent)}/#{id}")
json_entity = JSON.parse(response[:body], symbolize_names: true)[singular_endpoint_target.to_sym]
new(parent, json_entity)
end
|
.list(parent, **params) ⇒ Object
103
104
105
106
107
|
# File 'lib/manifestly/entity/endpoint.rb', line 103
def self.list(parent, **params)
response = client.get(location(parent), params: params)
json_entities = JSON.parse(response[:body], symbolize_names: true)[endpoint_target]
json_entities.map { |it| new(parent, it) }
end
|
.location(parent) ⇒ Object
99
100
101
|
# File 'lib/manifestly/entity/endpoint.rb', line 99
def self.location(parent)
"#{parent.location}/#{parent.id}/#{endpoint_target}"
end
|
.parent_class ⇒ Object
84
85
86
|
# File 'lib/manifestly/entity/endpoint.rb', line 84
def self.parent_class
raise 'Must specify parent_class'
end
|
Instance Method Details
#delete(path: location) ⇒ Object
120
121
122
123
|
# File 'lib/manifestly/entity/endpoint.rb', line 120
def delete(path: location)
client.delete("#{path}/#{id}")
nil
end
|
#location ⇒ Object
95
96
97
|
# File 'lib/manifestly/entity/endpoint.rb', line 95
def location
self.class.location(@parent)
end
|
#parent_class ⇒ Object
80
81
82
|
# File 'lib/manifestly/entity/endpoint.rb', line 80
def parent_class
self.class.parent_class
end
|
#update(path: location) ⇒ Object
115
116
117
118
|
# File 'lib/manifestly/entity/endpoint.rb', line 115
def update(path: location)
client.put("#{path}/#{id}", params: to_h)
self
end
|