Comparing version 0.0.2 to 0.0.3
@@ -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 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15020
14
371
2
1
+ Addedbluebird@^2.9.15
+ Addedbluebird@2.11.0(transitive)