Class: TextVeloper::AccountManager

Inherits:
Object
  • Object
show all
Includes:
Singleton, TextVeloper
Defined in:
lib/text_veloper.rb

Constant Summary

Constants included from TextVeloper

URL_BASE, VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TextVeloper

#url_base_for

Constructor Details

#initializeAccountManager

Returns a new instance of AccountManager.



71
72
73
74
75
# File 'lib/text_veloper.rb', line 71

def initialize
  @payload = {cuenta_token: ""}
  @memorizing = true
  @sub_accounts = {}
end

Instance Attribute Details

#memorizingObject

Returns the value of attribute memorizing.



69
70
71
# File 'lib/text_veloper.rb', line 69

def memorizing
  @memorizing
end

#payloadObject

Returns the value of attribute payload.



69
70
71
# File 'lib/text_veloper.rb', line 69

def payload
  @payload
end

#sub_accountsObject

Returns the value of attribute sub_accounts.



69
70
71
# File 'lib/text_veloper.rb', line 69

def sub_accounts
  @sub_accounts
end

#tokenObject

Returns the value of attribute token.



69
70
71
# File 'lib/text_veloper.rb', line 69

def token
  @token
end

Instance Method Details

#balanceObject



92
93
94
95
96
97
98
# File 'lib/text_veloper.rb', line 92

def balance
  response = RestClient.post url_base_for('saldo-cuenta'), @payload
rescue => e
  raise TextVeloperError.new "Problem with balance", e
ensure
  return response
end

#config_token_account(token_account, sub_account_record = true) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/text_veloper.rb', line 77

def  ,  = true
  @token = 
  @payload = {cuenta_token: @token}
  @memorizing = 
  @sub_accounts = {}
  self
end

#purchase_historyObject



100
101
102
103
104
105
106
# File 'lib/text_veloper.rb', line 100

def purchase_history
  response = RestClient.post url_base_for('historial-compras'), @payload
rescue => e
  raise TextVeloperError.new "Problem with purchase history", e
ensure
  return response
end

#sub_account_api(sub_token_param = nil) ⇒ Object



85
86
87
88
89
90
# File 'lib/text_veloper.rb', line 85

def  sub_token_param = nil
  sub_token = sub_token_param.nil? ? TextVeloper::Api.instance.sub_token : sub_token_param
  return TextVeloper::Api.instance. @token, sub_token unless @memorizing
  @sub_accounts[sub_token] = TextVeloper::Api.instance. @token, sub_token unless  @sub_accounts.keys.include? sub_token
  @sub_accounts[sub_token]
end