Class: Smsapi::Credits
- Inherits:
-
Object
- Object
- Smsapi::Credits
- Defined in:
- lib/smsapi/credits.rb
Instance Attribute Summary collapse
-
#balance ⇒ Object
Returns the value of attribute balance.
-
#eco_sms_limit ⇒ Object
Returns the value of attribute eco_sms_limit.
-
#error_code ⇒ Object
Returns the value of attribute error_code.
-
#mms_limit ⇒ Object
Returns the value of attribute mms_limit.
-
#pro_sms_limit ⇒ Object
Returns the value of attribute pro_sms_limit.
-
#status ⇒ Object
Returns the value of attribute status.
-
#vms_gsm_limit ⇒ Object
Returns the value of attribute vms_gsm_limit.
-
#vms_stac_limit ⇒ Object
Returns the value of attribute vms_stac_limit.
Instance Method Summary collapse
- #check ⇒ Object
- #error? ⇒ Boolean
- #error_message ⇒ Object
-
#initialize(server, options = {}) ⇒ Credits
constructor
A new instance of Credits.
- #read_response(response) ⇒ Object
- #sent? ⇒ Boolean
- #success? ⇒ Boolean
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, = {}) = .merge @server = server end |
Instance Attribute Details
#balance ⇒ Object
Returns the value of attribute balance.
4 5 6 |
# File 'lib/smsapi/credits.rb', line 4 def balance @balance end |
#eco_sms_limit ⇒ Object
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_code ⇒ Object
Returns the value of attribute error_code.
4 5 6 |
# File 'lib/smsapi/credits.rb', line 4 def error_code @error_code end |
#mms_limit ⇒ Object
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_limit ⇒ Object
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 |
#status ⇒ Object
Returns the value of attribute status.
4 5 6 |
# File 'lib/smsapi/credits.rb', line 4 def status @status end |
#vms_gsm_limit ⇒ Object
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_limit ⇒ Object
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
#check ⇒ Object
10 11 12 13 |
# File 'lib/smsapi/credits.rb', line 10 def check read_response @server.user(server_params).join(';') self end |
#error? ⇒ Boolean
19 20 21 |
# File 'lib/smsapi/credits.rb', line 19 def error? self.status == 'ERROR' end |
#error_message ⇒ Object
27 28 29 |
# File 'lib/smsapi/credits.rb', line 27 def 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
15 16 17 |
# File 'lib/smsapi/credits.rb', line 15 def sent? not self.status.nil? end |
#success? ⇒ Boolean
23 24 25 |
# File 'lib/smsapi/credits.rb', line 23 def success? self.status == 'Points' end |