forked from fyyyyy/Toggl-to-Jira-Chrome-Extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
identity.js
47 lines (43 loc) · 1.58 KB
/
identity.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
/*
Identity Management
Let's us test and get identities for Jira and Toggl
*/
var identity = {
// Attempt to connect to Jira
ConnectToJira: function (jiraURL) {
// https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-myself-get
return $.get(jiraURL + '/rest/api/2/myself').then(function (jiraResult) {
return result = { // transform the result
jiraUserName: jiraResult.displayName,
jiraEmailAddress: jiraResult.emailAddress
}
});
},
// Attempt to connect to Toggl
ConnectToToggl: function (togglApiToken) {
// https://github.com/toggl/toggl_api_docs/blob/master/chapters/users.md
return $.get({
url: 'https://www.toggl.com/api/v8/me',
headers: {
"Authorization": "Basic " + btoa(togglApiToken + ':api_token')
}
}).then(function (togglResult) {
return result = { // transform the result
togglUserName: togglResult.data.fullname,
togglEmailAddress: togglResult.data.email
}
});
},
// Attempt to connect to both
Connect: function (jiraURL, togglApiToken) {
return $.when( // Wait until both have completed
this.ConnectToJira(jiraURL),
this.ConnectToToggl(togglApiToken)
).then(function (jiraResult, togglResult) {
return result = { // transform the result, merge the other results
...jiraResult,
...togglResult
}
});
}
}