imported Request definitions from typescript-node-definitions

- as per https://github.com/borisyankov/DefinitelyTyped/issues/115
- added DT header (scraped creators from git history)
- added tests
- updated some fields
- restructured to be more accurate
This commit is contained in:
Bart van der Schoor
2014-04-23 00:58:42 +02:00
parent 09f3d7a8dc
commit ec18e20c24
3 changed files with 370 additions and 0 deletions

View File

@@ -238,6 +238,7 @@ All definitions files include a header with the author and editors, so at some p
* [Riot.js](https://github.com/moot/riotjs) (by [vvakame](https://github.com/vvakame))
* [Restify](https://github.com/mcavage/node-restify) (by [Bret Little](https://github.com/blittle))
* [Redis](https://github.com/mranney/node_redis) (by [Carlos Ballesteros Velasco](https://github.com/soywiz))
* [Request](https://github.com/mikeal/request) (by [Carlos Ballesteros Velasco](https://github.com/soywiz))
* [Royalslider](http://dimsemenov.com/plugins/royal-slider/) (by [Christiaan Rakowski](https://github.com/csrakowski))
* [Rx.js](http://rx.codeplex.com/) (by [gsino](http://www.codeplex.com/site/users/view/gsino), [Igor Oleinikov](https://github.com/Igorbek), [Carl de Billy](http://carl.debilly.net/), [zoetrope](https://github.com/zoetrope))
* [Raphael](http://raphaeljs.com/) (by [CheCoxshall](https://github.com/CheCoxshall))

198
request/request-tests.ts Normal file
View File

@@ -0,0 +1,198 @@
/// <reference path="request.d.ts" />
import request = require('request');
import http = require('http');
import stream = require('stream');
import formData = require('form-data');
var value: any;
var str: string;
var buffer: NodeBuffer;
var num: number;
var bool: boolean;
var date: Date;
var obj: Object;
var dest: string;
var uri: string;
var headers: {[key: string]: string};
var agent: http.Agent;
var write: stream.Writable;
var req: request.Request;
var form: formData.FormData;
var bodyArr: request.RequestPart[] = [{
body: value
}, {
body: value
}, {
body: value
}];
// --- --- --- --- --- --- --- --- --- --- --- ---
str = req.toJSON();
var cookieValue: request.CookieValue;
str = cookieValue.name;
value = cookieValue.value;
bool = cookieValue.httpOnly;
var cookie: request.Cookie;
str = cookie.str;
date = cookie.expires;
str = cookie.path;
str = cookie.toString();
var jar: request.CookieJar;
jar.add(cookie);
cookie = jar.get(req);
str = jar.cookieString(req);
var aws: request.AWSOptions;
str = aws.secret;
str = aws.bucket;
var oauth: request.OAuthOptions;
str = oauth.callback;
str = oauth.consumer_key;
str = oauth.consumer_secret;
str = oauth.token;
str = oauth.token_secret;
str = oauth.verifier;
var options: request.Options = {
url: str,
uri: str,
callback: (error: any, response: any, body: any) => {
},
jar: value,
form: value,
oauth: value,
aws: aws,
qs: obj,
json: value,
multipart: value,
agentOptions: value,
agentClass: value,
forever: value,
host: str,
port: num,
method: str,
headers: value,
body: value,
followRedirect: bool,
followAllRedirects: bool,
maxRedirects: num,
encoding: str,
pool: value,
timeout: num,
proxy: value,
strictSSL: bool
};
// --- --- --- --- --- --- --- --- --- --- --- ---
agent = req.getAgent();
//req.start();
//req.abort();
req.pipeDest(dest);
req = req.setHeader(str, str);
req = req.setHeader(str, str, bool);
req = req.setHeaders(headers);
req = req.qs(obj);
req = req.qs(obj, bool);
req = req.form(obj);
form = req.form();
req = req.multipart(bodyArr);
req = req.json(value);
req = req.aws(aws);
req = req.aws(aws, bool);
req = req.oauth(oauth);
req = req.jar(jar);
write = req.pipe(write);
write = req.pipe(write, value);
req.write();
req.end(str);
req.end(buffer);
req.pause();
req.resume();
req.abort();
req.destroy();
// --- --- --- --- --- --- --- --- --- --- --- ---
var callback: (error: any, response: any, body: any) => void;
value = request.initParams;
req = request(uri);
req = request(uri, options);
req = request(uri, options, callback);
req = request(uri, callback);
req = request(options);
req = request(options, callback);
req = request.request(uri);
req = request.request(uri, options);
req = request.request(uri, options, callback);
req = request.request(uri, callback);
req = request.request(options);
req = request.request(options, callback);
req = request.get(uri);
req = request.get(uri, options);
req = request.get(uri, options, callback);
req = request.get(uri, callback);
req = request.get(options);
req = request.get(options, callback);
req = request.post(uri);
req = request.post(uri, options);
req = request.post(uri, options, callback);
req = request.post(uri, callback);
req = request.post(options);
req = request.post(options, callback);
req = request.put(uri);
req = request.put(uri, options);
req = request.put(uri, options, callback);
req = request.put(uri, callback);
req = request.put(options);
req = request.put(options, callback);
req = request.head(uri);
req = request.head(uri, options);
req = request.head(uri, options, callback);
req = request.head(uri, callback);
req = request.head(options);
req = request.head(options, callback);
req = request.patch(uri);
req = request.patch(uri, options);
req = request.patch(uri, options, callback);
req = request.patch(uri, callback);
req = request.patch(options);
req = request.patch(options, callback);
req = request.del(uri);
req = request.del(uri, options);
req = request.del(uri, options, callback);
req = request.del(uri, callback);
req = request.del(options);
req = request.del(options, callback);
req = request.forever(value, value);
jar = request.jar();
cookie = request.cookie(str);
var r = request.defaults(options);
r(str);
r.get(str);
r.post(str);
r(options);
r.get(options);
r.post(options);

171
request/request.d.ts vendored Normal file
View File

@@ -0,0 +1,171 @@
// Type definitions for request
// Project: https://github.com/mikeal/request
// Definitions by: Carlos Ballesteros Velasco <https://github.com/soywiz>, bonnici <https://github.com/bonnici>, Bart van der Schoor <https://github.com/Bartvds>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
// Imported from: https://github.com/soywiz/typescript-node-definitions/d.ts
/// <reference path="../node/node.d.ts" />
/// <reference path="../form-data/form-data.d.ts" />
declare module 'request' {
import stream = require('stream');
import http = require('http');
import FormData = require('form-data');
export = RequestAPI;
function RequestAPI(uri: string, options?: RequestAPI.Options, callback?: (error: any, response: any, body: any) => void): RequestAPI.Request;
function RequestAPI(uri: string, callback?: (error: any, response: any, body: any) => void): RequestAPI.Request;
function RequestAPI(options: RequestAPI.Options, callback?: (error: any, response: any, body: any) => void): RequestAPI.Request;
module RequestAPI {
export function defaults(options: Options): typeof RequestAPI;
export function request(uri: string, options?: Options, callback?: (error: any, response: any, body: any) => void): Request;
export function request(uri: string, callback?: (error: any, response: any, body: any) => void): Request;
export function request(options?: Options, callback?: (error: any, response: any, body: any) => void): Request;
export function get(uri: string, options?: Options, callback?: (error: any, response: any, body: any) => void): Request;
export function get(uri: string, callback?: (error: any, response: any, body: any) => void): Request;
export function get(options: Options, callback?: (error: any, response: any, body: any) => void): Request;
export function post(uri: string, options?: Options, callback?: (error: any, response: any, body: any) => void): Request;
export function post(uri: string, callback?: (error: any, response: any, body: any) => void): Request;
export function post(options: Options, callback?: (error: any, response: any, body: any) => void): Request;
export function put(uri: string, options?: Options, callback?: (error: any, response: any, body: any) => void): Request;
export function put(uri: string, callback?: (error: any, response: any, body: any) => void): Request;
export function put(options: Options, callback?: (error: any, response: any, body: any) => void): Request;
export function head(uri: string, options?: Options, callback?: (error: any, response: any, body: any) => void): Request;
export function head(uri: string, callback?: (error: any, response: any, body: any) => void): Request;
export function head(options: Options, callback?: (error: any, response: any, body: any) => void): Request;
export function patch(uri: string, options?: Options, callback?: (error: any, response: any, body: any) => void): Request;
export function patch(uri: string, callback?: (error: any, response: any, body: any) => void): Request;
export function patch(options: Options, callback?: (error: any, response: any, body: any) => void): Request;
export function del(uri: string, options?: Options, callback?: (error: any, response: any, body: any) => void): Request;
export function del(uri: string, callback?: (error: any, response: any, body: any) => void): Request;
export function del(options: Options, callback?: (error: any, response: any, body: any) => void): Request;
export function forever(agentOptions: any, optionsArg: any): Request;
export function jar(): CookieJar;
export function cookie(str: string): Cookie;
export var initParams: any;
export interface Options {
url?: string;
uri?: string;
callback?: (error: any, response: any, body: any) => void;
jar?: any; // CookieJar
form?: FormData;
oauth?: OAuthOptions;
aws?: AWSOptions;
hawk ?: HawkOptions;
qs?: Object;
json?: any;
multipart?: RequestPart[];
agentOptions?: any;
agentClass?: any;
forever?: any;
host?: string;
port?: number;
method?: string;
headers?: Headers;
body?: any;
followRedirect?: boolean;
followAllRedirects?: boolean;
maxRedirects?: number;
encoding?: string;
pool?: any;
timeout?: number;
proxy?: any;
strictSSL?: boolean;
}
export interface RequestPart {
headers?: Headers;
body: any;
}
export interface Request {
getAgent(): http.Agent;
//start(): void;
//abort(): void;
pipeDest(dest: any): void;
setHeader(name: string, value: string, clobber?: boolean): Request;
setHeaders(headers: Headers): Request;
qs(q: Object, clobber?: boolean): Request;
form(): FormData.FormData;
form(form: any): Request;
multipart(multipart: RequestPart[]): Request;
json(val: any): Request;
aws(opts: AWSOptions, now?: boolean): Request;
oauth(oauth: OAuthOptions): Request;
jar(jar: CookieJar): Request;
pipe(dest: stream.Writable, opts?: any): stream.Writable;
write(): void;
end(chunk: string): void;
end(chunk: NodeBuffer): void;
pause(): void;
resume(): void;
abort(): void;
destroy(): void;
toJSON(): string;
}
export interface Headers {
[key: string]: any;
}
export interface AuthOptions {
user?: string;
username?: string;
pass?: string;
password?: string;
sendImmediately?: boolean;
}
export interface OAuthOptions {
callback?: string;
consumer_key?: string;
consumer_secret?: string;
token?: string;
token_secret?: string;
verifier?: string;
}
export interface HawkOptions {
credentials: any;
}
export interface AWSOptions {
secret: string;
bucket?: string;
}
export interface CookieJar {
add(cookie: Cookie): void;
get(req: Request): Cookie;
cookieString(req: Request): string;
}
export interface CookieValue {
name: string;
value: any;
httpOnly: boolean;
}
export interface Cookie extends Array<CookieValue> {
constructor(name: string, req: Request): void;
str: string;
expires: Date;
path: string;
toString(): string;
}
}
}