Module: Touggsl::RequestHelper

Extended by:
RequestHelper
Included in:
Auth, Customer, RequestHelper
Defined in:
lib/touggsl/request_helpers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#authObject (readonly)

Returns the value of attribute auth.



7
8
9
# File 'lib/touggsl/request_helpers.rb', line 7

def auth
  @auth
end

Instance Method Details

#billings_request(client_id, status) ⇒ Object



113
114
115
116
117
# File 'lib/touggsl/request_helpers.rb', line 113

def billings_request(client_id, status)
  HTTParty.post("#{Touggsl.get_uri}cobranca/index",
                 :body => {'identificador' => client_id, 'status' => status},
                 :headers => {'Cookie' => auth.get_cookie})
end

#checks_if_client_is_inadimplente(client_id) ⇒ Object



97
98
99
100
101
# File 'lib/touggsl/request_helpers.rb', line 97

def checks_if_client_is_inadimplente(client_id)
  today = Time.now.strftime("%m/%d/%Y")
  HTTParty.post("#{Touggsl.get_uri}inadimplencia/index",
                :body => {'identificador' => client_id, 'posicaoEm' => today}, :headers => {'Cookie' => auth.get_cookie})
end

#create_client(id, nome, nome_fantasia, email = nil, endereco = nil, numero = nil, bairro = nil, cidade = nil, estado = nil, cep = nil, dia_vencimento_sac = 0) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/touggsl/request_helpers.rb', line 34

def create_client(id, nome, nome_fantasia, email = nil, endereco = nil, numero = nil, bairro = nil, cidade = nil, estado = nil, cep = nil, dia_vencimento_sac =0)
  HTTParty.post("#{Touggsl.get_uri}sacados/put",
           :body => {'ST_SINCRO_SAC' => id,
                     'ST_NOME_SAC' => nome,
                     'ST_NOMEREF_SAC' => nome_fantasia,
                     'ST_EMAIL_SAC' => email,
                     'ST_DIAVENCIMENTO_SAC' => dia_vencimento_sac,
                     'ST_ENDERECO_SAC' => endereco,
                     'ST_ESTADO_SAC' => estado,
                     'ST_CIDADE_SAC' => cidade,
                     'ST_CEP_SAC' => cep,
                     'ST_NUMERO_SAC' => numero,
                     'ST_BAIRRO_SAC' => bairro},
           :headers => {'Cookie' => auth.get_cookie})
end

#do_request(username, password) ⇒ Object

Authenticate user in superlogica.

Params

  • username - your e-mail used to log in into superlogica

  • password - your password

Return

  • A valid json with response

Example

In order to authenticate you should call this method with following params:

do_request("[email protected]", "password")


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

def do_request(username, password)
  r = HTTParty.get("#{Touggsl.get_uri}auth/post")
  response = HTTParty.post("#{Touggsl.get_uri}auth/post",
                           body: {username: "#{username}",
                                  password: "#{password}"},
                           :headers => {'Cookie' => r.headers['Set-Cookie']})
  response
end


103
104
105
106
107
# File 'lib/touggsl/request_helpers.rb', line 103

def get_2via_link(client_id)
  today = Time.now.strftime("%m/%d/%Y")
  HTTParty.post("#{Touggsl.get_uri}inadimplencia/index",
                :body => {'identificador' => client_id, 'posicaoEm' => today}, :headers => {'Cookie' => auth.get_cookie})
end


109
110
111
# File 'lib/touggsl/request_helpers.rb', line 109

def get_2via_link_normal_client(client_id)
  HTTParty.post("#{Touggsl.get_uri}cobranca/index", :body => {'identificador' => client_id}, :headers => {'Cookie' => auth.get_cookie})
end

#get_clients_inadimplementesObject



90
91
92
93
94
95
# File 'lib/touggsl/request_helpers.rb', line 90

def get_clients_inadimplementes
  today = Time.now.strftime('%m/%d/%Y')
  HTTParty.get("#{Touggsl.get_uri}inadimplencia/index",
            :body => {'posicaoEm' => today}, :headers => {'Cookie' => auth.get_cookie})

end

#hiring_plan_for_client(plan_id, client_id, id_contrato, notification = 0, quantidade_parcelas_adesao = 1, forma_pagamento) ⇒ Object

Hiring a plan.

This method expect that you create the plan in Superlogica plataform.

Params

  • plan_id - the id of the plan in Superlogica

  • client_id - the id of client that wish hering plan

  • id_contrato - a unique ID for contract

  • notification - 0 to not send notification and 1 to send. Dont send by default

  • quantidade_parcela_adesao - Number of plots for the plan. By default is 1

  • forma_pagamento - 0 = boleto.



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/touggsl/request_helpers.rb', line 64

def hiring_plan_for_client(plan_id, client_id, id_contrato, notification=0, quantidade_parcelas_adesao=1, forma_pagamento)
   hiring_at = Time.now.strftime('%m/%d/%Y')
   HTTParty.post("#{Touggsl.get_uri}planosclientes/put",
            :body => {'PLANOS' => {1 => {'identificador' => client_id,
                                         'ID_PLANO_PLA' => plan_id,
                                         'DT_CONTRATO_PLC' => hiring_at,
                                         'ST_IDENTIFICADOR_PLC' => id_contrato,
                                         'FL_NOTIFICARCLIENTE' => notification,
                                         'QUANT_PARCELAS_ADESAO' => quantidade_parcelas_adesao,
                                         'ID_FORMAPAGAMENTO_RECB' => forma_pagamento}}},
            :headers => {'Cookie' => auth.get_cookie })

end

#include_auth_to_requests(auth) ⇒ Object

include the authenticator in order to use in future requests

Params

  • auth - A Touggsl::Auth



86
87
88
# File 'lib/touggsl/request_helpers.rb', line 86

def include_auth_to_requests(auth)
 @auth = auth
end

#new_billing_request(client_id, data_vencimento, product_id, value, account_id) ⇒ Object



138
139
140
141
142
143
144
145
# File 'lib/touggsl/request_helpers.rb', line 138

def new_billing_request(client_id, data_vencimento, product_id, value, )
  HTTParty.post("#{Touggsl.get_uri}cobranca/put",
                 :body => {'COMPO_RECEBIMENTO' => {0 => {'ID_PRODUTO_PRD' => product_id, 'ST_DESCRICAO_PRD' => product_id, 'NM_QUANTIDADE_PRD' => '1', 'VL_UNITARIO_PRD' => value, 'ST_VALOR_COMP' => value}},
                           'identificador' => client_id,
                           'DT_VENCIMENTO_RECB' => data_vencimento,
                           'ID_CONTA_CB' => },
                 :headers => {'Cookie' => auth.get_cookie})
end

#pay_request(pay_id, value) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/touggsl/request_helpers.rb', line 119

def pay_request(pay_id, value)
  date = Time.now.strftime('%m/%d/%Y')
  HTTParty.post("#{Touggsl.get_uri}cobranca/liquidar",
                 :body => {'ID_RECEBIMENTO_RECB' => pay_id,
                           'VL_EMITIDO_RECB' => value,
                           'VL_DEVIDO' => value,
                           'VL_TOTAL_RECB' => value,
                           'DT_LIQUIDACAO_RECB' => date,
                           'DT_RECEBIMENTO_RECB' => date,
                           'VL_MULTA' => 0,
                           'VL_JUROS' => 0,
                           'VL_DESCONTO' => 0,
                           'FL_DIFERENCA' => 0,
                           'DT_VENCIMENTO_PRE' => date,
                           'ID_FORMAPAGAMENTO_RECB' => 0,
                           'ID_CONTA_CB' => 1},
                 :headers => {'Cookie' => auth.get_cookie})
end