myfinance-rails 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/myfinance/account.rb +7 -0
- data/lib/myfinance/version.rb +1 -1
- data/lib/myfinance.rb +12 -3
- data/spec/features/account_spec.rb +50 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06b34f9d4993d5ee387e8957314d8a829a492bb1
|
4
|
+
data.tar.gz: 58f1941cbf736d5be8cc2002c55a2f2e3559c3c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca93a2bd23a86ae0b613d9c896fb03beb66ed0c222f9634b0c334c72ff2f4c49f87e571f9b33c0384bcd4fd9b910dc35168dddaf64dc91c903ff36663e65274e
|
7
|
+
data.tar.gz: 132c89675b297bde0d6860984385bb6042e49d7ba6e837d5e26bad5001c55d703e923694ece0f5739dc4c3d83a78b07fa7c8e9dec6e244a0065c11bfff6f5139
|
data/.gitignore
CHANGED
data/lib/myfinance/version.rb
CHANGED
data/lib/myfinance.rb
CHANGED
@@ -6,15 +6,16 @@ require 'myfinance/conta_a_receber'
|
|
6
6
|
require 'myfinance/imposto'
|
7
7
|
require 'myfinance/categoria'
|
8
8
|
require 'myfinance/centro_receita_custo'
|
9
|
+
require 'myfinance/account'
|
9
10
|
require 'json'
|
10
11
|
|
11
12
|
module Myfinance
|
12
13
|
|
13
14
|
include HTTParty
|
14
15
|
|
15
|
-
attr_accessor :token, :endpoint
|
16
|
+
attr_accessor :token, :endpoint, :account_id
|
16
17
|
|
17
|
-
def self.setup(token,production=false)
|
18
|
+
def self.setup(token, production=false, account_id=nil)
|
18
19
|
if production
|
19
20
|
@endpoint = 'https://app.myfinance.com.br'
|
20
21
|
else
|
@@ -22,8 +23,9 @@ module Myfinance
|
|
22
23
|
end
|
23
24
|
base_uri @endpoint
|
24
25
|
@token = token
|
26
|
+
@account_id = account_id
|
25
27
|
# testo com uma chamada simples
|
26
|
-
response =
|
28
|
+
response = accounts
|
27
29
|
# Resposta deve ser um array de hashes
|
28
30
|
unless response.code == 200
|
29
31
|
raise "Erro ao inicializar a API do MyFinance: #{response.code} : #{response.parsed_response}"
|
@@ -35,7 +37,9 @@ module Myfinance
|
|
35
37
|
def self.lget(url)
|
36
38
|
options = {
|
37
39
|
:basic_auth => {:username => @token, :password => 'x'},
|
40
|
+
:headers => { 'Content-Type' => 'application/json' }
|
38
41
|
}
|
42
|
+
add_account_id options
|
39
43
|
get url, options
|
40
44
|
end
|
41
45
|
|
@@ -45,6 +49,7 @@ module Myfinance
|
|
45
49
|
:body => post_data.to_json,
|
46
50
|
:headers => { 'Content-Type' => 'application/json' }
|
47
51
|
}
|
52
|
+
add_account_id options
|
48
53
|
response = post url, options
|
49
54
|
response
|
50
55
|
end
|
@@ -55,6 +60,7 @@ module Myfinance
|
|
55
60
|
:body => post_data.to_json,
|
56
61
|
:headers => { 'Content-Type' => 'application/json' }
|
57
62
|
}
|
63
|
+
add_account_id options
|
58
64
|
response = put url, options
|
59
65
|
response
|
60
66
|
end
|
@@ -63,5 +69,8 @@ module Myfinance
|
|
63
69
|
dt.strftime('%FT%H:%MZ') rescue nil
|
64
70
|
end
|
65
71
|
|
72
|
+
def self.add_account_id(options)
|
73
|
+
options[:headers]['ACCOUNT_ID'] = @account_id.to_s if @account_id
|
74
|
+
end
|
66
75
|
end
|
67
76
|
|
@@ -0,0 +1,50 @@
|
|
1
|
+
describe 'Account', type: :feature do
|
2
|
+
|
3
|
+
require 'myfinance'
|
4
|
+
|
5
|
+
it '#accounts' do
|
6
|
+
double accounts_double = double('account')
|
7
|
+
expect(Myfinance).to receive(:lget).once.with('/accounts.json').and_return accounts_double
|
8
|
+
expect(Myfinance.accounts).to eql(accounts_double)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "specific account" do
|
12
|
+
let(:response_double) { double("response", code: 200) }
|
13
|
+
describe "informed" do
|
14
|
+
before do
|
15
|
+
expect(Myfinance).to receive(:accounts).and_return response_double
|
16
|
+
Myfinance.setup "123456", false, 25
|
17
|
+
end
|
18
|
+
it "get" do
|
19
|
+
expect(Myfinance).to receive(:get).with("/entities.json", {:basic_auth=>{:username=>"123456", :password=>"x"}, :headers=>{"Content-Type"=>"application/json", "ACCOUNT_ID"=>"25"}})
|
20
|
+
Myfinance.entidades
|
21
|
+
end
|
22
|
+
it "post" do
|
23
|
+
expect(Myfinance).to receive(:post).with("/people.json", {:basic_auth=>{:username=>"123456", :password=>"x"}, :body=>"{\"person\":{}}", :headers=>{"Content-Type"=>"application/json", "ACCOUNT_ID"=>"25"}})
|
24
|
+
Myfinance.cria_pessoa({})
|
25
|
+
end
|
26
|
+
it "put" do
|
27
|
+
expect(Myfinance).to receive(:put).with("/people/30.json", {:basic_auth=>{:username=>"123456", :password=>"x"}, :body=>"{}", :headers=>{"Content-Type"=>"application/json", "ACCOUNT_ID"=>"25"}})
|
28
|
+
Myfinance.atualiza_pessoa(30, {})
|
29
|
+
end
|
30
|
+
end
|
31
|
+
describe "not informed" do
|
32
|
+
before do
|
33
|
+
expect(Myfinance).to receive(:accounts).and_return response_double
|
34
|
+
Myfinance.setup "123456", false
|
35
|
+
end
|
36
|
+
it "get" do
|
37
|
+
expect(Myfinance).to receive(:get).with("/entities.json", {:basic_auth=>{:username=>"123456", :password=>"x"}, :headers=>{"Content-Type"=>"application/json"}})
|
38
|
+
Myfinance.entidades
|
39
|
+
end
|
40
|
+
it "post" do
|
41
|
+
expect(Myfinance).to receive(:post).with("/people.json", {:basic_auth=>{:username=>"123456", :password=>"x"}, :body=>"{\"person\":{}}", :headers=>{"Content-Type"=>"application/json"}})
|
42
|
+
Myfinance.cria_pessoa({})
|
43
|
+
end
|
44
|
+
it "put" do
|
45
|
+
expect(Myfinance).to receive(:put).with("/people/30.json", {:basic_auth=>{:username=>"123456", :password=>"x"}, :body=>"{}", :headers=>{"Content-Type"=>"application/json"}})
|
46
|
+
Myfinance.atualiza_pessoa(30, {})
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: myfinance-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- José Lopes Neto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- README.md
|
82
82
|
- Rakefile
|
83
83
|
- lib/myfinance.rb
|
84
|
+
- lib/myfinance/account.rb
|
84
85
|
- lib/myfinance/categoria.rb
|
85
86
|
- lib/myfinance/centro_receita_custo.rb
|
86
87
|
- lib/myfinance/conta_a_pagar.rb
|
@@ -90,6 +91,7 @@ files:
|
|
90
91
|
- lib/myfinance/pessoa.rb
|
91
92
|
- lib/myfinance/version.rb
|
92
93
|
- myfinance-rails.gemspec
|
94
|
+
- spec/features/account_spec.rb
|
93
95
|
- spec/features/categoria_spec.rb
|
94
96
|
- spec/features/centro_receita_custo_spec.rb
|
95
97
|
- spec/features/contas_a_receber_spec.rb
|
@@ -122,6 +124,7 @@ signing_key:
|
|
122
124
|
specification_version: 4
|
123
125
|
summary: GEM para facilitar a uso da API do Myfinance em Aplicativos Rails
|
124
126
|
test_files:
|
127
|
+
- spec/features/account_spec.rb
|
125
128
|
- spec/features/categoria_spec.rb
|
126
129
|
- spec/features/centro_receita_custo_spec.rb
|
127
130
|
- spec/features/contas_a_receber_spec.rb
|