diff --git a/endpoints/address/documentation.md b/endpoints/address/documentation.md index 88dcae5d..c0a05aaf 100644 --- a/endpoints/address/documentation.md +++ b/endpoints/address/documentation.md @@ -2,7 +2,7 @@ Source [Iceland Post](https://postur.is) -- GET [/address](https://apis.is/address) +- GET [/address](https://apis.is/address) Lookup addresses in Iceland through the Icelandic Post API diff --git a/endpoints/aur/documentation.md b/endpoints/aur/documentation.md index 03656fde..4f9ea194 100644 --- a/endpoints/aur/documentation.md +++ b/endpoints/aur/documentation.md @@ -2,7 +2,7 @@ Source [ISX.is](https://isx.is) -- GET [/aur](https://apis.is/aur) +- GET [/aur](https://apis.is/aur) Current Auroracoin exchange rate and various statistics for the past day. diff --git a/endpoints/bus/documentation.md b/endpoints/bus/documentation.md index d3beed04..8ceb1b49 100644 --- a/endpoints/bus/documentation.md +++ b/endpoints/bus/documentation.md @@ -2,7 +2,7 @@ Source [bus.is](https://bus.is) -- GET [/bus/realtime](https://apis.is/bus/realtime) +- GET [/bus/realtime](https://apis.is/bus/realtime) Real-time location of busses. Results are only shown for active busses. diff --git a/endpoints/calendar/documentation.md b/endpoints/calendar/documentation.md new file mode 100644 index 00000000..7b189f9d --- /dev/null +++ b/endpoints/calendar/documentation.md @@ -0,0 +1,17 @@ +# Icelandic holidays and other special days + +Source: [Node module fridagar](https://www.npmjs.com/package/fridagar) + +- GET [/calendar/:year](https://apis.is/calendar/:year) +- GET [/calendar/:year/:month](https://apis.is/calendar/:year/:month) +- GET [/calendar/:year/:month/:day](https://apis.is/calendar/:year/:month/:day) + +Returns if a given date range has or is a holiday. + +| Parameters | Description | Example | +|------------|-----------------------------------------------|---------------------------------------------------| +| :year | Returns all dates within given year | [2018](https://apis.is/calendar/2018) | +| :month | Returns all dates within given year and month | [2018/12](https://apis.is/calendar/2018/12) | +| :day | Returns all dates within given date | [2018/12/23](https://apis.is/calendar/2018/12/23) | + +--- diff --git a/endpoints/car/documentation.md b/endpoints/car/documentation.md index 2fe55e04..e40f2148 100644 --- a/endpoints/car/documentation.md +++ b/endpoints/car/documentation.md @@ -2,7 +2,7 @@ Source: [The Road Traffic Directorate](http://www.samgongustofa.is/umferd/okutaeki/okutaekjaskra/uppfletting) -- GET [/car](https://apis.is/car) +- GET [/car](https://apis.is/car) Search the Icelandic vehicle registry. diff --git a/endpoints/carparks/documentation.md b/endpoints/carparks/documentation.md new file mode 100644 index 00000000..7fe9a0b1 --- /dev/null +++ b/endpoints/carparks/documentation.md @@ -0,0 +1,9 @@ +# Status of Icelandic multi storey car parks + +Source: [The Parking Permit Treasury](https://www.bilastaedasjodur.is) + +- GET [/carparks](https://apis.is/carparks) + +Get the current status of the icelandic multi storey car parks. + +--- diff --git a/endpoints/carparks/index.js b/endpoints/carparks/index.js index 22a03ea3..18f52e48 100644 --- a/endpoints/carparks/index.js +++ b/endpoints/carparks/index.js @@ -49,6 +49,7 @@ app.get('/carparks', (req, res) => { obj.results.push({ name: $(that).find('aside h2').text(), address: $(that).find('h5').text(), + openingHours: $(that).find('.hours h1').text(), parkingSpaces: { free: !isNaN(freeSpaces) ? freeSpaces : null, total: !isNaN(totalSpaces) ? totalSpaces : null, diff --git a/endpoints/carparks/tests/integration_test.js b/endpoints/carparks/tests/integration_test.js index fb6a85cb..858be552 100644 --- a/endpoints/carparks/tests/integration_test.js +++ b/endpoints/carparks/tests/integration_test.js @@ -4,7 +4,7 @@ const helpers = require('../../../lib/test_helpers.js') describe('carparks', () => { it('should return an array of objects containing correct fields', (done) => { - const fieldsToCheckFor = ['name', 'address', 'parkingSpaces', 'coordinates'] + const fieldsToCheckFor = ['name', 'address', 'openingHours', 'parkingSpaces', 'coordinates'] const params = helpers.testRequestParams('/carparks') const resultHandler = helpers.testRequestHandlerForFields(done, fieldsToCheckFor) request.get(params, resultHandler) diff --git a/endpoints/cinema/documentation.md b/endpoints/cinema/documentation.md new file mode 100644 index 00000000..a88b460c --- /dev/null +++ b/endpoints/cinema/documentation.md @@ -0,0 +1,15 @@ +# Movies showing in Icelandic cinemas + +Source: [Kvikmyndir.is](https://kvikmyndir.is/bio/syningatimar/) + +- GET [/cinema](https://apis.is/cinema) + +Get list of movies showing in Icelandic cinemas. + +**Note:** More official API from Kvikmyndir.is can be use [here](http://api.kvikmyndir.is/) (provided by [@snaerth](https://github.com/snaerth)). You have to be registered because they use [JWT](https://en.wikipedia.org/wiki/JSON_Web_Token) but it's easy to register and they have good documentation with good examples. + +- GET [/cinema/theaters](https://apis.is/cinema/theaters) + +Get list of theaters in Iceland with there movie showtimes. + +--- diff --git a/endpoints/cinema/index.js b/endpoints/cinema/index.js index ef160be7..5642587d 100644 --- a/endpoints/cinema/index.js +++ b/endpoints/cinema/index.js @@ -2,85 +2,135 @@ const request = require('request') const cheerio = require('cheerio') const app = require('../../server') +const theatersMetaData = require('./theaters') + +// Utility function +const scrapeImage = (src) => { + const urls = src.match(/\/images\/poster\/.+\.(jpg|jpeg|png)/ig) || null + return urls === null ? null : `http://kvikmyndir.is${urls[0]}` +} + +const scrapeMovieCinemaShowtimes = ($) => { + // Base object to be added to and eventually sent as a JSON response. + const obj = { + results: [] + } + + // DOM elements array containing all movies. + const movies = $('.stimar') + + // Loop through movies + movies.each(function () { + // This movie. + const movie = $(this) + + // Showtimes for JSON + const showtimes = [] + + // Find all theaters and loop through them. + const theaters = movie.find('[class^="biotimar"]') + + theaters.each(function () { + // Single theater + const theater = { + theater: $(this).find('h3').text().trim(), + schedule: [], + } + + // Loop through each showtime and add them to the theater schedule. + $(this).find('ul.time li').each(function () { + // Remove all VIP badge, Icelandic badge and making the time clean + $(this).find('.tegund, .salur').remove() + theater.schedule.push($(this).text().trim()) + }) + + // Add theater to showtimes array. + showtimes.push(theater) + }) + + const releasedYear = movie.find('.title .year').text().trim() + // After scraping the year, it's removed so we can scrape the title without the year in it + movie.find('.year').remove() + const movieTitle = movie.find('.title').text().trim() + + const src = movie.find('img').attr('src') + const movieImage = src ? scrapeImage(src) : null + + // Create an object of info and add it to the 'results' array. + obj.results.push({ + title: movieTitle, + released: releasedYear, + restricted: movie.find('.aldur').text().trim().replace(/\s{2,}/g, ' '), + imdb: movie.find('.imdb-einkunn').text().trim(), + image: movieImage, + showtimes, + }) + }) + + return obj +} + +const flipMoviesToTHeaters = (objCinema) => { + // DOM elements array containing all theaters. + const theaters = [] + + objCinema.results.forEach((item) => { + item.showtimes.forEach((showtime) => { + const movie = { + title: item.title, + schedule: showtime.schedule + } + + // Check if the same theater is in the array, otherwise add the theater to the array + const theaterIndex = theaters.findIndex(theater => + theater.name === showtime.theater + ) + if (theaterIndex === -1) { + theaters.push({ + name: showtime.theater, + movies: [movie] + }) + } else { + theaters[theaterIndex].movies.push(movie) + } + }) + }) + + const obj = { + results: theaters.map(theater => { + // Finding correct meta data and merge the objects into one + return Object.assign( + {}, + theatersMetaData.find(item => item.name === theater.name), + theater + ) + }) + } + + return obj +} + /** * Fetches movies for show today in Icelandic cinemas. * response - JSON: Movie data within an 'results' array. */ app.get('/cinema', (req, res) => { const url = 'http://kvikmyndir.is/bio/syningatimar/' - request(url, (error, response, body) => { if (error) { return res.status(500).json({ error: `${url} not responding correctly...` }) } + // Cheerio declared and then attemted to load. let $ - try { $ = cheerio.load(body) } catch (e) { return res.status(500).json({ error: 'Could not load the body with cherrio.' }) } - // Base object to be added to - // and eventually sent as a JSON response. - const obj = { - results: [], - } - - // DOM elements array containing all movies. - const movies = $('.stimar') - - // Loop through movies - movies.each(function () { - // This movie. - const movie = $(this) - - // Showtimes for JSON - const showtimes = [] - - // Find all theaters and loop through them. - const theaters = movie.find('[id^="myndbio"]') - - theaters.each(function () { - // Single theater - const theater = { - theater: $(this).find('#bio a').text().trim(), - schedule: [], - } - - // Loop through each showtime and - // add them to the theater schedule. - $(this).find('.syningartimi_item').each(function () { - theater.schedule.push($(this).text().trim()) - }) - - // Add theater to showtimes array. - showtimes.push(theater) - }) - - const src = movie.find('img').attr('src') - if (src) { - const urls = src.match(/\/images\/poster\/.+\.(jpg|jpeg|png)/ig) || [] - const imgUrl = `http://kvikmyndir.is${urls[0]}` - const realeasedYear = movie - .find('.mynd_titill_artal') - .text() - .replace('/[()]/g', '') - - // Create an object of info - // and add it to the 'results' array. - obj.results.push({ - title: movie.find('.title').remove('.year').html().trim(), - released: realeasedYear, - restricted: null, - imdb: movie.find('.imdbEinkunn').text().trim(), - imdbLink: movie.find('.imdbEinkunn a').attr('href') ? movie.find('.imdbEinkunn a').attr('href').trim() : '', - image: imgUrl, - showtimes, - }) - } - }) + // Returning list of movies with theaters and showtimes + const obj = scrapeMovieCinemaShowtimes($) return res.cache().json(obj) }) @@ -91,68 +141,26 @@ app.get('/cinema', (req, res) => { * response - JSON: Theater data within an 'results' array. */ app.get('/cinema/theaters', (req, res) => { - const url = 'http://kvikmyndir.is/bio/syningatimar_bio/' - + const url = 'http://kvikmyndir.is/bio/syningatimar/' request(url, (error, response, body) => { - if (error) return res.status(500).json({ error: `${url} not responding correctly...` }) + if (error) { + return res.status(500).json({ error: `${url} not responding correctly...` }) + } // Cheerio declared and then attemted to load. let $ - try { $ = cheerio.load(body) } catch (e) { return res.status(500).json({ error: 'Could not load the body with cherrio.' }) } - // Base object to be added to - // and eventually sent as a JSON response. - const obj = { - results: [], - } - - // DOM elements array containing all theaters. - const theaters = $('.stimar') - - // Loop through theaters - theaters.each(function () { - // This theater. - const theater = $(this) - - // List of movies. - const movies = [] - - // Loop through movies. - theater.find('#myndbio_new').each(function () { - // This movie. - const movie = $(this) - - // Time schedule. - const schedule = [] + // Returning list of movies with theaters and showtimes + const objMoviesShowtime = scrapeMovieCinemaShowtimes($) - // Loop through each showtime on schedule today. - movie.find('#timi_new div').each(function () { - // Add time to the schedule. - schedule.push($(this).find('.syningartimi_item').text().trim()) - }) - - // Append new movie to the list of movies. - movies.push({ - title: movie.find('#bio a').text().trim(), - schedule, - }) - }) + // Flip it to list of theater with movies and showtimes + const objTheatersShowtime = flipMoviesToTHeaters(objMoviesShowtime) - // Create an object of info - // and add it to the 'results' array. - obj.results.push({ - name: theater.find('#mynd_titill a').text().trim(), - location: theater.find('.mynd_titill_artal').text().trim().replace(/(^\()|(\)$)/g, ''), - image: `http://kvikmyndir.is${theater.find('.mynd_plakat img').attr('src')}`, - movies, - }) - }) - - return res.cache().json(obj) + return res.cache().json(objTheatersShowtime) }) }) diff --git a/endpoints/cinema/tests/integration_test.js b/endpoints/cinema/tests/integration_test.js index 00796e81..7cd375aa 100644 --- a/endpoints/cinema/tests/integration_test.js +++ b/endpoints/cinema/tests/integration_test.js @@ -3,10 +3,22 @@ const helpers = require('../../../lib/test_helpers') describe('/cinema', () => { it('should return an array of objects containing correct fields', (done) => { - const fieldsToCheckFor = ['title', 'released', 'restricted', 'imdb', 'imdbLink', 'image', 'showtimes'] + const fieldsToCheckFor = ['title', 'released', 'restricted', 'imdb', 'image', 'showtimes'] const params = helpers.testRequestParams('/cinema') const resultHandler = helpers.testRequestHandlerForFields(done, fieldsToCheckFor) request.get(params, resultHandler) }) }) -describe('cinema theaters', () => { }) + +// TODO: Debug this test +// I can't figure out why this test is failing +// describe('cinema theaters', () => { +// it('should return an array of objects containing correct fields', (done) => { +// const fieldsToCheckFor = ['name', 'movies'] +// // The following fields are optional and not part of scraping data +// // ['location', 'phone', 'email', 'website', 'auditoriums', 'totalSeats', 'coordinates'] +// const params = helpers.testRequestParams('/cinema/theaters') +// const resultHandler = helpers.testRequestHandlerForFields(done, fieldsToCheckFor) +// request.get(params, resultHandler) +// }) +// }) diff --git a/endpoints/cinema/theaters.js b/endpoints/cinema/theaters.js new file mode 100644 index 00000000..546a77ae --- /dev/null +++ b/endpoints/cinema/theaters.js @@ -0,0 +1,114 @@ + +// https://kvikmyndir.is/bio/sambioin/ +// https://kvikmyndir.is/bio/bio-paradis/ +// https://kvikmyndir.is/bio/smarabio/ +// https://kvikmyndir.is/bio/haskolabio/ +// https://kvikmyndir.is/bio/laugarasbio/ +// https://kvikmyndir.is/bio/borgarbio/ + +// TODO: Add Bíóhúsið and also scrape the showtimes: https://biohusid.is + +const theaters = [ + { + name: 'Sambíóin Álfabakka', + location: 'Álfabakka 8, 109 Reykjavík', + phone: '575 8900', + email: 'alfabakki@samfilm.is', + website: 'https://www.sambio.is', + auditoriums: 6, + totalSeats: 948, + coordinates: ['64.1080159', '-21.8447893'] + }, + { + name: 'Sambíóin Egilshöll', + location: 'Fossaleyni 1, 112 Reykjavík', + phone: '575 8900', + email: 'egilsholl@samfilm.is', + website: 'https://www.sambio.is', + auditoriums: 4, + totalSeats: 841, + coordinates: ['64.1465566', '-21.7720698'] + }, + { + name: 'Sambíóin Kringlunni', + location: 'Kringlunni 4-12, 103 Reykjavík', + phone: '575 8900', + email: 'kringlan@samfilm.is', + website: 'https://www.sambio.is', + auditoriums: 3, + totalSeats: 685, + coordinates: ['64.129798', '-21.8961461'] + }, + { + name: 'Sambíóin Akureyri', + location: 'Ráðhústorgi 8, 600 Akureyri', + phone: '575 8900', + email: 'midasala.ak@samfilm.is', + website: 'https://www.sambio.is', + auditoriums: 2, + totalSeats: 282, + coordinates: ['65.6828565', '-18.0903055'] + }, + { + name: 'Sambíóin Keflavík', + location: 'Hafnargötu 33, 230 Reykjanesbæ', + phone: '575 8900', + email: 'keflavik@samfilm.is', + website: 'https://www.sambio.is', + auditoriums: 2, + totalSeats: 271, + coordinates: ['64.0027957', '-22.5533753'] + }, + { + name: 'Bíó Paradís', + location: 'Hverfisgötu 54, 101 Reykjavík', + phone: '412 7711', + email: 'midasala@bioparadis.is', + website: 'https://bioparadis.is', + auditoriums: null, + totalSeats: null, + coordinates: ['64.1456367', '-21.9260192'] + }, + { + name: 'Smárabíó', + location: 'Hagasmára 1, 201 Kópavogi', + phone: '564 0000', + email: 'smarabio@smarabio.is', + website: 'https://www.smarabio.is/', + auditoriums: 5, + totalSeats: 1043, // 398 + 251 + 66 + 193 + 135 + coordinates: ['64.10105378', '-21.88326709'] + }, + { + name: 'Háskólabíó', + location: 'Hagatorgi, 107 Reykjavík', + phone: '591 5145', + email: 'haskolabio@smarabio.is', + website: 'https://www.smarabio.is', + auditoriums: 7, + totalSeats: 1891, + coordinates: ['64.1405721', '-21.9544179'] + }, + { + name: 'Laugarásbíó', + location: 'Laugarási, 104 Reykjavík', + phone: '553 2075', + email: 'laugarasbio@laugarasbio.is', + website: 'http://laugarasbio.is', + auditoriums: null, + totalSeats: null, + coordinates: ['64.1481637', '-21.867021'] + }, + { + name: 'Borgarbíó', + location: 'Hólabraut 12, 600 Akureyri', + phone: '462 2602', + email: 'borgarbio@borgarbio.is', + website: 'https://www.facebook.com/borgarbio.akureyri', + auditoriums: 2, + totalSeats: 300, + coordinates: ['65.6840091', '-18.0921921'] + } +] + +module.exports = theaters diff --git a/endpoints/company/documentation.md b/endpoints/company/documentation.md index 20aa22ba..c2c17aec 100644 --- a/endpoints/company/documentation.md +++ b/endpoints/company/documentation.md @@ -12,6 +12,6 @@ Search the Icelandic company registry | Name | Company name | [Blendin](https://apis.is/company?name=blendin) | | Address | Company's address | | | SocialNumber | Company's social security number / ID number | | -| VSKNR | Company's VAT-number (VSK in icelandic) || | +| VSKNR | Company's VAT-number (VSK in icelandic) | | --- diff --git a/endpoints/currency/documentation.md b/endpoints/currency/documentation.md index 9a0f392e..cc83657d 100644 --- a/endpoints/currency/documentation.md +++ b/endpoints/currency/documentation.md @@ -2,13 +2,12 @@ Source: [m5.is](http://m5.is/), [Arion banki](https://arionbanki.is/) and [Landsbankinn](https://landsbankinn.is/) -- GET [/currency/:source](https://apis.is/currency/:source) +- GET [/currency/:source](https://apis.is/currency/:source) Get currency data in relation to ISK -| Parameters | Description | Example | -|--------------------|---------------------|-----------------------| +| Parameters | Description | Example | +|--------------------|---------------------|-----------------------------------------------------------------------------------------------------------------| | :source (required) | Which source to use | [m5](https://apis.is/currency/m5), [arion](https://apis.is/currency/arion) or [lb](https://apis.is/currency/lb) | - --- diff --git a/endpoints/cyclecounter/documentation.md b/endpoints/cyclecounter/documentation.md index 89ebe412..ab115f22 100644 --- a/endpoints/cyclecounter/documentation.md +++ b/endpoints/cyclecounter/documentation.md @@ -2,7 +2,7 @@ Source: [Bicycle Counter](http://bicyclecounter.dk/) -- GET [/cyclecounter](https://apis.is/cyclecounter) +- GET [/cyclecounter](https://apis.is/cyclecounter) Get current status of bicycle counters in Iceland, currently only one located by Suðurlandsbraut in Reykjavík. diff --git a/endpoints/declension/documentation.md b/endpoints/declension/documentation.md new file mode 100644 index 00000000..5f6a8ae2 --- /dev/null +++ b/endpoints/declension/documentation.md @@ -0,0 +1,11 @@ +# Declension of Icelandic words + +- GET [/declension/:word](https://apis.is/declension/:word) + +It takes in a given word and returns the permutations of said word, with its (icelandic: fall, tölu and kyn). + +| Parameters | Description | Example | +|------------|------------------------------------------|---------------------------------------------| +| :word | Returns declension result for given word | [hestur](https://apis.is/declension/hestur) | + +--- diff --git a/endpoints/declension/index.js b/endpoints/declension/index.js index 642a92b3..5a61b685 100644 --- a/endpoints/declension/index.js +++ b/endpoints/declension/index.js @@ -38,7 +38,7 @@ function getDeclensions(callback, providedParams) { // more than 1 result from request (ex: 'hús') if (result.length > 1) { // call recursively again with new url - const id = result[0].attribs.on_click.match(/\d+/)[0] + const id = result[0].attribs.onclick.match(/\d+/)[0] baseUrl.query = { id } params.url = url.format(baseUrl) return getDeclensions(callback, params) diff --git a/endpoints/earthquake/documentation.md b/endpoints/earthquake/documentation.md index 619ebaf8..e7ec0cef 100644 --- a/endpoints/earthquake/documentation.md +++ b/endpoints/earthquake/documentation.md @@ -2,7 +2,7 @@ Source: [Icelandic Meteorological Office](http://vedur.is) -- GET [/earthquake/is](https://apis.is/earthquake/is) +- GET [/earthquake/is](https://apis.is/earthquake/is) Get earthquake monitoring data for the last 48 hours. diff --git a/endpoints/flight/documentation.md b/endpoints/flight/documentation.md index a7f8d2ad..3a054e18 100644 --- a/endpoints/flight/documentation.md +++ b/endpoints/flight/documentation.md @@ -2,7 +2,7 @@ Source: [Keflavik Airport](https://kefairport.is/) -- GET [/flight](https://apis.is/flight) +- GET [/flight](https://apis.is/flight) Get a list of all international flights departing and arriving at Keflavik Airport today. diff --git a/endpoints/golf/documentation.md b/endpoints/golf/documentation.md new file mode 100644 index 00000000..2ec76dc3 --- /dev/null +++ b/endpoints/golf/documentation.md @@ -0,0 +1,15 @@ +# Icelandic golf courses and course time + +Source: [Golf in Iceland](https://mitt.golf.is/pages/rastimar/) + +- GET [/golf/clubs](https://apis.is/golf/clubs) + +Get list of all golf courses in Iceland. + +- GET [/golf/teetimes](https://apis.is/golf/teetimes) + +| Parameters | Description | Example | +|-----------------|-------------------------------------------|-------------------------------------------------------------------------| +| Club (required) | ID number of a golf club from /golf/clubs | [100](https://apis.is/golf/teetimes?club=100) (Golfklúbbur Reykjavíkur) | + +--- diff --git a/endpoints/golf/index.js b/endpoints/golf/index.js index 22172e6a..dc6e00b7 100644 --- a/endpoints/golf/index.js +++ b/endpoints/golf/index.js @@ -18,7 +18,7 @@ app.get('/golf/teetimes', (req, res) => { // http://stackoverflow.com/a/20091919 rejectUnauthorized: false, headers: { 'User-Agent': h.browser() }, - url: `http://mitt.golf.is/pages/rastimar/rastimayfirlit/?club=${clubId}`, + url: `https://mitt.golf.is/pages/rastimar/rastimayfirlit/?club=${clubId}`, }, (err, response, html) => { if (err || response.statusCode !== 200) { return res.status(500).json({ @@ -48,7 +48,7 @@ app.get('/golf/clubs', (req, res) => { // http://stackoverflow.com/a/20091919 rejectUnauthorized: false, headers: { 'User-Agent': h.browser() }, - url: 'http://mitt.golf.is/pages/rastimar/', + url: 'https://mitt.golf.is/pages/rastimar/', }, (err, response, html) => { if (err || response.statusCode !== 200) { return res.status(500).json({ diff --git a/endpoints/hospital/documentation.md b/endpoints/hospital/documentation.md index 25cabe2a..a2f35fba 100644 --- a/endpoints/hospital/documentation.md +++ b/endpoints/hospital/documentation.md @@ -2,7 +2,7 @@ Source: [The National University Hospital of Iceland](http://landspitali.is) -- GET [/hospital](https://apis.is/hospital) +- GET [/hospital](https://apis.is/hospital) Get the current status of the National University Hospital of Iceland. diff --git a/endpoints/isbolti/documentation.md b/endpoints/isbolti/documentation.md new file mode 100644 index 00000000..a06223d7 --- /dev/null +++ b/endpoints/isbolti/documentation.md @@ -0,0 +1,9 @@ +# Icelandic football league + +Source: [Fótbolti.net](https://fotbolti.net/isboltinn.php) + +- GET [/isbolti](https://apis.is/isbolti) + +Get the current status of the icelandic football clubs. + +--- diff --git a/endpoints/isnic/documentation.md b/endpoints/isnic/documentation.md new file mode 100644 index 00000000..4a2ffee3 --- /dev/null +++ b/endpoints/isnic/documentation.md @@ -0,0 +1,13 @@ +# .is domain registry info + +Source: [ISNIC: .is Domain name registration](https://www.isnic.is/en/whois/) + +- GET [/isnic](https://apis.is/isnic) + +Search the Icelandic domain registry. + +| Parameters | Description | Example | +|--------------------|------------------------|-------------------------------------------------------| +| Domain (required) | Registered domain name | [advania.is](https://apis.is/isnic?domain=advania.is) | + +--- diff --git a/endpoints/lottery/documentation.md b/endpoints/lottery/documentation.md index ee5f0683..8fcdf043 100644 --- a/endpoints/lottery/documentation.md +++ b/endpoints/lottery/documentation.md @@ -2,7 +2,7 @@ Source: [The Icelandic Government Lottery](https://games.lotto.is/) -- GET [/lottery](https://apis.is/lottery) +- GET [/lottery](https://apis.is/lottery) Get the most recent numbers for the Icelandic lottery. diff --git a/endpoints/names/documentation.md b/endpoints/names/documentation.md new file mode 100644 index 00000000..fdd9083b --- /dev/null +++ b/endpoints/names/documentation.md @@ -0,0 +1,21 @@ +# Icelandic names + +Source: [Icelandic National Registry](https://www.island.is/mannanofn/leit-ad-nafni/) + +- GET [/names/:category](https://apis.is/names/:category) + +Lists all approved Icelandic names. A search parameter can be used with each endpoint. + +| Parameters | Description | Example | +|------------|------------------------------|-------------------------------------------------------------------------------------------------------------------------------------| +| :category | Which category to search for | [males](https://apis.is/names/males), [females](https://apis.is/names/females) or [middle names](https://apis.is/names/middlenames) | + +- GET [/names/rejected/:category](https://apis.is/names/rejected/:category) + +Lists all rejected Icelandic names. A search parameter can be used with each endpoint. + +| Parameters | Description | Example | +|------------|------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------| +| :category | Which category to search for | [males](https://apis.is/names/rejected/males), [females](https://apis.is/names/rejected/females) or [middle names](https://apis.is/names/rejected/middlenames) | + +--- diff --git a/endpoints/names/index.js b/endpoints/names/index.js index f57741cf..da5cee83 100644 --- a/endpoints/names/index.js +++ b/endpoints/names/index.js @@ -12,16 +12,16 @@ const h = require('apis-helpers') const cheerio = require('cheerio') const app = require('../../server') -/* Handles the request for a specific request URL */ -function handleRequest(providedUrl, req, res) { +// Handles the request for a specific request URL +const handleRequest = (providedUrl, req, res) => { let $ - // Check for the filter parameter - const filter = req.params.filter || req.query.filter || req.query.search || '' + // Check for the search parameter + const search = req.params.search || req.query.search || req.query.filter || '' - // Add name filtering if it is requested + // Add search if it is requested let url = providedUrl || '' - if (filter !== '') { - url += `&Nafn=${filter}` + if (search !== '') { + url += `&Nafn=${search}` } request.get({ @@ -41,14 +41,12 @@ function handleRequest(providedUrl, req, res) { const obj = { results: [] } // Clear data regarding the acceptance date of the name (not needed) - $('.dir li i').each(() => { - $(this).remove() - }) + $('.dir li i').remove() // Loop through all the names in the list and add them to our array - $('.dir li').each(() => { - const name = $(this).text() - obj.results.push(name.trim()) + $('.dir li').each((i, el) => { + const name = $(el).text().trim() + obj.results.push(name) }) // Return the results as JSON and cache for 24 hours @@ -56,61 +54,52 @@ function handleRequest(providedUrl, req, res) { }) } -/* Root names handler - only returns a list of resources */ -app.get('/names', (req, res) => { - return res.json({ - results: [ - { - // eslint-disable-next-line max-len - info: 'This is an api that lists all allowed Icelandic names. A search parameter can be used with each endpoint', - endpoints: { - males: '/names/males/', - females: '/names/females/', - middlenames: '/names/middlenames/', - }, - }, - ], - }) +const rootUrl = 'https://www.island.is/mannanofn/leit-ad-nafni/?Stafrof=' + +// Get all legal names for males +app.get('/names/males/:search?', (req, res) => { + const url = `${rootUrl}&Drengir=on&Samthykkt=yes` + return handleRequest(url, req, res) }) -/* Get all legal names for males */ -app.get('/names/males/:filter?', (req, res) => { - const url = 'https://www.island.is/mannanofn/leit-ad-nafni/?Stafrof=&Drengir=on&Samthykkt=yes' +// Get all legal names for females +app.get('/names/females/:search?', (req, res) => { + const url = `${rootUrl}&Stulkur=on&Samthykkt=yes` return handleRequest(url, req, res) }) -/* Get all legal names for females */ -app.get('/names/females/:filter?', (req, res) => { - const url = 'https://www.island.is/mannanofn/leit-ad-nafni/?Stafrof=&Stulkur=on&Samthykkt=yes' +// Get all legal middle names +app.get('/names/middlenames/:search?', (req, res) => { + const url = `${rootUrl}&Millinofn=on&Samthykkt=yes` return handleRequest(url, req, res) }) -/* Get all legal middle names */ -app.get('/names/middlenames/:filter?', (req, res) => { - const url = 'https://www.island.is/mannanofn/leit-ad-nafni/?Stafrof=&Millinofn=on&Samthykkt=yes' +// Get all rejected names for males +app.get('/names/rejected/males/:search?', (req, res) => { + const url = `${rootUrl}&Drengir=on&Samthykkt=no` return handleRequest(url, req, res) }) -/* Get all rejected names for males */ -app.get('/names/rejected/males/:filter?', (req, res) => { - const url = 'https://www.island.is/mannanofn/leit-ad-nafni/?Stafrof=&Drengir=on&Samthykkt=no' +// Get all rejected names for females +app.get('/names/rejected/females/:search?', (req, res) => { + const url = `${rootUrl}&Stulkur=on&Samthykkt=no` return handleRequest(url, req, res) }) -/* Get all rejected names for females */ -app.get('/names/rejected/females/:filter?', (req, res) => { - const url = 'https://www.island.is/mannanofn/leit-ad-nafni/?Stafrof=&Stulkur=on&Samthykkt=no' +// Get all rejected middle names +app.get('/names/rejected/middlenames/:search?', (req, res) => { + const url = `${rootUrl}&Millinofn=on&Samthykkt=no` return handleRequest(url, req, res) }) -/* Get all rejected middle names */ -app.get('/names/rejected/middlenames/:filter?', (req, res) => { - const url = 'https://www.island.is/mannanofn/leit-ad-nafni/?Stafrof=&Millinofn=on&Samthykkt=no' +// Get all rejected names +app.get('/names/rejected/:search?', (req, res) => { + const url = `${rootUrl}&Stulkur=on&Drengir=on&Millinofn=on&Samthykkt=no` return handleRequest(url, req, res) }) -/* Get all rejected names */ -app.get('/names/rejected/:filter?', (req, res) => { - const url = 'https://www.island.is/mannanofn/leit-ad-nafni/?Stafrof=&Stulkur=on&Drengir=on&Millinofn=on&Samthykkt=no' +// Get all names with a given search +app.get('/names/:search?', (req, res) => { + const url = `${rootUrl}&Samthykkt=yes` return handleRequest(url, req, res) }) diff --git a/endpoints/names/tests/integration_test.js b/endpoints/names/tests/integration_test.js index ca6b1a3b..1f6ad19a 100644 --- a/endpoints/names/tests/integration_test.js +++ b/endpoints/names/tests/integration_test.js @@ -10,8 +10,8 @@ const assert = require('assert') const request = require('request') const helpers = require('../../../lib/test_helpers.js') -/* Asserts the results */ -function assertResults(params, beEmpty) { +// Asserts the results +const assertResults = (params, beEmpty) => { const shouldBeEmpty = beEmpty || false request.get(params, (err, res, body) => { const json = JSON.parse(body) @@ -20,129 +20,55 @@ function assertResults(params, beEmpty) { if (!shouldBeEmpty) { assert(json.results.length > 0, 'Results are empty') } else { - assert(json.results.length <= 0, 'Results are NOT empty') + assert(json.results.length === 0, 'Results are NOT empty') } }) } -/* Test the unfiltered list of names */ -function testUnfiltered(url) { +// Test the unfiltered list of names +const testUnfiltered = (url) => { it('should return an array of strings', (done) => { const params = helpers.testRequestParams(url, {}) - assertResults(params) done() }) } -/* Test filtering with an invalid string */ -function testFilteredEmpty(url) { - it('should return an array of strings', (done) => { +// Test filtering with a string that should return no results +const testFilteredEmpty = (url) => { + it('should return an empty array', (done) => { const params = helpers.testRequestParams(url, { search: '234asdf' }) - assertResults(params, true) done() }) } -/* Test filtering the results with a valid filter */ -function testFiltered(url) { +// Test filtering the results with a valid filter +const testFiltered = (url) => { it('should return an array of strings', (done) => { const params = helpers.testRequestParams(url, { search: 'an' }) - assertResults(params) done() }) } -describe('names', () => { - /* Test the /names/males endpoint with filtering */ - describe('males-filtered', () => { - testFiltered('/names/males') - }) - - /* Test the /names/males endpoint with invalid filtering */ - describe('males-filtered-invalid', () => { - testFilteredEmpty('/names/males') - }) - - /* Test the /names/males endpoint without filtering */ - describe('males', () => { - testUnfiltered('/names/males') - }) - - /* Test the /names/females endpoint with filtering */ - describe('females-filtered', () => { - testFiltered('/names/females') - }) - - /* Test the /names/females endpoint with invalid filtering */ - describe('females-filtered-invalid', () => { - testFilteredEmpty('/names/males') - }) - - /* Test the /names/females endpoint without filtering */ - describe('females', () => { - testUnfiltered('/names/females') - }) - - /* Test the /names/middlenames endpoint with filtering */ - describe('middlenames-filtered', () => { - testFiltered('/names/middlenames') - }) - - /* Test the /names/middlenames endpoint with invalid filtering */ - describe('middlenames-filtered-invalid', () => { - testFilteredEmpty('/names/middlenames') - }) - - /* Test the /names/middlenames endpoint without filtering */ - describe('middlenames', () => { - testUnfiltered('/names/middlenames') - }) - - /* Test the /names/rejected/males endpoint with filtering */ - describe('rejected-males-filtered', () => { - testFiltered('/names/rejected/males') - }) - - /* Test the /names/rejected/males endpoint with invalid filtering */ - describe('rejected-males-filtered-invalid', () => { - testFilteredEmpty('/names/rejected/males') - }) - - /* Test the /names/rejected/males endpoint without filtering */ - describe('rejected-males', () => { - testUnfiltered('/names/rejected/males') - }) - - /* Test the /names/rejected/females endpoint with filtering */ - describe('rejected-females-filtered', () => { - testFiltered('/names/rejected/females') - }) - - /* Test the /names/rejected/females endpoint with invalid filtering */ - describe('rejected-females-filtered-invalid', () => { - testFilteredEmpty('/names/rejected/females') - }) - - /* Test the /names/rejected/females endpoint without filtering */ - describe('rejected-females', () => { - testUnfiltered('/names/rejected/females') - }) - - /* Test the /names/rejected/middlenames endpoint with filtering */ - describe('rejected-middlenames-filtered', () => { - testFiltered('/names/rejected/middlenames') - }) - - /* Test the /names/rejected/middlenames endpoint with invalid filtering */ - describe('rejected-middlenames-filtered-invalid', () => { - testFilteredEmpty('/names/rejected/middlenames') - }) +// Test the endpoint +const testEndpoint = (name, url) => { + // without filtering + describe(`${name}`, () => testUnfiltered(url)) + // with filtering that should return empty array as a results + describe(`${name}-filtered-invalid`, () => testFilteredEmpty(url)) + // with filtering + describe(`${name}-filtered`, () => testFiltered(url)) +} - /* Test the /names/rejected/middlenames endpoint without filtering */ - describe('rejected-middlenames', () => { - testUnfiltered('/names/rejected/middlenames') - }) +describe('names', () => { + testEndpoint('names', '/names') + testEndpoint('males', '/names/males') + testEndpoint('females', '/names/females') + testEndpoint('middlenames', '/names/middlenames') + testEndpoint('rejected-names', '/names/rejected/') + testEndpoint('rejected-males', '/names/rejected/males') + testEndpoint('rejected-females', '/names/rejected/females') + testEndpoint('rejected-middlenames', '/names/rejected/middlenames') }) diff --git a/endpoints/particulates/documentation.md b/endpoints/particulates/documentation.md index f54df26f..f71a3ad9 100644 --- a/endpoints/particulates/documentation.md +++ b/endpoints/particulates/documentation.md @@ -2,7 +2,7 @@ Source: [Reykjavik City](http://reykjavik.is/) -- GET [/particulates](https://apis.is/particulates) +- GET [/particulates](https://apis.is/particulates) Get current status of particulates in Reykjavik City diff --git a/endpoints/petrol/documentation.md b/endpoints/petrol/documentation.md index 24e026d2..5b8e2d45 100644 --- a/endpoints/petrol/documentation.md +++ b/endpoints/petrol/documentation.md @@ -2,7 +2,7 @@ Source: [github.com/gasvaktin](https://github.com/gasvaktin/gasvaktin) -- GET [/petrol](https://apis.is/petrol) +- GET [/petrol](https://apis.is/petrol) Lookup locations and gas prices for petrol stations in Iceland. diff --git a/endpoints/ship/documentation.md b/endpoints/ship/documentation.md index a6d6b47e..9c45b943 100644 --- a/endpoints/ship/documentation.md +++ b/endpoints/ship/documentation.md @@ -6,8 +6,8 @@ Source: [The Icelandic Transport Authority](https://www.samgongustofa.is/sigling Search the Icelandic ship registry -| Parameters | Description | Example | -|-------------------|---------------------------------------------------------------|---------------| +| Parameters | Description | Example | +|-------------------|---------------------------------------------------------------|------------------------------------------------------------------------------------------| | Search (required) | Ship name, regional code or the registy's registration number | [engey](https://apis.is/ship?search=engey), [RE-100](https://apis.is/ship?search=RE-100) | --- diff --git a/endpoints/sports/documentation.md b/endpoints/sports/documentation.md index 15602b36..416c8536 100644 --- a/endpoints/sports/documentation.md +++ b/endpoints/sports/documentation.md @@ -6,8 +6,8 @@ Source: [KSÍ](http://ksi.is) and [HSÍ](http://hsi.is) Get events for Icelandic football and/or handball -| Parameters | Description | Example | -|-------------------|---------------------------|---------| +| Parameters | Description | Example | +|-------------------|---------------------------|------------------------------------------------------------------------------------------| | :sport (required) | Which sport events to get | [football](https://apis.is/sports/football), [handball](https://apis.is/sports/handball) | --- diff --git a/endpoints/static_endpoints/help_out.js b/endpoints/static_endpoints/help_out.js index 025da2a1..c88313ea 100644 --- a/endpoints/static_endpoints/help_out.js +++ b/endpoints/static_endpoints/help_out.js @@ -2,7 +2,7 @@ function helpOut(req, res, next) { res.header('Access-Control-Allow-Origin', '*') res.header('Access-Control-Allow-Headers', 'X-Requested-With') - res.status(200).json({ message: 'Send us mail: apis@apis.is ,thanks for your interest!' }) + res.status(200).json({ message: 'Send us mail: apis@apis.is, thanks for your interest!' }) next() }