<commit_before># Who's got dirt? A federated search API for people and organizations

[![Build Status](https://secure.travis-ci.org/influencemapping/whos_got_dirt-server.png)](https://travis-ci.org/influencemapping/whos_got_dirt-server)
[![Dependency Status](https://gemnasium.com/influencemapping/whos_got_dirt-server.png)](https://gemnasium.com/influencemapping/whos_got_dirt-server)
[![Coverage Status](https://coveralls.io/repos/influencemapping/whos_got_dirt-server/badge.svg)](https://coveralls.io/r/influencemapping/whos_got_dirt-server)
[![Code Climate](https://codeclimate.com/github/influencemapping/whos_got_dirt-server.png)](https://codeclimate.com/github/influencemapping/whos_got_dirt-server)

See the [Ruby gem](https://github.com/influencemapping/whos_got_dirt-gem) for details.

## Usage

### People

`GET /people?queries=<queries>` where `<queries>` looks like:

```json
{
  "q0": {
    "query": {
      "type": "Person",
      "name~=": "<NAME>",
      "jurisdiction_code|=": ["gb", "ie"],
      "memberships": [{
        "role": "director",
        "inactive": false
      }]
    }
  }
}
```

You may use any query ID instead of `q0`. Not all APIs support every parameter and operator. **If a parameter or operator is unsupported, it is silently ignored.** See more in the [documentation](http://www.rubydoc.info/gems/whos_got_dirt/WhosGotDirt/Requests/Person).

**If an API returns an error, its response is silently ignored.** See more in the [documentation](http://www.rubydoc.info/gems/whos_got_dirt/WhosGotDirt/Responses/Person).

For example, run `bundle exec rackup` in a Unix shell, and run the following in a Ruby shell:

```ruby
require 'cgi'
require 'open-uri'
require 'json'

queries = <<-EOL
{
  "q0": {
    "query": {
      "type": "Person",
      "name~=": "<NAME>",
      "jurisdiction_code|=": ["gb", "ie"],
      "memberships": [{
        "role": "director",
        "inactive": false
      }]
    }
  }
}
EOL

value = JSON.dump(JSON.load(queries))

body = open("http://localhost:9292/people?queries=#{CGI.escape(value)}").read

results = JSON.load(body)
#=> {"q0"=>
#  {"count"=>3915,
#   "result"=>
#    [{"@type"=>"Person",
#      "name"=>"<NAME>",
#      "updated_at"=>"2014-10-25T00:34:16+00:00",
#      "identifiers"=>[{"identifier"=>"46065070", "scheme"=>"OpenCorporates"}],
#      "contact_details"=>[],<commit_msg>add more return values<commit_after># Who's got dirt? A federated search API for people and organizations

[![Build Status](https://secure.travis-ci.org/influencemapping/whos_got_dirt-server.png)](https://travis-ci.org/influencemapping/whos_got_dirt-server)
[![Dependency Status](https://gemnasium.com/influencemapping/whos_got_dirt-server.png)](https://gemnasium.com/influencemapping/whos_got_dirt-server)
[![Coverage Status](https://coveralls.io/repos/influencemapping/whos_got_dirt-server/badge.svg)](https://coveralls.io/r/influencemapping/whos_got_dirt-server)
[![Code Climate](https://codeclimate.com/github/influencemapping/whos_got_dirt-server.png)](https://codeclimate.com/github/influencemapping/whos_got_dirt-server)

See the [Ruby gem](https://github.com/influencemapping/whos_got_dirt-gem) for details.

## Usage

### People

`GET /people?queries=<queries>` where `<queries>` looks like:

```json
{
  "q0": {
    "query": {
      "type": "Person",
      "name~=": "<NAME>",
      "jurisdiction_code|=": ["gb", "ie"],
      "memberships": [{
        "role": "director",
        "inactive": false
      }]
    }
  }
}
```

You may use any query ID instead of `q0`. Not all APIs support every parameter and operator. **If a parameter or operator is unsupported, it is silently ignored.** See more in the [documentation](http://www.rubydoc.info/gems/whos_got_dirt/WhosGotDirt/Requests/Person).

**If an API returns an error, its response is silently ignored.** See more in the [documentation](http://www.rubydoc.info/gems/whos_got_dirt/WhosGotDirt/Responses/Person).

For example, run `bundle exec rackup` in a Unix shell, and run the following in a Ruby shell:

```ruby
require 'cgi'
require 'open-uri'
require 'json'

queries = <<-EOL
{
  "q0": {
    "query": {
      "type": "Person",
      "name~=": "<NAME>",
      "jurisdiction_code|=": ["gb", "ie"],
      "memberships": [{
        "role": "director",
        "inactive": false
      }]
    }
  }
}
EOL

value = JSON.dump(JSON.load(queries))
#=> {"q0":{"query":{"type":"Person","name~=":"<NAME>","jurisdiction_code|=":["gb","ie"],"memberships":[{"role":"director","inactive":false}]}}}

url = "http://localhost:9292/people?queries=#{CGI.escape(value)}"
#=> http://localhost:9292/people?queries=%7B%22q0%22%3A%7B%22query%22%3A%7B%22type%22%3A%22Person%22%2C%22name%7E%3D%22%3A%22John+Smith%22%2C%22jurisdiction_code%7C%3D%22%3A%5B%22gb%22%2C%22ie%22%5D%2C%22memberships%22%3A%5B%7B%22role%22%3A%22director%22%2C%22inactive%22%3Afalse%7D%5D%7D%7D%7D

results = JSON.load(open(url).read)
#=> {"q0"=>
#  {"count"=>3915,
#   "result"=>
#    [{"@type"=>"Person",
#      "name"=>"<NAME>",
#      "updated_at"=>"2014-10-25T00:34:16+00:00",
#      "identifiers"=>[{"identifier"=>"46065070", "scheme"=>"OpenCorporates"}],
#      "contact_details"=>[],
{'fraction_non_alphanumeric': 0.1946594427244582, 'fraction_numerical': 0.03154024767801858, 'mean_word_length': 4.736958934517203, 'pattern_counts': {'":': 40, '<': 18, '<?xml version=': 0, '>': 38, 'https://': 18, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2417809', 'n_tokens_mistral': 2063, 'n_tokens_neox': 1902, 'n_words': 314}