vpsa 0.0.4 → 0.0.5

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: d42eeb55ced6f3b44bd295c4786d44e6176bfaee
4
- data.tar.gz: 8b10170e20589348d809ac80a87e4ff1c4c4c8be
3
+ metadata.gz: 5b99996154201015b5360432b6b9d7e3c4e16027
4
+ data.tar.gz: 748354d80ac6ccf7d6b934859cdc71864c777fff
5
5
  SHA512:
6
- metadata.gz: e6fbd66525743aa3ab20e6d752d4481a9f654210c40dd54a51580ac220bf63f5e1a2c738d6122d51db7f78d0176f4ba86ca94cf943a669b7dd4a6f81e9659493
7
- data.tar.gz: b92d12c5223776b7287dd2f075ffc1b44f51e837cd8ed5180624dd8bfeb968070fe531e0600d6423e36d14ebc456b149f0b8822e7075411a729c532167d59ec6
6
+ metadata.gz: 4b47d17b4185451b6e234b2b774a18e6871dd2b988b768b282f4ad93d31b8c263891c4daa98c185e997773afafa08a3247aa42736a6ba7fdeba1f0d2ec13c9a5
7
+ data.tar.gz: 4053d2a534bd48c5541f82e0da010ddd41f71845cac5f19ca5e781e38d88465ca948461e0064a8b9742216b15e9b7d3e9b2b2320ecf1eca33c8a7cc2623cec9d
@@ -2,6 +2,7 @@ module Vpsa
2
2
  module Api
3
3
  class ThirdParties < Client
4
4
  require_all 'vpsa/searcher/administrative', 'third_party_searcher'
5
+ require_all 'vpsa/entity/administrative', 'third_party', 'address', 'phone'
5
6
 
6
7
  base_uri "https://www.vpsa.com.br/apps/api/terceiros"
7
8
 
@@ -15,6 +16,13 @@ module Vpsa
15
16
  def find(id)
16
17
  return parse_response(self.class.get("/#{id}", :body => build_body, :headers => header))
17
18
  end
19
+
20
+ def create(data)
21
+ return parse_response(self.class.post("/", :body => build_body(data), :headers => header)) if data.is_a?(Hash)
22
+ return parse_response(self.class.post("/", :body => build_body(data.as_parameter), :headers => header)) if data.is_a?(Vpsa::Entity::Administrative::ThirdParty)
23
+ raise ArgumentError
24
+ end
25
+ alias :new :create
18
26
  end
19
27
  end
20
28
  end
@@ -0,0 +1,11 @@
1
+ require 'vpsa/entity/base'
2
+
3
+ module Vpsa
4
+ module Entity
5
+ module Administrative
6
+ class Address < Base
7
+ attr_accessor :tipo, :logradouro, :numero, :bairro, :complemento, :cep, :codigoIBGECidade, :tipoEndereco
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'vpsa/entity/base'
2
+
3
+ module Vpsa
4
+ module Entity
5
+ module Administrative
6
+ class Phone < Base
7
+ attr_accessor :ddi, :ddd, :numero, :ramal
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,33 @@
1
+ require 'vpsa/entity/base'
2
+
3
+ module Vpsa
4
+ module Entity
5
+ module Administrative
6
+ class ThirdParty < Base
7
+ attr_accessor :id, :nome, :documento, :emails, :rg, :dataNascimento, :ie, :enderecos, :telefones, :classes
8
+
9
+ def initialize(*h)
10
+ self.emails = Array.new
11
+ self.enderecos = Array.new
12
+ self.telefones = Array.new
13
+ self.classes = Array.new
14
+
15
+ super
16
+ end
17
+
18
+ def as_parameter
19
+ variables = instance_variables.map do |name|
20
+ case name
21
+ when :@enderecos, :@telefones
22
+ [name.to_s.tr("@", ""), instance_variable_get(name).map(&:as_parameter)]
23
+ else
24
+ [name.to_s.tr("@", ""), instance_variable_get(name)]
25
+ end
26
+ end
27
+
28
+ Hash[variables.compact]
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,3 +1,3 @@
1
1
  module Vpsa
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -38,4 +38,49 @@ RSpec.describe Vpsa::Api::ThirdParties do
38
38
  Vpsa.new("abc").third_parties.find(5)
39
39
  end
40
40
  end
41
+
42
+ describe "creating" do
43
+ let(:third_party_params) {{:nome => "Nome do terceiro", :documento => "023.168.132-00", :token => "abc"}}
44
+
45
+ before(:each) do
46
+ @third_party = Vpsa::Entity::Administrative::ThirdParty.new({"id" => "5", "nome" => "Nome do terceiro", "documento" => "023.168.132-00",
47
+ "rg" => "42.943.412-1", "dataNascimento" => "12-08-1980"})
48
+
49
+ @third_party.emails = ["email@email.com", "other@email.com"]
50
+
51
+ @third_party.enderecos << Vpsa::Entity::Administrative::Address.new({"tipo" => "AVENIDA", "logradouro" => "9 de Julho", "numero" => "900", "bairro" => "CENTRO",
52
+ "complemento" => "APTO 1", "cep" => "12000111", "codigoIBGECidade" => "3554102", "tipoEndereco" => "ENDERECO_COBRANCA"})
53
+ @third_party.enderecos << Vpsa::Entity::Administrative::Address.new({"tipo" => "RUA", "logradouro" => "15 de Novembro", "numero" => "1020", "bairro" => "JD. MARIA",
54
+ "complemento" => "APTO 1", "cep" => "12600123", "codigoIBGECidade" => "3554102", "tipoEndereco" => "ENDERECO_SEDE"})
55
+
56
+ @third_party.telefones << Vpsa::Entity::Administrative::Phone.new({"ddi" => "55", "ddd" => "12", "numero" => "12341234"})
57
+ @third_party.telefones << Vpsa::Entity::Administrative::Phone.new({"ddi" => "0", "ddd" => "31", "numero" => "12340000", "ramal" => "1234"})
58
+
59
+ @third_party.classes = ["SOCIO_PROPRIETARIO", "FUNCIONARIO"]
60
+
61
+ stub_request(:post, "https://www.vpsa.com.br/apps/api/terceiros/").to_return(:status => 201)
62
+ end
63
+
64
+ describe "with raw parameters" do
65
+ it "should post to the third party url" do
66
+ expect(Vpsa::Api::ThirdParties).to receive(:post).with("/", :body => third_party_params.to_json, :headers => header).and_call_original
67
+
68
+ Vpsa.new("abc").third_parties.create({:nome => "Nome do terceiro", :documento => "023.168.132-00"})
69
+ end
70
+ end
71
+
72
+ describe "with entity parameter" do
73
+ it "should post to the third party url" do
74
+ expect(Vpsa::Api::ThirdParties).to receive(:post).with("/", :body => @third_party.as_parameter.merge!(:token => "abc").to_json, :headers => header).and_call_original
75
+
76
+ Vpsa.new("abc").third_parties.create(@third_party)
77
+ end
78
+ end
79
+
80
+ describe "with invalid parameter" do
81
+ it "should raise ArgumentError when passing neither a Hash nor a ThirdParty" do
82
+ expect{Vpsa.new("abc").third_parties.create(Array.new)}.to raise_error(ArgumentError)
83
+ end
84
+ end
85
+ end
41
86
  end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Vpsa::Entity::Administrative::Address do
4
+ describe "as_parameter" do
5
+ let(:address_as_parameter) {{"tipo" => "AVENIDA", "logradouro" => "9 de Julho", "numero" => "900",
6
+ "bairro" => "CENTRO", "complemento" => "APTO 1", "cep" => "12244111", "codigoIBGECidade" => "3554102", "tipoEndereco" => "ENDERECO_COBRANCA"}}
7
+
8
+ it "should return the address as parameter" do
9
+ address = Vpsa::Entity::Administrative::Address.new
10
+
11
+ address.tipo = "AVENIDA"
12
+ address.logradouro = "9 de Julho"
13
+ address.numero = "900"
14
+ address.bairro = "CENTRO"
15
+ address.complemento = "APTO 1"
16
+ address.cep = "12244111"
17
+ address.codigoIBGECidade = "3554102"
18
+ address.tipoEndereco = "ENDERECO_COBRANCA"
19
+
20
+ expect(address.as_parameter).to eq(address_as_parameter)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Vpsa::Entity::Administrative::Phone do
4
+ describe "as_parameter" do
5
+ let(:phone_as_parameter) {{"ddi" => "55", "ddd" => "12", "numero" => "12340000", "ramal" => "1269"}}
6
+
7
+ it "should return the phone as parameter" do
8
+ phone = Vpsa::Entity::Administrative::Phone.new
9
+
10
+ phone.ddi = "55"
11
+ phone.ddd = "12"
12
+ phone.numero = "12340000"
13
+ phone.ramal = "1269"
14
+
15
+ expect(phone.as_parameter).to eq(phone_as_parameter)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Vpsa::Entity::Administrative::ThirdParty do
4
+ describe "as_parameter" do
5
+ let(:third_party_as_parameter) {{"id" => "5", "nome" => "Nome do terceiro", "documento" => "023.168.132-00", "emails" => ["email@email.com", "other@email.com"],
6
+ "rg" => "42.943.412-1", "dataNascimento" => "12-08-1980", "enderecos" => [{"tipo" => "AVENIDA", "logradouro" => "9 de Julho", "numero" => "900", "bairro" => "CENTRO",
7
+ "complemento" => "APTO 1", "cep" => "12000111", "codigoIBGECidade" => "3554102", "tipoEndereco" => "ENDERECO_COBRANCA"}, {"tipo" => "RUA",
8
+ "logradouro" => "15 de Novembro", "numero" => "1020", "bairro" => "JD. MARIA", "complemento" => "APTO 1", "cep" => "12600123", "codigoIBGECidade" => "3554102",
9
+ "tipoEndereco" => "ENDERECO_SEDE"}], "telefones" => [{"ddi" => "55", "ddd" => "12", "numero" => "12341234"}, {"ddi" => "0", "ddd" => "31", "numero" => "12340000",
10
+ "ramal" => "1234"}], "classes" => ["SOCIO_PROPRIETARIO", "FUNCIONARIO"]}}
11
+
12
+ it "should return the third party as parameter" do
13
+ third_party = Vpsa::Entity::Administrative::ThirdParty.new({"id" => "5", "nome" => "Nome do terceiro", "documento" => "023.168.132-00",
14
+ "rg" => "42.943.412-1", "dataNascimento" => "12-08-1980"})
15
+
16
+ third_party.emails = ["email@email.com", "other@email.com"]
17
+
18
+ third_party.enderecos << Vpsa::Entity::Administrative::Address.new({"tipo" => "AVENIDA", "logradouro" => "9 de Julho", "numero" => "900", "bairro" => "CENTRO",
19
+ "complemento" => "APTO 1", "cep" => "12000111", "codigoIBGECidade" => "3554102", "tipoEndereco" => "ENDERECO_COBRANCA"})
20
+ third_party.enderecos << Vpsa::Entity::Administrative::Address.new({"tipo" => "RUA", "logradouro" => "15 de Novembro", "numero" => "1020", "bairro" => "JD. MARIA",
21
+ "complemento" => "APTO 1", "cep" => "12600123", "codigoIBGECidade" => "3554102", "tipoEndereco" => "ENDERECO_SEDE"})
22
+
23
+ third_party.telefones << Vpsa::Entity::Administrative::Phone.new({"ddi" => "55", "ddd" => "12", "numero" => "12341234"})
24
+ third_party.telefones << Vpsa::Entity::Administrative::Phone.new({"ddi" => "0", "ddd" => "31", "numero" => "12340000", "ramal" => "1234"})
25
+
26
+ third_party.classes = ["SOCIO_PROPRIETARIO", "FUNCIONARIO"]
27
+
28
+ expect(third_party.as_parameter).to eq(third_party_as_parameter)
29
+ end
30
+ end
31
+ 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.4
4
+ version: 0.0.5
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-02 00:00:00.000000000 Z
11
+ date: 2015-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -60,6 +60,9 @@ files:
60
60
  - lib/vpsa/api/third_parties.rb
61
61
  - lib/vpsa/api/user_data.rb
62
62
  - lib/vpsa/client.rb
63
+ - lib/vpsa/entity/administrative/address.rb
64
+ - lib/vpsa/entity/administrative/phone.rb
65
+ - lib/vpsa/entity/administrative/third_party.rb
63
66
  - lib/vpsa/entity/base.rb
64
67
  - lib/vpsa/init_from_hash.rb
65
68
  - lib/vpsa/searcher/administrative/entity_searcher.rb
@@ -76,6 +79,9 @@ files:
76
79
  - spec/vpsa/api/third_parties_spec.rb
77
80
  - spec/vpsa/api/user_data_spec.rb
78
81
  - spec/vpsa/client_spec.rb
82
+ - spec/vpsa/entity/administrative/address_spec.rb
83
+ - spec/vpsa/entity/administrative/phone_spec.rb
84
+ - spec/vpsa/entity/administrative/third_party_spec.rb
79
85
  - spec/vpsa_spec.rb
80
86
  - vpsa.gemspec
81
87
  homepage: https://github.com/coyosoftware/vpsa
@@ -111,4 +117,7 @@ test_files:
111
117
  - spec/vpsa/api/third_parties_spec.rb
112
118
  - spec/vpsa/api/user_data_spec.rb
113
119
  - spec/vpsa/client_spec.rb
120
+ - spec/vpsa/entity/administrative/address_spec.rb
121
+ - spec/vpsa/entity/administrative/phone_spec.rb
122
+ - spec/vpsa/entity/administrative/third_party_spec.rb
114
123
  - spec/vpsa_spec.rb