Created
August 31, 2016 17:46
-
-
Save pdehaan/56700418071713b46a806cd5431ba95a to your computer and use it in GitHub Desktop.
Usage for Google SafeBrowsing v4 API
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
| const API_KEY = 'xxx'; | |
| const promisify = require('es6-promisify'); | |
| const safebrowsing = require('googleapis').safebrowsing('v4'); | |
| const _findThreatMatches = promisify(safebrowsing.threatMatches.find); | |
| const pkg = require('./package.json'); | |
| const client = { | |
| clientId: pkg.name, | |
| clientVersion: pkg.version | |
| }; | |
| function findThreatMatches(urls=[], client) { | |
| const resource = { | |
| client, | |
| threatInfo: { | |
| platformTypes: ['ANY_PLATFORM'], | |
| threatEntries: urls.map(url => ({url})), | |
| threatEntryTypes: ['URL'], | |
| threatTypes: ['MALWARE', 'SOCIAL_ENGINEERING', 'POTENTIALLY_HARMFUL_APPLICATION', 'UNWANTED_SOFTWARE'] | |
| } | |
| }; | |
| return _findThreatMatches({ | |
| key: API_KEY, | |
| resource | |
| }); | |
| } | |
| findThreatMatches(['http://twitter.com', 'https://facebook.com', 'http://cnn.com'], client) | |
| .then(data => console.log(data)) | |
| .catch(err => console.error(err)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment