Created
July 19, 2018 09:14
-
-
Save salujaharkirat/1ce295a3a78918f3b9d57e8ab8ffaf03 to your computer and use it in GitHub Desktop.
Revisions
-
salujaharkirat created this gist
Jul 19, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,82 @@ /** Author - Harkirat Saluja Git - https://bitbucket.org/salujaharkirat/ **/ "use strict"; import {Platform} from "react-native"; import axios from "axios"; import {decamelizeKeys} from "humps"; import Config from "react-native-config"; const ACCEPT = { JSON: "application/json" }; const METHOD = { GET: "GET", POST: "POST" }; export const v0 = { root: Config.TAXY_API_URL, call: (url, parameters) => { const finalUrl = url.indexOf(v0.root) === 0 ? url : `${v0.root}${url}`; const {headers, method, body, params} = parameters; return axios({ url: finalUrl, headers, method, data: body, params }); }, parameters: (method = METHOD.GET, accept = ACCEPT.JSON, body = {}) => { const withBody = [METHOD.POST]; const accessToken = null; // TODO: Read access token from store const rsessionid = null; // TODO: Read rsessionid from store const version = Config.APP_VERSION; const params = { method, headers: { "Content-type": accept, Authorization: accessToken, "X-RSESSIONID": rsessionid, "X-APP-VERSION": Platform.OS === "android" ? `S-A-${version}` : `S-I-${version}` } }; if (method === METHOD.GET) { params.params = body; } if (withBody.indexOf(method) !== -1) { params.body = decamelizeKeys(body); } return params; }, getJson: async (url, params = {}) => { return await v0.call( url, v0.parameters(METHOD.GET, ACCEPT.JSON, params) ); // return response; }, postJson: async (url, body = {}) => { return await v0.call( url, v0.parameters(METHOD.POST, ACCEPT.JSON, body) ); } }; export let loginGoogle = (data) => v0.postJson("/social/login-by-token/google-oauth2/", data); // Used only for testing export const TEST_setLoginGoogle = (promise) => { loginGoogle = promise; }