From 6bd48467a36d7d9f7c706581f525449093cc8578 Mon Sep 17 00:00:00 2001 From: Niklas Fondberg Date: Mon, 19 Apr 2021 10:15:38 +0200 Subject: [PATCH] WIP --- src/datasources/api2-datasource.ts | 41 ++++++++++++++++++++++++++++++ src/datasources/utils.ts | 20 +++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 src/datasources/api2-datasource.ts create mode 100644 src/datasources/utils.ts diff --git a/src/datasources/api2-datasource.ts b/src/datasources/api2-datasource.ts new file mode 100644 index 0000000..dc8d946 --- /dev/null +++ b/src/datasources/api2-datasource.ts @@ -0,0 +1,41 @@ +import { RESTDataSource } from 'apollo-datasource-rest'; + +/* +https://wE4D45790.api.esales.apptus.cloud/api/v2/panels/category +?esales.market=SE& +esales.customerKey=471c09ac-a775-4dd2-8bfc-041bfbb6d7b7& +esales.sessionKey=b106299c-eac0-4f6f-96d2-93e57c255784& +window_first=1& +window_last=10& +selected_category=categories_SE:'root/animals'& +root_category=categories_SE:'root' +&max_facets=50 +&filter=blacklisted:'0' AND visible_in_listing:'1' AND visible_in_shop:'1' AND (group:'poster' OR group:'framed-print') +blacklisted:'0'%20AND%20visible_in_listing:'1'%20AND%20visible_in_shop:'1'%20AND%20(group:'poster'%20OR%20group:'framed-print') + +*/ +export class Api2DataSource extends RESTDataSource { + authHeader: string; + constructor() { + super(); + this.baseURL = 'https://api-staging.photowall.com/'; + this.authHeader = + 'Basic ZGExNzU5ZWEtOTBiNC00OTNjLWJjYWItNjAwNDg1NjA5YjkyOg=='; + } + + willSendRequest(request) { + request.headers.set('Authorization', this.authHeader); + } + + async getPrice(market, width, height, sku) { + return await this.get( + 'prices/wallpaper?' + + new URLSearchParams({ + width: '200', + height: '200', + market: '1', + product: '58941', + }), + ); + } +} diff --git a/src/datasources/utils.ts b/src/datasources/utils.ts new file mode 100644 index 0000000..3f650a5 --- /dev/null +++ b/src/datasources/utils.ts @@ -0,0 +1,20 @@ +function isNumeric(n: any) { + return !isNaN(n); +} + +function isBoolean(n: any) { + if (typeof n === 'boolean') { + return true; + } + n = new String(n).toLowerCase(); + if (n === 'true' || n == 'false') { + return Boolean(n); + } + return false; +} + +export function convertToPossibleType(n: any) { + if (isBoolean(n)) return Boolean('false'); + if (isNumeric(n)) return Number(n); + return n; +}