bugfix: request cannot be bound to repo url

This commit is contained in:
Cássio Zen 2016-07-18 16:09:35 -03:00
parent f7fb01e3cb
commit 2277a9c479

View File

@ -8,7 +8,7 @@ class API {
this.token = token; this.token = token;
this.repo = repo; this.repo = repo;
this.branch = branch; this.branch = branch;
this.baseURL = API_ROOT + `/repos/${this.repo}`; this.repoURL = `/repos/${this.repo}`;
} }
user() { user() {
@ -20,9 +20,9 @@ class API {
return cache.then((cached) => { return cache.then((cached) => {
if (cached) { return cached; } if (cached) { return cached; }
return this.request(`/contents/${path}`, { return this.request(`${this.repoURL}/contents/${path}`, {
headers: {Accept: 'application/vnd.github.VERSION.raw'}, headers: { Accept: 'application/vnd.github.VERSION.raw' },
data: {ref: this.branch}, data: { ref: this.branch },
cache: false cache: false
}).then((result) => { }).then((result) => {
if (sha) { if (sha) {
@ -35,8 +35,8 @@ class API {
} }
listFiles(path) { listFiles(path) {
return this.request(`/contents/${path}`, { return this.request(`${this.repoURL}/contents/${path}`, {
data: {ref: this.branch} data: { ref: this.branch }
}); });
} }
@ -60,7 +60,7 @@ class API {
request(path, options = {}) { request(path, options = {}) {
const headers = this.requestHeaders(options.headers || {}); const headers = this.requestHeaders(options.headers || {});
return fetch(this.baseURL + path, {...options, headers: headers}).then((response) => { return fetch(API_ROOT + path, { ...options, headers: headers }).then((response) => {
if (response.headers.get('Content-Type').match(/json/)) { if (response.headers.get('Content-Type').match(/json/)) {
return this.parseJsonResponse(response); return this.parseJsonResponse(response);
} }