whos_got_dirt 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: 1deb94dc54c2ea9e2f8b61d0b92b772b6a1319cf
4
- data.tar.gz: 9c699bef6687a839ec92aebfc24d16f8f9b65f85
3
+ metadata.gz: 84ee304532b79d4d989aeae5085c700d4e19ea84
4
+ data.tar.gz: 5c1a6022426e70affa41c335f7f2c8bbef978cb8
5
5
  SHA512:
6
- metadata.gz: 17e0533d244d23aa69dd1459a4c1d8d8cede94f5e793d700c5f36d10fd24c5e3d1b9d7c6cba38fd23a946e7eb57e55ef00175224ca8b2cae0171dbdd272d2fe1
7
- data.tar.gz: 28673a6d11fa8982803a02a148f9f3f9136005c31548af3dbda1b4083f40091bf842ab41f1ab5a80e4f29aa6bd22ed28b0f0f6dcd485706698cc9d28734a2a3b
6
+ metadata.gz: 4576f8a93268f16d22fd3bb717e6e6f2ecbdf10cde62b4955db5bbc1e737aee68b575b79ddbe37609bb3558def5a8046b6a6991fb777428444b8abf22d1a924a
7
+ data.tar.gz: 324bae3a7234a301cd920d3e3745f735d266b4f2c823b089199c9295bb1b3e236dbacf279cd800ea5baa0170960621075d4bfa35c6f4b3aa00aeac68af703ae2
@@ -48,6 +48,9 @@ module WhosGotDirt
48
48
  #
49
49
  # @example Limit the number of results.
50
50
  # "limit": 5
51
+ #
52
+ # @example Paginate the results.
53
+ # "page": 2
51
54
  module Entity
52
55
  end
53
56
  end
@@ -81,7 +81,8 @@ module WhosGotDirt
81
81
  # @see http://api.corpwatch.org/documentation/api_examples.html#A17
82
82
  def convert
83
83
  match('company_name', 'name')
84
- equal('limit', 'limit')
84
+ equal('limit', 'limit') # default 100, maximum 5000
85
+ equal('index', 'page', transform: lambda{|v| (v - 1) * (input['limit'] || 100)})
85
86
 
86
87
  input['identifiers'] && input['identifiers'].each do |identifier|
87
88
  case identifier['scheme']
@@ -38,7 +38,8 @@ module WhosGotDirt
38
38
  def convert
39
39
  match('q', 'name')
40
40
  one_of('type_ids', 'classification')
41
- equal('num', 'limit')
41
+ equal('num', 'limit') # default 20, maximum 1000?
42
+ equal('page', 'page')
42
43
 
43
44
  # API-specific parameters.
44
45
  equal('_key', 'little_sis_api_key')
@@ -78,7 +78,8 @@ module WhosGotDirt
78
78
  equal('created_since', 'created_at>=')
79
79
  date_range('incorporation_date', 'founding_date')
80
80
  date_range('dissolution_date', 'dissolution_date')
81
- equal('per_page', 'limit', default: input['open_corporates_api_key'] && 100)
81
+ equal('per_page', 'limit', default: input['open_corporates_api_key'] && 100) # default 30, maximum 100
82
+ equal('page', 'page')
82
83
 
83
84
  input['contact_details'] && input['contact_details'].each do |contact_detail|
84
85
  if contact_detail['type'] == 'address' && (contact_detail['value'] || contact_detail['value~='])
@@ -10,6 +10,9 @@ module WhosGotDirt
10
10
  #
11
11
  # @example Limit the number of results.
12
12
  # "limit": 5
13
+ #
14
+ # @example Paginate the results.
15
+ # "page": 2
13
16
  module List
14
17
  end
15
18
  end
@@ -24,7 +24,8 @@ module WhosGotDirt
24
24
  # @see http://api.littlesis.org/documentation#lists
25
25
  def convert
26
26
  match('q', 'name')
27
- equal('num', 'limit')
27
+ equal('num', 'limit') # default 100, maximum 100
28
+ equal('page', 'page')
28
29
 
29
30
  # API-specific parameters.
30
31
  equal('_key', 'little_sis_api_key')
@@ -23,7 +23,8 @@ module WhosGotDirt
23
23
  # @see https://api.opencorporates.com/documentation/API-Reference
24
24
  def convert
25
25
  match('q', 'name')
26
- equal('per_page', 'limit', default: input['open_corporates_api_key'] && 100)
26
+ equal('per_page', 'limit', default: input['open_corporates_api_key'] && 100) # default 30, maximum 100
27
+ equal('page', 'page')
27
28
 
28
29
  # API-specific parameters.
29
30
  equal('api_token', 'open_corporates_api_key')
@@ -45,6 +45,9 @@ module WhosGotDirt
45
45
  #
46
46
  # @example Limit the number of results.
47
47
  # "limit": 5
48
+ #
49
+ # @example Paginate the results.
50
+ # "page": 2
48
51
  module Relation
49
52
  end
50
53
  end
@@ -45,7 +45,8 @@ module WhosGotDirt
45
45
  # @return [Hash] API-specific parameters
46
46
  # @see https://api.opencorporates.com/documentation/API-Reference
47
47
  def convert
48
- equal('per_page', 'limit', default: input['open_corporates_api_key'] && 100)
48
+ equal('per_page', 'limit', default: input['open_corporates_api_key'] && 100) # default 30, maximum 100
49
+ equal('page', 'page')
49
50
 
50
51
  input['subject'] && input['subject'].each do |subject|
51
52
  match('q', 'name', input: subject)
@@ -29,7 +29,8 @@ module WhosGotDirt
29
29
  # @return [Hash] API-specific parameters
30
30
  # @see http://openoil.net/openoil-api/
31
31
  def convert
32
- equal('per_page', 'limit')
32
+ equal('per_page', 'limit') # default 100, no maximum
33
+ equal('page', 'page')
33
34
 
34
35
  input['subject'] && input['subject'].each do |subject|
35
36
  equal('licensee', 'name', input: subject) # doesn't work, upstream bug
@@ -62,8 +62,12 @@ module WhosGotDirt
62
62
  #
63
63
  # @return [Array<Hash>] the results
64
64
  def to_a
65
- parsed_body['result']['companies'].map do |_,data|
66
- Result.new('Entity', renderer.result(data), self).finalize!
65
+ if parsed_body['result']['companies']
66
+ parsed_body['result']['companies'].map do |_,data|
67
+ Result.new('Entity', renderer.result(data), self).finalize!
68
+ end
69
+ else
70
+ []
67
71
  end
68
72
  end
69
73
 
@@ -74,7 +78,7 @@ module WhosGotDirt
74
78
  def item_url(result)
75
79
  query = CGI.parse(env.url.query.to_s)
76
80
  url = "#{env.url.scheme}://#{env.url.host}#{env.url.path.sub(/\.json\z/, '')}/#{result['identifiers'][0]['identifier']}.json"
77
- if query['key']
81
+ if query['key'].any?
78
82
  url += "?key=#{CGI.escape(query['key'][0].to_s)}"
79
83
  end
80
84
  url
@@ -56,7 +56,11 @@ module WhosGotDirt
56
56
  #
57
57
  # @return [Array<Hash>] the results
58
58
  def to_a
59
- parsed_body['Data']['Entities']['Entity'].map do |data|
59
+ list = parsed_body['Data']['Entities']['Entity']
60
+ if Hash === list
61
+ list = [list]
62
+ end
63
+ list.map do |data|
60
64
  Result.new('Entity', renderer.result(data), self).finalize!
61
65
  end
62
66
  end
@@ -12,10 +12,10 @@ module WhosGotDirt
12
12
  'founding_date' => '/incorporation_date',
13
13
  'dissolution_date' => '/dissolution_date',
14
14
  'other_names' => [{
15
- 'name' => '/previous_names/company_name',
16
- 'start_date' => '/previous_names/start_date',
17
- 'end_date' => '/previous_names/end_date',
18
- 'note' => '/previous_names/type',
15
+ 'name' => '/previous_names/0/company_name',
16
+ 'start_date' => '/previous_names/0/start_date',
17
+ 'end_date' => '/previous_names/0/end_date',
18
+ 'note' => '/previous_names/0/type',
19
19
  }],
20
20
  'identifiers' => [{
21
21
  'identifier' => '/company_number',
@@ -64,7 +64,7 @@ module WhosGotDirt
64
64
  def item_url(result)
65
65
  query = CGI.parse(env.url.query.to_s)
66
66
  url = "#{env.url.scheme}://#{env.url.host}/companies/#{result['jurisdiction_code']}/#{result['identifiers'][0]['identifier']}"
67
- if query['api_token']
67
+ if query['api_token'].any?
68
68
  url += "?api_token=#{CGI.escape(query['api_token'][0].to_s)}"
69
69
  end
70
70
  url
@@ -32,7 +32,11 @@ module WhosGotDirt
32
32
  #
33
33
  # @return [Array<Hash>] the results
34
34
  def to_a
35
- parsed_body['Data']['Lists']['List'].map do |data|
35
+ list = parsed_body['Data']['Lists']['List']
36
+ if Hash === list
37
+ list = [list]
38
+ end
39
+ list.map do |data|
36
40
  Result.new('List', renderer.result(data), self).finalize!
37
41
  end
38
42
  end
@@ -36,7 +36,7 @@ module WhosGotDirt
36
36
  def item_url(result)
37
37
  query = CGI.parse(env.url.query.to_s)
38
38
  url = "#{env.url.scheme}://#{env.url.host}/corporate_groupings/#{CGI.escape(result['name'].to_s)}"
39
- if query['api_token']
39
+ if query['api_token'].any?
40
40
  url += "?api_token=#{CGI.escape(query['api_token'][0].to_s)}"
41
41
  end
42
42
  url
@@ -68,7 +68,7 @@ module WhosGotDirt
68
68
  def item_url(result)
69
69
  query = CGI.parse(env.url.query.to_s)
70
70
  url = "#{env.url.scheme}://#{env.url.host}/officers/#{result['identifiers'][0]['identifier']}"
71
- if query['api_token']
71
+ if query['api_token'].any?
72
72
  url += "?api_token=#{CGI.escape(query['api_token'][0].to_s)}"
73
73
  end
74
74
  url
@@ -1,3 +1,3 @@
1
1
  module WhosGotDirt
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -17,6 +17,10 @@ module WhosGotDirt::Requests::Entity
17
17
  include_examples 'equal', 'limit', 'limit', 5
18
18
  end
19
19
 
20
+ context 'when given a page' do
21
+ include_examples 'equal', 'index', 'page', 2, transformed: 100
22
+ end
23
+
20
24
  context 'when given an IRS identifier' do
21
25
  it 'should return a criterion' do
22
26
  expect(CorpWatch.new({
@@ -21,6 +21,10 @@ module WhosGotDirt::Requests::Entity
21
21
  include_examples 'equal', 'num', 'limit', 5
22
22
  end
23
23
 
24
+ context 'when given a page' do
25
+ include_examples 'equal', 'page', 'page', 2
26
+ end
27
+
24
28
  context 'when given an API key' do
25
29
  include_examples 'equal', '_key', 'little_sis_api_key', 123
26
30
  end
@@ -43,6 +43,10 @@ module WhosGotDirt::Requests::Entity
43
43
  end
44
44
  end
45
45
 
46
+ context 'when given a page' do
47
+ include_examples 'equal', 'page', 'page', 2
48
+ end
49
+
46
50
  context 'when given an API key' do
47
51
  it 'should return an API key parameter' do
48
52
  expect(OpenCorporates.new('open_corporates_api_key' => 123).convert).to eq('api_token' => 123, 'per_page' => 100)
@@ -17,6 +17,10 @@ module WhosGotDirt::Requests::List
17
17
  include_examples 'equal', 'num', 'limit', 5
18
18
  end
19
19
 
20
+ context 'when given a page' do
21
+ include_examples 'equal', 'page', 'page', 2
22
+ end
23
+
20
24
  context 'when given an API key' do
21
25
  include_examples 'equal', '_key', 'little_sis_api_key', 123
22
26
  end
@@ -23,6 +23,10 @@ module WhosGotDirt::Requests::List
23
23
  end
24
24
  end
25
25
 
26
+ context 'when given a page' do
27
+ include_examples 'equal', 'page', 'page', 2
28
+ end
29
+
26
30
  context 'when given an API key' do
27
31
  it 'should return an API key parameter' do
28
32
  expect(OpenCorporates.new('open_corporates_api_key' => 123).convert).to eq('api_token' => 123, 'per_page' => 100)
@@ -31,6 +31,10 @@ module WhosGotDirt::Requests::Relation
31
31
  end
32
32
  end
33
33
 
34
+ context 'when given a page' do
35
+ include_examples 'equal', 'page', 'page', 2
36
+ end
37
+
34
38
  context 'when given an API key' do
35
39
  it 'should return an API key parameter' do
36
40
  expect(OpenCorporates.new('open_corporates_api_key' => 123).convert).to eq('api_token' => 123, 'per_page' => 100)
@@ -17,6 +17,10 @@ module WhosGotDirt::Requests::Relation
17
17
  include_examples 'equal', 'per_page', 'limit', 5
18
18
  end
19
19
 
20
+ context 'when given a page' do
21
+ include_examples 'equal', 'page', 'page', 2
22
+ end
23
+
20
24
  context 'when given an API key' do
21
25
  include_examples 'equal', 'apikey', 'open_oil_api_key', 123
22
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whos_got_dirt
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
  - James McKinney
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-15 00:00:00.000000000 Z
11
+ date: 2016-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport