Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bulletinmybeard/f805fb20d965d3c775a484f86e036bd8 to your computer and use it in GitHub Desktop.
Save bulletinmybeard/f805fb20d965d3c775a484f86e036bd8 to your computer and use it in GitHub Desktop.
Scrab website content from Postmark its API documentation with browser devtools.
// https://postmarkapp.com/developer/api/overview
[].reduce.call(document.querySelectorAll("li[id^='error-code-'] strong:first-child"), (accumulator, item) => {

    let liText = item.outerText;
    let code = '';
    let description = '';

    if (liText.indexOf('-') > -1) {
        [code, description] = liText.split('-');
    }

    if (liText.indexOf('—') > -1) {
        [code, description] = liText.split('—');
    }

    if (description.length) {
        accumulator[parseInt(`${code}`.trim(), 10)] = `${description}`.trim();
    }

    return accumulator;
}, {});

/**
 *  10: 'Bad or missing API token',
 *  100: 'Maintenance',
 *  300: 'Invalid email request',
 *  ...
 */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment