Created
March 21, 2017 20:43
-
-
Save sunnygleason/841f45a286236a294e09cfaf926d32d5 to your computer and use it in GitHub Desktop.
PubNub Image Recognition BLOCK w/ AIception
This file contains 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
export default (request) => { | |
const xhr = require('xhr'); | |
const base64 = require('codec/base64'); | |
const authToken = 'YOUR_AUTH_TOKEN'; | |
const url = "https://aiception.com/api/v2.1/detect_object"; | |
const httpOptions = { | |
"method": "POST", | |
"timeout": 10000, | |
"headers": { | |
"Authorization": "Basic " + base64.btoa(authToken + ":" + 'password is ignored'), | |
"Content-Type": "application/json" | |
}, | |
"body": JSON.stringify({image_url:request.message.image_url,async:false}) | |
}; | |
return xhr.fetch(url, httpOptions).then((response) => { | |
request.message.ai_result = JSON.parse(response.body); | |
return request.ok(); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment