Class: Textveloper::Sdk

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

Instance Method Summary collapse

Constructor Details

#initialize(account_token_number, subaccount_token_number) ⇒ Sdk



9
10
11
12
# File 'lib/textveloper.rb', line 9

def initialize(, subaccount_token_number)
  @account_token_number = 
  @subaccount_token_number = subaccount_token_number
end

Instance Method Details

#account_balanceObject



81
82
83
# File 'lib/textveloper.rb', line 81

def 
  hash_contructor(Curl.post(url + api_actions[:puntos_cuenta] + '/', ).body_str)
end

#account_dataObject



75
76
77
78
79
# File 'lib/textveloper.rb', line 75

def 
  {
    :cuenta_token => @account_token_number,
  }
end

#account_historyObject



93
94
95
# File 'lib/textveloper.rb', line 93

def 
  hash_contructor(Curl.post(url + api_actions[:envios] + '/',transactional_data).body_str)
end

#api_actionsObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/textveloper.rb', line 14

def api_actions
  {
  :enviar => 'enviar',
  :puntos_cuenta => 'saldo-cuenta',
  :puntos_subcuenta => 'saldo-subcuenta',
  :compras => 'historial-compras',
  :envios => 'historial-envios',
  :transferencias => 'historial-transferencias'
  }
end

#buy_historyObject



85
86
87
# File 'lib/textveloper.rb', line 85

def buy_history
  hash_contructor(Curl.post(url + api_actions[:compras] + '/', ).body_str)
end

#core_operation(number, message) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/textveloper.rb', line 25

def core_operation(number, message)
  data = {
    :cuenta_token => @account_token_number,
    :subcuenta_token => @subaccount_token_number,
    :telefono => format_phone(number),
    :mensaje => message
  }
  return Curl.post(url + api_actions[:enviar] + '/', data ).body_str
end

#hash_constructor_with_numbers(numbers, response) ⇒ Object



107
108
109
110
111
112
113
# File 'lib/textveloper.rb', line 107

def hash_constructor_with_numbers(numbers,response)
  data = Hash.new
  numbers.each_with_index do |number, index|
    data[number.to_sym] = hash_contructor(response[index])
  end
  data
end

#mass_messages(numbers, message) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/textveloper.rb', line 49

def mass_messages(numbers, message)
  response = []
  if message.size <= 160
    numbers.each do |number|
      response << core_operation(number, message)
    end
  else
    numbers.each do |number|
      chunck_message(message).each do |m|
        response << core_operation(number,m)
      end
    end
  end
  numbers.map!{ |n| format_phone(n)}
  show_format_response(numbers,response)
end

#send_sms(number, message) ⇒ Object

Servicio SMS



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/textveloper.rb', line 37

def send_sms(number,message)
  response = []
  if message.size <= 160
    response << core_operation(number,message)
  else
    chunck_message(message).each do |m|
      response << core_operation(number, m)
    end
  end
  show_format_response([format_phone(number)],response)
end

#show_format_response(numbers, response) ⇒ Object

metodos de formato de data



103
104
105
# File 'lib/textveloper.rb', line 103

def show_format_response(numbers,response)
  hash_constructor_with_numbers(numbers,response)        
end

#subaccount_balanceObject



89
90
91
# File 'lib/textveloper.rb', line 89

def subaccount_balance
  hash_contructor(Curl.post(url + api_actions[:puntos_subcuenta] + '/', transactional_data).body_str)
end

#transactional_dataObject

Historial de Transacciones



68
69
70
71
72
73
# File 'lib/textveloper.rb', line 68

def transactional_data
  {
    :cuenta_token => @account_token_number,
    :subcuenta_token => @subaccount_token_number
  }
end

#transfer_historyObject



97
98
99
# File 'lib/textveloper.rb', line 97

def transfer_history
  hash_contructor(Curl.post(url + api_actions[:transferencias] + '/',transactional_data).body_str)
end