diff --git a/lib/matrix.js b/lib/matrix.js index 27ea55c49..75bc265ee 100644 --- a/lib/matrix.js +++ b/lib/matrix.js @@ -38,10 +38,34 @@ var init = function(exports){ return this.credentials.accessToken != undefined; }, + // Room operations + // =============== + + createRoom: function(options, callback) { + // valid options include: room_alias_name, visibility, invite + return this._doAuthedRequest( + callback, "POST", "/createRoom", undefined, options + ); + }, + + // Public (non-authed) operations + // ============================== + publicRooms: function(callback) { return this._doRequest(callback, "GET", "/publicRooms"); }, + registerFlows: function(callback) { + return this._doRequest(callback, "GET", "/register"); + }, + + loginFlows: function(callback) { + return this._doRequest(callback, "GET", "/login"); + }, + + // Syncing operations + // ================== + initialSync: function(limit, callback) { var params = { limit: limit @@ -51,6 +75,9 @@ var init = function(exports){ ); }, + // Internals + // ========= + _doAuthedRequest: function(callback, method, path, params, data) { if (!params) { params = {}; } params.access_token = this.credentials.accessToken; @@ -61,7 +88,7 @@ var init = function(exports){ var fullUri = this.credentials.baseUrl + PREFIX + path; if (!params) { params = {}; } - request( + return request( { uri: fullUri, method: method, @@ -102,19 +129,6 @@ var init = function(exports){ } }; }; - - - exports.test = function(){ - request({ - uri: "http://localhost:8008/_matrix/client/api/v1/publicRooms", - method: "GET", - withCredentials: false, - }, - function(err, response, body) { - console.log(body); - }); - }; - }; if (typeof exports === 'undefined') { diff --git a/package.json b/package.json index 613ff0fcb..83fa8e936 100644 --- a/package.json +++ b/package.json @@ -11,5 +11,9 @@ ], "browserify": "browser/index.js", "author": "matrix.org", - "license": "Apache 2.0" + "license": "Apache 2.0", + "dependencies": { + "browser-request": "^0.3.3", + "request": "^2.53.0" + } }