Class: Touggsl::Customer

Inherits:
Object
  • Object
show all
Includes:
RequestHelper
Defined in:
lib/touggsl/customer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RequestHelper

#checks_if_client_is_inadimplente, #create_client, #do_request, #get_2via_link, #get_clients_inadimplementes, #hiring_plan_for_client, #include_auth_to_requests

Constructor Details

#initialize(auth) ⇒ Customer

Recebe um Touggsl::Auth

Exemplo:

auth = Touggsl::Auth
auth.login("email, "password")
Touggsl::Client.new(auth)


19
20
21
22
# File 'lib/touggsl/customer.rb', line 19

def initialize(auth)
  @auth = auth
  include_auth_to_requests(@auth)
end

Instance Attribute Details

#authObject

Returns the value of attribute auth.



8
9
10
# File 'lib/touggsl/customer.rb', line 8

def auth
  @auth
end

Instance Method Details

#create_new_client(id, client_name, nome_fantasia, dia_vencimento = 0) ⇒ Object

Cadastra um novo cliente na Superlogica

Prams

  • id - ID para identificar o cliente.

  • client_name - Nome do cliente. Ex: Paulo

  • nome_fantasia - Nome fantasia. Ex: Tougg

  • dia_vencimento - Parametro opcional, por padrao eh setado como 0, isso significa que nao existe “dia de vencimento” para a fatura do cliente. Se voce deseja configurar algum dia, 5 por exemplo, para o “vencimento”



34
35
36
37
38
39
40
41
# File 'lib/touggsl/customer.rb', line 34

def create_new_client(id, client_name, nome_fantasia, dia_vencimento=0)
  response = create_client(id,client_name, nome_fantasia,dia_vencimento)
  json = JSON.parse(response)

  #create a class for response, at the time only return the
  # status
 json["status"] 
end

#get_all_inadimplentesObject

Retorna todos os clientes que estão inadimplentes



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/touggsl/customer.rb', line 67

def get_all_inadimplentes
  clients = []
  clients_json = JSON.parse(get_clients_inadimplementes)
  clients_json["data"].each do |j|
    name = j["st_nomeref_sac"]
    recebimento = j["recebimento"]
    dias_atraso = recebimento[0]["encargos"][0]["diasatraso"]
    id_client = j["id_sacado_sac"]
    segunda_via = recebimento[0]["link_2via"]
    clients << Customer.new(id_client, name, dias_atraso, segunda_via)
  end
  clients
end

#hiring_plan(plan_id, client_id, contract_id, forma_pagamento) ⇒ Object

Contrata um plano para o cliente.

Params

  • plan_id - ID do plano cadastrado na Superlogica

  • client_id - ID do cliente que deseja contratar o plano

  • contract_id - ID do contrato. Unico para cada contratacao de plano



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/touggsl/customer.rb', line 50

def hiring_plan(plan_id, client_id, contract_id, forma_pagamento)
  response = hiring_plan_for_client(plan_id, client_id, contract_id, forma_pagamento)
  json = JSON.parse(response)

  status = json["status"]
  if status == "206"
    return "Plano ja contratado para o cliente informado."
  else
    json["data"].each do |d|
      return d["data"]["link_boleto"]
    end
  end
end

#is_inadimplente(client_id) ⇒ Object

Retorna boolean se cliente esta inadimplente



84
85
86
87
88
89
90
91
# File 'lib/touggsl/customer.rb', line 84

def is_inadimplente(client_id)
  client = JSON.parse(checks_if_client_is_inadimplente(client_id))
  if client['data'].length > 0
    return true
  else
    return false
  end
end

Retorna link de 2 via do boleto para cliente inadimplente



96
97
98
99
100
101
102
103
# File 'lib/touggsl/customer.rb', line 96

def link_2via(client_id)
  link = JSON.parse(get_2via_link(client_id))
  link['data'].each do |d|
    d['recebimento'].each do |v|
      return v['link_2via']
    end
  end
end