mirror of
https://github.com/turt2live/matrix-dimension.git
synced 2024-10-01 01:05:53 -04:00
826364e803
This is part of a rewrite for Dimension to better support integrations. Only the bare minimum scalar APIs are implemented at this point - dimension is non-functional.
32 lines
1.2 KiB
TypeScript
32 lines
1.2 KiB
TypeScript
import { OpenId } from "../models/OpenId";
|
|
import { ScalarRegisterResponse } from "../models/ScalarResponses";
|
|
import * as Promise from "bluebird";
|
|
import * as request from "request";
|
|
import { LogService } from "matrix-js-snippets";
|
|
import Upstream from "../db/models/Upstream";
|
|
|
|
export class ScalarClient {
|
|
constructor(private upstream: Upstream) {
|
|
}
|
|
|
|
public register(openId: OpenId): Promise<ScalarRegisterResponse> {
|
|
return new Promise((resolve, reject) => {
|
|
request({
|
|
method: "POST",
|
|
url: this.upstream.scalarUrl + "/register",
|
|
json: openId,
|
|
}, (err, res, _body) => {
|
|
if (err) {
|
|
LogService.error("ScalarClient", "Error registering for token");
|
|
LogService.error("ScalarClient", err);
|
|
reject(err);
|
|
} else if (res.statusCode !== 200) {
|
|
LogService.error("ScalarClient", "Got status code " + res.statusCode + " while registering for token");
|
|
reject(new Error("Could not get token"));
|
|
} else {
|
|
resolve(res.body);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
} |