-
Notifications
You must be signed in to change notification settings - Fork 0
/
teamwork.js
112 lines (99 loc) · 3.51 KB
/
teamwork.js
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
var request = require( "request" );
var apiKey;
var teamworkWebsite;
/**
Get the request to send at teamwork api
@param request {string} - Message command
@param method {string} - Optional. Method HTTP to send a request. Default is set to GET.
@param body {Object} - Optional. Payload of the request. Default is set to '{}'.
@return {Object} - The options to send correctly request ( with authentication ) at the teamwork's api
*/
function getTarget( request, method, body ) {
method = method || "GET";
body = body || {};
return {
url: "https://"+apiKey+":xxx@"+teamworkWebsite+"/"+request+".json",
method: method,
body: JSON.stringify( body ),
headers: {
"Accept": "application/json",
"Content-Type": "application/json"
}
};
}
/**
Create a object to use the teamwork's api
@param authentication {Object}
A object with the below parameters:
- api_key
- teamwork_website
*/
function TeamWork( authentication ) {
apiKey = authentication.api_key;
teamworkWebsite = authentication.teamwork_website;
}
/**
Retrieve information to the single task
@param id {number} - Id task
@param callback {function}
Function to call when the request is finished with below parameters:
+ error {Object} - information error
+ response {Object} - Object to rappresent the payload sended from receiver
+ body {Object} - result data
*/
TeamWork.prototype.retrieveTask = function ( id, callback ) {
request( getTarget( "tasks/"+id ), callback );
};
/**
Retrieve information to the single task list
@param id {number} - Id task list
@param callback {function}
Function to call when the request is finished with below parameters:
+ error {Object} - information error
+ response {Object} - Object to rappresent the payload sended from receiver
+ body {Object} - result data
*/
TeamWork.prototype.retrieveTaskList = function ( id, callback ) {
request( getTarget( "tasklists/"+id ), callback );
};
/**
Retrieve information to the milestone
@param id {number} - Id milestone
@param callback {function}
Function to call when the request is finished with above parameters:
+ error {Object} - infomation error
+ response {Object} - Object to rappresent the payload sended from receiver
+ body {Object} - result data
*/
TeamWork.prototype.retrieveMilestone = function ( id, callback ) {
request( getTarget( "milestones/"+id ), callback );
};
/**
Mark the task with id, it passed as arguments, as complete
@param id {number} - Id task
@param callback {function} -
Function to call when the request is finished with below parameters:
+ error {Object} - Information error
+ response {Object} - Object to rappresent the payload sended from receiver
+ body {Object} - result data
*/
TeamWork.prototype.closeTask = function( id, callback ) {
request( getTarget( "tasks/"+id+"/complete", "PUT" ), callback );
};
/**
Send message at the project with the id passed as argument.
@param projectId {number} - Id project
@param post {Object} - Object with parameters needed to send message
@param callback {function}
Function to call when the request is finished with below parameters:
+ error {Object} - Information error
+ response {Object} - Object to rappresent the payload sended from receiver
+ body {Object} - result data
*/
TeamWork.prototype.sendMessage = function ( projectId, post, callback ) {
request(
getTarget( "projects/"+projectId+"/posts", "POST", { post: post } ),
callback
);
};
module.exports = TeamWork;