@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.
- package/LICENSE +21 -0
- package/README.md +285 -0
- package/config.js +22 -0
- package/docs/RTMClient.html +2798 -0
- package/docs/RTMError.html +1029 -0
- package/docs/RTMList.html +966 -0
- package/docs/RTMResponse.html +868 -0
- package/docs/RTMSuccess.html +337 -0
- package/docs/RTMTask.html +2461 -0
- package/docs/RTMUser.html +6761 -0
- package/docs/client_auth.js.html +123 -0
- package/docs/client_index.js.html +241 -0
- package/docs/client_user.js.html +170 -0
- package/docs/global.html +386 -0
- package/docs/index.html +305 -0
- package/docs/list_index.js.html +159 -0
- package/docs/response_error.js.html +172 -0
- package/docs/response_response.js.html +160 -0
- package/docs/response_success.js.html +104 -0
- package/docs/scripts/linenumber.js +25 -0
- package/docs/scripts/prettify/Apache-License-2.0.txt +202 -0
- package/docs/scripts/prettify/lang-css.js +2 -0
- package/docs/scripts/prettify/prettify.js +28 -0
- package/docs/styles/jsdoc.css +664 -0
- package/docs/styles/prettify.css +79 -0
- package/docs/task_helper.js.html +531 -0
- package/docs/task_index.js.html +304 -0
- package/docs/user_index.js.html +347 -0
- package/docs/user_lists.js.html +208 -0
- package/docs/user_tasks.js.html +703 -0
- package/jsdoc.json +13 -0
- package/package.json +33 -0
- package/src/client/auth.js +65 -0
- package/src/client/index.js +182 -0
- package/src/client/user.js +112 -0
- package/src/list/helper.js +131 -0
- package/src/list/index.js +101 -0
- package/src/response/error.js +114 -0
- package/src/response/index.js +8 -0
- package/src/response/parse.js +51 -0
- package/src/response/response.js +102 -0
- package/src/response/success.js +46 -0
- package/src/task/helper.js +469 -0
- package/src/task/index.js +264 -0
- package/src/user/index.js +288 -0
- package/src/user/lists.js +150 -0
- package/src/user/tasks.js +708 -0
- package/src/utils/auth.js +188 -0
- package/src/utils/fetch.js +67 -0
- package/src/utils/get.js +247 -0
- package/src/utils/sign.js +93 -0
- package/src/utils/taskIds.js +188 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 David Waring
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
Remember The Milk API Interface
|
|
2
|
+
===============================
|
|
3
|
+
|
|
4
|
+
**node module:** [rtm-api](https://www.npmjs.com/package/@beauraines/rtm-api)
|
|
5
|
+
**GitHub repo:** [beauraines/rtm-api](https://github.com/beauraines/rtm-api)
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
This Node module provides a wrapper around the Remember the Milk API.
|
|
10
|
+
|
|
11
|
+
You will need your own RTM API Key and Secret, available from the Remember the
|
|
12
|
+
Milk [website](https://www.rememberthemilk.com/services/api/keys.rtm).
|
|
13
|
+
|
|
14
|
+
This is a fork of [dwaring87/rtm-api](https://github.com/dwaring87/rtm-api) so that I can maintain, modernize and add features. Your contributions are welcome!
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## Main Features
|
|
18
|
+
|
|
19
|
+
- Two-step User Authorization procedure
|
|
20
|
+
|
|
21
|
+
- Direct RTM API Requests
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
// Requests are automatically signed and include the User's Auth Token
|
|
25
|
+
user.get('rtm.method', {param: 'value'}, function(err, response) {
|
|
26
|
+
if ( err ) {
|
|
27
|
+
return console.error(err.toString());
|
|
28
|
+
}
|
|
29
|
+
console.log(response);
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
- Basic Error Handling and Response Parsing
|
|
34
|
+
|
|
35
|
+
- Per-User Rate Limiting (following RTM API guidelines)
|
|
36
|
+
|
|
37
|
+
- Helper Classes and Functions for **Lists** and **Tasks**
|
|
38
|
+
|
|
39
|
+
```javascript
|
|
40
|
+
// Optional filter selecting tasks with a priority of 1
|
|
41
|
+
user.tasks.get('priority:1', function(err, tasks) {
|
|
42
|
+
if ( err ) {
|
|
43
|
+
return console.error(err.toString());
|
|
44
|
+
}
|
|
45
|
+
tasks.forEach(function(task){
|
|
46
|
+
// task is an RTMTask instance
|
|
47
|
+
console.log(task.priority);
|
|
48
|
+
console.log(task.name);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
## Installation
|
|
55
|
+
|
|
56
|
+
This module can be installed via `npm`:
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
npm install rtm-api
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
or downloaded directly from the [GitHub repository](https://github.com/beauraines/rtm-api).
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
## Documentation
|
|
66
|
+
|
|
67
|
+
Full documentation is available in the **/docs/** directory of this repository or
|
|
68
|
+
online at [https://dwaring87.github.io/rtm-api/](https://dwaring87.github.io/rtm-api/).
|
|
69
|
+
|
|
70
|
+
Additional usage examples can be found in the repository's [wiki pages](https://github.com/dwaring87/rtm-api/wiki).
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
## Usage
|
|
74
|
+
|
|
75
|
+
Set up your API credentials by specifying your API Key, API Secret and the
|
|
76
|
+
requested account permissions.
|
|
77
|
+
|
|
78
|
+
```javascript
|
|
79
|
+
const RTM = require('rtm-api');
|
|
80
|
+
let client = new RTM('API_KEY', 'API_SECRET', RTM.PERM_DELETE); // An instance of RTMClient
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Account permissions can be granted in one of three categories:
|
|
84
|
+
|
|
85
|
+
- **read** – gives the ability to read task, contact, group and list details and contents.
|
|
86
|
+
- **write** – gives the ability to add and modify task, contact, group and list details and contents (also allows you to read).
|
|
87
|
+
- **delete** – gives the ability to delete tasks, contacts, groups and lists (also allows you to read and write).
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
### User Authentication
|
|
91
|
+
|
|
92
|
+
Almost all RTM API methods require an authorized user's Auth Token. This is
|
|
93
|
+
kept in the `RTMUser` class which can be instantiated manually if you already
|
|
94
|
+
have the User's information with a valid Auth Token:
|
|
95
|
+
|
|
96
|
+
```javascript
|
|
97
|
+
let user = client.user.create(id, 'username', 'fullname', 'authToken');
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Otherwise, an Auth Token can be obtained via the API using the steps outlined
|
|
101
|
+
in the following sections.
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
#### Generate an Auth URL
|
|
105
|
+
|
|
106
|
+
First, generate an Auth URL that the RTM User will open in their browser. This
|
|
107
|
+
will direct the RTM User to the Remember the Milk website where they will log in
|
|
108
|
+
and authorize this program to access their account.
|
|
109
|
+
|
|
110
|
+
```javascript
|
|
111
|
+
// Get an RTM Auth URL that will ask the RTM User to grant access to your client
|
|
112
|
+
client.auth.getAuthUrl(function(err, authUrl, frob) {
|
|
113
|
+
if ( err ) {
|
|
114
|
+
return console.error(err.toString());
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Have the User open the authUrl
|
|
118
|
+
console.log(authUrl);
|
|
119
|
+
|
|
120
|
+
// Save the frob for the next step
|
|
121
|
+
...
|
|
122
|
+
|
|
123
|
+
});
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
#### Generate an Auth Token
|
|
127
|
+
|
|
128
|
+
Once the RTM User has opened the `authUrl` and granted access to the program,
|
|
129
|
+
pass the `frob` from the first step to the `getAuthToken` function to
|
|
130
|
+
get an `RTMUser` with an Auth Token to be used in future API calls.
|
|
131
|
+
|
|
132
|
+
```javascript
|
|
133
|
+
// Get an Auth Token for the User once they've authorized the frob
|
|
134
|
+
client.auth.getAuthToken(frob, function(err, user) {
|
|
135
|
+
if ( err ) {
|
|
136
|
+
return console.error(err.toString());
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// If successful, the returned user will include the property `authToken`
|
|
140
|
+
console.log(user.authToken);
|
|
141
|
+
|
|
142
|
+
// Save the user for making authenticated API calls via user.get()
|
|
143
|
+
|
|
144
|
+
});
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
#### Verify the Auth Token
|
|
148
|
+
|
|
149
|
+
The Auth Token can be verified at any point using the `verifyAuthToken` function.
|
|
150
|
+
|
|
151
|
+
```javascript
|
|
152
|
+
client.auth.verifyAuthToken(user.authToken, function(err, verified) {
|
|
153
|
+
|
|
154
|
+
// verified will be true if auth token can be used for API calls
|
|
155
|
+
|
|
156
|
+
});
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
### API Requests
|
|
161
|
+
|
|
162
|
+
To make a request to the RTM API, a [method name](https://www.rememberthemilk.com/services/api/methods.rtm)
|
|
163
|
+
and callback function are required.
|
|
164
|
+
|
|
165
|
+
If the RTM API method requires any parameters, they should be provided as
|
|
166
|
+
an object with the parameters set as key/value pairs. For example, if the
|
|
167
|
+
method requires the parameters: abc=foo and xyz=bar then they should be provided
|
|
168
|
+
as:
|
|
169
|
+
```
|
|
170
|
+
{
|
|
171
|
+
abc: "foo",
|
|
172
|
+
xyz: "bar"
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
If the API Method does not require a User's Auth Token, the request can be made
|
|
177
|
+
using the `get` function available from the `RTMClient`.
|
|
178
|
+
|
|
179
|
+
```javascript
|
|
180
|
+
client.get('rtm.auth.getFrob', function(err, resp) {
|
|
181
|
+
if ( err ) {
|
|
182
|
+
return console.error(err.toString());
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Handle the Response
|
|
186
|
+
console.log(resp.frob);
|
|
187
|
+
});
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
However, most API Methods will require a User's Auth Token. This can be provided
|
|
191
|
+
directly as an `auth_token` parameter or by calling the `get` function available
|
|
192
|
+
from the `RTMUser` instance, which will automatically provide the Auth Token.
|
|
193
|
+
|
|
194
|
+
```javascript
|
|
195
|
+
let params = {
|
|
196
|
+
list_id: "list id",
|
|
197
|
+
filter: "tasks filter"
|
|
198
|
+
};
|
|
199
|
+
user.get('rtm.tasks.getList', params, function(err, resp) {
|
|
200
|
+
if ( err ) {
|
|
201
|
+
return console.error(err.toString());
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Handle the Response
|
|
205
|
+
console.log(resp);
|
|
206
|
+
});
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
### API Responses
|
|
211
|
+
|
|
212
|
+
The arguments returned in the callback of the `get` function will include an
|
|
213
|
+
`RTMError` instance (if the RTM API returned a status of 'fail') or an
|
|
214
|
+
`RTMSuccess` instance for successful requests.
|
|
215
|
+
|
|
216
|
+
#### Error Responses
|
|
217
|
+
|
|
218
|
+
An `RTMError` response will have `code` and `msg` properties set based on the
|
|
219
|
+
RTM API response.
|
|
220
|
+
|
|
221
|
+
Additional error codes are added by `rtm-api`:
|
|
222
|
+
|
|
223
|
+
|error code | error description|
|
|
224
|
+
|:---------:|------------------|
|
|
225
|
+
| -1 | **Network Error**: `rtm-api` could not connect to the RTM API Server.|
|
|
226
|
+
| -2 | **Response Error**: `rtm-api` could not parse the response from the RTM API Server.|
|
|
227
|
+
| -3 | **Reference Error**: An `RTMTask` index is out of range or RTM item could not be found with the given reference.|
|
|
228
|
+
| -4 | **Rate Limit Error**: The RTM User has reached the API request rate limit set by the RTM API Server.|
|
|
229
|
+
| -5 | **Server Error**: `rtm-api` encountered a problem with the RTM API Server. Try the request again later.|
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
#### Successful Responses
|
|
233
|
+
|
|
234
|
+
For a successful response, the API response properties can be accessed directly
|
|
235
|
+
from the `RTMSuccess` properties (`resp.tasks`, `resp.tasks.list`, etc). All
|
|
236
|
+
response properties are available via `resp.props`
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
### Helper Functions
|
|
240
|
+
|
|
241
|
+
`rtm-api` includes a number of helper classes & functions for commonly used API
|
|
242
|
+
methods used to obtain and modify RTM Lists and Tasks. These functions are
|
|
243
|
+
available via an `RTMUser` instance's `lists` and `tasks` properties.
|
|
244
|
+
|
|
245
|
+
The following **list** functions are available:
|
|
246
|
+
|
|
247
|
+
- `get()`: get an array of `RTMList`s
|
|
248
|
+
- `add()`: add a new List
|
|
249
|
+
- `archive()`: archive a List
|
|
250
|
+
- `rename()`: rename a List
|
|
251
|
+
- `remove()`: remove a List
|
|
252
|
+
|
|
253
|
+
The following **task** functions are available:
|
|
254
|
+
|
|
255
|
+
- `get()`: get an array of `RTMTasks`s (with the Tasks's `RTMList` added to the `list` property)
|
|
256
|
+
- `getTask()`: get a specific Task (specified by a Task Index)
|
|
257
|
+
- `add()`: add a new Task
|
|
258
|
+
- `remove()`: remove a Task
|
|
259
|
+
- `complete()`: mark a Task as completed
|
|
260
|
+
- `uncomplete()`: mark a Task as NOT completed
|
|
261
|
+
- `addTags()`: add one or tags to a Task
|
|
262
|
+
- `addNotes()`: add one or more notes to a Task
|
|
263
|
+
- `removeTags()`: remove one or more tags from a Task
|
|
264
|
+
- `priority()`: set the Priority of a Task
|
|
265
|
+
- `decreasePriority()`: decrease the Priority of a Task
|
|
266
|
+
- `increasePriority()`: increase the Priority of a Task
|
|
267
|
+
- `move()`: move a Task to a different List
|
|
268
|
+
- `setDueDate()`: set the due date of a Task
|
|
269
|
+
- `setStartDate()`: set the start date of a Task
|
|
270
|
+
- `postpone()`: postpone the due date of Task by one day
|
|
271
|
+
- `setName()`: set the name of a Task
|
|
272
|
+
- `setURL()`: set the URL of a Task
|
|
273
|
+
|
|
274
|
+
See the `RTMUser` entry in the **Documentation** for more information on the
|
|
275
|
+
Helper Functions.
|
|
276
|
+
|
|
277
|
+
Examples using the helper functions can be found in the repository's
|
|
278
|
+
[wiki pages](https://github.com/dwaring87/rtm-api/wiki).
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
## Advanced Configuration
|
|
282
|
+
|
|
283
|
+
The API configuration (such as the URL and connection rate limiting parameters) are defined in the `config.js` file. In addition,
|
|
284
|
+
the location of the cache file used to associate specific tasks with their Task ID numbers can be specified in the file or by
|
|
285
|
+
setting the `RTM_INDEX_CACHE` environment parameter.
|
package/config.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
const os = require('os');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
"api": {
|
|
7
|
+
"scheme": "https",
|
|
8
|
+
"url": {
|
|
9
|
+
"auth": "www.rememberthemilk.com/services/auth/",
|
|
10
|
+
"base": "api.rememberthemilk.com/services/rest/"
|
|
11
|
+
},
|
|
12
|
+
"version": 2,
|
|
13
|
+
"format": "json",
|
|
14
|
+
"rate": {
|
|
15
|
+
"bursts": 3,
|
|
16
|
+
"burstTimeout": 333,
|
|
17
|
+
"burstWait": 120000,
|
|
18
|
+
"timeout": 1000
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"task_id_cache_file": process.env.RTM_INDEX_CACHE ? process.env.RTM_INDEX_CACHE : path.normalize(os.homedir() + '/' + '.rtm.indexcache.json')
|
|
22
|
+
}
|