Class: SMSTradeRB::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/smstraderb/response.rb

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



8
9
10
11
12
# File 'lib/smstraderb/response.rb', line 8

def initialize(response)
  check_response_string(response)
  @code, @message_id, @cost, @count = response.split("\n")
  check_response_code
end

Instance Method Details

#codeObject



14
15
16
# File 'lib/smstraderb/response.rb', line 14

def code
  @code.to_i
end

#costObject



22
23
24
# File 'lib/smstraderb/response.rb', line 22

def cost
  blank?(@cost) ? nil : @cost.to_f
end

#countObject



26
27
28
# File 'lib/smstraderb/response.rb', line 26

def count
  blank?(@count) ? nil : @count.to_i
end

#error?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/smstraderb/response.rb', line 34

def error?
  !ok?
end

#message_idObject



18
19
20
# File 'lib/smstraderb/response.rb', line 18

def message_id
  blank?(@message_id) ? nil : @message_id
end

#ok?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/smstraderb/response.rb', line 30

def ok?
  code == 100
end

#response_messageObject



38
39
40
# File 'lib/smstraderb/response.rb', line 38

def response_message
  SMSTradeRB::RESPONSE_CODES[code]
end