Skip to content

Commit

Permalink
Updated documentation and README.md.
Browse files Browse the repository at this point in the history
Closes #18.
Bump version.
  • Loading branch information
levz0r committed Jan 24, 2020
1 parent 92522d8 commit e6b1321
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,20 @@ An array of `email` objects with the following fields:<br>

_Some senders will send you `text/html` content, the others will send you `plain/text`, and some will send you both. Make sure you are looking for the content in the right body field._

### `check_inbox(credentials_json, token_path, subject, from, to, wait_time_sec = 30, max_wait_time_sec = 60, options = {})`
### `check_inbox(credentials_json, token_path, options = {})`

`credentials_json`: Path to credentials JSON file.<br>
`token_path`: Path to OAuth2 token file.<br>
`subject`: Subject to look for. Exact match.<br>
`from`: Sender email to look for. Exact match.<br>
`to`: Receiver's email. Exact match.<br>
`wait_time_sec`: Interval between inbox checks (in seconds). _Default: 30 seconds_.<br>
`max_wait_time_sec`: Maximum wait time (in seconds). When reached and the email was not found, the script exits. _Default: 60 seconds_.<br>
`options`: <br>

* `include_body`: boolean. Set to `true` to fetch decoded email bodies. _Default: false_.
* `from`: String. Filter on the email address of the receiver.
* `to`: String. Filter on the email address of the sender.
* `subject`: String. Filter on the subject of the email.
* `include_body`: boolean. Set to `true` to fetch decoded email bodies.
* `before`: Date. Filter messages received _after_ the specified date.
* `after`: Date. Filter messages received _before_ the specified date.
* `wait_time_sec`: Integer. Interval between inbox checks (in seconds). _Default: 30 seconds_.
* `max_wait_time_sec`: Integer. Maximum wait time (in seconds). When reached and the email was not found, the script exits. _Default: 60 seconds_.

**Returns:**
An array of `email` objects with the following fields:<br>
Expand Down
22 changes: 19 additions & 3 deletions gmail-tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,21 @@ async function __check_inbox(credentials_json, token_path, options = {}) {
}
}

/**
* Poll inbox.
*
* @param {string} credentials_json - Path to credentials json file.
* @param {string} token_path - Path to token json file.
* @param {Object} options
* @param {boolean} options.include_body - Set to `true` to fetch decoded email bodies.
* @param {boolean} options.from - Filter on the email address of the receiver.
* @param {boolean} options.to - Filter on the email address of the sender.
* @param {boolean} options.subject - Filter on the subject of the email.
* @param {boolean} options.before - Date. Filter messages received _after_ the specified date.
* @param {boolean} options.after - Date. Filter messages received _before_ the specified date.
* @param {boolean} options.wait_time_sec - Interval between inbox checks (in seconds). Default: 30 seconds.
* @param {boolean} options.max_wait_time_sec - Maximum wait time (in seconds). When reached and the email was not found, the script exits. Default: 60 seconds.
*/
async function check_inbox(
credentials_json,
token_path,
Expand All @@ -147,12 +162,13 @@ async function check_inbox(
from: undefined,
to: undefined,
wait_time_sec: 30,
max_wait_time_sec: 30
max_wait_time_sec: 30,
include_body: false
}
) {
if (typeof options === "string") {
if (typeof options !== "object") {
console.error(
"This functionality is absolete! Please pass all filter params using options object!"
"This functionality is absolete! Please pass all params in options object!"
);
process.exit(1);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gmail-tester",
"version": "1.1.5",
"version": "1.2.0",
"description": "A simple NodeJS gmail client which checks the inbox for specific message existance",
"main": "gmail-tester.js",
"scripts": {},
Expand Down

0 comments on commit e6b1321

Please sign in to comment.