Class: ExvoAuth::Models::Message
- Inherits:
-
Object
- Object
- ExvoAuth::Models::Message
- Includes:
- ActiveModel::Serialization, ActiveModel::Validations
- Defined in:
- lib/exvo_auth/models/message.rb
Defined Under Namespace
Classes: RecordInvalid, RecordNotFound
Instance Attribute Summary collapse
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#id ⇒ Object
Returns the value of attribute id.
-
#label ⇒ Object
Returns the value of attribute label.
-
#read ⇒ Object
Returns the value of attribute read.
-
#text ⇒ Object
Returns the value of attribute text.
-
#user_uid ⇒ Object
Returns the value of attribute user_uid.
Class Method Summary collapse
Instance Method Summary collapse
- #deliver ⇒ Object
-
#initialize(attributes = {}) ⇒ Message
constructor
A new instance of Message.
- #persisted? ⇒ Boolean
Constructor Details
#initialize(attributes = {}) ⇒ Message
Returns a new instance of Message.
14 15 16 17 18 |
# File 'lib/exvo_auth/models/message.rb', line 14 def initialize(attributes = {}) attributes.each do |name, value| send("#{name}=", value) end end |
Instance Attribute Details
#created_at ⇒ Object
Returns the value of attribute created_at.
12 13 14 |
# File 'lib/exvo_auth/models/message.rb', line 12 def created_at @created_at end |
#id ⇒ Object
Returns the value of attribute id.
12 13 14 |
# File 'lib/exvo_auth/models/message.rb', line 12 def id @id end |
#label ⇒ Object
Returns the value of attribute label.
12 13 14 |
# File 'lib/exvo_auth/models/message.rb', line 12 def label @label end |
#read ⇒ Object
Returns the value of attribute read.
12 13 14 |
# File 'lib/exvo_auth/models/message.rb', line 12 def read @read end |
#text ⇒ Object
Returns the value of attribute text.
12 13 14 |
# File 'lib/exvo_auth/models/message.rb', line 12 def text @text end |
#user_uid ⇒ Object
Returns the value of attribute user_uid.
12 13 14 |
# File 'lib/exvo_auth/models/message.rb', line 12 def user_uid @user_uid end |
Class Method Details
.all ⇒ Object
30 31 32 33 34 |
# 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 = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/exvo_auth/models/message.rb', line 20 def self.create(attributes = {}) = new(attributes) if .valid? .deliver else raise RecordInvalid, .errors..join(", ") end end |
.find(id) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# 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 |
Instance Method Details
#deliver ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# 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..join(", ") else raise "Unknown error" end end |
#persisted? ⇒ Boolean
70 71 72 |
# File 'lib/exvo_auth/models/message.rb', line 70 def persisted? !!id end |