Browse Source

index: de-privatize `fetch`

master
Guillermo Rauch 9 years ago
parent
commit
69fda5cf98
  1. 10
      lib/index.js

10
lib/index.js

@ -74,7 +74,7 @@ export default class Now extends EventEmitter {
const deployment = await retry(async (bail) => { const deployment = await retry(async (bail) => {
if (this._debug) console.time('> [debug] /now/create'); if (this._debug) console.time('> [debug] /now/create');
const res = await this._fetch('/now/create', { const res = await this.fetch('/now/create', {
method: 'POST', method: 'POST',
body: { body: {
forceNew, forceNew,
@ -164,7 +164,7 @@ export default class Now extends EventEmitter {
if (this._debug) console.time(`> [debug] /sync #${attempt} ${names.join(' ')}`); if (this._debug) console.time(`> [debug] /sync #${attempt} ${names.join(' ')}`);
const stream = resumer().queue(data).end(); const stream = resumer().queue(data).end();
const res = await this._fetch('/now/sync', { const res = await this.fetch('/now/sync', {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/octet-stream', 'Content-Type': 'application/octet-stream',
@ -198,7 +198,7 @@ export default class Now extends EventEmitter {
const { deployments } = await retry(async (bail) => { const { deployments } = await retry(async (bail) => {
if (this._debug) console.time('> [debug] /list'); if (this._debug) console.time('> [debug] /list');
const res = await this._fetch('/now/list' + query); const res = await this.fetch('/now/list' + query);
if (this._debug) console.timeEnd('> [debug] /list'); if (this._debug) console.timeEnd('> [debug] /list');
// no retry on 4xx // no retry on 4xx
@ -224,7 +224,7 @@ export default class Now extends EventEmitter {
await retry(async (bail) => { await retry(async (bail) => {
if (this._debug) console.time('> [debug] /remove'); if (this._debug) console.time('> [debug] /remove');
const res = await this._fetch('/now/remove', { const res = await this.fetch('/now/remove', {
method: 'DELETE', method: 'DELETE',
body: data body: data
}); });
@ -277,7 +277,7 @@ export default class Now extends EventEmitter {
return this._syncAmount; return this._syncAmount;
} }
_fetch (_url, opts = {}) { fetch (_url, opts = {}) {
opts.headers = opts.headers || {}; opts.headers = opts.headers || {};
opts.headers.authorization = `Bearer ${this._token}`; opts.headers.authorization = `Bearer ${this._token}`;
return this._agent.fetch(_url, opts); return this._agent.fetch(_url, opts);

Loading…
Cancel
Save