From 9b2af6eb539a52b4db896e1ed98114d02e8e4bf1 Mon Sep 17 00:00:00 2001 From: Francesco Esposito <33671357+frsposito@users.noreply.github.com> Date: Thu, 22 Aug 2019 17:27:23 +0200 Subject: [PATCH] Add api --- src/api.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/api.js diff --git a/src/api.js b/src/api.js new file mode 100644 index 0000000..51cbf9d --- /dev/null +++ b/src/api.js @@ -0,0 +1,39 @@ +import axios from 'axios'; +import config from './config'; +import logger from './logger'; + + +export const rainCheck = (cityId) => { + const options = { + params: { + cityId, + }, + }; + + return axios.get(`${config.umbrello.apiURL}/weather/forecast`, options) + .then((res) => { + const { data } = res; + // const flag = (data.rain === 'Y'); + return Promise.resolve(data); + }) + .catch((err) => { + logger.error(err); + Promise.reject(err); + }); +}; + + +export const searchCity = (cityName) => { + const options = { + params: { + city: cityName, + }, + }; + + return axios.get(`${config.umbrello.apiURL}/weather/search`, options) + .then((res) => Promise.resolve(res.data)) + .catch((err) => { + logger.error(err); + Promise.reject(err); + }); +};