Skip to content

Commit

Permalink
feat: add method to load coles catalogues (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
szdc committed Jul 8, 2018
1 parent f975914 commit 00f5c25
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/catalogue/ColesCatalogue.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import axios from 'axios';

import { ISaleFinderAPI, SaleFinderAPIConfig } from '../api';
import { CatalogueParser, DefaultCatalogueParser } from '../api/CatalogueParser';
import Category from '../api/Category';
Expand All @@ -12,6 +14,23 @@ export default class ColesCatalogue {

specialsByCategory: Category[];

static getCatalogues = (apiKey: string, postcode = 2000, format = 'njson') =>
axios.get<ColesCatalogueResponse|string>(
'https://webservice.salefinder.com.au/index.php/api/sales/colescatalogues/',
{
params: {
postcode,
format,
apikey: apiKey,
},
},
).then((res) => {
if (!(<ColesCatalogueResponse>res.data).items) {
throw new Error(<string>res.data);
}
return (<ColesCatalogueResponse>res.data).items;
})

constructor(api: ISaleFinderAPI, catalogueId: number, retailerId = 148, locationId = 8245) {
this.api = api;
this.catalogueId = catalogueId;
Expand Down Expand Up @@ -62,3 +81,21 @@ export default class ColesCatalogue {
return renderer(categories);
}
}

export interface ColesCatalogueResponse {
items: ColesCatalogueDetail[];
}

export interface ColesCatalogueDetail {
catalogueLink?: string;
dateDisplay: string;
description?: string;
displayName: string;
endDate?: string;
featureImage?: string;
publishDate?: string;
saleId?: string;
saleName: string;
startDate: string;
updateTimeStamp?: string;
}

0 comments on commit 00f5c25

Please sign in to comment.