2016-02-06 12:42:19 +00:00
|
|
|
import endpoints from './endpoints';
|
|
|
|
import request from './request';
|
2016-02-10 22:42:45 +00:00
|
|
|
import token from './token';
|
2016-02-06 12:42:19 +00:00
|
|
|
|
2016-02-21 11:59:53 +00:00
|
|
|
function JSONify(response) {
|
|
|
|
return response.json();
|
|
|
|
}
|
|
|
|
|
2016-02-23 23:12:32 +00:00
|
|
|
const [GET] = ['GET'];
|
|
|
|
|
2016-02-10 22:42:45 +00:00
|
|
|
export function checkToken(possibleToken) {
|
2016-02-06 12:42:19 +00:00
|
|
|
const url = endpoints.get('USER_INFO');
|
2016-02-23 23:12:32 +00:00
|
|
|
return request(url, GET, {}, possibleToken).then(function (response) {
|
2016-02-06 12:42:19 +00:00
|
|
|
return response.ok;
|
|
|
|
});
|
|
|
|
}
|
2016-02-10 22:42:45 +00:00
|
|
|
|
2016-02-23 23:12:32 +00:00
|
|
|
export async function getUserDetails() {
|
|
|
|
const CIToken = await token.get();
|
|
|
|
const url = endpoints.get('USER_INFO');
|
|
|
|
return await request(url, GET, {}, CIToken).then(JSONify);
|
|
|
|
}
|
|
|
|
|
2016-02-21 11:59:53 +00:00
|
|
|
export async function getProjects() {
|
|
|
|
const CIToken = await token.get();
|
2016-02-10 22:42:45 +00:00
|
|
|
const url = endpoints.get('ALL_PROJECTS');
|
2016-02-23 23:12:32 +00:00
|
|
|
return await request(url, GET, {}, CIToken).then(JSONify);
|
|
|
|
}
|
|
|
|
|
2016-03-11 20:47:12 +00:00
|
|
|
export async function getProjectRecentBuilds(user, repo, limit = 1) {
|
2016-02-23 23:12:32 +00:00
|
|
|
const CIToken = await token.get();
|
2016-03-11 20:47:12 +00:00
|
|
|
const url = endpoints.get('PROJECT_RECENTS').param({ user, repo }).query({ limit });
|
2016-02-23 23:12:32 +00:00
|
|
|
return await request(
|
|
|
|
url,
|
|
|
|
GET,
|
|
|
|
{},
|
|
|
|
CIToken)
|
|
|
|
.then(JSONify);
|
2016-02-10 22:42:45 +00:00
|
|
|
}
|