Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added endpoint for postcodes in Iceland #490

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions endpoints/postcodes/documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Icelandic Addresses

Source [Iceland Post](https://postur.is)

- GET [/postcodes](https://apis.is/postcodes)

Lookup postcodes in Iceland through the Icelandic Post API
---
20 changes: 20 additions & 0 deletions endpoints/postcodes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* eslint-disable import/first */
const request = require('request')
const h = require('apis-helpers')
const app = require('../../server')

app.get('/postcodes', async (req, res) => {
request.get({
headers: { 'User-Agent': h.browser() },
url: `https://posturapi.prod.postur.is/api/postcodes`,
}, (error, response, body) => {
if (error || response.statusCode !== 200) {
return res.status(500).json({ error: 'www.postur.is refuses to respond or give back data' })
}
try {
return res.cache(86400).send({ results: JSON.parse(body) })
} catch (error) {
return res.status(500).json({ error: 'www.postur.is changed format of data' })
}
})
})
20 changes: 20 additions & 0 deletions endpoints/postcodes/tests/integration_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const request = require('request')
const helpers = require('../../../lib/test_helpers')

describe('postcodes', () => {
it('should return an array of objects containing correct fields', (done) => {
const fieldsToCheckFor = ['postCode', 'city']
const params = helpers.testRequestParams('/postcodes')
const resultHandler = helpers.testRequestHandlerForFields(done, fieldsToCheckFor)
request.get(params, resultHandler)
})
})

describe('concerts', () => {
it('should return an array of objects containing correct fields', (done) => {
const fieldsToCheckFor = ['postCode', 'city']
const params = helpers.testRequestParams('/postcodes')
const resultHandler = helpers.testRequestHandlerForFields(done, fieldsToCheckFor)
request.get(params, resultHandler)
})
})
Loading