-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
94 lines (86 loc) · 3.08 KB
/
Copy pathindex.js
File metadata and controls
94 lines (86 loc) · 3.08 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
'use strict';
var rp = require('request-promise');
var { Projects } = require('./src/resources/Projects.js');
var { Users } = require('./src/resources/Users.js');
var { Placeholders } = require('./src/resources/Placeholders.js');
var { Holidays } = require('./src/resources/Holidays.js');
var { Disciplines } = require('./src/resources/Disciplines.js');
var { Approvals } = require('./src/resources/Approvals.js');
var { Roles } = require('./src/resources/Roles.js');
var { LeaveTypes } = require('./src/resources/LeaveTypes.js');
var { TimeEntries, TimeEntryCategories } = require('./src/resources/TimeEntries.js');
var { BillRates } = require('./src/resources/BillRates.js');
var { BudgetItems } = require('./src/resources/BudgetItems.js');
var { ExpenseItemCategories } = require('./src/resources/ExpenseItems.js');
/**
Builds an object to create a request.
@param {string} url - The Base URL to call the API with
@param {string} endpoint - The resource URI endpoint.
@param {Object} - An object containing key values for headers, body and qs expected by Request.
*/
function defaultRequest(url, endpoint, { headers, body, qs, method}) {
var params = {
uri: `${url}${endpoint}`,
json: true,
headers: headers,
resolveWithFullResponse: true
}
if (body) { params.body = body };
if (qs) {params.qs = qs};
if (method) {params.method = method};
return params
};
/**
@param {string} auth_token - api token for 10000ft
@param {string} api_base - defaults to the staging server if api_base not given.
*/
class TenK {
constructor({token = '', apiBase = 'https://vnext-api.10000ft.com/api/v1/'} = {}) {
this.authToken = token;
this.apiBase = apiBase;
this.headers = {
'auth': this.authToken,
'User-Agent': 'node-tenK',
}
this.approvals = new Approvals(this);
this.billRates = new BillRates(``,this);
this.budgetItems = new BudgetItems(``,this);
this.disciplines = new Disciplines(this);
this.expenseItemCategories = new ExpenseItemCategories(``,this);
this.holidays = new Holidays(this);
this.leaveTypes = new LeaveTypes(this);
this.placeholders = new Placeholders(this);
this.projects = new Projects(this);
this.roles = new Roles(this);
this.timeEntries = new TimeEntries('',this);
this.timeEntryCategories = new TimeEntryCategories('',this);
this.users = new Users('',this);
}
get(endpoint, options) {
return rp(defaultRequest(this.apiBase, endpoint, {
method: 'GET',
headers: this.headers,
qs: options}));
};
post(endpoint,options) {
return rp(defaultRequest(this.apiBase, endpoint, {
method: 'POST',
headers: this.headers,
body: options
}));
}
put(endpoint, options) {
return rp(defaultRequest(this.apiBase, endpoint, {
method: 'PUT',
headers: this.headers,
body: options
}));
}
delete(endpoint, options) {
return rp(defaultRequest(this.apiBase, endpoint, {
method: 'DELETE',
headers: this.headers
}));
}
}
module.exports = TenK;