Class: Sms

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

Direct Known Subclasses

Clickatell, Nexmo, Smsru

Defined Under Namespace

Classes: Clickatell, Nexmo, Smsru

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

Constructor Details

#initialize(attrs = {}) ⇒ Sms



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

def initialize(attrs = {})
  attrs.each do |name, value|
    send("#{name}=", value)
  end

  @status = STATUSES[:created]
end

Instance Attribute Details

#api_message_idObject

Returns the value of attribute api_message_id.



2
3
4
# File 'lib/smster/sms.rb', line 2

def api_message_id
  @api_message_id
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/smster/sms.rb', line 2

def name
  @name
end

#statusObject

Returns the value of attribute status.



2
3
4
# File 'lib/smster/sms.rb', line 2

def status
  @status
end

#status_messageObject

Returns the value of attribute status_message.



2
3
4
# File 'lib/smster/sms.rb', line 2

def status_message
  @status_message
end

#textObject

Returns the value of attribute text.



2
3
4
# File 'lib/smster/sms.rb', line 2

def text
  @text
end

#toObject

Returns the value of attribute to.



2
3
4
# File 'lib/smster/sms.rb', line 2

def to
  @to
end

#typeObject

Returns the value of attribute type.



2
3
4
# File 'lib/smster/sms.rb', line 2

def type
  @type
end

Class Method Details

.send_sms(attrs = {}) ⇒ Object

Etc.



10
11
12
# File 'lib/smster/sms.rb', line 10

def self.send_sms(attrs = {})
  new(attrs).send_sms
end

Instance Method Details

#send_smsObject



22
23
24
25
26
27
28
29
# File 'lib/smster/sms.rb', line 22

def send_sms
  send_to_provider

  status_name = api_message_id ? :sent : :failed
  self.status = STATUSES[status_name]

  self
end