class Siteleaf::Entity
Attributes
error[R]
message[R]
Public Class Methods
all()
click to toggle source
# File lib/siteleaf/entity.rb, line 10 def self.all result = Client.get endpoint result.map { |r| new(r) } if result.is_a? Array end
class_name()
click to toggle source
# File lib/siteleaf/entity.rb, line 54 def self.class_name self.name.split('::')[-1] end
create(attributes = {})
click to toggle source
# File lib/siteleaf/entity.rb, line 20 def self.create(attributes = {}) new(attributes).save end
delete(identifier)
click to toggle source
# File lib/siteleaf/entity.rb, line 24 def self.delete(identifier) Client.delete "#{endpoint}/#{identifier}" end
endpoint()
click to toggle source
# File lib/siteleaf/entity.rb, line 58 def self.endpoint "#{self.class_name.downcase}s" end
find(identifier)
click to toggle source
# File lib/siteleaf/entity.rb, line 15 def self.find(identifier) result = Client.get "#{endpoint}/#{identifier}" new(result) if result end
new(attributes = {})
click to toggle source
# File lib/siteleaf/entity.rb, line 6 def initialize(attributes = {}) self.attributes = attributes end
Public Instance Methods
attributes()
click to toggle source
# File lib/siteleaf/entity.rb, line 46 def attributes Hash[self.instance_variables.map { |name| [name[1..-1], self.instance_variable_get(name)] }] end
attributes=(attributes = {})
click to toggle source
# File lib/siteleaf/entity.rb, line 50 def attributes=(attributes = {}) attributes.each_pair { |k, v| self.instance_variable_set("@#{k}", v) } end
create_endpoint()
click to toggle source
# File lib/siteleaf/entity.rb, line 62 def create_endpoint self.class.endpoint end
delete()
click to toggle source
# File lib/siteleaf/entity.rb, line 42 def delete Client.delete entity_endpoint end
entity_endpoint()
click to toggle source
# File lib/siteleaf/entity.rb, line 66 def entity_endpoint "#{self.class.endpoint}/#{identifier}" end
identifier()
click to toggle source
# File lib/siteleaf/entity.rb, line 70 def identifier id end
save()
click to toggle source
# File lib/siteleaf/entity.rb, line 28 def save if identifier result = Client.put entity_endpoint, attributes else result = Client.post create_endpoint, attributes end if result.is_a?(Hash) self.attributes = result return self else raise 'Invalid response' end end