diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 9f4f84f19c..4e7cb6074f 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -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)) diff --git a/request/request-tests.ts b/request/request-tests.ts new file mode 100644 index 0000000000..d422c3abc5 --- /dev/null +++ b/request/request-tests.ts @@ -0,0 +1,198 @@ +/// + +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); diff --git a/request/request.d.ts b/request/request.d.ts new file mode 100644 index 0000000000..e6a1d100e9 --- /dev/null +++ b/request/request.d.ts @@ -0,0 +1,171 @@ +// Type definitions for request +// Project: https://github.com/mikeal/request +// Definitions by: Carlos Ballesteros Velasco , bonnici , Bart van der Schoor +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +// Imported from: https://github.com/soywiz/typescript-node-definitions/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 { + constructor(name: string, req: Request): void; + str: string; + expires: Date; + path: string; + toString(): string; + } + } +}