@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
package/jsdoc.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "plugins": ["plugins/markdown"],
3
+ "source": {
4
+ "include": ["src/"],
5
+ "exclude": ["node_modules/"],
6
+ "includePattern": ".+\\.js(doc|x)?$",
7
+ "excludePattern": "(^|\\/|\\\\)_"
8
+ },
9
+ "opts": {
10
+ "destination": "docs/",
11
+ "recurse": true
12
+ }
13
+ }
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@beauraines/rtm-api",
3
+ "version": "1.4.1",
4
+ "description": "Remember the Milk API Interface",
5
+ "author": "Beau Raines <beau.raines@gmail.com>",
6
+ "license": "MIT",
7
+ "keywords": [
8
+ "rtm",
9
+ "api",
10
+ "remember the milk",
11
+ "tasks",
12
+ "todo",
13
+ "gtd"
14
+ ],
15
+ "main": "src/client/index.js",
16
+ "scripts": {
17
+ "docs": "jsdoc -c jsdoc.json --readme README.md --template $NODE_PATH/@dwaring87/docdash"
18
+ },
19
+ "devDependencies": {
20
+ "@dwaring87/docdash": "^0.4.1",
21
+ "jsdoc": "^3.6.3"
22
+ },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/beauraines/rtm-api.git"
26
+ },
27
+ "bugs": {
28
+ "url": "https://github.com/beauraines/rtm-api/issues"
29
+ },
30
+ "dependencies": {
31
+ "node-fetch": "^2.6.7"
32
+ }
33
+ }
@@ -0,0 +1,65 @@
1
+ 'use strict';
2
+
3
+ const _auth = require('../utils/auth.js');
4
+
5
+
6
+ /**
7
+ * This module returns the auth-related functions for RTMClient
8
+ * @param {RTMClient} client RTMClient instance
9
+ * @returns {{getAuthUrl: function, getAuthToken: function, verifyAuthToken: function}}
10
+ * @private
11
+ */
12
+ module.exports = function(client) {
13
+ let rtn = {};
14
+
15
+ /**
16
+ * Get an Auth URL.
17
+ *
18
+ * This function will generate an Auth URL that will be given to the RTM User
19
+ * to authorize the RTM Client to access their account. It will also request
20
+ * a frob that will be used to gain an auth token in `getAuthToken()`.
21
+ * @param {function} callback Callback function(err, authUrl, frob)
22
+ * @param {RTMError} callback.err RTM Error Response, if encountered
23
+ * @param {string} callback.authUrl Auth URL to be given to User
24
+ * @param {string} callback.frob Auth Frob to be used in `getAuthToken()`
25
+ * @function RTMClient~auth/getAuthUrl
26
+ */
27
+ rtn.getAuthUrl = function(callback) {
28
+ _auth.getAuthUrl(client, callback);
29
+ };
30
+
31
+ /**
32
+ * Get an Auth Token.
33
+ *
34
+ * This function takes the frob that was generated by `getAuthUrl()` and
35
+ * requests an Auth Token. The callback function will return an `RTMUser`
36
+ * which will include the RTM User's information and an Auth Token to be
37
+ * used in future API calls.
38
+ * @param {string} frob Auth Frob from `getAuthUrl()`
39
+ * @param {function} callback Callback function(err, user)
40
+ * @param {RTMError} callback.err RTM Error Response, if encountered
41
+ * @param {RTMUser} callback.user RTM User, with user information and auth token
42
+ * @function RTMClient~auth/getAuthToken
43
+ */
44
+ rtn.getAuthToken = function(frob, callback) {
45
+ _auth.getAuthToken(frob, client, callback);
46
+ };
47
+
48
+ /**
49
+ * Verify Auth Token.
50
+ *
51
+ * This function will check if the User's Auth Token is still valid and
52
+ * can be used to make authenticated RTM API requests.
53
+ * @param {string|RTMUser} token Auth Token or RTMUser containing an auth token
54
+ * @param {function} callback Callback function(err, verified)
55
+ * @param {RTMError} callback.err RTM Error, if encountered (excluding a `Login failed / Invalid auth token` error)
56
+ * @param {boolean} callback.verified `true` if the User's auth token was successfully verified or `false` if
57
+ * a `Login failed / Invalid auth token` error was encountered
58
+ * @function RTMClient~auth/verifyAuthToken
59
+ */
60
+ rtn.verifyAuthToken = function(token, callback) {
61
+ _auth.verifyAuthToken(token, client, callback);
62
+ };
63
+
64
+ return rtn;
65
+ };
@@ -0,0 +1,182 @@
1
+ 'use strict';
2
+
3
+
4
+ /**
5
+ * ### RTM API Client
6
+ *
7
+ * This Class is used to represent an RTM API Client. The Client contains
8
+ * the API Key, API Secret and access permissions used to access the
9
+ * RTM API endpoints.
10
+ *
11
+ * It also includes API wrapper functions for making a general RTM API request
12
+ * as well as the auth-related functions.
13
+ *
14
+ * #### Usage
15
+ *
16
+ * The `RTMClient` Class is what is exported when the entire `rtm-api` module
17
+ * is loaded via `require`.
18
+ *
19
+ * ```
20
+ * const RTM = require('rtm-api');
21
+ * let client = new RTM(API_KEY, API_SECRET, RTM.PERM_DELETE);
22
+ * ```
23
+ *
24
+ * #### Auth Example
25
+ *
26
+ * This example gets an Auth URL to be opened by the RTM User
27
+ *
28
+ * ```
29
+ * client.auth.getAuthUrl(function(err, authUrl, frob) {
30
+ * // Have user authenticate and authorize the program with the authUrl
31
+ * // Once authorized by the user, use the frob to get an authToken
32
+ * )};
33
+ * ```
34
+ *
35
+ * #### RTM API Example
36
+ *
37
+ * This example makes an RTM API request using the method `rtm.method` and the
38
+ * parameter foo=bar.
39
+ *
40
+ * ```
41
+ * client.get('rtm.method', {foo: "bar"}, function(err, resp) {
42
+ * if ( err ) {
43
+ * // handle error
44
+ * }
45
+ * // use the response
46
+ * });
47
+ * ```
48
+ *
49
+ * See {@link RTMUser#get|RTMUser.get} for making User-authenticated API requests.
50
+ *
51
+ * @class
52
+ */
53
+ class RTMClient {
54
+
55
+ /**
56
+ * Create a new RTM Client with the specified API access information
57
+ * @param {string} key RTM API Client Key
58
+ * @param {string} secret RTM API Client Secret
59
+ * @param {string} [perms=RTMClient.PERM_READ] RTM API Client Access Permissions. This
60
+ * should be one of {@link RTMClient.PERM_READ}, {@link RTMClient.PERM_WRITE} or
61
+ * {@link RTMClient.PERM_DELETE}.
62
+ * @constructor
63
+ */
64
+ constructor(key, secret, perms=RTMClient.PERM_READ) {
65
+ this._apiKey = key;
66
+ this._apiSecret = secret;
67
+ this._perms = perms;
68
+ }
69
+
70
+
71
+ /**
72
+ * RTM API Client Key
73
+ * @type {string}
74
+ */
75
+ get key() {
76
+ return this._apiKey;
77
+ }
78
+
79
+ /**
80
+ * RTM API Client Secret
81
+ * @type {string}
82
+ */
83
+ get secret() {
84
+ return this._apiSecret;
85
+ }
86
+
87
+ /**
88
+ * RTM API Client Access Permissions
89
+ * @type {string}
90
+ */
91
+ get perms() {
92
+ return this._perms;
93
+ }
94
+
95
+
96
+
97
+ // ===== USER FUNCTIONS ===== //
98
+
99
+ /**
100
+ * User export/import-related functions:
101
+ * - {@link RTMClient~user/create|create}
102
+ * - {@link RTMClient~user/export|export}
103
+ * - {@link RTMClient~user/exportToString|exportToString}
104
+ * - {@link RTMClient~user/import|import}
105
+ * - {@link RTMClient~user/importFromString|importFromString}
106
+ * @returns {{create: function, export: function, exportToString: function, import: function, importFromString: function}}
107
+ */
108
+ get user() {
109
+ return require('./user.js')(this);
110
+ }
111
+
112
+
113
+
114
+ // ===== API HELPER FUNCTIONS ===== //
115
+
116
+
117
+ /**
118
+ * Make the specified RTM API call.
119
+ *
120
+ * The `method` should be the name of the RTM API method. Any necessary
121
+ * parameters should be provided with `params` as an object with the properties
122
+ * of the object as the parameters' key/value pairs.
123
+ *
124
+ * RTM API methods that require an AuthToken should set the `params` `auth_token`
125
+ * property or provide a valid `RTMUser` with an AuthToken.
126
+ * @param {string} method RTM API Method
127
+ * @param {object} [params] RTM Method Parameters (as an object with key/value pairs)
128
+ * @param {RTMUser} [user=undefined] The RTM User making the request
129
+ * @param {function} callback Callback function(err, resp)
130
+ * @param {RTMError} callback.err RTM Error Response, if encountered
131
+ * @param {RTMSuccess} callback.resp The parsed RTM API Response, if successful
132
+ */
133
+ get(method, params, user, callback) {
134
+ require('../utils/get.js')(method, params, user, this, callback);
135
+ }
136
+
137
+ /**
138
+ * Auth-related functions:
139
+ * - {@link RTMClient~auth/getAuthUrl|getAuthUrl}
140
+ * - {@link RTMClient~auth/getAuthToken|getAuthToken}
141
+ * - {@link RTMClient~auth/verifyAuthToken|verifyAuthToken}
142
+ * @returns {{getAuthUrl: function, getAuthToken: function, verifyAuthToken: function}}
143
+ */
144
+ get auth() {
145
+ return require('./auth.js')(this);
146
+ }
147
+
148
+ }
149
+
150
+
151
+
152
+ // ==== RTM API PERMISSION LEVELS ==== //
153
+
154
+ /**
155
+ * RTM API Access: `read` -
156
+ * gives the ability to read task, contact, group and list details and contents.
157
+ * @type {string}
158
+ * @default
159
+ */
160
+ RTMClient.PERM_READ = 'read';
161
+
162
+ /**
163
+ * RTM API Access: `write` -
164
+ * gives the ability to add and modify task, contact, group and list details and
165
+ * contents (also allows you to `read`).
166
+ * @type {string}
167
+ * @default
168
+ */
169
+ RTMClient.PERM_WRITE = 'write';
170
+
171
+ /**
172
+ * RTM API Access: `delete` -
173
+ * gives the ability to delete task, contacts, groups and list (also allows
174
+ * you to `read` and `write`).
175
+ * @type {string}
176
+ * @default
177
+ */
178
+ RTMClient.PERM_DELETE = 'delete';
179
+
180
+
181
+
182
+ module.exports = RTMClient;
@@ -0,0 +1,112 @@
1
+ 'use strict';
2
+
3
+ const RTMClient = require('./index.js');
4
+ const RTMUser = require('../user/index.js');
5
+
6
+
7
+ /**
8
+ * This module returns the user-related functions for RTMClient
9
+ * @param {RTMClient} client RTMClient instance
10
+ * @returns {{create: function, export: function, exportToString: function, import: function, importFromString: function}}
11
+ */
12
+ module.exports = function(client) {
13
+ let rtn = {};
14
+
15
+ /**
16
+ * Create a new `RTMUser` manually.
17
+ *
18
+ * This will also set the User's RTM API Client to this `RTMClient`.
19
+ * @param {number} id The RTM User's ID
20
+ * @param {string} username The RTM User's username
21
+ * @param {string} fullname The RTM User's full name
22
+ * @param {string} authToken The RTM User's Auth Token
23
+ * @returns {RTMUser}
24
+ * @function RTMClient~user/create
25
+ */
26
+ rtn.create = function(id, username, fullname, authToken) {
27
+ let user = new RTMUser(id, username, fullname, authToken);
28
+ user.client = client;
29
+ return user;
30
+ };
31
+
32
+ /**
33
+ * Get the User's required information:
34
+ * - id
35
+ * - username
36
+ * - fullname
37
+ * - authToken
38
+ * - client (if set or use this `RTMClient`)
39
+ * @param {RTMUser} user The RTMUser to export
40
+ * @returns {object}
41
+ * @function RTMClient~user/export
42
+ */
43
+ rtn.export = function(user) {
44
+ let rtn = {
45
+ id: user.id,
46
+ username: user.username,
47
+ fullname: user.fullname,
48
+ authToken: user.authToken,
49
+ timeline: user._timeline
50
+ };
51
+ if ( user.client ) {
52
+ rtn.client = {
53
+ apiKey: user.client.key,
54
+ apiSecret: user.client.secret,
55
+ perms: user.client.perms
56
+ }
57
+ }
58
+ else {
59
+ rtn.client = {
60
+ apiKey: client.key,
61
+ apiSecret: client.key,
62
+ perms: client.perms
63
+ }
64
+ }
65
+
66
+ return rtn;
67
+ };
68
+
69
+ /**
70
+ * Get the User's required information as a JSON-string
71
+ * @param {RTMUser} user The RTMUser to export
72
+ * @returns {string}
73
+ * @function RTMClient~user/exportToString
74
+ */
75
+ rtn.exportToString = function(user) {
76
+ return JSON.stringify(rtn.export(user));
77
+ };
78
+
79
+ /**
80
+ * Create a new `RTMUser` from an exported User's properties
81
+ * @param {Object} properties The RTM User's required properties
82
+ * @returns {RTMUser}
83
+ * @function RTMClient~user/import
84
+ */
85
+ rtn.import = function(properties) {
86
+ if ( properties.id && properties.username && properties.fullname && properties.authToken ) {
87
+ let user = new RTMUser(properties.id, properties.username, properties.fullname, properties.authToken);
88
+ if ( properties.timeline ) {
89
+ user.timeline = properties.timeline;
90
+ }
91
+ if ( properties.client ) {
92
+ user.client = new RTMClient(properties.client.apiKey, properties.client.apiSecret, properties.client.perms);
93
+ }
94
+ return user;
95
+ }
96
+ else {
97
+ throw "Missing User Properties";
98
+ }
99
+ };
100
+
101
+ /**
102
+ * Create a new `RTMUser` from an exported User's properties' JSON-string
103
+ * @param {string} string JSON-string of RTM User's required properties
104
+ * @returns {RTMUser}
105
+ * @function RTMClient~user/importFromString
106
+ */
107
+ rtn.importFromString = function(string) {
108
+ return rtn.import(JSON.parse(string));
109
+ };
110
+
111
+ return rtn;
112
+ };
@@ -0,0 +1,131 @@
1
+ 'use strict';
2
+
3
+ const RTMList = require('./index.js');
4
+
5
+
6
+ /**
7
+ * API Call: rtm.lists.getList
8
+ * @param user RTMUser
9
+ * @param callback Callback function(err, lists)
10
+ * @private
11
+ */
12
+ function get(user, callback) {
13
+ user.get('rtm.lists.getList', function(err, resp) {
14
+ if ( err ) {
15
+ return callback(err);
16
+ }
17
+
18
+ // List of lists to return
19
+ let rtn = [];
20
+
21
+ // Parse each of the lists
22
+ let lists = resp.lists.list;
23
+ for ( let i = 0; i < lists.length; i++ ) {
24
+ rtn.push(
25
+ new RTMList(lists[i])
26
+ );
27
+ }
28
+
29
+ // Call the callback
30
+ return callback(null, rtn);
31
+ });
32
+ }
33
+
34
+
35
+ /**
36
+ * API Call: rtm.lists.add
37
+ * @param name RTM List Name
38
+ * @param [filter] RTM Smart List Filter
39
+ * @param user RTMUser
40
+ * @param callback Callback function(err)
41
+ * @private
42
+ */
43
+ function add(name, filter, user, callback) {
44
+
45
+ // Parse Parameters
46
+ if ( callback === undefined && typeof user === 'function' ) {
47
+ callback = user;
48
+ user = filter;
49
+ filter = undefined;
50
+ }
51
+
52
+ // Invalid List Names
53
+ if ( name === 'Inbox' || name === 'Sent' ) {
54
+ throw "Invalid List Name"
55
+ }
56
+
57
+ // Set Parameters
58
+ let params = {
59
+ name: name,
60
+ timeline: user.timeline
61
+ };
62
+ if ( filter !== undefined ) {
63
+ params.filter = filter;
64
+ }
65
+
66
+ // Add List
67
+ user.get('rtm.lists.add', params, function(err) {
68
+ return callback(err);
69
+ });
70
+ }
71
+
72
+ /**
73
+ * API Call: rtm.lists.delete
74
+ * @param id RTM List ID
75
+ * @param user RTMUser
76
+ * @param callback Callback function(err)
77
+ * @private
78
+ */
79
+ function remove(id, user, callback) {
80
+ let params = {
81
+ timeline: user.timeline,
82
+ list_id: id
83
+ };
84
+ user.get('rtm.lists.delete', params, function(err) {
85
+ return callback(err);
86
+ });
87
+ }
88
+
89
+ /**
90
+ * API Call: rtm.lists.setName
91
+ * @param id RTM List ID
92
+ * @param name New RTM List Name
93
+ * @param user RTMUser
94
+ * @param callback Callback function(err)
95
+ * @private
96
+ */
97
+ function rename(id, name, user, callback) {
98
+ let params = {
99
+ timeline: user.timeline,
100
+ list_id: id,
101
+ name: name
102
+ };
103
+ user.get('rtm.lists.setName', params, function(err) {
104
+ return callback(err);
105
+ });
106
+ }
107
+
108
+ /**
109
+ * API Call: rtm.lists.archive
110
+ * @param id RTM List ID
111
+ * @param user RTMUser
112
+ * @param callback Callback function(err)
113
+ * @private
114
+ */
115
+ function archive(id, user, callback) {
116
+ let params = {
117
+ timeline: user.timeline,
118
+ list_id: id
119
+ };
120
+ user.get('rtm.lists.archive', params, function(err) {
121
+ return callback(err);
122
+ });
123
+ }
124
+
125
+ module.exports = {
126
+ get: get,
127
+ add: add,
128
+ remove: remove,
129
+ rename: rename,
130
+ archive: archive
131
+ };
@@ -0,0 +1,101 @@
1
+ 'use strict';
2
+
3
+
4
+ /**
5
+ * ### RTM List
6
+ *
7
+ * This Class is used to represent the properties of an RTM List.
8
+ *
9
+ * All of the list properties from RTM are directly accessible from this Class.
10
+ *
11
+ * ```
12
+ * let list = new RTMList(...);
13
+ * let name = list.name;
14
+ * ```
15
+ * @class
16
+ */
17
+ class RTMList {
18
+
19
+ /**
20
+ * Create a new RTM List
21
+ * @param {object} props The properties from the RTM API response `resp.lists.list`
22
+ */
23
+ constructor(props) {
24
+
25
+ /**
26
+ * List ID
27
+ * @type {Number}
28
+ */
29
+ this.id = parseFloat(props.id);
30
+
31
+ /**
32
+ * List Name
33
+ * @type {string}
34
+ */
35
+ this.name = props.name;
36
+
37
+ /**
38
+ * List Deleted Flag
39
+ * @type {boolean}
40
+ */
41
+ this.deleted = props.deleted.toString() === '1';
42
+
43
+ /**
44
+ * List Locked Flag
45
+ * @type {boolean}
46
+ */
47
+ this.locked = props.locked.toString() === '1';
48
+
49
+ /**
50
+ * List Archived Flag
51
+ * @type {boolean}
52
+ */
53
+ this.archived = props.archived.toString() === '1';
54
+
55
+ /**
56
+ * List Position
57
+ * @type {Number}
58
+ */
59
+ this.position = parseInt(props.position);
60
+
61
+ /**
62
+ * Smart List Flag
63
+ * @type {boolean}
64
+ */
65
+ this.smart = props.smart.toString() === '1';
66
+ if ( this.smart ) {
67
+
68
+ /**
69
+ * Smart List Filter
70
+ * @type {string}
71
+ */
72
+ this.filter = props.filter;
73
+
74
+ }
75
+
76
+ /**
77
+ * List Sort Order
78
+ * @type {Number}
79
+ */
80
+ this.sort_order = parseInt(props.sort_order);
81
+
82
+ }
83
+
84
+ /**
85
+ * All of the RTM List properties
86
+ * @type {object}
87
+ */
88
+ get props() {
89
+ let rtn = {};
90
+ for ( let key in this ) {
91
+ if ( this.hasOwnProperty(key) && key !== '_index' ) {
92
+ rtn[key] = this[key];
93
+ }
94
+ }
95
+ return rtn;
96
+ }
97
+
98
+ }
99
+
100
+
101
+ module.exports = RTMList;