Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/buren/polisen-api
Polisen API client
https://github.com/buren/polisen-api
api-client npm-package polisen polisen-api
Last synced: 27 days ago
JSON representation
Polisen API client
- Host: GitHub
- URL: https://github.com/buren/polisen-api
- Owner: buren
- Created: 2018-08-17T08:02:22.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-08-01T04:16:10.000Z (over 1 year ago)
- Last Synced: 2024-08-04T01:12:28.727Z (3 months ago)
- Topics: api-client, npm-package, polisen, polisen-api
- Language: JavaScript
- Size: 15.6 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-sweden - JavaScript - events and police stations (Misc)
README
# PolisenAPI
Simple JavaScript API client for [Polisen API](https://polisen.se/om-polisen/om-webbplatsen/oppna-data/api-over-polisens-handelser/).
## Getting started
Requires `node` >= 8.9.0
```
npm install --save polisen-api
```# Usage
Initialize
```javascript
const PolisenAPI = require('polisen-api')
```Get police stations
```javascript
api.fetchPoliceStations()
.then((stations) => {
console.log(stations.map(s => s.name))
})
```Get latest events
```javascript
const api = new PolisenAPI()api.fetchEvents()
.then((events) => {
console.log(events.map(e => e.name))
})
```:warning: The API does __not__ let you filter further back than the last ~500 events or so. See [this note on filters](#filter-note) for more info.
Filter events on location
```javascript
api.fetchEvents({ locations: ['Stockholm', 'Järfälla'] })
```Filter events on type
```javascript
api.fetchEvents({ types: ['Djur skadat/omhändertaget', 'Trafikbrott'] })
```Filter on year/month/day/hour
```javascript
api.fetchEvents({ date: { year: 2018 } })
api.fetchEvents({ date: { year: 2018, month: 8 } })
api.fetchEvents({ date: { year: 2018, month: 8, day: 16 } })
api.fetchEvents({ date: { year: 2018, month: 8, day: 16, hour: 8 } })
```Multiple filters
```javascript
api.fetchEvents({
date: { year: 2018 },
locations: ['Järfälla'],
types: ['Djur skadat/omhändertaget'],
})
```Throws errors for invalid arguments
```javascript
api.fetchEvents({ date: { year: 2018, month: '-1' } })
//
```If you only want to get build the URL
```javascript
api.getEventsURL({ locations: ['Stockholm'], date: { year: 2018, month: '3' } })
// supports the same params as fetchEventsapi.getPoliceStationsURL()
```You can require all available event types
```javascript
const policeEventTypes = require('polisen-api/event_types_data')
```Add latitude and longitude to location data
```javascript
const apiLatLong = require('polisen-api/api-lat-long')api.fetchEvents()
.then(events => {
events.map(event => apiLatLong(event.location))
// { latitude: 63.176683, longitude: 14.636068, ...event.location }
})api.fetchPoliceStations()
.then(stations => {
stations.map(station => apiLatLong(station.location))
// { latitude: 63.176683, longitude: 14.636068, ...station.location }
})
```## Filter note
When given no parameters the API returns last 500 events. The API __does not__ let you filter more than a week back (during my very limited testing), so unfortunately you can't do historical analysis.
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/buren/polisen-api.
## Development
Setup
```
$ git clone https://github.com/buren/polisen-api
$ cd polisen-api
$ npm install
```Run the example
```
$ node example.js
```## License
The library is available as open source under the terms of the [MIT License](LICENSE).