cabana: routes api auth

main
Andy Haden 2017-06-26 21:41:53 -07:00
parent a822561696
commit c86001b257
3 changed files with 17 additions and 31 deletions

View File

@ -12,6 +12,7 @@
"hls": "0.0.1",
"hls.js": "^0.7.9",
"int64-buffer": "^0.1.9",
"js-cookie": "^2.1.4",
"moment": "^2.18.1",
"prop-types": "^15.5.10",
"react": "^15.6.1",

View File

@ -1,28 +0,0 @@
import SignalLegend from '../../components/SignalLegend';
import React from 'react';
import { shallow, mount, render } from 'enzyme';
import {StyleSheetTestUtils} from 'aphrodite';
// Prevents style injection from firing after test finishes
// and jsdom is torn down.
beforeEach(() => {
StyleSheetTestUtils.suppressStyleInjection();
});
afterEach(() => {
StyleSheetTestUtils.clearBufferAndResumeStyleInjection();
});
test('a little endian signal spanning one byte should switch to big endian preserving its bit coverage', () => {
});
test('a big endian signal spanning two bytes should switch to little endian preserving its bit coverage', () => {
});
test("a big endian signal spanning one and a half bytes should switch to little endian preserving the first byte's coverage", () => {
});

View File

@ -1,3 +1,5 @@
import Cookies from 'js-cookie';
const ROUTES_ENDPOINT = 'https://api.commadotai.com/v1/{dongleId}/routes/';
const DEMO_ROUTES = {
@ -9607,13 +9609,24 @@ const DEMO_ROUTES = {
}
};
function getCommaAccessToken() {
return Cookies.get('comma_access_token');
}
export async function fetchRoutes(dongleId) {
if(dongleId !== undefined) {
if(dongleId === undefined) {
dongleId = 'me';
}
const endpoint= ROUTES_ENDPOINT.replace('{dongleId}', dongleId);
const endpoint = ROUTES_ENDPOINT.replace('{dongleId}', dongleId);
const headers = new Headers();
const accessToken = getCommaAccessToken();
if(accessToken) {
headers.append('Authorization', `JWT ${getCommaAccessToken()}`);
}
try {
const resp = await fetch(endpoint);
const request = new Request(endpoint, {headers});
const resp = await fetch(request);
const routes = await resp.json();
if('routes' in routes) {
return routes;