@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,114 @@
1
+ 'use strict';
2
+
3
+ const RTMResponse = require('./response.js');
4
+
5
+
6
+ /**
7
+ * ### RTM Error Response
8
+ *
9
+ * This Class represents a failed request to the RTM API Server: the
10
+ * RTM API Server returned a response with a status of 'fail'. This
11
+ * Class will include the error code and error message from the
12
+ * response.
13
+ *
14
+ * `RTMError` extends {@link RTMResponse}
15
+ * @class
16
+ * @alias RTMError
17
+ */
18
+ class RTMError extends RTMResponse{
19
+
20
+ /**
21
+ * Create a new RTM Error Response
22
+ * @param {number} code Error Code
23
+ * @param {string} msg Error Message
24
+ * @constructor
25
+ */
26
+ constructor(code, msg) {
27
+ super(RTMResponse.STATUS_FAIL);
28
+ this._code = parseInt(code);
29
+ this._msg = msg;
30
+ }
31
+
32
+ /**
33
+ * The RTM Error Code
34
+ * @type {number}
35
+ */
36
+ get code() {
37
+ return this._code;
38
+ }
39
+
40
+ /**
41
+ * The RTM Error Message
42
+ * @type {string}
43
+ */
44
+ get msg() {
45
+ return this._msg;
46
+ }
47
+
48
+ /**
49
+ * Get a String representation of the Error
50
+ * @returns {string}
51
+ */
52
+ toString() {
53
+ return super.toString() + " ERROR " + this._code + ": " + this._msg;
54
+ }
55
+
56
+ }
57
+
58
+
59
+ // === CUSTOM ERRORS ==== //
60
+
61
+ /**
62
+ * Create a new `RTMError` that represents a network error.
63
+ *
64
+ * Error Code: `-1`
65
+ * @returns {RTMError}
66
+ */
67
+ RTMError.networkError = function() {
68
+ return new RTMError(-1, "Network Error: Could not make request to RTM API Server");
69
+ };
70
+
71
+ /**
72
+ * Create a new `RTMError` that represents an API response error.
73
+ *
74
+ * Error Code: `-2`
75
+ * @returns {RTMError}
76
+ */
77
+ RTMError.responseError = function() {
78
+ return new RTMError(-2, "Response Error: Could not parse the response from the RTM API Server");
79
+ };
80
+
81
+ /**
82
+ * Create a new `RTMError` that represents an index error (ie, task index is out
83
+ * of range).
84
+ *
85
+ * Error Code: `-3`
86
+ * @returns {RTMError}
87
+ */
88
+ RTMError.referenceError = function() {
89
+ return new RTMError(-3, "Reference Error: Could not find item by reference index number or name");
90
+ };
91
+
92
+ /**
93
+ * Create a new `RTMError` that represents an RTM API Rate Limit (the RTM API
94
+ * returned a HTTP Status code of `503`).
95
+ *
96
+ * Error Code: `-4`
97
+ * @returns {RTMError}
98
+ */
99
+ RTMError.rateLimitError = function() {
100
+ return new RTMError(-4, "Rate Limit Error: Your Account has temporarily reached the RTM API Rate Limit. Please wait a minute and try the request again later.");
101
+ };
102
+
103
+ /**
104
+ * Create a new `RTMError` that represents an RTM API Server Error (the RTM API
105
+ * returned a HTTP Status code of `5xx` - excluding `503`).
106
+ *
107
+ * Error Code: `-5`
108
+ * @returns {RTMError}
109
+ */
110
+ RTMError.serverError = function() {
111
+ return new RTMError(-5, "RTM API Server Error: The RTM API Server is not responding. Please try the request again later.");
112
+ };
113
+
114
+ module.exports = RTMError;
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ module.exports = {
4
+ error: require('./error.js'),
5
+ parse: require('./parse.js'),
6
+ response: require('./response.js'),
7
+ success: require('./success.js')
8
+ };
@@ -0,0 +1,51 @@
1
+ 'use strict';
2
+
3
+ const success = require('./success.js');
4
+ const error = require('./error.js');
5
+
6
+
7
+ /**
8
+ * Parse the raw RTM API Response into either a `RTMSuccess` or
9
+ * `RTMError` Class with the Response's properties.
10
+ * @param {string} raw Raw RTM API Server Response (as a JSON-formatted String)
11
+ * @returns {RTMError|RTMSuccess}
12
+ * @private
13
+ */
14
+ function parse(raw) {
15
+
16
+ // Parse the response into JSON
17
+ let response = undefined;
18
+ try {
19
+ response = JSON.parse(raw);
20
+ }
21
+ catch(exception) {
22
+ return error.responseError();
23
+ }
24
+
25
+ // Make sure there is a response status
26
+ if ( !response || !response.rsp || !response.rsp.stat ) {
27
+ return error.responseError();
28
+ }
29
+
30
+ // Get the response status
31
+ let status = response.rsp.stat;
32
+
33
+ // SUCCESS
34
+ if ( status === 'ok' ) {
35
+ return new success(response.rsp);
36
+ }
37
+
38
+ // ERROR
39
+ else if ( status === 'fail' ) {
40
+ return new error(response.rsp.err.code, response.rsp.err.msg);
41
+ }
42
+
43
+ // UNKNOWN STATUS
44
+ else {
45
+ return error.responseError();
46
+ }
47
+
48
+ }
49
+
50
+
51
+ module.exports = parse;
@@ -0,0 +1,102 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * ### RTM Generic Response
5
+ *
6
+ * This Class represents a generic Response from the RTM API Server.
7
+ * The `RTMError` and `RTMSuccess` Classes represent the actual failed
8
+ * and successful responses from the RTM API Server.
9
+ *
10
+ * This Class is extended by the {@link RTMSuccess} and {@link RTMError} Classes.
11
+ * @class
12
+ * @alias RTMResponse
13
+ */
14
+ class RTMResponse {
15
+
16
+ /**
17
+ * Create a new Generic RTM Response with a status of either
18
+ * {@link RTMResponse.STATUS_OK} or {@link RTMResponse.STATUS_FAIL}.
19
+ * @param {string} status RTM API Status
20
+ * @constructor
21
+ */
22
+ constructor(status) {
23
+ this._status = status;
24
+ }
25
+
26
+ /**
27
+ * The RTM Response Status
28
+ * @type {string}
29
+ */
30
+ get status() {
31
+ return this._status;
32
+ }
33
+
34
+ /**
35
+ * The success of the RTM Response (ie, is `true` when status is 'ok')
36
+ * @type {boolean}
37
+ */
38
+ get isOk() {
39
+ return this._status === RTMResponse.STATUS_OK;
40
+ }
41
+
42
+ /**
43
+ * The RTM API properties of the Response
44
+ * @type {object}
45
+ */
46
+ get props() {
47
+ let rtn = {};
48
+ for ( let key in this ) {
49
+ if ( this.hasOwnProperty(key) && key !== '_status' ) {
50
+ rtn[key] = this[key];
51
+ }
52
+ }
53
+ return rtn;
54
+ }
55
+
56
+ /**
57
+ * Check if the Response has the specified property
58
+ * @param {string} property Property Name
59
+ * @returns {boolean}
60
+ */
61
+ has(property) {
62
+ let parts = property.split('.');
63
+ let object = this;
64
+
65
+ for ( let i = 0; i < parts.length; i++ ) {
66
+ object = object[parts[i]];
67
+ if ( object === undefined ) {
68
+ return false;
69
+ }
70
+ }
71
+
72
+ return true;
73
+ }
74
+
75
+ /**
76
+ * Get a String representation of the Response
77
+ * @returns {string}
78
+ */
79
+ toString() {
80
+ return "[" + this._status + "]";
81
+ }
82
+
83
+ }
84
+
85
+
86
+ /**
87
+ * RTM Status of 'ok' = successful
88
+ * @type {string}
89
+ * @default
90
+ */
91
+ RTMResponse.STATUS_OK = "ok";
92
+
93
+ /**
94
+ * RTM Status of 'fail' = error
95
+ * @type {string}
96
+ * @default
97
+ */
98
+ RTMResponse.STATUS_FAIL = "fail";
99
+
100
+
101
+
102
+ module.exports = RTMResponse;
@@ -0,0 +1,46 @@
1
+ 'use strict';
2
+
3
+ const RTMResponse = require('./response.js');
4
+
5
+
6
+ /**
7
+ * ### RTM Success Response
8
+ *
9
+ * This Class represents a successful response from the RTM API Server: the
10
+ * RTM API Server returned a response with a status of 'ok'. This Class will
11
+ * include all of the properties of the RTM `rsp` property.
12
+ *
13
+ * `RTMSuccess` extends {@link RTMResponse}
14
+ * @class
15
+ * @alias RTMSuccess
16
+ */
17
+ class RTMSuccess extends RTMResponse {
18
+
19
+ /**
20
+ * Create a new RTM Success Response
21
+ * @param {object} rsp The RTM API Response's `rsp` property
22
+ * @constructor
23
+ */
24
+ constructor(rsp) {
25
+ super(RTMResponse.STATUS_OK);
26
+
27
+ // Parse the response properties
28
+ for ( let key in rsp ) {
29
+ if ( rsp.hasOwnProperty(key) && key !== 'stat' ) {
30
+ this[key] = rsp[key];
31
+ }
32
+ }
33
+ }
34
+
35
+ /**
36
+ * Get a String representation of the Success Response
37
+ * @returns {string}
38
+ */
39
+ toString() {
40
+ return super.toString() + " " + JSON.stringify(this.props);
41
+ }
42
+
43
+ }
44
+
45
+
46
+ module.exports = RTMSuccess;