All files / src/lib gnibIreland.ts

92.86% Statements 13/14
100% Branches 9/9
100% Functions 5/5
92.86% Lines 13/14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 441x   1x 1x     1x 1x     1x 1x 1x                   1x     1x 1x 1x         1x                      
import request = require('request-promise');
 
export enum Categories {
  Work = 'Work'
}
 
export enum Subcategories {
  All = 'All'
}
 
export enum Types {
  New = 'New',
  Renewal = 'Renewal'
}
 
export interface AvailabilityParams {
  type: Types;
  category?: Categories;
  subcateogry?: Subcategories;
}
 
function buildUrl(type: Types, category: Categories, subcategory: Subcategories): string {
  return `https://burghquayregistrationoffice.inis.gov.ie/Website/AMSREG/AMSRegWeb.nsf/(getAppsNear)?openpage&cat=${category}&sbcat=${subcategory}&typ=${type}&_=1507583431263`;
}
 
export async function checkSlotsAvailability(type: Types = Types.New, category: Categories = Categories.Work, subcategory: Subcategories = Subcategories.All): Promise<any> {
  try {
    const response = await request({
      url: buildUrl(type, category, subcategory),
      ciphers: 'DES-CBC3-SHA',
      rejectUnauthorized: false
    });
    return {
      status: 'success',
      data: JSON.parse(response)
    };
  } catch(error) {
    return {
      status: 'error',
      error
    };
  }
}