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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ae5852aa35e41081d6d38dffe06d0bb8fe30547
4
- data.tar.gz: 25bbe5ec5c93cffdf8f7432b580d3b91b2de316d
3
+ metadata.gz: 7ad1c9488a11d8532476be62fa113d6707f965fe
4
+ data.tar.gz: e58ec7c188eec5c58971039ee995bc42a83f793d
5
5
  SHA512:
6
- metadata.gz: 53417d713c4bf7a3ff364f00fe489e52bd8ccc08298828ce9d569fbf998b26726fffd47cbb76e334205dedf5504b05b690d876512cda13f986d8d2c17632a8e5
7
- data.tar.gz: fa72cad1490acda1e6c84936cc789d9033d534cf9595d8ff6432ab9bd88988e71b489522e4a0a9bc3452cb3927d5cdb8b67f9dd137ddd3e762025177a198a7d6
6
+ metadata.gz: 9fb2789e804158d47600cbdd1a017c777fd9fea5472b8a095c826d8889b50487f908b2a91f06880e5276299c42afc3af8db525c839f5a19d0a6c3ccd3329f26b
7
+ data.tar.gz: 2da102a9ffbc7b071db60ef9605a37bbcff4f5b6b176834dc1714c03508a810d2c61cd419653a9cffa00e74b295b754b87a38e84f85a9ae6259b1e278dbd1ba2
@@ -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
- response = lget '/people.json'
6
- response.each do | people |
7
- cliente = people['person']
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
 
@@ -1,3 +1,3 @@
1
1
  module Myfinance
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
@@ -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('67977504000137')
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
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-09 00:00:00.000000000 Z
11
+ date: 2014-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler