Who's got dirt? A federated search API for influence data

Gem Version Build Status Dependency Status Coverage Status Code Climate

Usage

This gem provides a common API to multiple APIs. See the server for a deployment.

To add support for new APIs, see the documentation for Request and Response.

In this example, we convert generic API parameters to an OpenCorporates API URL, and request the URL with Faraday. Then, we convert the OpenCorporates API response to a generic API response.

require 'whos_got_dirt'
require 'faraday'

input = {
  'subject' => [{
    'name~=' => 'John Smith',
  }],
  'jurisdiction_code|=' => ['gb', 'ie'],
  'role' => 'director',
  'inactive' => false,
}

url = WhosGotDirt::Requests::Relation::OpenCorporates.new(input).to_s
#=> "https://api.opencorporates.com/officers/search?q=John+Smith&jurisdiction_code=gb%7Cie&position=director&inactive=false&order=score"

response = Faraday.get(url)

results = WhosGotDirt::Responses::Relation::OpenCorporates.new(response).to_a
#=> [{"@type"=>"Relation",
#  "subject"=>
#   {"name"=>"JOHN SMITH",
#    "contact_details"=>[],
#    "occupation"=>"CONTRACTS DIRECTORS"},
#  "object"=>
#   {"name"=>"IMPERIAL DUCTWORK SERVICES HOLDINGS LIMITED",
#    "identifiers"=>[{"identifier"=>"08484366", "scheme"=>"Company Register"}],
#    "links"=>[{"url"=>"https://opencorporates.com/companies/gb/08484366", "note"=>"OpenCorporates URL"}],
#    "jurisdiction_code"=>"gb"},
#  "start_date"=>"2013-04-30",
#  "identifiers"=>[{"identifier"=>"71863990", "scheme"=>"OpenCorporates"}],
#  "links"=>[{"url"=>"https://opencorporates.com/officers/71863990", "note"=>"OpenCorporates URL"}],
#  "updated_at"=>"2014-10-13T13:57:58+00:00",
#  "current_status"=>"CURRENT",
#  "jurisdiction_code"=>"gb",
#  "role"=>"director",
#  "sources"=>[{"url"=>"https://api.opencorporates.com/officers/search?inactive=false&jurisdiction_code=gb%7Cie&order=score&position=director&q=John+Smith", "note"=>"OpenCorporates"}]},
#  ...]

Acknowledgements

Most terms are from Popolo. The request and response formats are inspired from the Metaweb Query Language and the OpenRefine Reconciliation Service API.

Copyright (c) 2015 James McKinney, released under the MIT license