Comparing version 0.0.1 to 0.1.0
var pluk = require('./src/pluk'); | ||
pluk.hood('Bank, London').info().then(function(result) { | ||
pluk.hood('Westminster, London').info().then(function(result) { | ||
console.warn('Result:', result); | ||
@@ -5,0 +5,0 @@ }, function(err) { |
{ | ||
"name": "pluk", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "data.police.uk API wrapper", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/padolsey/pluk", |
Pluk | ||
== | ||
Bindings for [data.police.uk/api](http://data.police.uk/api). | ||
Bindings for **[data.police.uk](http://data.police.uk/docs/)**. | ||
@@ -17,24 +17,4 @@ ## Install | ||
pluk.hood('Bank, London').info().then(function(data) { | ||
data; /* => | ||
{ | ||
contact_details: | ||
{ telephone: '020 7601 2452', | ||
email: 'community@cityoflondon.police.uk' }, | ||
name: 'Community Policing', | ||
links: [], | ||
centre: { latitude: '51.5151', longitude: '-0.0934' }, | ||
locations: | ||
[ { name: 'Snow Hill Police Station', | ||
longitude: null, | ||
postcode: 'EC1A 2DP', | ||
address: '5 Snow Hill\nLondon', | ||
latitude: null, | ||
type: 'station', | ||
description: null } ], | ||
url_force: 'http://www.cityoflondon.police.uk/community-policing/', | ||
population: '208596', | ||
id: 'cp', | ||
description: '<p>City of London Police Community Policing</p>' | ||
}*/ | ||
pluk.hood('Westminster, London').info().then(function(data) { | ||
console.log(data); | ||
}, function(err) { | ||
@@ -45,10 +25,36 @@ // err occurred | ||
## Current methods | ||
```js | ||
// Logged: | ||
{ | ||
contact_details: | ||
{ telephone: '020 7601 2452', | ||
email: 'community@cityoflondon.police.uk' }, | ||
name: 'Community Policing', | ||
links: [], | ||
centre: { latitude: '51.5151', longitude: '-0.0934' }, | ||
locations: | ||
[ { name: 'Snow Hill Police Station', | ||
longitude: null, | ||
postcode: 'EC1A 2DP', | ||
address: '5 Snow Hill\nLondon', | ||
latitude: null, | ||
type: 'station', | ||
description: null } ], | ||
url_force: 'http://www.cityoflondon.police.uk/community-policing/', | ||
population: '208596', | ||
id: 'cp', | ||
description: '<p>City of London Police Community Policing</p>' | ||
} | ||
``` | ||
* `info()` | ||
* `events()` | ||
* `priorities()` | ||
* `boundary()` | ||
* `people()` | ||
## Current API | ||
* `hood(ADDR | POST-CODE | [LAT, LNG])` - returns methods: | ||
* *Each method returns a when.js promise* | ||
* `info()` | ||
* `events()` | ||
* `priorities()` | ||
* `boundary()` | ||
* `people()` | ||
See http://data.police.uk/docs/ for additional docs. | ||
@@ -55,0 +61,0 @@ |
@@ -10,2 +10,5 @@ 'use strict'; | ||
return new Hood(search); | ||
}, | ||
direct: function(path) { | ||
return plgrab(path); | ||
} | ||
@@ -29,3 +32,3 @@ }; | ||
if (err) reject(err); | ||
else if (/^not found/i.test(body)) reject(body) | ||
else if (response.statusCode != 200) reject(body) | ||
else resolve(JSON.parse(body)); | ||
@@ -42,7 +45,15 @@ }); | ||
var t = this; | ||
this.search = search; | ||
this._hood = typeof search == 'string' ? | ||
grab('http://maps.googleapis.com/maps/api/geocode/json?address=' + encodeURIComponent(search) + '&sensor=false').then(function(l) { | ||
grab( | ||
'http://maps.googleapis.com/maps/api/geocode/json?' + | ||
[ | ||
'address=' + encodeURIComponent(search), | ||
'sensor=false', | ||
'region=UK' | ||
].join('&') | ||
).then(function(l) { | ||
return t._getByLatLng(l.results[0].geometry.location); | ||
}) : | ||
this._getByLatLng(search[0], search[1]); | ||
this._getByLatLng({ lat: search[0], lng: search[1] }); | ||
} | ||
@@ -77,5 +88,9 @@ | ||
_getByLatLng: function(loc) { | ||
return grab('http://data.police.uk/api/locate-neighbourhood?q='+loc.lat+','+loc.lng).then(null, function(err) { | ||
var e = new Error('Cannot locate neighbourhood @ ' + [loc.lat, loc.lng]); | ||
var t = this; | ||
var lat = loc.lat; | ||
var lng = loc.lng; | ||
return plgrab('locate-neighbourhood?q='+lat+','+lng).then(null, function(err) { | ||
var e = new Error('Cannot locate neighbourhood @ ' + [lat, lng]); | ||
e.detail = err; | ||
e.search = t.search; | ||
throw e; | ||
@@ -82,0 +97,0 @@ }); |
5443
5
121
63