Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Api.prototype.execute = function(url, method, args, do_something_with_chunk) {
- if (url && method) {
- basicAuth = new Buffer(this._user+':'+this._apiKey).toString('base64');
- var http = require('http');
- var api = http.createClient(80, this._host);
- var request = api.request(method, this._url+url,
- { 'host': this._host, 'authorization': 'Basic '+basicAuth });
- request.end();
- request.on('response', function (response) {
- response.setEncoding('utf8');
- response.on('data', function (chunk) {
- do_something_with_chunk(chunk);
- });
- });
- } else {
- return false;
- }
- }
Add Comment
Please, Sign In to add comment