@beauraines/rtm-api 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +285 -0
  3. package/config.js +22 -0
  4. package/docs/RTMClient.html +2798 -0
  5. package/docs/RTMError.html +1029 -0
  6. package/docs/RTMList.html +966 -0
  7. package/docs/RTMResponse.html +868 -0
  8. package/docs/RTMSuccess.html +337 -0
  9. package/docs/RTMTask.html +2461 -0
  10. package/docs/RTMUser.html +6761 -0
  11. package/docs/client_auth.js.html +123 -0
  12. package/docs/client_index.js.html +241 -0
  13. package/docs/client_user.js.html +170 -0
  14. package/docs/global.html +386 -0
  15. package/docs/index.html +305 -0
  16. package/docs/list_index.js.html +159 -0
  17. package/docs/response_error.js.html +172 -0
  18. package/docs/response_response.js.html +160 -0
  19. package/docs/response_success.js.html +104 -0
  20. package/docs/scripts/linenumber.js +25 -0
  21. package/docs/scripts/prettify/Apache-License-2.0.txt +202 -0
  22. package/docs/scripts/prettify/lang-css.js +2 -0
  23. package/docs/scripts/prettify/prettify.js +28 -0
  24. package/docs/styles/jsdoc.css +664 -0
  25. package/docs/styles/prettify.css +79 -0
  26. package/docs/task_helper.js.html +531 -0
  27. package/docs/task_index.js.html +304 -0
  28. package/docs/user_index.js.html +347 -0
  29. package/docs/user_lists.js.html +208 -0
  30. package/docs/user_tasks.js.html +703 -0
  31. package/jsdoc.json +13 -0
  32. package/package.json +33 -0
  33. package/src/client/auth.js +65 -0
  34. package/src/client/index.js +182 -0
  35. package/src/client/user.js +112 -0
  36. package/src/list/helper.js +131 -0
  37. package/src/list/index.js +101 -0
  38. package/src/response/error.js +114 -0
  39. package/src/response/index.js +8 -0
  40. package/src/response/parse.js +51 -0
  41. package/src/response/response.js +102 -0
  42. package/src/response/success.js +46 -0
  43. package/src/task/helper.js +469 -0
  44. package/src/task/index.js +264 -0
  45. package/src/user/index.js +288 -0
  46. package/src/user/lists.js +150 -0
  47. package/src/user/tasks.js +708 -0
  48. package/src/utils/auth.js +188 -0
  49. package/src/utils/fetch.js +67 -0
  50. package/src/utils/get.js +247 -0
  51. package/src/utils/sign.js +93 -0
  52. package/src/utils/taskIds.js +188 -0
@@ -0,0 +1,188 @@
1
+ 'use strict';
2
+
3
+ const config = require('../../config');
4
+ const fs = require('fs');
5
+
6
+ const FILE = config.task_id_cache_file;
7
+
8
+ // Cache of User's Task Indices --> Task IDs
9
+ let CACHE = {
10
+ USERS: {}
11
+ };
12
+
13
+
14
+
15
+ // Read the Cache
16
+ _readCache();
17
+
18
+
19
+
20
+ /**
21
+ * Get a Task Index for the specified User's Task ID.
22
+ *
23
+ * This will return a previously assigned Task Index for a given Task ID
24
+ * or return an unassigned number for an unassigned task
25
+ * @param {number} userId RTM User ID
26
+ * @param {RTMTask} task RTM Task
27
+ * @returns {int} Task Index
28
+ * @private
29
+ */
30
+ function getIndex(userId, task) {
31
+ userId = parseFloat(userId);
32
+ let taskId = parseFloat(task.task_id);
33
+ let taskSeriesId = parseFloat(task.taskseries_id);
34
+ let listId = parseFloat(task.list_id);
35
+
36
+ // Get User Cache
37
+ let user = getUser(userId);
38
+ let indices = Object.keys(user);
39
+ let ids = Object.values(user);
40
+
41
+ // Find matching cached index
42
+ for ( let i = 0; i < ids.length; i++ ) {
43
+ if ( ids[i]['task_id'] === taskId ) {
44
+ if ( ids[i]['taskseries_id'] === taskSeriesId ) {
45
+ if ( ids[i]['list_id'] === listId ) {
46
+ return parseInt(indices[i]);
47
+ }
48
+ }
49
+ }
50
+ }
51
+
52
+ // Create a new Index
53
+ let index = 1;
54
+ while ( indices.indexOf(index.toString()) > -1 ) {
55
+ index++;
56
+ }
57
+ if ( CACHE.USERS[userId] === undefined ) {
58
+ CACHE.USERS[userId] = {};
59
+ }
60
+ CACHE.USERS[userId][index] = {
61
+ task_id: taskId,
62
+ taskseries_id: taskSeriesId,
63
+ list_id: listId
64
+ };
65
+ return parseInt(index);
66
+
67
+ }
68
+
69
+
70
+ /**
71
+ * Get a Task ID by Task Index Number.
72
+ *
73
+ * This will return the cached task id number for the specified user
74
+ * for the given task index number or undefined if not found in the cache.
75
+ * @param {number} userId RTM User ID
76
+ * @param {int} taskIndex Task Index
77
+ * @returns {number|undefined} RTM Task ID
78
+ * @private
79
+ */
80
+ function getTaskId(userId, taskIndex) {
81
+ userId = parseFloat(userId);
82
+ taskIndex = parseInt(taskIndex);
83
+
84
+ let user = getUser(userId);
85
+ let task = user[taskIndex.toString()];
86
+
87
+ return task === undefined ? undefined : task['task_id'];
88
+ }
89
+
90
+ /**
91
+ * Get a TaskSeries ID by Task Index Number.
92
+ *
93
+ * This will return the cached task series id number for the specified user
94
+ * for the given task index number or undefined if not found in the cache.
95
+ * @param {number} userId RTM User ID
96
+ * @param {int} taskIndex Task Index
97
+ * @returns {number|undefined} RTM Task Series ID
98
+ * @private
99
+ */
100
+ function getTaskSeriesId(userId, taskIndex) {
101
+ userId = parseFloat(userId);
102
+ taskIndex = parseInt(taskIndex);
103
+
104
+ let user = getUser(userId);
105
+ let task = user[taskIndex.toString()];
106
+
107
+ return task === undefined ? undefined : task['taskseries_id'];
108
+ }
109
+
110
+ /**
111
+ * Get a List ID by Task Index Number.
112
+ *
113
+ * This will return the cached list id number for the specified user
114
+ * for the given task index number or undefined if not found in the cache.
115
+ * @param {number} userId RTM User ID
116
+ * @param {int} taskIndex Task Index
117
+ * @returns {number|undefined} RTM List ID
118
+ * @private
119
+ */
120
+ function getListId(userId, taskIndex) {
121
+ userId = parseFloat(userId);
122
+ taskIndex = parseInt(taskIndex);
123
+
124
+ let user = getUser(userId);
125
+ let task = user[taskIndex.toString()];
126
+
127
+ return task === undefined ? undefined : task['list_id'];
128
+ }
129
+
130
+
131
+ /**
132
+ * Get the User's Entire Cache.
133
+ *
134
+ * This will return an Object of the entire User's task index / id cache. The
135
+ * Object's name is the index number and the value is the task id.
136
+ * @param userId
137
+ * @returns {{}}
138
+ * @private
139
+ */
140
+ function getUser(userId) {
141
+ userId = parseFloat(userId);
142
+ return CACHE.USERS[userId] === undefined ? {} : CACHE.USERS[userId];
143
+ }
144
+
145
+
146
+ /**
147
+ * Save the current Task Index Cache to Disk
148
+ * @private
149
+ */
150
+ function save() {
151
+ fs.writeFileSync(FILE, JSON.stringify(CACHE));
152
+ }
153
+
154
+
155
+ /**
156
+ * Clear the current Task Index Cache for the specified User
157
+ * @param {number} userId RTM User ID
158
+ * @private
159
+ */
160
+ function clear(userId) {
161
+ userId = parseFloat(userId);
162
+ _readCache();
163
+ CACHE.USERS[userId] = {};
164
+ save();
165
+ }
166
+
167
+
168
+ /**
169
+ * Load the saved cache
170
+ * @private
171
+ */
172
+ function _readCache() {
173
+ if ( fs.existsSync(FILE) ) {
174
+ CACHE = require(FILE);
175
+ }
176
+ }
177
+
178
+
179
+
180
+ module.exports = {
181
+ getIndex: getIndex,
182
+ getTaskId: getTaskId,
183
+ getTaskSeriesId: getTaskSeriesId,
184
+ getListId: getListId,
185
+ getUser: getUser,
186
+ save: save,
187
+ clear: clear
188
+ };