Skip to content

Instantly share code, notes, and snippets.

@ismaelc
Last active December 27, 2015 01:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ismaelc/7242220 to your computer and use it in GitHub Desktop.
Save ismaelc/7242220 to your computer and use it in GitHub Desktop.
The Cloud Module Yoda Speak where the Mashape API is called
// Cloud Module yoda-1.0.0.js
// Set url of Mashape API to call
var url = 'https://yoda.p.mashape.com/yoda';
var key = '';
module.exports = {
// Method to initialize module
initialize: function(mashapeKey) {
key = mashapeKey;
return this;
},
// 'yodaSpeak' method to make an HTTP request call to Mashape API
// Uses Javascript Promises ('then') to execute success or error callback through 'options'
yodaSpeak: function(params, options) {
return Parse.Cloud.httpRequest({
url: url,
headers: {
'X-Mashape-Authorization': key
},
params: params,
}).then(function(httpResponse) {
if (options && options.success) {
options.success(httpResponse);
}
}, function(httpResponse) {
if (options && options.error) {
options.error(httpResponse);
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment