touggsl 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "httparty"
12
+ gem 'mocha'
13
+ gem "json"
14
+ gem "bundler", "~> 1.0"
15
+ gem "webmock"
16
+ gem "jeweler", "~> 1.8.7"
17
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,86 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (4.0.0)
5
+ i18n (~> 0.6, >= 0.6.4)
6
+ minitest (~> 4.2)
7
+ multi_json (~> 1.3)
8
+ thread_safe (~> 0.1)
9
+ tzinfo (~> 0.3.37)
10
+ addressable (2.3.5)
11
+ atomic (1.1.14)
12
+ builder (3.2.2)
13
+ crack (0.3.2)
14
+ faraday (0.8.8)
15
+ multipart-post (~> 1.2.0)
16
+ git (1.2.6)
17
+ github_api (0.10.1)
18
+ addressable
19
+ faraday (~> 0.8.1)
20
+ hashie (>= 1.2)
21
+ multi_json (~> 1.4)
22
+ nokogiri (~> 1.5.2)
23
+ oauth2
24
+ hashie (2.0.5)
25
+ highline (1.6.20)
26
+ httparty (0.12.0)
27
+ json (~> 1.8)
28
+ multi_xml (>= 0.5.2)
29
+ httpauth (0.2.0)
30
+ i18n (0.6.5)
31
+ jeweler (1.8.8)
32
+ builder
33
+ bundler (~> 1.0)
34
+ git (>= 1.2.5)
35
+ github_api (= 0.10.1)
36
+ highline (>= 1.6.15)
37
+ nokogiri (= 1.5.10)
38
+ rake
39
+ rdoc
40
+ json (1.8.1)
41
+ jwt (0.1.8)
42
+ multi_json (>= 1.5)
43
+ metaclass (0.0.1)
44
+ minitest (4.7.5)
45
+ mocha (0.14.0)
46
+ metaclass (~> 0.0.1)
47
+ multi_json (1.8.2)
48
+ multi_xml (0.5.5)
49
+ multipart-post (1.2.0)
50
+ nokogiri (1.5.10)
51
+ oauth2 (0.9.2)
52
+ faraday (~> 0.8)
53
+ httpauth (~> 0.2)
54
+ jwt (~> 0.1.4)
55
+ multi_json (~> 1.0)
56
+ multi_xml (~> 0.5)
57
+ rack (~> 1.2)
58
+ rack (1.5.2)
59
+ rake (10.1.0)
60
+ rdoc (3.12.2)
61
+ json (~> 1.4)
62
+ shoulda (3.5.0)
63
+ shoulda-context (~> 1.0, >= 1.0.1)
64
+ shoulda-matchers (>= 1.4.1, < 3.0)
65
+ shoulda-context (1.1.5)
66
+ shoulda-matchers (2.4.0)
67
+ activesupport (>= 3.0.0)
68
+ thread_safe (0.1.3)
69
+ atomic
70
+ tzinfo (0.3.38)
71
+ webmock (1.9.0)
72
+ addressable (>= 2.2.7)
73
+ crack (>= 0.1.7)
74
+
75
+ PLATFORMS
76
+ ruby
77
+
78
+ DEPENDENCIES
79
+ bundler (~> 1.0)
80
+ httparty
81
+ jeweler (~> 1.8.7)
82
+ json
83
+ mocha
84
+ rdoc (~> 3.12)
85
+ shoulda
86
+ webmock
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Edipo Luis Federle
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,51 @@
1
+ = Touggsl - Access Superlogica API through Ruby Code
2
+
3
+ Até o momento essa gem fornece três operações sobre a API da Superlogica
4
+
5
+ * Autenticação
6
+ * Cadastro de cliente
7
+ * Assinar um plano para um cliente
8
+ * Buscar clientes inadimplentes
9
+
10
+ == Autenticação
11
+
12
+ Touggsl.set_uri("http://sua_conta.superlogica.net/financeiro/atual/")
13
+ @auth = Touggsl::Auth
14
+ @auth.login("jack", "secret")
15
+
16
+ == Criando um cliente
17
+
18
+ cliente = Touggsl::Client.new(auth)
19
+ client.create_new_client("0303030", "Jack", "Tougg") # retorna "200" para sucesso
20
+
21
+ == Vinculando um cliente a um plano
22
+
23
+ client.hiring_plan(plan_id, client_id, contract_id) #retorna "200" para sucesso.
24
+
25
+ == Buscando inadimplentes
26
+
27
+ client.get_inadimplentes #retorna uma array de Client
28
+
29
+
30
+ Para maiores informações recomenda-se dar uma olhada nos testes e na documentação.
31
+
32
+ == Contributing to Touggsl
33
+
34
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
35
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
36
+ * Fork the project.
37
+ * Start a feature/bugfix branch.
38
+ * Commit and push until you are happy with your contribution.
39
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
40
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
41
+
42
+ == Authors
43
+
44
+ * Édipo Luis Féderle - edipofederle@gmail.com
45
+ * Dyan Carlos Carra - dyancarra@gmail.com
46
+
47
+ == Copyright
48
+
49
+ Copyright (c) 2013 {Tougg}[http://tougg.com.br]. See LICENSE.txt for
50
+ further details.
51
+
data/Rakefile ADDED
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ require './lib/version'
6
+ begin
7
+ Bundler.setup(:default, :development)
8
+ rescue Bundler::BundlerError => e
9
+ $stderr.puts e.message
10
+ $stderr.puts "Run `bundle install` to install missing gems"
11
+ exit e.status_code
12
+ end
13
+ require 'rake'
14
+
15
+ require 'jeweler'
16
+ Jeweler::Tasks.new do |gem|
17
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
18
+ gem.name = "touggsl"
19
+ gem.homepage = "http://github.com/edipofederle/touggsl"
20
+ gem.license = "MIT"
21
+ gem.version = Touggsl::VERSION
22
+ gem.summary = %Q{Ruby code to access superlogica API}
23
+ gem.description = %Q{Ruby code to access superlogica API}
24
+ gem.email = "edipofederle@gmail.com"
25
+ gem.authors = ["Edipo Luis Federle"]
26
+ # dependencies defined in Gemfile
27
+ end
28
+ Jeweler::RubygemsDotOrgTasks.new
29
+
30
+ require 'rake/testtask'
31
+ Rake::TestTask.new(:test) do |test|
32
+ test.libs << 'lib' << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+
37
+ #require 'rcov/rcovtask'
38
+ #Rcov::RcovTask.new do |test|
39
+ # test.libs << 'test'
40
+ # test.pattern = 'test/**/test_*.rb'
41
+ # test.verbose = true
42
+ # test.rcov_opts << '--exclude "gems/*"'
43
+ #end
44
+
45
+ task :default => :test
46
+
47
+ require 'rdoc/task'
48
+ Rake::RDocTask.new do |rdoc|
49
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "touggsl #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
@@ -0,0 +1,64 @@
1
+ require 'touggsl'
2
+ require 'json'
3
+ require 'touggsl/request_helpers'
4
+
5
+ class Touggsl::Auth
6
+
7
+ class << self
8
+
9
+ include Touggsl::RequestHelper
10
+
11
+ attr_accessor :session
12
+ attr_accessor :status
13
+
14
+ ##
15
+ # Autentica o usuário na Superlogica
16
+ #
17
+ # === Params
18
+ #
19
+ # * <tt>username</tt> - O e-mail que voce utiliza para logar no sistema da Suerlogica
20
+ # * <tt>passoword</tt> - sua senha
21
+ #
22
+ # === Exceptions
23
+ # Uma excesao eh lancada caso o username ou a senha estejam incorretos
24
+ #
25
+ def login(username, password)
26
+ response = do_request(username,password)
27
+ json = JSON.parse(response)
28
+ @status = json["status"]
29
+ if @status == "401"
30
+ @session = nil
31
+ raise "Invalid username or password!"
32
+ end
33
+ @session = json["session"]
34
+ @cookie = response.request.options[:headers]['Cookie']
35
+ json
36
+ end
37
+
38
+ ##
39
+ # Retorna a sessao da autenticacao
40
+ #
41
+ def get_session
42
+ @session
43
+ end
44
+
45
+ ##
46
+ # Retorna o status da autenticacao.
47
+ #
48
+ # Os status seguem o padrao HTTP
49
+ #
50
+ def get_status
51
+ @status
52
+ end
53
+
54
+ ##
55
+ # Retorna um cookie da autenticacao. Esse cookie eh usado
56
+ # em todas as futuras autenticacoes, assim voce nao precisa logar
57
+ # novamente
58
+ #
59
+ def get_cookie
60
+ @cookie
61
+ end
62
+ end
63
+
64
+ end
@@ -0,0 +1,76 @@
1
+ require 'touggsl'
2
+ require 'json'
3
+ require 'touggsl/request_helpers'
4
+ require 'touggsl/models/client'
5
+ class Touggsl::Client
6
+ include Touggsl::RequestHelper
7
+
8
+ attr_accessor :auth
9
+
10
+ ##
11
+ # Recebe um Touggsl::Auth
12
+ #
13
+ # Exemplo:
14
+ #
15
+ # auth = Touggsl::Auth
16
+ # auth.login("email, "password")
17
+ # Touggsl::Client.new(auth)
18
+ #
19
+ def initialize(auth)
20
+ @auth = auth
21
+ include_auth_to_requests(@auth)
22
+ end
23
+
24
+ ##
25
+ # Cadastra um novo cliente na Superlogica
26
+ #
27
+ # ==== Prams
28
+ # * <tt>id</tt> - ID para identificar o cliente.
29
+ # * <tt>client_name</tt> - Nome do cliente. Ex: Paulo
30
+ # * <tt>nome_fantasia</tt> - Nome fantasia. Ex: Tougg
31
+ # * <tt>dia_vencimento</tt> - Parametro opcional, por padrao eh setado como 0,
32
+ # isso significa que nao existe "dia de vencimento" para a fatura do cliente. Se voce deseja
33
+ # configurar algum dia, 5 por exemplo, para o "vencimento"
34
+ def create_new_client(id, client_name, nome_fantasia, dia_vencimento=0)
35
+ response = create_client(id,client_name, nome_fantasia,dia_vencimento)
36
+ json = JSON.parse(response)
37
+
38
+ #create a class for response, at the time only return the
39
+ # status
40
+ json["status"]
41
+ end
42
+
43
+ ##
44
+ # Contrata um plano para o cliente.
45
+ #
46
+ # ==== Params
47
+ # * <tt>plan_id</tt> - ID do plano cadastrado na Superlogica
48
+ # * <tt>client_id</tt> - ID do cliente que deseja contratar o plano
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)
52
+ json = JSON.parse(response)
53
+
54
+ status = json["status"]
55
+ if status == "206"
56
+ return "Plano ja contratado para o cliente informado."
57
+ else
58
+ return status
59
+ end
60
+ end
61
+
62
+ def get_inadimplentes
63
+ clients = []
64
+ clients_json = JSON.parse(get_clients_inadimplementes)
65
+ clients_json["data"].each do |j|
66
+ name = j["st_nomeref_sac"]
67
+ recebimento = j["recebimento"]
68
+ dias_atraso = recebimento[0]["encargos"][0]["diasatraso"]
69
+ id_client = j["id_sacado_sac"]
70
+ segunda_via = recebimento[0]["link_2via"]
71
+ clients << Client.new(id_client, name, dias_atraso, segunda_via)
72
+ end
73
+ clients
74
+ end
75
+ end
76
+
@@ -0,0 +1,22 @@
1
+ ##
2
+ # Representa um cliente inadimplemente
3
+ #
4
+ # Uma lista de objetos desse tipo é retornada
5
+ # no método get_inadimplementes
6
+ # === Attributes
7
+ # * <tt>client_id</tt> - ID do cliente
8
+ # * <tt>name</tt> - Nome do cliente
9
+ # * <tt>dias_atraso</tt> - Numero em dias do atraso do pagamento
10
+ # * <tt>segunda_via_cobranca</tt> - Link para a cobranca em atraso
11
+ #
12
+ ##
13
+ class Client
14
+ attr_accessor :client_id, :name, :dias_atraso, :segunda_via_cobranca
15
+
16
+ def initialize(client_id, name, dias_atraso, segunda_via)
17
+ @client_id = client_id
18
+ @name = name
19
+ @dias_atraso = dias_atraso
20
+ @segunda_via_cobranca = segunda_via
21
+ end
22
+ end
@@ -0,0 +1,82 @@
1
+ require 'httparty'
2
+
3
+ module Touggsl
4
+ module RequestHelper
5
+ extend self
6
+
7
+ attr_reader :auth
8
+ ##
9
+ # Authenticate user in superlogica.
10
+ #
11
+ # ==== Params
12
+ #
13
+ # * <tt>username</tt> - your e-mail used to log in into superlogica
14
+ # * <tt>password</tt> - your password
15
+ # ==== Return
16
+ #
17
+ # * A valid json with response
18
+ #
19
+ # ==== Example
20
+ # In order to authenticate you shoulid call
21
+ # this method with following params:
22
+ #
23
+ # do_request("email@email.com", "password")
24
+ #
25
+ def do_request(username, password)
26
+ r = HTTParty.get("#{Touggsl.get_uri}auth/post")
27
+ response = HTTParty.post("#{Touggsl.get_uri}auth/post",
28
+ body: {username: "#{username}",
29
+ password: "#{password}"},
30
+
31
+ :headers => {'Cookie' => r.headers['Set-Cookie']})
32
+ response
33
+ end
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})
38
+ end
39
+
40
+ ##
41
+ # Hiring a plan.
42
+ #
43
+ # This method expect that you create the plan in Superlogica plataform.
44
+ #
45
+ # === Params
46
+ # * <tt>plan_id</tt> - the id of the plan in Superlogica
47
+ # * <tt>client_id</tt> - the id of client that wish hering plan
48
+ # * <tt>id_contrato</tt> - a unique ID for contract
49
+ # * <tt>notification</tt> - 0 to not send notification and 1 to send. Dont send by default
50
+ # * <tt>quantidade_parcela_adesao</tt> - Number of plots for the plan. By default is 1
51
+ #
52
+ #
53
+ def hiring_plan_for_client(plan_id, client_id, id_contrato, notification=0, quantidade_parcelas_adesao=1)
54
+ hiring_at = Time.now.strftime('%m/%d/%Y')
55
+ 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})
62
+ end
63
+ ##
64
+ # include the authenticator in order to use in future requests
65
+ #
66
+ # ==== Params
67
+ #
68
+ # * <tt>auth</tt> - A Touggsl::Auth
69
+ #
70
+ #
71
+ def include_auth_to_requests(auth)
72
+ @auth = auth
73
+ end
74
+
75
+ def get_clients_inadimplementes
76
+ today = Time.now.strftime('%m/%d/%Y')
77
+ HTTParty.get("#{Touggsl.get_uri}inadimplencia/index",
78
+ :body => {'posicaoEm' => today}, :headers => {'Cookie' => auth.get_cookie})
79
+
80
+ end
81
+ end
82
+ end
data/lib/touggsl.rb ADDED
@@ -0,0 +1,23 @@
1
+ require 'touggsl/auth'
2
+ require 'touggsl/client'
3
+ ##
4
+ # Main module, there is only one method
5
+ # used to set your URL.
6
+ #
7
+ # For exemplo, given that name of your account in Superlogica
8
+ # is "my-company" probably your URL is some thing like:
9
+ # https://my-company.superlogica.net/financeiro/atual/
10
+ #
11
+ module Touggsl
12
+
13
+ attr_accessor :uri
14
+
15
+ def self.set_uri(uri)
16
+ @uri = uri
17
+ end
18
+
19
+ def self.get_uri
20
+ @uri
21
+ end
22
+
23
+ end
data/lib/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module Touggsl
2
+ VERSION = "0.1"
3
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ require 'webmock/test_unit'
4
+ require 'mocha/setup'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'test/unit'
13
+ require 'shoulda'
14
+
15
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
16
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
17
+ require 'touggsl'
18
+
19
+ class Test::Unit::TestCase
20
+ end
@@ -0,0 +1,125 @@
1
+ {
2
+ "status": "200",
3
+ "session": "2f5uq21od95hqd642ib3cflg87",
4
+ "msg": "",
5
+ "data": [
6
+ {
7
+ "recebimento": [
8
+ {
9
+ "id_recebimento_recb": "21",
10
+ "dt_vencimento_recb": "05/06/2013",
11
+ "vl_emitido_recb": "24.90",
12
+ "vl_txmulta_recb": "",
13
+ "vl_txjuros_recb": "",
14
+ "encargos": [
15
+ {
16
+ "valorcorrigido": "24.9",
17
+ "diasatraso": "180",
18
+ "mesesatraso": "5",
19
+ "anosatraso": "0",
20
+ "cidade": "Ibiaçá"
21
+ }
22
+ ],
23
+ "link_2via": "http://touggweb-001.superlogica.net-001.superlogica.net/clients/extranet/cobranca/id/21?filename=touggweb-001&accesskey=e479383dd2aa47be5f1e81237729be3c&identificador=661"
24
+ }
25
+ ],
26
+ "id_sacado_sac": "40",
27
+ "st_sincro_sac": "661",
28
+ "st_nome_sac": "Capeta 1",
29
+ "dt_desativacao_sac": "",
30
+ "st_diavencimento_sac": "5",
31
+ "st_nomeref_sac": "Capeta Em Forma De Guri 1",
32
+ "st_cartaobandeira_sac": "",
33
+ "nome_formatado": "<span class=cliente><a class=identificador href='#'>661</a> - <a href=http://touggweb-001.superlogica.net/clients/financeiro/sacados/id/40?status=2><span class=nome>Capeta Em Forma De Guri 1</span></a></span>"
34
+ },
35
+ {
36
+ "recebimento": [
37
+ {
38
+ "id_recebimento_recb": "22",
39
+ "dt_vencimento_recb": "05/06/2013",
40
+ "vl_emitido_recb": "24.90",
41
+ "vl_txmulta_recb": "",
42
+ "vl_txjuros_recb": "",
43
+ "encargos": [
44
+ {
45
+ "valorcorrigido": "24.9",
46
+ "diasatraso": "180",
47
+ "mesesatraso": "5",
48
+ "anosatraso": "0",
49
+ "cidade": "Ibiaçá"
50
+ }
51
+ ],
52
+ "link_2via": "http://touggweb-001.superlogica.net-001.superlogica.net/clients/extranet/cobranca/id/22?filename=touggweb-001&accesskey=32af0ab3a4c7f9ded22ce2a386ad7c01&identificador=662"
53
+ }
54
+ ],
55
+ "id_sacado_sac": "45",
56
+ "st_sincro_sac": "662",
57
+ "st_nome_sac": "Paulo",
58
+ "dt_desativacao_sac": "",
59
+ "st_diavencimento_sac": "5",
60
+ "st_nomeref_sac": "Capeta Em Forma De Guri 2",
61
+ "st_cartaobandeira_sac": "",
62
+ "nome_formatado": "<span class=cliente><a class=identificador href='#'>662</a> - <a href=http://touggweb-001.superlogica.net/clients/financeiro/sacados/id/45?status=2><span class=nome>Capeta Em Forma De Guri 2</span></a></span>"
63
+ },
64
+ {
65
+ "recebimento": [
66
+ {
67
+ "id_recebimento_recb": "23",
68
+ "dt_vencimento_recb": "05/06/2013",
69
+ "vl_emitido_recb": "24.90",
70
+ "vl_txmulta_recb": "",
71
+ "vl_txjuros_recb": "",
72
+ "encargos": [
73
+ {
74
+ "valorcorrigido": "24.9",
75
+ "diasatraso": "180",
76
+ "mesesatraso": "5",
77
+ "anosatraso": "0",
78
+ "cidade": "Ibiaçá"
79
+ }
80
+ ],
81
+ "link_2via": "http://touggweb-001.superlogica.net-001.superlogica.net/clients/extranet/cobranca/id/23?filename=touggweb-001&accesskey=c566d9d02fc1a10041522ae7f9cca4ca&identificador=663"
82
+ }
83
+ ],
84
+ "id_sacado_sac": "46",
85
+ "st_sincro_sac": "663",
86
+ "st_nome_sac": "Maria",
87
+ "dt_desativacao_sac": "",
88
+ "st_diavencimento_sac": "5",
89
+ "st_nomeref_sac": "Capeta Em Forma De Guri 3",
90
+ "st_cartaobandeira_sac": "",
91
+ "nome_formatado": "<span class=cliente><a class=identificador href='#'>663</a> - <a href=http://touggweb-001.superlogica.net/clients/financeiro/sacados/id/46?status=2><span class=nome>Capeta Em Forma De Guri 3</span></a></span>"
92
+ },
93
+ {
94
+ "recebimento": [
95
+ {
96
+ "id_recebimento_recb": "24",
97
+ "dt_vencimento_recb": "05/06/2013",
98
+ "vl_emitido_recb": "24.90",
99
+ "vl_txmulta_recb": "",
100
+ "vl_txjuros_recb": "",
101
+ "encargos": [
102
+ {
103
+ "valorcorrigido": "24.9",
104
+ "diasatraso": "180",
105
+ "mesesatraso": "5",
106
+ "anosatraso": "0",
107
+ "cidade": "Ibiaçá"
108
+ }
109
+ ],
110
+ "link_2via": "http://touggweb-001.superlogica.net-001.superlogica.net/clients/extranet/cobranca/id/24?filename=touggweb-001&accesskey=1cbffab955aa0d018dfe7878f188f777&identificador=664"
111
+ }
112
+ ],
113
+ "id_sacado_sac": "47",
114
+ "st_sincro_sac": "664",
115
+ "st_nome_sac": "Joana",
116
+ "dt_desativacao_sac": "",
117
+ "st_diavencimento_sac": "5",
118
+ "st_nomeref_sac": "Capeta Em Forma De Guri 4",
119
+ "st_cartaobandeira_sac": "",
120
+ "nome_formatado": "<span class=cliente><a class=identificador href='#'>664</a> - <a href=http://touggweb-001.superlogica.net/clients/financeiro/sacados/id/47?status=2><span class=nome>Capeta Em Forma De Guri 4</span></a></span>"
121
+ }
122
+ ],
123
+ "executiontime": "0.1288s"
124
+ }
125
+
@@ -0,0 +1,72 @@
1
+ require 'helper'
2
+ require 'json'
3
+ require 'touggsl'
4
+ require 'touggsl_helper'
5
+
6
+ class TestAuth < Test::Unit::TestCase
7
+
8
+ def setup
9
+
10
+
11
+ url = "http://touggweb-001.superlogica.net/financeiro/atual/auth/post"
12
+
13
+
14
+ stub_request(:get, "http://touggweb-001.superlogica.net/financeiro/atual/auth/post").
15
+ to_return(:status => 401, :body => "", :headers => {'Set-Cookie' => "xpto"})
16
+
17
+ WebMock.stub_request(:post,url).
18
+ with(:body => {username: 'jack', password: 'secret'}).
19
+ to_return(:body => TouggHelper.json_success_auth)
20
+
21
+ WebMock.stub_request(:post,url).
22
+ with(:body => {username: 'invalid', password: 'invalid'}).
23
+ to_return(:body => TouggHelper.json_user_or_password_invalid)
24
+
25
+ Touggsl.set_uri("http://touggweb-001.superlogica.net/financeiro/atual/")
26
+ @auth = Touggsl::Auth
27
+ end
28
+
29
+ def test_login
30
+ json_return = @auth.login("jack", "secret")
31
+ assert_not_nil json_return["session"]
32
+ assert_equal json_return["session"], "secret_session111"
33
+ end
34
+
35
+ def test_login_status
36
+ json_return = @auth.login("jack", "secret")
37
+ assert_equal("202", json_return["status"])
38
+ end
39
+
40
+ def test_after_login_should_have_a_session
41
+ @auth.login("jack","secret")
42
+ assert_not_nil @auth.get_session
43
+ assert_equal @auth.get_session, "secret_session111"
44
+ end
45
+
46
+ def test_after_login_should_have_a_status
47
+ @auth.login("jack","secret")
48
+ assert_equal "202", @auth.get_status
49
+ end
50
+
51
+ def test_raise_exception_username_or_password_invalid
52
+ e = assert_raise RuntimeError do
53
+ @auth.login("invalid", "invalid")
54
+ end
55
+ assert_equal "Invalid username or password!", e.message
56
+ assert_equal "401", @auth.get_status
57
+ end
58
+
59
+ def test_session_should_be_nil_if_login_fail
60
+ assert_raise RuntimeError do
61
+ @auth.login("invalid","invalid")
62
+ end
63
+ assert_nil @auth.get_session
64
+ end
65
+
66
+ def test_should_have_a_cookie_after_authentication
67
+ @auth.login("jack", "secret")
68
+ assert_not_nil @auth.get_cookie
69
+ assert_equal "xpto", @auth.get_cookie
70
+ end
71
+
72
+ end
@@ -0,0 +1,82 @@
1
+ require 'helper'
2
+ require 'json'
3
+ require 'touggsl'
4
+ require 'touggsl_helper'
5
+ require './lib/touggsl/client'
6
+ class TestClient < Test::Unit::TestCase
7
+
8
+
9
+ def setup
10
+
11
+ Time.stubs(:now).returns(Time.mktime(2013,11,03))
12
+ stub_request(:get, "http://touggweb-001.superlogica.net/financeiro/atual/auth/post").
13
+ to_return(:status => 401, :body => "", :headers => {'Set-Cookie' => "xpto"})
14
+
15
+ url = "http://touggweb-001.superlogica.net/financeiro/atual/auth/post"
16
+ WebMock.stub_request(:post,url).
17
+ with(:body => {username: 'jack', password: 'secret'}).
18
+ to_return(:body => TouggHelper.json_success_auth)
19
+
20
+ auth = Touggsl::Auth
21
+ auth.login("jack", "secret")
22
+ @client = Touggsl::Client.new(auth)
23
+
24
+ end
25
+
26
+ def test_client_should_have_a_auth
27
+ assert_not_nil @client.auth
28
+ end
29
+
30
+ def test_create_new_client
31
+
32
+ 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 => {})
36
+
37
+ client_created = @client.create_new_client("0303030", "Jack", "Tougg")
38
+ assert_equal "200", client_created
39
+ end
40
+
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
+
48
+ plan_id = 2
49
+ client_id = 10
50
+ contract_id = 1000
51
+ plan = @client.hiring_plan(plan_id, client_id, contract_id)
52
+ assert_equal "200", plan
53
+ end
54
+
55
+ def test_try_hiring_plan_again
56
+ 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 => {})
60
+
61
+ plan_id = 2
62
+ client_id = 10
63
+ contract_id = 1000
64
+ plan = @client.hiring_plan(plan_id, client_id, contract_id)
65
+ assert_equal "Plano ja contratado para o cliente informado.", plan
66
+ end
67
+
68
+ def test_get_inadimplmentes
69
+ stub_request(:get, "http://touggweb-001.superlogica.net/financeiro/atual/inadimplencia/index").
70
+ with(:body => "posicaoEm=11%2F03%2F2013").
71
+ to_return(:status => 200, :body => TouggHelper.inadimplementes, :headers => {})
72
+
73
+ clients = @client.get_inadimplentes
74
+
75
+ assert_not_nil clients
76
+ assert_equal 4, clients.size
77
+ assert_equal "40", clients[0].client_id
78
+ segunda_via_cobranca = "http://touggweb-001.superlogica.net-001.superlogica.net/clients/extranet/cobranca/id/21?filename=touggweb-001&accesskey=e479383dd2aa47be5f1e81237729be3c&identificador=661"
79
+ assert_equal segunda_via_cobranca, clients[0].segunda_via_cobranca
80
+ end
81
+
82
+ end
@@ -0,0 +1,14 @@
1
+ require 'helper'
2
+ require 'json'
3
+ require 'touggsl'
4
+ require 'touggsl_helper'
5
+
6
+ class TestTouggsl< Test::Unit::TestCase
7
+
8
+ def test_have_uri
9
+ Touggsl.set_uri("http://tougg")
10
+ assert_not_nil Touggsl.get_uri
11
+ assert_equal "http://tougg", Touggsl.get_uri
12
+ end
13
+
14
+ end
@@ -0,0 +1,13 @@
1
+ require 'helper'
2
+ require 'json'
3
+ require 'touggsl/auth'
4
+ require 'version'
5
+ module Touggsl
6
+ class TestAuth < Test::Unit::TestCase
7
+
8
+
9
+ def test_version
10
+ assert_equal "0.1",Touggsl::VERSION
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,47 @@
1
+ class TouggHelper
2
+ def self.json_success_auth
3
+ "{\"status\":\"202\",\"session\":\"secret_session111\",
4
+ \"msg\":\"\",\"columns\":[\"id\",\"name\",\"md5logo\",
5
+ \"database\",\"errosschema\",\"APPLICATION_ENV\",
6
+ \"support_user_active\",\"app_version_server\",
7
+ \"app_version_db\",\"acessosUsr\",\"isCloud\"],
8
+ \"types\":[],\"data\":[[\"1\",\"email@company.com.br\",
9
+ \"\",\"\\/hiome\\/cloud-db\\/\\/login_db.fdb\",\"\",
10
+ \"testing\",\"\",\"123\",\"2323\",[\"1000\",\"1010\",
11
+ \"1031\",\"1041\",\"1061\",\"1060\",\"1071\",\"1070\",
12
+ \"1072\",\"1073\",\"1081\",\"1080\",\"1082\",\"1091\",
13
+ \"1090\",\"1200\",\"1201\",\"1221\",\"1220\",\"1231\",
14
+ \"1241\",\"1240\",\"1251\",\"1250\",\"1261\",\"1260\",
15
+ \"1270\",\"1290\",\"1300\"],\"1\"]],\"count\":\"1\",
16
+ \"executiontime\":\"0.6528s\"}"
17
+ end
18
+
19
+ def self.json_user_or_password_invalid
20
+ "{\"status\":\"401\",\"session\":\"kavfhjms5gt4sl5g96g1068h76\",\"msg\":\"Login ou senha incorreta.\",\"executiontime\":\"0.1695s\"}"
21
+ end
22
+
23
+ def self.success_create_client
24
+ json = <<CMD
25
+ {"multipleresponse":"1","status":"200","msg":"Todos os itens foram processados com sucesso.","data":[{"status":"200","msg":"Sucesso","data":{"st_nome_sac":"Capeta","st_nomeref_sac":"Capeta Em Forma De Guri","st_cgc_sac":"","st_email_sac":"","st_telefone_sac":"","st_endereco_sac":"","st_complemento_sac":"","st_cidade_sac":"","st_estado_sac":"","st_cep_sac":"","st_inscricao_sac":"","tx_observacao_sac":"","tx_contatos_sac":"","st_diavencimento_sac":"0","st_contrato_sac":"","dt_cadastro_sac":"11\/02\/2013","dt_alteracao_sincro":"","fl_desativar_sac":"0","id_sacado_sac":"39","st_sincro_sac":"666","st_codemp_sac":"","st_senha_sac":"","campo1":"","campo2":"","campo3":"","campo4":"","fl_status_sac":"","id_grupo_grp":"","st_sacadornome_sac":"","st_sacadorcgc_sac":"","st_sincroorder_sac":"000000000666","st_numero_sac":"","dt_desativacao_sac":"","dt_emissaorg_sac":"","st_sexo_sac":"","st_nacionalidade_sac":"","dt_nascimento_sac":"","st_naturalidade_sac":"","st_celular_sac":"","st_carteiraidentidade_sac":"","dt_emissaocarteira_sac":"","st_orgao_sac":"","st_numtituloeleitor_sac":"","st_titulozona_sac":"","st_titulosecao_sac":"","dt_emissaotitulo_sac":"","st_obssaude_sac":"","st_numcertidaonascimento_sac":"","st_distcertidaonascimento_sac":"","st_cmarcacertidaonascimento_sac":"","st_livrocertidaocasamento_sac":"","st_folhacertidaocasamento_sac":"","st_cartcertidaocasamento_sac":"","st_estadocartorio_sac":"","dt_certidaocasamento_sac":"","fl_situacaomilitar_sac":"","st_csmmilitar_sac":"","st_certmilitar_sac":"","st_rmmilitar_sac":"","dt_expedicaomilitar_sac":"","st_rg_sac":"","st_orgaoexpedicaomilitar_sac":"","fl_tipocertidao_sac":"","st_numcertidaonascasament_sac":"","st_distcertidaonascasament_sac":"","st_cmarcacertidaonascasamen_sac":"","st_livrocertidaonascasament_sac":"","st_folhacertidaonascasament_sac":"","st_cartcertidaonascasament_sac":"","st_estadocartorionascasamen_sac":"","st_bairro_sac":"","idraca":"0","nm_cartao_sac":"","nm_mescartaovencimento_sac":"","nm_anocartaovencimento_sac":"","st_cartaovencimento_sac":"","st_cartaotoken_sac":"","st_cartaoseguranca_sac":"","st_cartaobandeira_sac":"","st_inscmunicipal_sac":"","st_fax_sac":"","st_codigocontabil_sac":"","vl_txpis_sac":"","vl_txinss_sac":"","vl_txirrf_sac":"","vl_txcontribuicaosocial_sac":"","vl_txcofins_sac":"","fl_reterissqn_sac":"","fl_reterpis_sac":"","fl_reterinss_sac":"","fl_reterirrf_sac":"","fl_retercontribuicaosocial_sac":"","fl_retercofins_sac":"","fl_pessoajuridica_sac":"","id_crmidentificador_sac":"","fl_crmsincro_sac":"0"}}],"executiontime":"0.2428s"}
26
+ CMD
27
+ json
28
+ end
29
+
30
+ def self.success_hiring_plan
31
+ json =<<CMD
32
+ {"multipleresponse":"1","status":"200","msg":"Todos os itens foram processados com sucesso.","data":[{"status":"200","msg":"Plano contratado com sucesso.","data":{"id_sacado_sac":"35","id_plano_pla":"2","st_identificador_plc":"07","dt_contrato_plc":"11\/01\/2013","dt_cancelamento_plc":"","id_planocliente_plc":"30","fl_trial_plc":"","dt_trialfim_plc":"","dt_trialinicio_plc":"","fl_autocontratar_plc":"0","id_vendedor_for":"","st_emailindicacao_plc":"","columnidname":"2"}}],"executiontime":"0.685s"}
33
+ CMD
34
+ json
35
+ end
36
+
37
+ def self.hiring_plan_again
38
+ json =<<CMD
39
+ {"multipleresponse":"1","status":"206","msg":"Todos os 1 itens foram processados COM ERRO.","data":[{"status":"500","msg":"Essa empresa j\u00e1 contratou esse plano.","columnidname":""}],"executiontime":"0.2211s"}
40
+ CMD
41
+ json
42
+ end
43
+
44
+ def self.inadimplementes
45
+ File.read("./test/inadimplentes.json")
46
+ end
47
+ end
metadata ADDED
@@ -0,0 +1,196 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: touggsl
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Edipo Luis Federle
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-11-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: shoulda
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rdoc
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '3.12'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '3.12'
46
+ - !ruby/object:Gem::Dependency
47
+ name: httparty
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: mocha
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: json
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: bundler
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: '1.0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '1.0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: webmock
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: jeweler
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ~>
132
+ - !ruby/object:Gem::Version
133
+ version: 1.8.7
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ~>
140
+ - !ruby/object:Gem::Version
141
+ version: 1.8.7
142
+ description: Ruby code to access superlogica API
143
+ email: edipofederle@gmail.com
144
+ executables: []
145
+ extensions: []
146
+ extra_rdoc_files:
147
+ - LICENSE.txt
148
+ - README.rdoc
149
+ files:
150
+ - Gemfile
151
+ - Gemfile.lock
152
+ - LICENSE.txt
153
+ - README.rdoc
154
+ - Rakefile
155
+ - lib/touggsl.rb
156
+ - lib/touggsl/auth.rb
157
+ - lib/touggsl/client.rb
158
+ - lib/touggsl/models/client.rb
159
+ - lib/touggsl/request_helpers.rb
160
+ - lib/version.rb
161
+ - test/helper.rb
162
+ - test/inadimplentes.json
163
+ - test/touggsl/test_auth.rb
164
+ - test/touggsl/test_client.rb
165
+ - test/touggsl/test_touggsl.rb
166
+ - test/touggsl/test_version.rb
167
+ - test/touggsl_helper.rb
168
+ homepage: http://github.com/edipofederle/touggsl
169
+ licenses:
170
+ - MIT
171
+ post_install_message:
172
+ rdoc_options: []
173
+ require_paths:
174
+ - lib
175
+ required_ruby_version: !ruby/object:Gem::Requirement
176
+ none: false
177
+ requirements:
178
+ - - ! '>='
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ segments:
182
+ - 0
183
+ hash: -1935791911110106383
184
+ required_rubygems_version: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ requirements: []
191
+ rubyforge_project:
192
+ rubygems_version: 1.8.23
193
+ signing_key:
194
+ specification_version: 3
195
+ summary: Ruby code to access superlogica API
196
+ test_files: []