class Manifestly::Entity::Endpoint

Public Class Methods

client() click to toggle source
# File lib/manifestly/entity/endpoint.rb, line 37
def self.client
  @client ||= Manifestly::Client.new
end
endpoint_target() click to toggle source
# File lib/manifestly/entity/endpoint.rb, line 9
def self.endpoint_target
  raise 'Must specify endpoint_target'
end
get(id, path: location) click to toggle source
# File lib/manifestly/entity/endpoint.rb, line 54
def self.get(id, path: location)
  response = client.get("#{path}/#{id}")
  json_entity = JSON.parse(response[:body], symbolize_names: true)[singular_endpoint_target.to_sym]
  new(json_entity)
end
list(path: location, **params) click to toggle source
# File lib/manifestly/entity/endpoint.rb, line 48
def self.list(path: location, **params)
  response = client.get(path, params: params)
  json_entities = JSON.parse(response[:body], symbolize_names: true)[endpoint_target]
  json_entities.map { |it| new(it) }
end
location() click to toggle source
# File lib/manifestly/entity/endpoint.rb, line 29
def self.location
  endpoint_target
end
singular_endpoint_target() click to toggle source
# File lib/manifestly/entity/endpoint.rb, line 17
def self.singular_endpoint_target
  endpoint_target.to_s.chomp('s').to_sym
end

Public Instance Methods

client() click to toggle source
# File lib/manifestly/entity/endpoint.rb, line 33
def client
  self.class.client
end
create(path: location) click to toggle source
# File lib/manifestly/entity/endpoint.rb, line 41
def create(path: location)
  response = client.post(path, params: to_h)
  json_entity = JSON.parse(response[:body], symbolize_names: true)[singular_endpoint_target]
  self.attributes = json_entity
  self
end
delete(path: location) click to toggle source
# File lib/manifestly/entity/endpoint.rb, line 73
def delete(path: location)
  client.delete(path, params: {external_id: external_id})
  nil
end
endpoint_target() click to toggle source
# File lib/manifestly/entity/endpoint.rb, line 13
def endpoint_target
  self.class.endpoint_target
end
location() click to toggle source
# File lib/manifestly/entity/endpoint.rb, line 25
def location
  self.class.location
end
save() click to toggle source
# File lib/manifestly/entity/endpoint.rb, line 65
def save
  if id
    update
  else
    create
  end
end
singular_endpoint_target() click to toggle source
# File lib/manifestly/entity/endpoint.rb, line 21
def singular_endpoint_target
  self.class.singular_endpoint_target
end
update(path: location) click to toggle source
# File lib/manifestly/entity/endpoint.rb, line 60
def update(path: location)
  client.post("#{path}/#{id}", params: to_h)
  self
end