Class: Smsapi::Credits

Inherits:
Object
  • Object
show all
Defined in:
lib/smsapi/credits.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server, options = {}) ⇒ Credits

Returns a new instance of Credits.



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

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

Instance Attribute Details

#balanceObject

Returns the value of attribute balance.



4
5
6
# File 'lib/smsapi/credits.rb', line 4

def balance
  @balance
end

#eco_sms_limitObject

Returns the value of attribute eco_sms_limit.



4
5
6
# File 'lib/smsapi/credits.rb', line 4

def eco_sms_limit
  @eco_sms_limit
end

#error_codeObject

Returns the value of attribute error_code.



4
5
6
# File 'lib/smsapi/credits.rb', line 4

def error_code
  @error_code
end

#mms_limitObject

Returns the value of attribute mms_limit.



4
5
6
# File 'lib/smsapi/credits.rb', line 4

def mms_limit
  @mms_limit
end

#pro_sms_limitObject

Returns the value of attribute pro_sms_limit.



4
5
6
# File 'lib/smsapi/credits.rb', line 4

def pro_sms_limit
  @pro_sms_limit
end

#statusObject

Returns the value of attribute status.



4
5
6
# File 'lib/smsapi/credits.rb', line 4

def status
  @status
end

#vms_gsm_limitObject

Returns the value of attribute vms_gsm_limit.



4
5
6
# File 'lib/smsapi/credits.rb', line 4

def vms_gsm_limit
  @vms_gsm_limit
end

#vms_stac_limitObject

Returns the value of attribute vms_stac_limit.



4
5
6
# File 'lib/smsapi/credits.rb', line 4

def vms_stac_limit
  @vms_stac_limit
end

Instance Method Details

#checkObject



10
11
12
13
# File 'lib/smsapi/credits.rb', line 10

def check
  read_response @server.user(server_params).join(';')
  self
end

#error?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/smsapi/credits.rb', line 19

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

#error_messageObject



27
28
29
# File 'lib/smsapi/credits.rb', line 27

def error_message
  Smsapi::ERROR_MESSAGES[error_code]
end

#read_response(response) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/smsapi/credits.rb', line 31

def read_response(response)
  response = response.split(':').map(&:strip)

  self.status = response[0]
  if status == 'ERROR'
    self.error_code = response[1]
  else
    data = response[1].split(';')
    self.balance        = data[0].to_f
    self.pro_sms_limit  = data[1].to_i
    self.eco_sms_limit  = data[2].to_i
    self.mms_limit      = data[3].to_i
    self.vms_gsm_limit  = data[4].to_i
    self.vms_stac_limit = data[5].to_i
  end
end

#sent?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/smsapi/credits.rb', line 15

def sent?
  not self.status.nil?
end

#success?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/smsapi/credits.rb', line 23

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