forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
easy-api-request.d.ts
115 lines (99 loc) · 4.18 KB
/
easy-api-request.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Type definitions for easy-api-request
// Project: https://github.com/DeadAlready/easy-api-request
// Definitions by: Karl Düüna <https://github.com/DeadAlready/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../q/Q.d.ts" />
/// <reference path="../node/node.d.ts" />
/// <reference path="../request/request.d.ts" />
/// <reference path="../bunyan/bunyan.d.ts" />
/// <reference path="../express/express.d.ts" />
declare module "easy-api-request" {
import stream = require('stream');
import http = require('http');
import request = require('request');
import bunyan = require('bunyan');
import express = require('express');
export function create(opts: {
name: any;
config: {
url: string;
internal?: boolean;
headers?: string[];
cookies?: string[];
replyCookies?: string[];
jSend?: boolean;
opts?: Object;
};
}): void;
import Q = require('q');
interface Result {
response: http.IncomingMessage;
body: any;
err?: any;
data?: any;
}
class BaseRequest {
protected base: request.Request;
protected req: express.Request;
protected log: bunyan.Logger;
protected replyCookies: string[];
protected jSend: boolean;
constructor(opts: any);
_parseOptions(args: IArguments, type: string): {
opts: any;
cb: any;
};
_do(args: IArguments, type?: string): any;
_request(opts?: any, cb?:any): any;
get(url?: any, opts?: any, cb?: any): any;
post(url?: any, opts?: any, cb?: any): any;
patch(url?: any, opts?: any, cb?: any): any;
del(url?: any, opts?: any, cb?: any): any;
}
class StreamRequest extends BaseRequest {
_request(opts: Object): stream.Stream;
get(url: string, params: Object): stream.Stream;
get(opts: Object): stream.Stream;
get(url: string): stream.Stream;
post(url: string, params: Object): stream.Stream;
post(opts: Object): stream.Stream;
post(url: string): stream.Stream;
patch(url: string, params: Object): stream.Stream;
patch(opts: Object): stream.Stream;
patch(url: string): stream.Stream;
del(url: string, params: Object): stream.Stream;
del(opts: Object): stream.Stream;
del(url: string): stream.Stream;
}
class CBPromiseRequest extends BaseRequest {
_request(opts: Object): stream.Stream;
get(url: string, params: Object, cb:(err?:any, resp?: Result) => void): void;
get(url: string, cb:(err?:any, resp?: Result) => void): void;
get(opts: Object, cb:(err?:any, resp?: Result) => void): void;
get(url: string, params: Object): Q.Promise<Result>;
get(opts: Object): Q.Promise<Result>;
get(url: string): Q.Promise<Result>;
post(url: string, params: Object, cb:(err?:any, resp?: Result) => void): void;
post(url: string, cb:(err?:any, resp?: Result) => void): void;
post(opts: Object, cb:(err?:any, resp?: Result) => void): void;
post(url: string, params: Object): Q.Promise<Result>;
post(opts: Object): Q.Promise<Result>;
post(url: string): Q.Promise<Result>;
patch(url: string, params: Object, cb:(err?:any, resp?: Result) => void): void;
patch(url: string, cb:(err?:any, resp?: Result) => void): void;
patch(opts: Object, cb:(err?:any, resp?: Result) => void): void;
patch(url: string, params: Object): Q.Promise<Result>;
patch(opts: Object): Q.Promise<Result>;
patch(url: string): Q.Promise<Result>;
del(url: string, params: Object, cb:(err?:any, resp?: Result) => void): void;
del(url: string, cb:(err?:any, resp?: Result) => void): void;
del(opts: Object, cb:(err?:any, resp?: Result) => void): void;
del(url: string, params: Object): Q.Promise<Result>;
del(opts: Object): Q.Promise<Result>;
del(url: string): Q.Promise<Result>;
}
export interface RequestMaker {
(): CBPromiseRequest;
(stream: boolean): StreamRequest | CBPromiseRequest;
}
}