Class: Manifestly::Entity::Endpoint
- Inherits:
-
Base
- Object
- Base
- Manifestly::Entity::Endpoint
show all
- Defined in:
- lib/manifestly/entity/endpoint.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
attr_accessor, attr_reader, #attributes, attributes, #attributes=, #initialize, invalid_class_method, invalid_method, #to_h
Class Method Details
.client ⇒ Object
21
22
23
|
# File 'lib/manifestly/entity/endpoint.rb', line 21
def self.client
@client ||= Manifestly::Client.new
end
|
.get(id) ⇒ Object
38
39
40
41
42
|
# File 'lib/manifestly/entity/endpoint.rb', line 38
def self.get(id)
response = client.get("#{path}/#{id}")
json_entity = JSON.parse(response[:body], symbolize_names: true)[path.chomp('s').to_sym]
new(json_entity)
end
|
.list(**params) ⇒ Object
32
33
34
35
36
|
# File 'lib/manifestly/entity/endpoint.rb', line 32
def self.list(**params)
response = client.get(path, params: params)
json_entities = JSON.parse(response[:body], symbolize_names: true)[path.to_sym]
json_entities.map { |it| new(it) }
end
|
.path ⇒ Object
13
14
15
|
# File 'lib/manifestly/entity/endpoint.rb', line 13
def self.path
raise 'Must override method'
end
|
Instance Method Details
#client ⇒ Object
17
18
19
|
# File 'lib/manifestly/entity/endpoint.rb', line 17
def client
self.class.client
end
|
#create ⇒ Object
25
26
27
28
29
30
|
# File 'lib/manifestly/entity/endpoint.rb', line 25
def create
response = client.post(path, params: to_h)
json_entity = JSON.parse(response[:body], symbolize_names: true)[path.chomp('s').to_sym]
self.attributes = json_entity
self
end
|
#delete ⇒ Object
57
58
59
60
|
# File 'lib/manifestly/entity/endpoint.rb', line 57
def delete
client.delete(path, params: {external_id: external_id})
nil
end
|
#path ⇒ Object
9
10
11
|
# File 'lib/manifestly/entity/endpoint.rb', line 9
def path
self.class.path
end
|
#save ⇒ Object
49
50
51
52
53
54
55
|
# File 'lib/manifestly/entity/endpoint.rb', line 49
def save
if id
update
else
create
end
end
|
#update ⇒ Object
44
45
46
47
|
# File 'lib/manifestly/entity/endpoint.rb', line 44
def update
client.post("#{path}/#{id}", params: to_h)
self
end
|