Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

matrixorg

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

matrixorg - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

examples/simple.js

30

lib/client.js

@@ -16,2 +16,4 @@ "use strict"

this.version = options.version || "v1";
this.access_token = null;
this.user_id = null;

@@ -23,19 +25,24 @@ this.prepareRequest = function(req){

this.prepareUrl = function(path){
return options.host + "/_matrix/client/api/" + this.version + ((path[0] == "/")?path:("/" + path));
return options.host + "/_matrix/client/api/" + this.version + ((path[0] == "/")?path:("/" + path)) +
(this.access_token ? "?access_token=" + this.access_token:"");
}
}
module.exports = Client;
Client.prototype.login = function(options, callback){
this.makeRequest("post", "login", options, callback)
// if(res.ok){
// callback(null, res)
// }else {
// callback(err)
// }
// })
var self = this;
this.makeRequest("post", "login", options, function(err, res){
if(err){
callback(err)
}else {
self.access_token = res.access_token;
self.user_id = res.user_id;
callback(null,res);
}
})
}
Client.prototype.register = function(options, callback) {
this.makeRequest("post", "register", options, callback);
}
Client.prototype.createRequest = function(method, path){

@@ -97,2 +104,3 @@ return this.prepareRequest(superagent[method](this.prepareUrl(path)));

module.exports = Client;
"use strict";
module.exports = {
Client: require("./client"),
Room: require("./room"),
Presence: require("./presence")
};
{
"name": "matrixorg",
"version": "0.0.2",
"version": "0.0.3",
"description": "Helper library for Matrix.org APIs",

@@ -24,2 +24,3 @@ "main": "index.js",

"dependencies": {
"bluebird": "^2.9.15",
"superagent": "^0.21.0"

@@ -26,0 +27,0 @@ },

@@ -41,2 +41,21 @@ var Client = require("../").Client;

})
describe("#register", function() {
var response = {
"access_token": "atoken",
"home_server": "localhost",
"user_id":"@example:localhost"
}
it("should register successfully", function(done){
helper.nock().post("/_matrix/client/api/v1/register").reply(200, response);
helper.createClient().register({"username":"test", "password":"password", "type":"m.login.password"}, function(err, res){
if(err){
return done(err)
}
res.access_token.should.eql(response.access_token)
done();
})
})
})
});
var Client = require("../").Client;
var nock = require("nock");
module.exports = {
createClient: function(){
return new Client({"host":"http://localhost:8448"});
createClient: function(access_token, user_id){
var client = new Client({"host":"http://localhost:8448"})
client.access_token = access_token || null;
client.user_id = user_id || null;
return client;
},

@@ -7,0 +10,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc