touggsl 0.3 → 0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -47,18 +47,23 @@ class Touggsl::Client
47
47
  # * <tt>plan_id</tt> - ID do plano cadastrado na Superlogica
48
48
  # * <tt>client_id</tt> - ID do cliente que deseja contratar o plano
49
49
  # * <tt>contract_id</tt> - ID do contrato. Unico para cada contratacao de plano
50
- def hiring_plan(plan_id, client_id, contract_id)
51
- response = hiring_plan_for_client(plan_id, client_id, contract_id)
50
+ def hiring_plan(plan_id, client_id, contract_id, forma_pagamento)
51
+ response = hiring_plan_for_client(plan_id, client_id, contract_id, forma_pagamento)
52
52
  json = JSON.parse(response)
53
53
 
54
54
  status = json["status"]
55
55
  if status == "206"
56
56
  return "Plano ja contratado para o cliente informado."
57
57
  else
58
- return status
58
+ json["data"].each do |d|
59
+ return d["data"]["link_boleto"]
60
+ end
59
61
  end
60
62
  end
61
-
63
+
64
+ ##
65
+ # Retorna todos os clientes que estão inadimplentes
66
+ #
62
67
  def get_inadimplentes
63
68
  clients = []
64
69
  clients_json = JSON.parse(get_clients_inadimplementes)
@@ -32,9 +32,20 @@ module Touggsl
32
32
  response
33
33
  end
34
34
 
35
- def create_client(id, name, st_nome_sac, nome_fantasia, dia_vencimento_sac = 0)
36
- HTTParty.post("#{Touggsl.get_uri}sacados/put",
37
- :body => {'ST_SINCRO_SAC' => id,'ST_NOME_SAC' => name, 'ST_NOMEREF_SAC' => nome_fantasia, 'ST_DIAVENCIMENTO_SAC' => dia_vencimento_sac}, :headers => {'Cookie' => auth.get_cookie})
35
+ 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)
36
+ HTTParty.post("#{Touggsl.get_uri}sacados/put",
37
+ :body => {'ST_SINCRO_SAC' => id,
38
+ 'ST_NOME_SAC' => nome,
39
+ 'ST_NOMEREF_SAC' => nome_fantasia,
40
+ 'ST_EMAIL_SAC' => email,
41
+ 'ST_DIAVENCIMENTO_SAC' => dia_vencimento_sac,
42
+ 'ST_ENDERECO_SAC' => endereco,
43
+ 'ST_ESTADO_SAC' => estado,
44
+ 'ST_CIDADE_SAC' => cidade,
45
+ 'ST_CEP_SAC' => cep,
46
+ 'ST_NUMERO_SAC' => numero,
47
+ 'ST_BAIRRO_SAC' => bairro},
48
+ :headers => {'Cookie' => auth.get_cookie})
38
49
  end
39
50
 
40
51
  ##
@@ -48,17 +59,21 @@ module Touggsl
48
59
  # * <tt>id_contrato</tt> - a unique ID for contract
49
60
  # * <tt>notification</tt> - 0 to not send notification and 1 to send. Dont send by default
50
61
  # * <tt>quantidade_parcela_adesao</tt> - Number of plots for the plan. By default is 1
62
+ # * <tt>forma_pagamento</tt> - 0 = boleto.
51
63
  #
52
64
  #
53
- def hiring_plan_for_client(plan_id, client_id, id_contrato, notification=0, quantidade_parcelas_adesao=1)
65
+ def hiring_plan_for_client(plan_id, client_id, id_contrato, notification=0, quantidade_parcelas_adesao=1, forma_pagamento)
54
66
  hiring_at = Time.now.strftime('%m/%d/%Y')
55
67
  HTTParty.post("#{Touggsl.get_uri}planosclientes/put",
56
- :body => {'PLANOS' =>
57
- {1 => {'identificador' => client_id,
58
- 'ID_PLANO_PLA' => plan_id,
59
- 'DT_CONTRATO_PLC' => hiring_at,
60
- 'ST_IDENTIFICADOR_PLC' => id_contrato, 'FL_NOTIFICARCLIENTE' => notification, 'QUANT_PARCELAS_ADESAO' => quantidade_parcelas_adesao}}},
61
- :headers => {'Cookie' => auth.get_cookie})
68
+ :body => {'PLANOS' => {1 => {'identificador' => client_id,
69
+ 'ID_PLANO_PLA' => plan_id,
70
+ 'DT_CONTRATO_PLC' => hiring_at,
71
+ 'ST_IDENTIFICADOR_PLC' => id_contrato,
72
+ 'FL_NOTIFICARCLIENTE' => notification,
73
+ 'QUANT_PARCELAS_ADESAO' => quantidade_parcelas_adesao,
74
+ 'ID_FORMAPAGAMENTO_RECB' => forma_pagamento}}},
75
+ :headers => {'Cookie' => auth.get_cookie })
76
+
62
77
  end
63
78
  ##
64
79
  # include the authenticator in order to use in future requests
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Touggsl
2
- VERSION = "0.3"
2
+ VERSION = "0.4"
3
3
  end
@@ -0,0 +1,28 @@
1
+ {
2
+ "multipleresponse":"1",
3
+ "status":"200",
4
+ "msg":"Todos os itens foram processados com sucesso.",
5
+ "data":[
6
+ {
7
+ "status":"200",
8
+ "msg":"Plano contratado com sucesso.",
9
+ "data":{
10
+ "id_sacado_sac":"83",
11
+ "id_plano_pla":"2",
12
+ "st_identificador_plc":"tougg_ordens13",
13
+ "dt_contrato_plc":"11\/08\/2013",
14
+ "dt_cancelamento_plc":"",
15
+ "id_planocliente_plc":"69",
16
+ "fl_trial_plc":"",
17
+ "dt_trialfim_plc":"",
18
+ "dt_trialinicio_plc":"",
19
+ "fl_autocontratar_plc":"0",
20
+ "id_vendedor_for":"",
21
+ "st_emailindicacao_plc":"",
22
+ "columnidname":"2",
23
+ "link_boleto":"http:\/\/touggweb-001.superlogica.net\/clients\/financeiro\/publico\/cobranca?id=59&publickey=ce4dc5b51dc6b45d15de28c2ba181e3323540adb"
24
+ }
25
+ }
26
+ ],
27
+ "executiontime":"1.2118s"
28
+ }
@@ -20,7 +20,6 @@ Time.stubs(:now).returns(Time.mktime(2013,11,03))
20
20
  auth = Touggsl::Auth
21
21
  auth.login("jack", "secret")
22
22
  @client = Touggsl::Client.new(auth)
23
-
24
23
  end
25
24
 
26
25
  def test_client_should_have_a_auth
@@ -30,38 +29,41 @@ Time.stubs(:now).returns(Time.mktime(2013,11,03))
30
29
  def test_create_new_client
31
30
 
32
31
  stub_request(:post, "http://touggweb-001.superlogica.net/financeiro/atual/sacados/put").
33
- with(:body => "ST_SINCRO_SAC=0303030&ST_NOME_SAC=Jack&ST_NOMEREF_SAC=0&ST_DIAVENCIMENTO_SAC=0",
34
- :headers => {'Cookie'=>'xpto'}).
35
- to_return(:status => 200, :body => TouggHelper.success_create_client, :headers => {})
32
+ with(:body => "ST_SINCRO_SAC=0303030&ST_NOME_SAC=Jack&ST_NOMEREF_SAC=Tougg&ST_EMAIL_SAC=0&ST_DIAVENCIMENTO_SAC=0&ST_ENDERECO_SAC=&ST_ESTADO_SAC=&ST_CIDADE_SAC=&ST_CEP_SAC=&ST_NUMERO_SAC=&ST_BAIRRO_SAC=",
33
+ :headers => {'Cookie'=>'xpto'}).
34
+ to_return(:status => 200, :body => TouggHelper.success_create_client, :headers => {})
35
+
36
36
 
37
37
  client_created = @client.create_new_client("0303030", "Jack", "Tougg")
38
38
  assert_equal "200", client_created
39
39
  end
40
40
 
41
41
  def test_hiring_plan
42
- stub_request(:post, "http://touggweb-001.superlogica.net/financeiro/atual/planosclientes/put").
43
- with(:body => "PLANOS[1][identificador]=10&PLANOS[1][ID_PLANO_PLA]=2&PLANOS[1][DT_CONTRATO_PLC]=11%2F03%2F2013&PLANOS[1][ST_IDENTIFICADOR_PLC]=1000&PLANOS[1][FL_NOTIFICARCLIENTE]=0&PLANOS[1][QUANT_PARCELAS_ADESAO]=1",
44
- :headers => {'Cookie'=>'xpto'}).
45
- to_return(:status => 200, :body => TouggHelper::success_hiring_plan, :headers => {})
46
-
47
42
 
43
+ stub_request(:post, "http://touggweb-001.superlogica.net/financeiro/atual/planosclientes/put").
44
+ with(:body => "PLANOS[1][identificador]=10&PLANOS[1][ID_PLANO_PLA]=2&PLANOS[1][DT_CONTRATO_PLC]=11%2F03%2F2013&PLANOS[1][ST_IDENTIFICADOR_PLC]=1000&PLANOS[1][FL_NOTIFICARCLIENTE]=0&PLANOS[1][QUANT_PARCELAS_ADESAO]=1&PLANOS[1][ID_FORMAPAGAMENTO_RECB]=0",
45
+ :headers => {'Cookie'=>'xpto'}).
46
+ to_return(:status => 200, :body => TouggHelper::contratar_plano,:headers => {})
47
+
48
48
  plan_id = 2
49
49
  client_id = 10
50
50
  contract_id = 1000
51
- plan = @client.hiring_plan(plan_id, client_id, contract_id)
52
- assert_equal "200", plan
51
+ forma_pagamento = 0
52
+ plan = @client.hiring_plan(plan_id, client_id, contract_id, forma_pagamento)
53
+ assert_equal "http://touggweb-001.superlogica.net/clients/financeiro/publico/cobranca?id=59&publickey=ce4dc5b51dc6b45d15de28c2ba181e3323540adb", plan
53
54
  end
54
55
 
55
56
  def test_try_hiring_plan_again
56
57
  stub_request(:post, "http://touggweb-001.superlogica.net/financeiro/atual/planosclientes/put").
57
- with(:body => "PLANOS[1][identificador]=10&PLANOS[1][ID_PLANO_PLA]=2&PLANOS[1][DT_CONTRATO_PLC]=11%2F03%2F2013&PLANOS[1][ST_IDENTIFICADOR_PLC]=1000&PLANOS[1][FL_NOTIFICARCLIENTE]=0&PLANOS[1][QUANT_PARCELAS_ADESAO]=1",
58
- :headers => {'Cookie'=>'xpto'}).
59
- to_return(:status => 200, :body => TouggHelper::hiring_plan_again, :headers => {})
58
+ with(:body => "PLANOS[1][identificador]=10&PLANOS[1][ID_PLANO_PLA]=2&PLANOS[1][DT_CONTRATO_PLC]=11%2F03%2F2013&PLANOS[1][ST_IDENTIFICADOR_PLC]=1000&PLANOS[1][FL_NOTIFICARCLIENTE]=0&PLANOS[1][QUANT_PARCELAS_ADESAO]=1&PLANOS[1][ID_FORMAPAGAMENTO_RECB]=0",
59
+ :headers => {'Cookie'=>'xpto'}).
60
+ to_return(:status => 200, :body => TouggHelper::hiring_plan_again, :headers => {})
60
61
 
61
62
  plan_id = 2
62
63
  client_id = 10
63
64
  contract_id = 1000
64
- plan = @client.hiring_plan(plan_id, client_id, contract_id)
65
+ forma_pagamento = 0
66
+ plan = @client.hiring_plan(plan_id, client_id, contract_id, forma_pagamento)
65
67
  assert_equal "Plano ja contratado para o cliente informado.", plan
66
68
  end
67
69
 
@@ -79,4 +81,6 @@ Time.stubs(:now).returns(Time.mktime(2013,11,03))
79
81
  assert_equal segunda_via_cobranca, clients[0].segunda_via_cobranca
80
82
  end
81
83
 
84
+
85
+
82
86
  end
@@ -7,7 +7,7 @@ module Touggsl
7
7
 
8
8
 
9
9
  def test_version
10
- assert_equal "0.3",Touggsl::VERSION
10
+ assert_equal "0.4",Touggsl::VERSION
11
11
  end
12
12
  end
13
13
  end
@@ -44,4 +44,8 @@ CMD
44
44
  def self.inadimplementes
45
45
  File.read("./test/inadimplentes.json")
46
46
  end
47
+
48
+ def self.contratar_plano
49
+ File.read("./test/contratarplano.json")
50
+ end
47
51
  end
data/touggsl.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "touggsl"
8
- s.version = "0.3"
8
+ s.version = "0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Edipo Luis Federle", "Dyan Carlos Carra"]
12
- s.date = "2013-11-04"
12
+ s.date = "2013-11-09"
13
13
  s.description = "Ruby code to access superlogica API"
14
14
  s.email = ["edipofederle@gmail.com", "dyancarra@gmail.com"]
15
15
  s.executables = ["touggsl"]
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
30
30
  "lib/touggsl/models/client.rb",
31
31
  "lib/touggsl/request_helpers.rb",
32
32
  "lib/version.rb",
33
+ "test/contratarplano.json",
33
34
  "test/helper.rb",
34
35
  "test/inadimplentes.json",
35
36
  "test/touggsl/test_auth.rb",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: touggsl
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: '0.4'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-11-04 00:00:00.000000000 Z
13
+ date: 2013-11-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: shoulda
@@ -163,6 +163,7 @@ files:
163
163
  - lib/touggsl/models/client.rb
164
164
  - lib/touggsl/request_helpers.rb
165
165
  - lib/version.rb
166
+ - test/contratarplano.json
166
167
  - test/helper.rb
167
168
  - test/inadimplentes.json
168
169
  - test/touggsl/test_auth.rb
@@ -186,7 +187,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
186
187
  version: '0'
187
188
  segments:
188
189
  - 0
189
- hash: 2581629456447863970
190
+ hash: -2138812775724009612
190
191
  required_rubygems_version: !ruby/object:Gem::Requirement
191
192
  none: false
192
193
  requirements: