"use strict"; // wrap in a closure for browsers var init = function(exports){ // expose the underlying request object so different environments can use // different request libs (e.g. request or browser-request) var request; exports.request = function(r) { request = r; }; // entry point function MatrixClient(credentials) { if (typeof credentials === "string") { credentials = { "baseUrl": credentials }; } var requiredKeys = [ "baseUrl" ]; for (var i=0; i %s", uri); console.log(" %s", JSON.stringify(data)); return request( { uri: uri, method: method, withCredentials: false, qs: params, body: data, json: true, headers: HEADERS }, requestCallback(callback) ); } }; var encodeUri = function(pathTemplate, variables) { for (var key in variables) { if (!variables.hasOwnProperty(key)) { continue; } pathTemplate = pathTemplate.replace( key, encodeURIComponent(variables[key]) ); } return pathTemplate; }; var requestCallback = function(userDefinedCallback) { if (!userDefinedCallback) { return undefined; } return function(err, response, body) { if (err) { return userDefinedCallback(err); } if (response.statusCode >= 400) { return userDefinedCallback(body); } else { userDefinedCallback(null, body); } }; }; var isFunction = function(value) { return Object.prototype.toString.call(value) == "[object Function]"; }; }; if (typeof exports === 'undefined') { init(this['matrixcs']={}); // this assigns to "window" on browsers } else { init(exports); }