Class: Sms

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/smster/sms.rb

Constant Summary collapse

STATUSES =

Codes

{ created: 0, sent: 1, delivered: 2, failed: 3 }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_message_idObject

Returns the value of attribute api_message_id.



4
5
6
# File 'lib/smster/sms.rb', line 4

def api_message_id
  @api_message_id
end

#balanceObject

Returns the value of attribute balance.



4
5
6
# File 'lib/smster/sms.rb', line 4

def balance
  @balance
end

#costObject

Returns the value of attribute cost.



4
5
6
# File 'lib/smster/sms.rb', line 4

def cost
  @cost
end

#fromObject

Returns the value of attribute from.



4
5
6
# File 'lib/smster/sms.rb', line 4

def from
  @from
end

Class Method Details

.create(attrs = {}) ⇒ Object

Etc.



13
14
15
16
17
18
19
# File 'lib/smster/sms.rb', line 13

def self.create(attrs = {})
  sms = new(attrs).send_sms
  sms.assing_code
  sms.save

  sms
end

Instance Method Details

#accept!Object



25
26
27
# File 'lib/smster/sms.rb', line 25

def accept!
  update(status: STATUSES[:delivered])
end

#assing_codeObject



29
30
31
# File 'lib/smster/sms.rb', line 29

def assing_code
  self.code = api_message_id
end

#assing_statusObject

Callbacks



7
# File 'lib/smster/sms.rb', line 7

before_validation :assing_status