myfinance-rails 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 +4 -4
- data/lib/myfinance/pessoa.rb +27 -5
- data/lib/myfinance/version.rb +1 -1
- data/spec/features/pessoas_spec.rb +1 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ad1c9488a11d8532476be62fa113d6707f965fe
|
4
|
+
data.tar.gz: e58ec7c188eec5c58971039ee995bc42a83f793d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fb2789e804158d47600cbdd1a017c777fd9fea5472b8a095c826d8889b50487f908b2a91f06880e5276299c42afc3af8db525c839f5a19d0a6c3ccd3329f26b
|
7
|
+
data.tar.gz: 2da102a9ffbc7b071db60ef9605a37bbcff4f5b6b176834dc1714c03508a810d2c61cd419653a9cffa00e74b295b754b87a38e84f85a9ae6259b1e278dbd1ba2
|
data/lib/myfinance/pessoa.rb
CHANGED
@@ -1,18 +1,30 @@
|
|
1
1
|
module Myfinance
|
2
2
|
|
3
3
|
def self.pessoa_id(cnpj)
|
4
|
+
@everyone ||= all_people
|
4
5
|
mid = nil
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
if cliente['federation_subscription_number_only_numbers'] == cnpj or cliente['federation_subscription_number'] == cnpj
|
9
|
-
mid = cliente['id']
|
6
|
+
@everyone.each do | pessoa |
|
7
|
+
if pessoa['federation_subscription_number_only_numbers'] == cnpj or pessoa['federation_subscription_number'] == cnpj
|
8
|
+
mid = pessoa['id']
|
10
9
|
break
|
11
10
|
end
|
12
11
|
end
|
13
12
|
mid
|
14
13
|
end
|
15
14
|
|
15
|
+
def self.all_people
|
16
|
+
everyone = []
|
17
|
+
response = lget "/people.json"
|
18
|
+
total_pages = get_last_page(response)
|
19
|
+
for page in 1..total_pages
|
20
|
+
response = lget "/people.json?page=#{page}"
|
21
|
+
response.each do | people |
|
22
|
+
everyone << people['person']
|
23
|
+
end
|
24
|
+
end
|
25
|
+
everyone
|
26
|
+
end
|
27
|
+
|
16
28
|
def self.pessoa(cnpj)
|
17
29
|
mid = pessoa_id(cnpj)
|
18
30
|
response = lget "/people/#{mid}.json"
|
@@ -32,6 +44,16 @@ module Myfinance
|
|
32
44
|
end
|
33
45
|
|
34
46
|
|
47
|
+
def self.get_last_page(response)
|
48
|
+
total_pages = 1
|
49
|
+
links = (response.header['link'].split(',') rescue [])
|
50
|
+
link = links.find{ |l| l.include?('last') }
|
51
|
+
if link
|
52
|
+
total_pages = (link.split(";")[0].split('?')[1].gsub('page=','').to_i rescue 1)
|
53
|
+
end
|
54
|
+
total_pages
|
55
|
+
end
|
56
|
+
|
35
57
|
|
36
58
|
end
|
37
59
|
|
data/lib/myfinance/version.rb
CHANGED
@@ -39,10 +39,8 @@ describe 'Manipulando Pessoas', type: :feature do
|
|
39
39
|
|
40
40
|
it 'Se procurar por um cnpj não cadastrado, deve voltar nulo' do
|
41
41
|
Myfinance.setup('2acecbb483842ebbfb2c638070bf019b70e757190166d277')
|
42
|
-
id = Myfinance.pessoa_id('
|
42
|
+
id = Myfinance.pessoa_id('67977504999999')
|
43
43
|
expect(id).to be_nil
|
44
44
|
end
|
45
45
|
|
46
|
-
|
47
|
-
|
48
46
|
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.5
|
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: 2014-12-
|
11
|
+
date: 2014-12-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|