mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Modified the http module to remove the cyclic references. Added promises.d.ts.
This commit is contained in:
47
http/http.impl.ts
Normal file
47
http/http.impl.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import image = require("image-source");
|
||||
import promises = require("promises");
|
||||
import request = require("http/http-request");
|
||||
|
||||
// merge the exports of the request file with the exports of this file
|
||||
declare var exports;
|
||||
require("utils/module-merge").merge(request, exports);
|
||||
|
||||
/**
|
||||
* Gets string from url.
|
||||
*/
|
||||
export function getString(arg: any): promises.Promise<string> {
|
||||
var d = promises.defer<string>();
|
||||
|
||||
request.request(typeof arg === "string" ? { url: arg, method: "GET" } : arg)
|
||||
.then(r => d.resolve(r.content.toString()))
|
||||
.fail(e => d.reject(e));
|
||||
|
||||
return d.promise();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets JSON from url.
|
||||
*/
|
||||
export function getJSON<T>(arg: any): promises.Promise<T> {
|
||||
var d = promises.defer<T>();
|
||||
|
||||
request.request(typeof arg === "string" ? { url: arg, method: "GET" } : arg)
|
||||
.then(r => d.resolve(r.content.toJSON()))
|
||||
.fail(e => d.reject(e));
|
||||
|
||||
return d.promise();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets image from url.
|
||||
*/
|
||||
|
||||
export function getImage(arg: any): promises.Promise<image.ImageSource> {
|
||||
var d = promises.defer<image.ImageSource>();
|
||||
|
||||
request.request(typeof arg === "string" ? { url: arg, method: "GET" } : arg)
|
||||
.then(r => d.resolve(r.content.toImage()))
|
||||
.fail(e => d.reject(e));
|
||||
|
||||
return d.promise();
|
||||
}
|
||||
Reference in New Issue
Block a user