diff options
| author | Florian Dold <florian.dold@gmail.com> | 2016-01-06 15:58:18 +0100 |
|---|---|---|
| committer | Florian Dold <florian.dold@gmail.com> | 2016-01-06 15:58:18 +0100 |
| commit | 5bb1c95ec531c4cf7848466e4ff5c3408f2dca7f (patch) | |
| tree | 366c7fce1e6fcec0196f301b4cf2539f32733fb8 /extension/background/http.ts | |
| parent | abf15268acafe588191fffb7ca6ddb963244bb0f (diff) | |
make wallet independent of chrome/WX api
Diffstat (limited to 'extension/background/http.ts')
| -rw-r--r-- | extension/background/http.ts | 71 |
1 files changed, 36 insertions, 35 deletions
diff --git a/extension/background/http.ts b/extension/background/http.ts index 9355add6f..fdbf8425c 100644 --- a/extension/background/http.ts +++ b/extension/background/http.ts @@ -28,50 +28,51 @@ interface HttpResponse { } -function httpReq(method: string, - url: string|uri.URI, - options?: any): Promise<HttpResponse> { - let urlString: string; - if (url instanceof URI) { - urlString = url.href(); - } else if (typeof url === "string") { - urlString = url; - } - - return new Promise((resolve, reject) => { - let myRequest = new XMLHttpRequest(); - myRequest.open(method, urlString); - if (options && options.req) { - myRequest.send(options.req); - } else { - myRequest.send(); +class BrowserHttpLib { + req(method: string, + url: string|uri.URI, + options?: any): Promise<HttpResponse> { + let urlString: string; + if (url instanceof URI) { + urlString = url.href(); + } else if (typeof url === "string") { + urlString = url; } - myRequest.addEventListener("readystatechange", (e) => { - if (myRequest.readyState == XMLHttpRequest.DONE) { - let resp = { - status: myRequest.status, - responseText: myRequest.responseText - }; - resolve(resp); + + return new Promise((resolve, reject) => { + let myRequest = new XMLHttpRequest(); + myRequest.open(method, urlString); + if (options && options.req) { + myRequest.send(options.req); + } else { + myRequest.send(); } + myRequest.addEventListener("readystatechange", (e) => { + if (myRequest.readyState == XMLHttpRequest.DONE) { + let resp = { + status: myRequest.status, + responseText: myRequest.responseText + }; + resolve(resp); + } + }); }); - }); -} - + } -function httpGet(url: string|uri.URI) { - return httpReq("get", url); -} + get(url: string|uri.URI) { + return this.req("get", url); + } -function httpPostJson(url: string|uri.URI, body) { - return httpReq("post", url, {req: JSON.stringify(body)}); -} + postJson(url: string|uri.URI, body) { + return this.req("post", url, {req: JSON.stringify(body)}); + } -function httpPostForm(url: string|uri.URI, form) { - return httpReq("post", url, {req: form}); + postForm(url: string|uri.URI, form) { + return this.req("post", url, {req: form}); + } } |
