myfinance-rails 0.0.3 → 0.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.
- checksums.yaml +4 -4
- data/lib/myfinance/pessoa.rb +9 -1
- data/lib/myfinance/version.rb +1 -1
- data/lib/myfinance.rb +15 -4
- data/spec/features/contas_a_receber_spec.rb +9 -4
- data/spec/features/pessoas_spec.rb +11 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ae5852aa35e41081d6d38dffe06d0bb8fe30547
|
4
|
+
data.tar.gz: 25bbe5ec5c93cffdf8f7432b580d3b91b2de316d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53417d713c4bf7a3ff364f00fe489e52bd8ccc08298828ce9d569fbf998b26726fffd47cbb76e334205dedf5504b05b690d876512cda13f986d8d2c17632a8e5
|
7
|
+
data.tar.gz: fa72cad1490acda1e6c84936cc789d9033d534cf9595d8ff6432ab9bd88988e71b489522e4a0a9bc3452cb3927d5cdb8b67f9dd137ddd3e762025177a198a7d6
|
data/lib/myfinance/pessoa.rb
CHANGED
@@ -16,7 +16,7 @@ module Myfinance
|
|
16
16
|
def self.pessoa(cnpj)
|
17
17
|
mid = pessoa_id(cnpj)
|
18
18
|
response = lget "/people/#{mid}.json"
|
19
|
-
response['
|
19
|
+
response['person'] if response
|
20
20
|
end
|
21
21
|
|
22
22
|
def self.cria_pessoa( pessoa )
|
@@ -25,5 +25,13 @@ module Myfinance
|
|
25
25
|
lpost '/people.json', people
|
26
26
|
end
|
27
27
|
|
28
|
+
def self.atualiza_pessoa( people_id, pessoa )
|
29
|
+
# Vou rezar para que de certo
|
30
|
+
# people = { 'person' => pessoa }
|
31
|
+
lput "/people/#{people_id}.json", pessoa
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
|
28
36
|
end
|
29
37
|
|
data/lib/myfinance/version.rb
CHANGED
data/lib/myfinance.rb
CHANGED
@@ -6,6 +6,7 @@ require 'myfinance/conta_a_receber'
|
|
6
6
|
require 'myfinance/imposto'
|
7
7
|
require 'myfinance/categoria'
|
8
8
|
require 'myfinance/centro_receita_custo'
|
9
|
+
require 'json'
|
9
10
|
|
10
11
|
module Myfinance
|
11
12
|
|
@@ -24,8 +25,8 @@ module Myfinance
|
|
24
25
|
# testo com uma chamada simples
|
25
26
|
response = lget('/entities.json')
|
26
27
|
# Resposta deve ser um array de hashes
|
27
|
-
unless response.
|
28
|
-
raise "Erro ao inicializar a API do MyFinance: #{response}"
|
28
|
+
unless response.code == 200
|
29
|
+
raise "Erro ao inicializar a API do MyFinance: #{response.code} : #{response.parsed_response}"
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
@@ -38,16 +39,26 @@ module Myfinance
|
|
38
39
|
get url, options
|
39
40
|
end
|
40
41
|
|
41
|
-
def self.lpost(url,
|
42
|
+
def self.lpost(url,post_data)
|
42
43
|
options = {
|
43
44
|
:basic_auth => {:username => @token, :password => 'x'},
|
44
|
-
:body =>
|
45
|
+
:body => post_data.to_json,
|
45
46
|
:headers => { 'Content-Type' => 'application/json' }
|
46
47
|
}
|
47
48
|
response = post url, options
|
48
49
|
response
|
49
50
|
end
|
50
51
|
|
52
|
+
def self.lput(url,post_data)
|
53
|
+
options = {
|
54
|
+
:basic_auth => {:username => @token, :password => 'x'},
|
55
|
+
:body => post_data.to_json,
|
56
|
+
:headers => { 'Content-Type' => 'application/json' }
|
57
|
+
}
|
58
|
+
response = put url, options
|
59
|
+
response
|
60
|
+
end
|
61
|
+
|
51
62
|
def self.format_time(dt)
|
52
63
|
dt.strftime('%FT%H:%MZ') rescue nil
|
53
64
|
end
|
@@ -2,6 +2,14 @@ describe 'Manipulando Contas a Receber', type: :feature do
|
|
2
2
|
|
3
3
|
require 'myfinance'
|
4
4
|
|
5
|
+
it 'Se a cav não der acesso, ja devemos dar erro na chamado do setup' do
|
6
|
+
expect { Myfinance.setup('nowaythiskeucanwork') }.to raise_error
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'Se a cav não der acesso, ja devemos dar erro na chamado do setup' do
|
10
|
+
expect { Myfinance.setup('2acecbb483842ebbfb2c638070bf019b70e757190166d277') }.to_not raise_error
|
11
|
+
end
|
12
|
+
|
5
13
|
it 'deve poder criar uma conta a receber para uma entidade e um cliente' do
|
6
14
|
Myfinance.setup('2acecbb483842ebbfb2c638070bf019b70e757190166d277')
|
7
15
|
|
@@ -47,12 +55,9 @@ describe 'Manipulando Contas a Receber', type: :feature do
|
|
47
55
|
}
|
48
56
|
conta_a_receber = Myfinance.cria_conta_a_receber('Minhas Finanças',faturamento)
|
49
57
|
expect(conta_a_receber['id']).to_not be_nil
|
50
|
-
|
51
58
|
end
|
52
59
|
|
53
|
-
|
54
|
-
expect { Myfinance.setup('nowaythiskeucanwork') }.to raise_error
|
55
|
-
end
|
60
|
+
|
56
61
|
|
57
62
|
|
58
63
|
end
|
@@ -22,10 +22,19 @@ describe 'Manipulando Pessoas', type: :feature do
|
|
22
22
|
'zip_code'=>'22290-080'
|
23
23
|
}
|
24
24
|
novo_cliente = Myfinance.cria_pessoa(cliente)
|
25
|
-
expect(novo_cliente['
|
25
|
+
expect(novo_cliente['federation_subscription_number']).to_not be_nil
|
26
26
|
|
27
27
|
id = Myfinance.pessoa_id(cliente['federation_subscription_number'])
|
28
28
|
expect(id).to_not be_nil
|
29
|
+
|
30
|
+
cliente['name'] = 'Ciclano'
|
31
|
+
response = Myfinance.atualiza_pessoa(id, cliente)
|
32
|
+
expect(response.code).to equal(200)
|
33
|
+
|
34
|
+
mesmo_cliente = Myfinance.pessoa(cliente['federation_subscription_number'])
|
35
|
+
expect(mesmo_cliente).to_not be_nil
|
36
|
+
expect(mesmo_cliente['name']).to eq('Ciclano')
|
37
|
+
|
29
38
|
end
|
30
39
|
|
31
40
|
it 'Se procurar por um cnpj não cadastrado, deve voltar nulo' do
|
@@ -35,4 +44,5 @@ describe 'Manipulando Pessoas', type: :feature do
|
|
35
44
|
end
|
36
45
|
|
37
46
|
|
47
|
+
|
38
48
|
end
|