Created
June 26, 2017 21:58
-
-
Save reallistic/2bc7bca0d7d98697fccbdea3d04ba22e to your computer and use it in GitHub Desktop.
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 characters
import superagent from 'superagent'; | |
import { WebsocketService } from './services'; | |
export function getData() { | |
return superagent.get('/api/').then(response => { | |
return response.body; | |
}); | |
} | |
export function getProducts(collection) { | |
return superagent.get('/api/products').then(response => { | |
let rv = response.body; | |
if (collection != null) { | |
collection.receiveData(rv); | |
} | |
return rv; | |
}); | |
} | |
export function getProduct(productId, collection) { | |
return superagent.get('/api/product/' + productId).then(response => { | |
let rv = response.body; | |
if (collection != null) { | |
collection.receiveData(rv); | |
} | |
return rv; | |
}); | |
} | |
export function startPlans() { | |
return superagent.post('/api/', {}).then(response => { | |
return response.body; | |
}); | |
} | |
export function refreshData() { | |
return superagent.post('/api/refresh', {}).then(response => { | |
return response.body; | |
}); | |
} | |
export function resetPlans() { | |
return superagent.post('/api/reset', {}).then(response => { | |
return response.body; | |
}); | |
} | |
export function stopPlans() { | |
return superagent.delete('/api/', {}).then(response => { | |
return response.body; | |
}); | |
} | |
export function connectWebsocket() { | |
let ws = new WebsocketService('/'); | |
ws.connect(); | |
return ws; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment