Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
48 additions
and
95 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require('isomorphic-fetch') | ||
|
||
module.exports = class NowClient { | ||
constructor(token) { | ||
if (!token) { | ||
throw new Error('token must be required') | ||
} | ||
this._token = token; | ||
} | ||
get origin() { | ||
return 'https://api.zeit.co' | ||
} | ||
get token() { | ||
return this._token; | ||
} | ||
get header() { | ||
return { | ||
Authorization: `Bearer ${this.token}`, | ||
'Content-Type': 'application/json', | ||
} | ||
} | ||
async request(pathname, opts) { | ||
try { | ||
const res = await fetch(`${this.origin}${pathname}`, { | ||
headers: this.header, | ||
...opts, | ||
}) | ||
return await res.json() | ||
} catch (e) { | ||
throw e | ||
} | ||
} | ||
|
||
async getDeployments() { | ||
const res = await this.request('/v2/now/deployments') | ||
return res.deployments | ||
} | ||
async getAliases() { | ||
const res = await this.request('/v2/now/aliases') | ||
return res.aliases | ||
} | ||
async deleteDeployment(uid) { | ||
return await this.request(`/v2/now/deployments/${uid}`, { method: 'DELETE' }) | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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