vpsa 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5b99996154201015b5360432b6b9d7e3c4e16027
4
- data.tar.gz: 748354d80ac6ccf7d6b934859cdc71864c777fff
3
+ metadata.gz: e6b4d8b0fed4ff40e9261960c1f8f0878a572479
4
+ data.tar.gz: ff9f391fa16f63ed859cb56b73a3b2a5cdbdf1eb
5
5
  SHA512:
6
- metadata.gz: 4b47d17b4185451b6e234b2b774a18e6871dd2b988b768b282f4ad93d31b8c263891c4daa98c185e997773afafa08a3247aa42736a6ba7fdeba1f0d2ec13c9a5
7
- data.tar.gz: 4053d2a534bd48c5541f82e0da010ddd41f71845cac5f19ca5e781e38d88465ca948461e0064a8b9742216b15e9b7d3e9b2b2320ecf1eca33c8a7cc2623cec9d
6
+ metadata.gz: 5adab1ea1aa5b44c6c3fd0f88e256612c4359e9c200eafdb3ced889e2baed84d208ce66ffe6f3701796b0c38e8c1feb9fcc63789f658efd6007303c42df038ff
7
+ data.tar.gz: 85a8a4b51fabec034bd3cf8abb5e4423939b72d74c4205ceed8dce48007b91b7309313f651c12346887e830cfc11348a2813e85203edb62ab30d8005cc189a70
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ .project
data/README.md CHANGED
@@ -30,7 +30,7 @@ Create a new instance of VPSA class passing your access token:
30
30
 
31
31
  With the client instance, you can access the following resources:
32
32
 
33
- * Terceiros (client.third_parties) **Listing and finding**
33
+ * Terceiros (client.third_parties) **Listing, finding and creation**
34
34
  * Entidades (client.entities) **Listing and finding**
35
35
  * Lançamentos Padrões (client.default_entries) **Listing and finding**
36
36
  * Provisões (client.provisions) **Only Creation**
@@ -0,0 +1,16 @@
1
+ module Vpsa
2
+ module Api
3
+ class CreditLimits < Client
4
+ require_all 'vpsa/searcher/commercial', 'credit_limit_searcher'
5
+
6
+ base_uri "https://www.vpsa.com.br/apps/api/limitescredito"
7
+
8
+ def list(searcher = nil)
9
+ raise ArgumentError unless searcher.nil? || searcher.is_a?(Vpsa::Searcher::Commercial::CreditLimitSearcher)
10
+
11
+ return parse_response(self.class.get("/", :body => build_body(searcher.as_parameter), :headers => header)) if searcher
12
+ return parse_response(self.class.get("/", :body => build_body, :headers => header)) unless searcher
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,27 +1,16 @@
1
1
  module Vpsa
2
2
  module Api
3
3
  class Installments < Client
4
- require_all 'vpsa/searcher/financial', 'installment_searcher'
4
+ require_all 'vpsa/entity/commercial', 'installment'
5
5
 
6
6
  base_uri "https://www.vpsa.com.br/apps/api/crediarios"
7
-
8
- def list(searcher = nil)
9
- raise ArgumentError unless searcher.nil? || searcher.is_a?(Vpsa::Searcher::Financial::InstallmentSearcher)
10
-
11
- return parse_response(self.class.get("/", :body => build_body(searcher.as_parameter), :headers => header)) if searcher
12
- return parse_response(self.class.get("/", :body => build_body, :headers => header)) unless searcher
13
- end
14
-
15
- def create(data)
7
+
8
+ def configure(data)
16
9
  return parse_response(self.class.post("/", :body => build_body(data), :headers => header))
17
10
  end
18
11
 
19
- def update(id, data)
20
- return parse_response(self.class.put("/#{id}", :body => build_body(data), :headers => header))
21
- end
22
-
23
- def find(id)
24
- return parse_response(self.class.get("/#{id}", :body => build_body, :headers => header))
12
+ def information
13
+ return parse_response(self.class.get("/", :body => build_body, :headers => header))
25
14
  end
26
15
  end
27
16
  end
@@ -6,6 +6,7 @@ module Vpsa
6
6
  def create(data)
7
7
  return parse_response(self.class.post("/", :body => build_body(data), :headers => header))
8
8
  end
9
+ alias :new :create
9
10
  end
10
11
  end
11
12
  end
@@ -3,6 +3,7 @@ module Vpsa
3
3
  class ThirdParties < Client
4
4
  require_all 'vpsa/searcher/administrative', 'third_party_searcher'
5
5
  require_all 'vpsa/entity/administrative', 'third_party', 'address', 'phone'
6
+ require_all 'vpsa/entity/commercial', 'credit_limit'
6
7
 
7
8
  base_uri "https://www.vpsa.com.br/apps/api/terceiros"
8
9
 
@@ -16,13 +17,31 @@ module Vpsa
16
17
  def find(id)
17
18
  return parse_response(self.class.get("/#{id}", :body => build_body, :headers => header))
18
19
  end
19
-
20
+
20
21
  def create(data)
21
22
  return parse_response(self.class.post("/", :body => build_body(data), :headers => header)) if data.is_a?(Hash)
22
23
  return parse_response(self.class.post("/", :body => build_body(data.as_parameter), :headers => header)) if data.is_a?(Vpsa::Entity::Administrative::ThirdParty)
23
24
  raise ArgumentError
24
25
  end
25
26
  alias :new :create
27
+
28
+ def credit_limit_information(id)
29
+ return parse_response(self.class.get("/#{id}/limites_credito", :body => build_body, :headers => header))
30
+ end
31
+
32
+ def update_credit_limit(id, data)
33
+ return parse_response(self.class.put("/#{id}/limites_credito", :body => build_body(data), :headers => header)) if data.is_a?(Hash)
34
+ return parse_response(self.class.put("/#{id}/limites_credito", :body => build_body(data.as_parameter), :headers => header)) if data.is_a?(Vpsa::Entity::Commercial::CreditLimit)
35
+ raise ArgumentError
36
+ end
37
+
38
+ def block_credit_limit(id, justification)
39
+ return parse_response(self.class.put("/#{id}/limites_credito/bloquear", :body => build_body({"justificativa" => justification}), :headers => header))
40
+ end
41
+
42
+ def unlock_credit_limit(id, justification)
43
+ return parse_response(self.class.put("/#{id}/limites_credito/desbloquear", :body => build_body({"justificativa" => justification}), :headers => header))
44
+ end
26
45
  end
27
46
  end
28
47
  end
data/lib/vpsa/client.rb CHANGED
@@ -8,7 +8,7 @@ module Vpsa
8
8
  default_options.update(verify: false)
9
9
  parser Proc.new {|b| JSON.parse(b) rescue b}
10
10
 
11
- require_all 'vpsa/api', 'third_parties', 'entities', 'default_entries', 'provisions', 'user_data', 'installments'
11
+ require_all 'vpsa/api', 'third_parties', 'entities', 'default_entries', 'provisions', 'user_data', 'installments', 'credit_limits'
12
12
 
13
13
  attr_accessor :access_token
14
14
 
@@ -40,6 +40,10 @@ module Vpsa
40
40
  def installments
41
41
  Vpsa::Api::Installments.new(@access_token)
42
42
  end
43
+
44
+ def credit_limits
45
+ Vpsa::Api::CreditLimits.new(@access_token)
46
+ end
43
47
 
44
48
  protected
45
49
  def header
@@ -0,0 +1,11 @@
1
+ require 'vpsa/entity/base'
2
+
3
+ module Vpsa
4
+ module Entity
5
+ module Commercial
6
+ class CreditLimit < Base
7
+ attr_accessor :total
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ require 'vpsa/entity/base'
2
+
3
+ module Vpsa
4
+ module Entity
5
+ module Commercial
6
+ class Installment < Base
7
+ attr_accessor :"bloquearSemAnalise", :bloqueio, :"mensagemBloqueio", :"liberarValorExcedente", :"liberarBloqueioManual", :"venderSemAnalise"
8
+ attr_accessor :"creditoMaximoPorCliente", :"valorCreditoMaximoPorCliente", :"calculoValorCredito", :"limiteMensalMaximo"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -4,7 +4,7 @@ module Vpsa
4
4
  module Searcher
5
5
  module Administrative
6
6
  class ThirdPartySearcher < Base
7
- attr_accessor :classes, :"alteradoApos", :documento
7
+ attr_accessor :classes, :"alteradoApos", :documento, :nome
8
8
  end
9
9
  end
10
10
  end
@@ -0,0 +1,11 @@
1
+ require 'vpsa/searcher/base'
2
+
3
+ module Vpsa
4
+ module Searcher
5
+ module Commercial
6
+ class CreditLimitSearcher < Base
7
+ attr_accessor :classes, :"idTerceiro", :endereco, :uf, :cidade, :email
8
+ end
9
+ end
10
+ end
11
+ end
data/lib/vpsa/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Vpsa
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Vpsa::Api::CreditLimits do
4
+ let(:header) {{"Content-Type" => "application/json", "Accept" => "application/json"}}
5
+
6
+ describe "listing" do
7
+ before(:each) do
8
+ stub_request(:get, "https://www.vpsa.com.br/apps/api/limitescredito/").to_return(:status => 200)
9
+ end
10
+
11
+ it "should issue a get to the credit_limits url" do
12
+ expect(Vpsa::Api::CreditLimits).to receive(:get).with("/", :body => {:token => "abc"}.to_json, :headers => header).and_call_original
13
+
14
+ Vpsa.new("abc").credit_limits.list()
15
+ end
16
+
17
+ it "should issue a get to the credit_limits url using the searcher" do
18
+ searcher = Vpsa::Searcher::Commercial::CreditLimitSearcher.new({:quantidade => 10, :inicio => 0})
19
+
20
+ expect(Vpsa::Api::CreditLimits).to receive(:get).with("/", :body => searcher.as_parameter.merge!({:token => "abc"}).to_json, :headers => header).and_call_original
21
+
22
+ Vpsa.new("abc").credit_limits.list(searcher)
23
+ end
24
+
25
+ it "should raise ArgumentError if the parameter is not a CreditLimitSearcher" do
26
+ expect{Vpsa.new("abc").credit_limits.list(Array.new)}.to raise_error(ArgumentError)
27
+ end
28
+ end
29
+ end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  RSpec.describe Vpsa::Api::Installments do
4
4
  let(:header) {{"Content-Type" => "application/json", "Accept" => "application/json"}}
5
5
 
6
- describe "listing" do
6
+ describe "information" do
7
7
  before(:each) do
8
8
  stub_request(:get, "https://www.vpsa.com.br/apps/api/crediarios/").to_return(:status => 200)
9
9
  end
@@ -11,15 +11,11 @@ RSpec.describe Vpsa::Api::Installments do
11
11
  it "should issue a get to the installments url" do
12
12
  expect(Vpsa::Api::Installments).to receive(:get).with("/", :body => {:token => "abc"}.to_json, :headers => header).and_call_original
13
13
 
14
- Vpsa.new("abc").installments.list
15
- end
16
-
17
- it "should raise ArgumentError if the parameter is not a InstallmentSearcher" do
18
- expect{Vpsa.new("abc").installments.list(Array.new)}.to raise_error(ArgumentError)
14
+ Vpsa.new("abc").installments.information
19
15
  end
20
16
  end
21
17
 
22
- describe "creation" do
18
+ describe "configuration" do
23
19
  before(:each) do
24
20
  stub_request(:post, "https://www.vpsa.com.br/apps/api/crediarios/").to_return(:status => 201)
25
21
  end
@@ -29,33 +25,7 @@ RSpec.describe Vpsa::Api::Installments do
29
25
  it "should issue a post to the installments url" do
30
26
  expect(Vpsa::Api::Installments).to receive(:post).with("/", :body => installment_param.merge!({:token => "abc"}).to_json, :headers => header).and_call_original
31
27
 
32
- Vpsa.new("abc").installments.create(installment_param)
33
- end
34
- end
35
-
36
- describe "updating" do
37
- before(:each) do
38
- stub_request(:put, "https://www.vpsa.com.br/apps/api/crediarios/1").to_return(:status => 200)
39
- end
40
-
41
- let(:installment_param) {{}}
42
-
43
- it "should issue a put to the installments url" do
44
- expect(Vpsa::Api::Installments).to receive(:put).with("/1", :body => installment_param.merge!({:token => "abc"}).to_json, :headers => header).and_call_original
45
-
46
- Vpsa.new("abc").installments.update(1, installment_param)
47
- end
48
- end
49
-
50
- describe "finding" do
51
- before(:each) do
52
- stub_request(:get, "https://www.vpsa.com.br/apps/api/crediarios/5").to_return(:status => 200)
53
- end
54
-
55
- it "should issue a get to the installment url" do
56
- expect(Vpsa::Api::Installments).to receive(:get).with("/5", :body => {:token => "abc"}.to_json, :headers => header).and_call_original
57
-
58
- Vpsa.new("abc").installments.find(5)
28
+ Vpsa.new("abc").installments.configure(installment_param)
59
29
  end
60
30
  end
61
31
  end
@@ -83,4 +83,78 @@ RSpec.describe Vpsa::Api::ThirdParties do
83
83
  end
84
84
  end
85
85
  end
86
- end
86
+
87
+ describe "credit limit" do
88
+ context "information" do
89
+ before(:each) do
90
+ stub_request(:get, "https://www.vpsa.com.br/apps/api/terceiros/5/limites_credito").to_return(:status => 200)
91
+ end
92
+
93
+ it "should issue a get to the third party credit limit url" do
94
+ expect(Vpsa::Api::ThirdParties).to receive(:get).with("/5/limites_credito", :body => {:token => "abc"}.to_json, :headers => header).and_call_original
95
+
96
+ Vpsa.new("abc").third_parties.credit_limit_information(5)
97
+ end
98
+ end
99
+
100
+ context "modification" do
101
+ let(:credit_limit_params) {{"total" => BigDecimal.new("154.32"), :token => "abc"}}
102
+
103
+ before(:each) do
104
+ @credit_limit = Vpsa::Entity::Commercial::CreditLimit.new({"total" => BigDecimal.new("154.32")})
105
+
106
+ stub_request(:put, "https://www.vpsa.com.br/apps/api/terceiros/5/limites_credito").to_return(:status => 200)
107
+ end
108
+
109
+ describe "with raw parameters" do
110
+ it "should put to the third party credit limit url" do
111
+ expect(Vpsa::Api::ThirdParties).to receive(:put).with("/5/limites_credito", :body => credit_limit_params.to_json, :headers => header).and_call_original
112
+
113
+ Vpsa.new("abc").third_parties.update_credit_limit(5, {"total" => BigDecimal.new("154.32")})
114
+ end
115
+ end
116
+
117
+ describe "with entity parameter" do
118
+ it "should put to the third party credit limit url" do
119
+ expect(Vpsa::Api::ThirdParties).to receive(:put).with("/5/limites_credito", :body => @credit_limit.as_parameter.merge!(:token => "abc").to_json, :headers => header).and_call_original
120
+
121
+ Vpsa.new("abc").third_parties.update_credit_limit(5, @credit_limit)
122
+ end
123
+ end
124
+
125
+ describe "with invalid parameter" do
126
+ it "should raise ArgumentError when passing neither a Hash nor a CreditLimit" do
127
+ expect{Vpsa.new("abc").third_parties.update_credit_limit(5, Array.new)}.to raise_error(ArgumentError)
128
+ end
129
+ end
130
+ end
131
+
132
+ context "blocking" do
133
+ let(:credit_limit_block_params) {{"justificativa" => "Cliente caloteiro", :token => "abc"}}
134
+
135
+ before(:each) do
136
+ stub_request(:put, "https://www.vpsa.com.br/apps/api/terceiros/5/limites_credito/bloquear").to_return(:status => 200)
137
+ end
138
+
139
+ it "should put to the third party credit block url" do
140
+ expect(Vpsa::Api::ThirdParties).to receive(:put).with("/5/limites_credito/bloquear", :body => credit_limit_block_params.to_json, :headers => header).and_call_original
141
+
142
+ Vpsa.new("abc").third_parties.block_credit_limit(5, "Cliente caloteiro")
143
+ end
144
+ end
145
+
146
+ context "unlocking" do
147
+ let(:credit_limit_unlock_params) {{"justificativa" => "Cliente pagou", :token => "abc"}}
148
+
149
+ before(:each) do
150
+ stub_request(:put, "https://www.vpsa.com.br/apps/api/terceiros/5/limites_credito/desbloquear").to_return(:status => 200)
151
+ end
152
+
153
+ it "should put to the third party credit unlock url" do
154
+ expect(Vpsa::Api::ThirdParties).to receive(:put).with("/5/limites_credito/desbloquear", :body => credit_limit_unlock_params.to_json, :headers => header).and_call_original
155
+
156
+ Vpsa.new("abc").third_parties.unlock_credit_limit(5, "Cliente pagou")
157
+ end
158
+ end
159
+ end
160
+ end
@@ -24,4 +24,8 @@ RSpec.describe Vpsa::Client do
24
24
  it "should return a new Vpsa::Api::Installments" do
25
25
  expect(Vpsa.new("abc").installments.class).to eq(Vpsa::Api::Installments)
26
26
  end
27
+
28
+ it "should return a new Vpsa::Api::CreditLimits" do
29
+ expect(Vpsa.new("abc").credit_limits.class).to eq(Vpsa::Api::CreditLimits)
30
+ end
27
31
  end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Vpsa::Entity::Commercial::CreditLimit do
4
+ describe "as_parameter" do
5
+ let(:credit_limit_as_parameter) {{"total" => BigDecimal.new("1000.53")}}
6
+
7
+ it "should return the installment as parameter" do
8
+ credit_limit = Vpsa::Entity::Commercial::CreditLimit.new({"total" => BigDecimal.new("1000.53")})
9
+
10
+ expect(credit_limit.as_parameter).to eq(credit_limit_as_parameter)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Vpsa::Entity::Commercial::Installment do
4
+ describe "as_parameter" do
5
+ let(:installment_as_parameter) {{"bloquearSemAnalise" => true, "bloqueio" => "MANUAL", "mensagemBloqueio" => "Seu crédito está bloqueado! :(",
6
+ "liberarValorExcedente" => false, "liberarBloqueioManual" => true, "venderSemAnalise" => false, "creditoMaximoPorCliente" => true,
7
+ "valorCreditoMaximoPorCliente" => BigDecimal.new("1000.35"), "calculoValorCredito" => "LIMITE_SOBRE_RENDA",
8
+ "limiteMensalMaximo" => "SOBRE_TOTAL_DE_CREDITO"}}
9
+
10
+ it "should return the installment as parameter" do
11
+ installment = Vpsa::Entity::Commercial::Installment.new({"bloquearSemAnalise" => true, "bloqueio" => "MANUAL", "mensagemBloqueio" => "Seu crédito está bloqueado! :(",
12
+ "liberarValorExcedente" => false, "liberarBloqueioManual" => true, "venderSemAnalise" => false, "creditoMaximoPorCliente" => true,
13
+ "valorCreditoMaximoPorCliente" => BigDecimal.new("1000.35"), "calculoValorCredito" => "LIMITE_SOBRE_RENDA",
14
+ "limiteMensalMaximo" => "SOBRE_TOTAL_DE_CREDITO"})
15
+
16
+ expect(installment.as_parameter).to eq(installment_as_parameter)
17
+ end
18
+ end
19
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vpsa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gustavo Berdugo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-05 00:00:00.000000000 Z
11
+ date: 2015-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -53,6 +53,7 @@ files:
53
53
  - README.md
54
54
  - Rakefile
55
55
  - lib/vpsa.rb
56
+ - lib/vpsa/api/credit_limits.rb
56
57
  - lib/vpsa/api/default_entries.rb
57
58
  - lib/vpsa/api/entities.rb
58
59
  - lib/vpsa/api/installments.rb
@@ -64,14 +65,17 @@ files:
64
65
  - lib/vpsa/entity/administrative/phone.rb
65
66
  - lib/vpsa/entity/administrative/third_party.rb
66
67
  - lib/vpsa/entity/base.rb
68
+ - lib/vpsa/entity/commercial/credit_limit.rb
69
+ - lib/vpsa/entity/commercial/installment.rb
67
70
  - lib/vpsa/init_from_hash.rb
68
71
  - lib/vpsa/searcher/administrative/entity_searcher.rb
69
72
  - lib/vpsa/searcher/administrative/third_party_searcher.rb
70
73
  - lib/vpsa/searcher/base.rb
74
+ - lib/vpsa/searcher/commercial/credit_limit_searcher.rb
71
75
  - lib/vpsa/searcher/financial/default_entry_searcher.rb
72
- - lib/vpsa/searcher/financial/installment_searcher.rb
73
76
  - lib/vpsa/version.rb
74
77
  - spec/spec_helper.rb
78
+ - spec/vpsa/api/credit_limits_spec.rb
75
79
  - spec/vpsa/api/default_entries_spec.rb
76
80
  - spec/vpsa/api/entities_spec.rb
77
81
  - spec/vpsa/api/installments_spec.rb
@@ -82,6 +86,8 @@ files:
82
86
  - spec/vpsa/entity/administrative/address_spec.rb
83
87
  - spec/vpsa/entity/administrative/phone_spec.rb
84
88
  - spec/vpsa/entity/administrative/third_party_spec.rb
89
+ - spec/vpsa/entity/commercial/credit_limit_spec.rb
90
+ - spec/vpsa/entity/commercial/installment_spec.rb
85
91
  - spec/vpsa_spec.rb
86
92
  - vpsa.gemspec
87
93
  homepage: https://github.com/coyosoftware/vpsa
@@ -110,6 +116,7 @@ specification_version: 4
110
116
  summary: This gem provides integration with VPSA APIs (http://www.vpsa.com.br/)
111
117
  test_files:
112
118
  - spec/spec_helper.rb
119
+ - spec/vpsa/api/credit_limits_spec.rb
113
120
  - spec/vpsa/api/default_entries_spec.rb
114
121
  - spec/vpsa/api/entities_spec.rb
115
122
  - spec/vpsa/api/installments_spec.rb
@@ -120,4 +127,6 @@ test_files:
120
127
  - spec/vpsa/entity/administrative/address_spec.rb
121
128
  - spec/vpsa/entity/administrative/phone_spec.rb
122
129
  - spec/vpsa/entity/administrative/third_party_spec.rb
130
+ - spec/vpsa/entity/commercial/credit_limit_spec.rb
131
+ - spec/vpsa/entity/commercial/installment_spec.rb
123
132
  - spec/vpsa_spec.rb
@@ -1,10 +0,0 @@
1
- require 'vpsa/searcher/base'
2
-
3
- module Vpsa
4
- module Searcher
5
- module Financial
6
- class InstallmentSearcher < Base
7
- end
8
- end
9
- end
10
- end