forked from pkgcloud/pkgcloud
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.js
More file actions
73 lines (63 loc) · 1.61 KB
/
Copy pathclient.js
File metadata and controls
73 lines (63 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* client.js: Base client from which all Joyent clients inherit from
*
* (C) 2012 Charlie Robbins, Ken Perkins, Ross Kukulinski & the Contributors.
*
*/
var util = require('util'),
base = require('../core/base');
//
// ### constructor (options)
// #### @opts {Object} an object literal with options
// #### @clientKey {String} Client key
// #### @apiKey {String} API key
// #### @throws {TypeError} On bad input
//
var Client = exports.Client = function (opts) {
if (!opts || !opts.token) {
throw new TypeError('token is required');
}
base.Client.call(this, opts);
this.provider = 'digitalocean';
this.protocol = opts.protocol || 'https://';
this.serversUrl = opts.serversUrl;
if (!this.before) {
this.before = [];
}
this.before.push(function setJSON(req) {
req.json = true;
if (typeof req.body !== 'undefined') {
req.json = req.body;
delete req.body;
}
});
this.before.push(function setAuth(req) {
req.headers = req.headers || {};
req.headers.authorization = [
'Bearer', opts.token
].join(' ');
});
};
util.inherits(Client, base.Client);
Client.prototype.failCodes = {
400: 'Bad Request',
401: 'Unauthorized',
403: 'Forbidden',
404: 'Not Found',
405: 'Method Not Allowed',
406: 'Not Acceptable',
409: 'Conflict',
413: 'Request Entity Too Large',
415: 'Unsupported Media Type',
420: 'Slow Down',
449: 'Retry With',
500: 'Internal Error',
503: 'Service Unavailable'
};
Client.prototype.successCodes = {
200: 'OK',
201: 'Created',
202: 'Accepted',
203: 'Non-authoritative information',
204: 'No content'
};