Class: Smsapi::SMS

Inherits:
Object
  • Object
show all
Includes:
Defaults
Defined in:
lib/smsapi/sms.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Defaults

#default_options

Constructor Details

#initialize(to, message, server, options = {}) ⇒ SMS

Returns a new instance of SMS.



6
7
8
9
10
11
# File 'lib/smsapi/sms.rb', line 6

def initialize(to, message, server, options = {})
  @options = default_options.merge options
  @to = to
  @message = message
  @server = server
end

Instance Attribute Details

#dateObject

Returns the value of attribute date.



5
6
7
# File 'lib/smsapi/sms.rb', line 5

def date
  @date
end

#error_codeObject

Returns the value of attribute error_code.



5
6
7
# File 'lib/smsapi/sms.rb', line 5

def error_code
  @error_code
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/smsapi/sms.rb', line 5

def id
  @id
end

#messageObject

Returns the value of attribute message.



5
6
7
# File 'lib/smsapi/sms.rb', line 5

def message
  @message
end

#pointsObject

Returns the value of attribute points.



5
6
7
# File 'lib/smsapi/sms.rb', line 5

def points
  @points
end

#statusObject

Returns the value of attribute status.



5
6
7
# File 'lib/smsapi/sms.rb', line 5

def status
  @status
end

#toObject

Returns the value of attribute to.



5
6
7
# File 'lib/smsapi/sms.rb', line 5

def to
  @to
end

Instance Method Details

#deliverObject



13
14
15
16
# File 'lib/smsapi/sms.rb', line 13

def deliver
  read_response @server.sms(server_params).first
  self
end

#deliver_at(date) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/smsapi/sms.rb', line 18

def deliver_at(date)
  @date = date
  params = server_params.merge(date: date.to_time.to_i)

  read_response @server.sms(params).first
  self
end

#error?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/smsapi/sms.rb', line 30

def error?
  self.status == 'ERROR'
end

#error_messageObject



38
39
40
# File 'lib/smsapi/sms.rb', line 38

def error_message
  Smsapi::ERROR_MESSAGES[error_code]
end

#read_response(response) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/smsapi/sms.rb', line 42

def read_response(response)
  response = response.split(':')

  self.status = response[0]
  if status == 'ERROR'
    self.error_code = response[1]
  else
    self.id = response[1]
    self.points = response[2]
  end
end

#sent?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/smsapi/sms.rb', line 26

def sent?
  not self.status.nil?
end

#success?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/smsapi/sms.rb', line 34

def success?
  self.status == 'SUCCESS'
end