class ExvoAuth::Models::Message
Attributes
created_at[RW]
id[RW]
label[RW]
read[RW]
text[RW]
user_uid[RW]
Public Class Methods
all()
click to toggle source
# File lib/exvo_auth/models/message.rb, line 30 def self.all auth = ExvoAuth::Autonomous::Auth.instance response = auth.get("/api/private/app_messages.json") response.map{ |m| new(m) } end
create(attributes = {})
click to toggle source
# File lib/exvo_auth/models/message.rb, line 20 def self.create(attributes = {}) message = new(attributes) if message.valid? message.deliver message else raise RecordInvalid, message.errors.full_messages.join(", ") end end
find(id)
click to toggle source
# File lib/exvo_auth/models/message.rb, line 36 def self.find(id) auth = ExvoAuth::Autonomous::Auth.instance response = auth.get("/api/private/app_messages/#{id}.json") if response.code == 200 new(response) else raise RecordNotFound, "Couldn't find #{model_name} with ID=#{id}" end end
new(attributes = {})
click to toggle source
# File lib/exvo_auth/models/message.rb, line 14 def initialize(attributes = {}) attributes.each do |name, value| send("#{name}=", value) end end
Public Instance Methods
deliver()
click to toggle source
# File lib/exvo_auth/models/message.rb, line 46 def deliver auth = ExvoAuth::Autonomous::Auth.instance attributes = { :label => label, :text => text, :user_uid => user_uid } response = auth.post("/api/private/app_messages.json", :body => attributes) case response.code when 201 then response.parsed_response.each do |k, v| send("#{k}=", v) end when 422 then response.parsed_response.each{ |attr, error| errors.add(attr, error) } raise RecordInvalid, errors.full_messages.join(", ") else raise "Unknown error" end end
persisted?()
click to toggle source
# File lib/exvo_auth/models/message.rb, line 70 def persisted? !!id end