Created
May 14, 2015 06:04
-
-
Save pdehaan/91f87b46558076b19829 to your computer and use it in GitHub Desktop.
restmail+fetch example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var fetch = require('node-fetch') | |
| fetch.Promise = require('promise') | |
| getEmails('testfetch@restmail.net') | |
| // Filter only FxA emails and only return the x-link header. | |
| .then((messages) => messages.filter(filterFunc).map(getLink)) | |
| .then(console.log) | |
| .catch(console.error) | |
| function getEmails (account) { | |
| // Retrieve restmail account and convert response to JSON. | |
| return fetch(`https://restmail.net/mail/${account}`).then((response) => response.json()) | |
| } | |
| function getLink (message) { | |
| return message.headers['x-link'] | |
| } | |
| function isFxAEmail (message) { | |
| return (message.from[0].name === 'Firefox Accounts') | |
| } | |
| function filterFunc (message) { | |
| return isFxAEmail(message) && !!getLink(message) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "name": "node-fetch-test", | |
| "version": "1.0.0", | |
| "author": "Peter deHaan", | |
| "dependencies": { | |
| "babel": "5.3.3", | |
| "node-fetch": "1.2.1", | |
| "promise": "7.0.1" | |
| }, | |
| "devDependencies": { | |
| "standard": "3.8.0" | |
| }, | |
| "license": "WTFPL", | |
| "main": "index.js", | |
| "scripts": { | |
| "start": "babel-node index", | |
| "test": "standard" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment