whos_got_dirt 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +6 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +20 -0
  5. data/.yardopts +3 -0
  6. data/Gemfile +7 -0
  7. data/LICENSE +20 -0
  8. data/README.md +61 -0
  9. data/Rakefile +69 -0
  10. data/lib/whos_got_dirt/renderer.rb +66 -0
  11. data/lib/whos_got_dirt/request.rb +218 -0
  12. data/lib/whos_got_dirt/requests/entity/corp_watch.rb +123 -0
  13. data/lib/whos_got_dirt/requests/entity/little_sis.rb +52 -0
  14. data/lib/whos_got_dirt/requests/entity/open_corporates.rb +104 -0
  15. data/lib/whos_got_dirt/requests/entity/open_duka.rb +33 -0
  16. data/lib/whos_got_dirt/requests/entity/poderopedia.rb +48 -0
  17. data/lib/whos_got_dirt/requests/entity.rb +54 -0
  18. data/lib/whos_got_dirt/requests/list/little_sis.rb +37 -0
  19. data/lib/whos_got_dirt/requests/list/open_corporates.rb +36 -0
  20. data/lib/whos_got_dirt/requests/list.rb +16 -0
  21. data/lib/whos_got_dirt/requests/relation/open_corporates.rb +72 -0
  22. data/lib/whos_got_dirt/requests/relation/open_oil.rb +49 -0
  23. data/lib/whos_got_dirt/requests/relation.rb +51 -0
  24. data/lib/whos_got_dirt/response.rb +79 -0
  25. data/lib/whos_got_dirt/responses/entity/corp_watch.rb +72 -0
  26. data/lib/whos_got_dirt/responses/entity/little_sis.rb +66 -0
  27. data/lib/whos_got_dirt/responses/entity/open_corporates.rb +61 -0
  28. data/lib/whos_got_dirt/responses/entity/open_duka.rb +42 -0
  29. data/lib/whos_got_dirt/responses/entity/poderopedia.rb +44 -0
  30. data/lib/whos_got_dirt/responses/entity.rb +7 -0
  31. data/lib/whos_got_dirt/responses/helpers/little_sis.rb +34 -0
  32. data/lib/whos_got_dirt/responses/helpers/open_corporates.rb +28 -0
  33. data/lib/whos_got_dirt/responses/list/little_sis.rb +42 -0
  34. data/lib/whos_got_dirt/responses/list/open_corporates.rb +34 -0
  35. data/lib/whos_got_dirt/responses/list.rb +7 -0
  36. data/lib/whos_got_dirt/responses/relation/open_corporates.rb +66 -0
  37. data/lib/whos_got_dirt/responses/relation/open_oil.rb +70 -0
  38. data/lib/whos_got_dirt/responses/relation.rb +7 -0
  39. data/lib/whos_got_dirt/result.rb +106 -0
  40. data/lib/whos_got_dirt/validator.rb +52 -0
  41. data/lib/whos_got_dirt/version.rb +3 -0
  42. data/lib/whos_got_dirt.rb +43 -0
  43. data/schemas/popolo.json +1619 -0
  44. data/spec/cassettes/corp_watch_entity.yml +35 -0
  45. data/spec/cassettes/little_sis_entity.yml +98 -0
  46. data/spec/cassettes/little_sis_list.yml +159 -0
  47. data/spec/cassettes/open_corporates_entity.yml +137 -0
  48. data/spec/cassettes/open_corporates_list.yml +60 -0
  49. data/spec/cassettes/open_corporates_relation.yml +121 -0
  50. data/spec/cassettes/open_duka_entity.yml +1149 -0
  51. data/spec/cassettes/open_oil_relation.yml +640 -0
  52. data/spec/cassettes/poderopedia_entity.yml +43 -0
  53. data/spec/renderer_spec.rb +48 -0
  54. data/spec/request_spec.rb +205 -0
  55. data/spec/requests/entity/corp_watch_spec.rb +99 -0
  56. data/spec/requests/entity/little_sis_spec.rb +33 -0
  57. data/spec/requests/entity/open_corporates_spec.rb +81 -0
  58. data/spec/requests/entity/open_duka_spec.rb +21 -0
  59. data/spec/requests/entity/poderopedia_spec.rb +21 -0
  60. data/spec/requests/list/little_sis_spec.rb +25 -0
  61. data/spec/requests/list/open_corporates_spec.rb +33 -0
  62. data/spec/requests/relation/open_corporates_spec.rb +53 -0
  63. data/spec/requests/relation/open_oil_spec.rb +37 -0
  64. data/spec/response_spec.rb +119 -0
  65. data/spec/responses/entity/corp_watch_spec.rb +31 -0
  66. data/spec/responses/entity/little_sis_spec.rb +31 -0
  67. data/spec/responses/entity/open_corporates_spec.rb +31 -0
  68. data/spec/responses/entity/open_duka_spec.rb +25 -0
  69. data/spec/responses/entity/poderopedia_spec.rb +25 -0
  70. data/spec/responses/list/little_sis_spec.rb +31 -0
  71. data/spec/responses/list/open_corporates_spec.rb +31 -0
  72. data/spec/responses/relation/open_corporates_spec.rb +31 -0
  73. data/spec/responses/relation/open_oil_spec.rb +31 -0
  74. data/spec/result_spec.rb +90 -0
  75. data/spec/spec_helper.rb +21 -0
  76. data/spec/support/shared_examples_for_requests.rb +155 -0
  77. data/spec/validator_spec.rb +43 -0
  78. data/whos_got_dirt.gemspec +28 -0
  79. metadata +281 -0
@@ -0,0 +1,37 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ module WhosGotDirt::Requests::Relation
4
+ RSpec.describe OpenOil do
5
+ describe '#to_s' do
6
+ it 'should return the URL to request' do
7
+ expect(OpenOil.new(subject: [name: 'Petrobras']).to_s).to eq('https://api.openoil.net/concession/search?licensee=Petrobras')
8
+ end
9
+ end
10
+
11
+ describe '#convert' do
12
+ context 'when given a name' do
13
+ include_examples 'equal', 'licensee', 'name', 'Petrobras', scope: 'subject'
14
+ end
15
+
16
+ context 'when given a limit' do
17
+ include_examples 'equal', 'per_page', 'limit', 5
18
+ end
19
+
20
+ context 'when given an API key' do
21
+ include_examples 'equal', 'apikey', 'open_oil_api_key', 123
22
+ end
23
+
24
+ context 'when given a country' do
25
+ include_examples 'equal', 'country', 'country_code', 'br', transformed: 'BR'
26
+ end
27
+
28
+ context 'when given a status' do
29
+ include_examples 'equal', 'status', 'status', 'licensed', valid: ['licensed', 'unlicensed']
30
+ end
31
+
32
+ context 'when given a type' do
33
+ include_examples 'equal', 'type', 'type', 'offshore', valid: ['offshore', 'onshore']
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,119 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ module WhosGotDirt
4
+ RSpec.describe Response do
5
+ let :klass do
6
+ Class.new(Response) do
7
+ class << self
8
+ def name
9
+ 'MyResponse'
10
+ end
11
+ end
12
+
13
+ @template = {
14
+ '@type' => 'Person',
15
+ 'id' => 123,
16
+ 'name' => '/fn',
17
+ 'identifiers' => [{
18
+ 'identifier' => '/id',
19
+ 'scheme' => 'ACME',
20
+ }]
21
+ }
22
+
23
+ def parse_body
24
+ JSON.load(body)
25
+ end
26
+
27
+ def to_a
28
+ parsed_body.map do |data|
29
+ Result.new('Person', renderer.result(data), self).finalize!
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ let :response do
36
+ env = Faraday::Env.new
37
+ env.url = 'https://api.example.com/endpoint?name~=John+Smith'
38
+ env.body = '[{"fn":"John Smith","id":"john-smith"},{"fn":"John Aaron Smith","id":"john-aaron-smith"}]'
39
+ Faraday::Response.new(env)
40
+ end
41
+
42
+ let :instance do
43
+ klass.new(response)
44
+ end
45
+
46
+ let :template do
47
+ {
48
+ '@type' => 'Person',
49
+ 'id' => 123,
50
+ 'name' => '/fn',
51
+ 'identifiers' => [{
52
+ 'identifier' => '/id',
53
+ 'scheme' => 'ACME',
54
+ }]
55
+ }
56
+ end
57
+
58
+ let :parsed_body do
59
+ [
60
+ {'fn' => 'John Smith', 'id' => 'john-smith'},
61
+ {'fn' => 'John Aaron Smith', 'id' => 'john-aaron-smith'},
62
+ ]
63
+ end
64
+
65
+ describe '.template' do
66
+ it 'should return the template' do
67
+ expect(klass.template).to eq(template)
68
+ end
69
+ end
70
+
71
+ describe '#renderer' do
72
+ it 'should return the renderer' do
73
+ expect(instance.renderer.template).to eq(template)
74
+ end
75
+ end
76
+
77
+ describe '#parsed_body' do
78
+ it 'should return the parsed response body' do
79
+ expect(instance.parsed_body).to eq(parsed_body)
80
+ end
81
+ end
82
+
83
+ describe '#parse_body' do
84
+ it 'should return the parsed response body' do
85
+ expect(instance.parse_body).to eq(parsed_body)
86
+ end
87
+ end
88
+
89
+ describe '#to_a' do
90
+ it 'should return the results' do
91
+ expect(instance.to_a).to eq([{
92
+ '@type' => 'Person',
93
+ 'id' => '123',
94
+ 'name' => 'John Smith',
95
+ 'identifiers' => [{
96
+ 'identifier' => 'john-smith',
97
+ 'scheme' => 'ACME',
98
+ }],
99
+ 'sources' => [{
100
+ 'url' => 'https://api.example.com/endpoint?name~=John+Smith',
101
+ 'note' => 'MyResponse',
102
+ }],
103
+ }, {
104
+ '@type' => 'Person',
105
+ 'id' => '123',
106
+ 'name' => 'John Aaron Smith',
107
+ 'identifiers' => [{
108
+ 'identifier' => 'john-aaron-smith',
109
+ 'scheme' => 'ACME',
110
+ }],
111
+ 'sources' => [{
112
+ 'url' => 'https://api.example.com/endpoint?name~=John+Smith',
113
+ 'note' => 'MyResponse',
114
+ }],
115
+ }])
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,31 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ module WhosGotDirt::Responses::Entity
4
+ RSpec.describe CorpWatch, vcr: {cassette_name: 'corp_watch_entity'} do
5
+ let :response do
6
+ Faraday.get("http://api.corpwatch.org/companies.json?company_name=bank&key=#{ENV['CORP_WATCH_API_KEY']}")
7
+ end
8
+
9
+ let :instance do
10
+ CorpWatch.new(response)
11
+ end
12
+
13
+ describe '#to_a' do
14
+ it 'should return the results' do
15
+ expect{instance.to_a}.to_not raise_error
16
+ end
17
+ end
18
+
19
+ describe '#count' do
20
+ it 'should return the number of results' do
21
+ expect(instance.count).to be > 3_000
22
+ end
23
+ end
24
+
25
+ describe '#index' do
26
+ it 'should return the current index' do
27
+ expect(instance.index).to eq(0)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ module WhosGotDirt::Responses::Entity
4
+ RSpec.describe LittleSis, vcr: {cassette_name: 'little_sis_entity'} do
5
+ let :response do
6
+ Faraday.get("https://api.littlesis.org/entities.xml?q=bar&_key=#{ENV['LITTLE_SIS_API_KEY']}")
7
+ end
8
+
9
+ let :instance do
10
+ LittleSis.new(response)
11
+ end
12
+
13
+ describe '#to_a' do
14
+ it 'should return the results' do
15
+ expect{instance.to_a}.to_not raise_error
16
+ end
17
+ end
18
+
19
+ describe '#count' do
20
+ it 'should return the number of results' do
21
+ expect(instance.count).to be > 1_000
22
+ end
23
+ end
24
+
25
+ describe '#page' do
26
+ it 'should return the current page number' do
27
+ expect(instance.page).to eq(1)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ module WhosGotDirt::Responses::Entity
4
+ RSpec.describe OpenCorporates, vcr: {cassette_name: 'open_corporates_entity'} do
5
+ let :response do
6
+ Faraday.get('https://api.opencorporates.com/companies/search')
7
+ end
8
+
9
+ let :instance do
10
+ OpenCorporates.new(response)
11
+ end
12
+
13
+ describe '#to_a' do
14
+ it 'should return the results' do
15
+ expect{instance.to_a}.to_not raise_error
16
+ end
17
+ end
18
+
19
+ describe '#count' do
20
+ it 'should return the number of results' do
21
+ expect(instance.count).to be > 80_000_000
22
+ end
23
+ end
24
+
25
+ describe '#page' do
26
+ it 'should return the current page number' do
27
+ expect(instance.page).to eq(1)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ module WhosGotDirt::Responses::Entity
4
+ RSpec.describe OpenDuka, vcr: {cassette_name: 'open_duka_entity'} do
5
+ let :response do
6
+ Faraday.get("http://www.openduka.org/index.php/api/search?term=the&key=#{ENV['OPEN_DUKA_API_KEY']}")
7
+ end
8
+
9
+ let :instance do
10
+ OpenDuka.new(response)
11
+ end
12
+
13
+ describe '#to_a' do
14
+ it 'should return the results' do
15
+ expect{instance.to_a}.to_not raise_error
16
+ end
17
+ end
18
+
19
+ describe '#count' do
20
+ it 'should return the number of results' do
21
+ expect(instance.count).to be > 1_000
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ module WhosGotDirt::Responses::Entity
4
+ RSpec.describe Poderopedia, vcr: {cassette_name: 'poderopedia_entity'} do
5
+ let :response do
6
+ Faraday.get("http://api.poderopedia.org/visualizacion/search?alias=juan&entity=persona&user_key=#{ENV['PODEROPEDIA_API_KEY']}")
7
+ end
8
+
9
+ let :instance do
10
+ Poderopedia.new(response)
11
+ end
12
+
13
+ describe '#to_a' do
14
+ it 'should return the results' do
15
+ expect{instance.to_a}.to_not raise_error
16
+ end
17
+ end
18
+
19
+ describe '#count' do
20
+ it 'should return the number of results' do
21
+ expect(instance.count).to eq(10)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,31 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ module WhosGotDirt::Responses::List
4
+ RSpec.describe LittleSis, vcr: {cassette_name: 'little_sis_list'} do
5
+ let :response do
6
+ Faraday.get("https://api.littlesis.org/lists.xml?q=united&_key=#{ENV['LITTLE_SIS_API_KEY']}")
7
+ end
8
+
9
+ let :instance do
10
+ LittleSis.new(response)
11
+ end
12
+
13
+ describe '#to_a' do
14
+ it 'should return the results' do
15
+ expect{instance.to_a}.to_not raise_error
16
+ end
17
+ end
18
+
19
+ describe '#count' do
20
+ it 'should return the number of results' do
21
+ expect(instance.count).to be > 10
22
+ end
23
+ end
24
+
25
+ describe '#page' do
26
+ it 'should return the current page number' do
27
+ expect(instance.page).to eq(1)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ module WhosGotDirt::Responses::List
4
+ RSpec.describe OpenCorporates, vcr: {cassette_name: 'open_corporates_list'} do
5
+ let :response do
6
+ Faraday.get('https://api.opencorporates.com/corporate_groupings/search')
7
+ end
8
+
9
+ let :instance do
10
+ OpenCorporates.new(response)
11
+ end
12
+
13
+ describe '#to_a' do
14
+ it 'should return the results' do
15
+ expect{instance.to_a}.to_not raise_error
16
+ end
17
+ end
18
+
19
+ describe '#count' do
20
+ it 'should return the number of results' do
21
+ expect(instance.count).to be > 800
22
+ end
23
+ end
24
+
25
+ describe '#page' do
26
+ it 'should return the current page number' do
27
+ expect(instance.page).to eq(1)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ module WhosGotDirt::Responses::Relation
4
+ RSpec.describe OpenCorporates, vcr: {cassette_name: 'open_corporates_relation'} do
5
+ let :response do
6
+ Faraday.get('https://api.opencorporates.com/officers/search')
7
+ end
8
+
9
+ let :instance do
10
+ OpenCorporates.new(response)
11
+ end
12
+
13
+ describe '#to_a' do
14
+ it 'should return the results' do
15
+ expect{instance.to_a}.to_not raise_error
16
+ end
17
+ end
18
+
19
+ describe '#count' do
20
+ it 'should return the number of results' do
21
+ expect(instance.count).to be > 100_000_000
22
+ end
23
+ end
24
+
25
+ describe '#page' do
26
+ it 'should return the current page number' do
27
+ expect(instance.page).to eq(1)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ module WhosGotDirt::Responses::Relation
4
+ RSpec.describe OpenOil, vcr: {cassette_name: 'open_oil_relation'} do
5
+ let :response do
6
+ Faraday.get("https://api.openoil.net/concession/search?apikey=#{ENV['OPEN_OIL_API_KEY']}")
7
+ end
8
+
9
+ let :instance do
10
+ OpenOil.new(response)
11
+ end
12
+
13
+ describe '#to_a' do
14
+ it 'should return the results' do
15
+ expect{instance.to_a}.to_not raise_error
16
+ end
17
+ end
18
+
19
+ describe '#count' do
20
+ it 'should return the number of results' do
21
+ expect(instance.count).to be > 10_000
22
+ end
23
+ end
24
+
25
+ describe '#page' do
26
+ it 'should return the current page number' do
27
+ expect(instance.page).to eq(1)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,90 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ module WhosGotDirt
4
+ RSpec.describe Result do
5
+ let :result do
6
+ {
7
+ 'id' => 123,
8
+ 'name' => 'John Smith',
9
+ 'identifiers' => [{
10
+ 'scheme' => 'ACME',
11
+ }, {
12
+ 'identifier' => 'john-smith',
13
+ }, {
14
+ 'scheme' => 'ACME',
15
+ }],
16
+ }
17
+ end
18
+
19
+ let :response do
20
+ env = Faraday::Env.new
21
+ env.url = 'https://api.example.com/endpoint?name~=John+Smith'
22
+ env.body = '[{"fn":"John Smith","id":"john-smith"},{"fn":"John Aaron Smith","id":"john-aaron-smith"}]'
23
+ Faraday::Response.new(env)
24
+ end
25
+
26
+ let :instance do
27
+ Result.new('Person', result, response)
28
+ end
29
+
30
+ describe '#initialize' do
31
+ it 'should set the type, result and response' do
32
+ expect(instance.type).to eq('Person')
33
+ expect(instance.result).to eq(result)
34
+ expect(instance.response).to eq(response)
35
+ end
36
+ end
37
+
38
+ describe '#add_source!' do
39
+ it 'should add a source to a result' do
40
+ expect(instance.add_source!).to eq({
41
+ 'id' => 123,
42
+ 'name' => 'John Smith',
43
+ 'identifiers' => [{
44
+ 'scheme' => 'ACME',
45
+ }, {
46
+ 'identifier' => 'john-smith',
47
+ }, {
48
+ 'scheme' => 'ACME',
49
+ }],
50
+ 'sources' => [{
51
+ 'url' => 'https://api.example.com/endpoint?name~=John+Smith',
52
+ 'note' => 'Response',
53
+ }],
54
+ })
55
+ end
56
+ end
57
+
58
+ describe 'validate!' do
59
+ it 'should validate the result' do
60
+ expect(instance.validate!).to eq({
61
+ 'id' => '123',
62
+ 'name' => 'John Smith',
63
+ 'identifiers' => [{
64
+ 'identifier' => 'john-smith',
65
+ }],
66
+ })
67
+ end
68
+
69
+ it 'should raise an error if validation is strict' do
70
+ expect{instance.validate!(strict: true)}.to raise_error(ValidationError)
71
+ end
72
+ end
73
+
74
+ describe '#finalize!' do
75
+ it 'should finalize the result' do
76
+ expect(instance.finalize!).to eq({
77
+ 'id' => '123',
78
+ 'name' => 'John Smith',
79
+ 'identifiers' => [{
80
+ 'identifier' => 'john-smith',
81
+ }],
82
+ 'sources' => [{
83
+ 'url' => 'https://api.example.com/endpoint?name~=John+Smith',
84
+ 'note' => 'Response',
85
+ }],
86
+ })
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,21 @@
1
+ require 'rubygems'
2
+
3
+ require 'simplecov'
4
+ require 'coveralls'
5
+ SimpleCov.formatter = Coveralls::SimpleCov::Formatter
6
+ SimpleCov.start do
7
+ add_filter 'spec'
8
+ end
9
+
10
+ require 'vcr'
11
+ VCR.configure do |c|
12
+ c.cassette_library_dir = 'spec/cassettes'
13
+ c.hook_into :faraday
14
+ c.configure_rspec_metadata!
15
+ end
16
+
17
+ require 'rspec'
18
+ require 'faraday'
19
+
20
+ Dir['./spec/support/**/*.rb'].sort.each { |f| require f}
21
+ require File.dirname(__FILE__) + '/../lib/whos_got_dirt'