This repository has been archived by the owner on Apr 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
145 lines (131 loc) · 3.91 KB
/
index.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
* Typings for devrant-lite
*
* @version 1.0
* @author Skayo (https://skayo.dev)
*
* @example
* const DevRant = require('devrant-lite')
*
* const client = DevRant.withAuthToken({
* key: '123abcdefghijklmnopqrstuvxyz',
* id: 12345678,
* user_id: 12345
* });
*
* @example
* // Enable esModuleInterop in your tsconfig to import typings
* import DevRant, { DevRantOptions } from 'devrant-lite'
*
* const config: DevRantOptions = {
* token: {
* key: '123abcdefghijklmnopqrstuvxyz',
* id: 12345678,
* user_id: 12345
* }
* };
*
* const client = new DevRant(config);
*/
/// <reference types="node" />
export default class DevRant {
private _token: AuthToken;
private _baseUrl: string;
private _app: string;
private _plat: string;
/**
* Helper function to create a DevRant instance and login with user credentials
*
* @param {string} username Account name or email
* @param {string} password Account password
* @param {{baseUrl: string, app: number, plat: number}} options Options passed to the DevRant constructor
* @return DevRant A new DevRant instance
*/
static withCredentials(username: string, password: string, options: DevRantOptions): Promise<DevRant>;
/**
* Helper function to create DevRant instance and set an auth token
*
* @param {{id: number, key: string, user_id: number}} authToken Auth token
* @param {{baseUrl: string, app: number, plat: number}} options Options passed to the DevRant constructor
* @return DevRant A new DevRant instance
*/
static withAuthToken(authToken: AuthToken, options: DevRantOptions): Promise<DevRant>;
/**
* Constructor
* @param {{baseUrl: string, app: number, plat: number}} options
*/
constructor(options: DevRantOptions);
/**
* Parse the JSON from a Response object and add a hidden `headers` property
*/
private static _handleResponse(response: Response): Promise<object>;
/**
* Construct the options and url for an authenticated HTTP request to the devRant API
* @param {'GET'|'POST'|'DELETE'} method Request method
* @param {string} resource The API endpoint
* @param {object} parameters Request parameters
* @param {Object} headers Additional headers added to base headers
*/
private _makeRequest(
method: 'GET' | 'POST' | 'DELETE',
resource: string,
parameters: object,
headers: object,
): {
url: string,
options: {
headers: object,
method: string,
body: string | undefined
}
};
/**
* Send a GET request
*
* @param {string} resource The endpoint (e.g. `devrant/rants/1234`)
* @param {object} parameters Optional GET parameters.
* @returns {Promise<object>} Promise resolving to the response from the devRant API.
* The hidden `headers` property will be set to the Response headers
*/
public get<T = any>(resource: string, parameters?: object): Promise<T>;
/**
* Send a POST request
*
* @param {string} resource The endpoint (e.g. `devrant/rants`)
* @param {object} body Optional POST parameters.
* @returns {Promise<object>} Promise resolving to the response from the devRant API.
* The hidden `headers` property will be set to the Response headers
*/
public post<T = any>(resource: string, body?: object): Promise<T>;
/**
* Send a DELETE request
*
* @param {string} resource The endpoint (e.g. `devrant/rants/1234`)
* @param {object} parameters Optional DELETE parameters. (Will be appended to the URL)
* @returns {Promise<object>} Promise resolving to the response from the devRant API.
* The hidden `headers` property will be set to the Response headers
*/
public delete<T = any>(resource: string, parameters?: object): Promise<T>;
}
interface DevRantOptions {
/**
* API Base URL (useful for proxying and testing)
* @default https://devrant.com/api
*/
baseUrl: string,
/**
* App ID
* @default 3
*/
app: number,
/**
* Platform ID
* @default 3
*/
plat: number
}
interface AuthToken {
id: number;
key: string;
user_id: number
}