Skip to content

Commit 2106135

Browse files
Private API support and documentation
1 parent 4f9818f commit 2106135

6 files changed

Lines changed: 307 additions & 15 deletions

File tree

README.md

Lines changed: 106 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ When every millisecond counts.
123123

124124
`clientside`
125125

126-
_coming soon..._
126+
Suitable for clientside only frameworks such as React.
127127

128128

129129
Gatekeeper Overrides
@@ -230,15 +230,116 @@ You can override the class inferred performance metrics and provide your own if
230230
| statusCode | integer | 200 | 2xx-5xx | Status code that associated with the request. |
231231

232232

233+
# PrivateClient
234+
235+
`PrivateClient` is a class extending `Client` which serves as the main entry point for interacting with private CrowdHandler API methods. It requires a private API key for instantiation which can be found in the CrowdHandler control panel.
236+
237+
## Instantiate a Private API Client
238+
239+
const private_clent = new crowdhandler.PrivateClient (your_private_key, options)
240+
241+
**your_public_key**: string
242+
243+
**options** : object (optional)
244+
245+
| Option | Type | Default | Values | Explanation |
246+
| ------ | ---- | ------- | ------ | ----------- |
247+
| api_url | string | https://api.crowdhandler.com | * | API endpoint. |
248+
| debug | string | false | false/true | Outputs debugging information. |
249+
| timeout | integer | 5000 | 1 - 30000 | Outbound API communication timeout in milliseconds. |
250+
251+
252+
## Methods
253+
254+
All methods return a new `Resource` instance for interacting with a specific endpoint of the API.
255+
256+
**Note1**: Full API documentation containing response examples, required parameter fields and more can be found in your control panel. Navigate to **account** -> **api**.
257+
258+
**Note2**: In all the methods below, the `ID_PLACEHOLDER` is a placeholder for the actual id required by the specific API endpoint. It should be replaced by the actual id before making the API call.
259+
260+
### account()
261+
262+
This method returns a `Resource` instance for interacting with the `/v1/account/` endpoint.
263+
264+
### accountPlan()
265+
266+
This method returns a `Resource` instance for interacting with the `/v1/account/plan` endpoint.
267+
268+
### codes()
269+
270+
This method returns a `Resource` instance for interacting with the `/v1/codes/ID_PLACEHOLDER` endpoint.
271+
272+
### domains()
273+
274+
This method returns a `Resource` instance for interacting with the `/v1/domains/ID_PLACEHOLDER` endpoint.
275+
276+
### domainsIPs()
277+
278+
This method returns a `Resource` instance for interacting with the `/v1/domains/ID_PLACEHOLDER/ips` endpoint.
279+
280+
### domainsReports()
281+
282+
This method returns a `Resource` instance for interacting with the `/v1/domains/ID_PLACEHOLDER/reports` endpoint.
283+
284+
### domainsRequests()
285+
286+
This method returns a `Resource` instance for interacting with the `/v1/domains/ID_PLACEHOLDER/requests` endpoint.
287+
288+
### domainsRooms()
289+
290+
This method returns a `Resource` instance for interacting with the `/v1/domains/ID_PLACEHOLDER/rooms` endpoint.
291+
292+
### domainsURLs()
293+
294+
This method returns a `Resource` instance for interacting with the `/v1/domains/ID_PLACEHOLDER/urls` endpoint.
295+
296+
### groups()
297+
298+
This method returns a `Resource` instance for interacting with the `/v1/groups/ID_PLACEHOLDER` endpoint.
299+
300+
### groupsBatch()
301+
302+
This method returns a `Resource` instance for interacting with the `/v1/groups/ID_PLACEHOLDER/batch` endpoint.
303+
304+
### groupsCodes()
305+
306+
This method returns a `Resource` instance for interacting with the `/v1/groups/ID_PLACEHOLDER/codes` endpoint.
307+
308+
### ips()
309+
310+
This method returns a `Resource` instance for interacting with the `/v1/ips/ID_PLACEHOLDER` endpoint.
311+
312+
### reports()
313+
314+
This method returns a `Resource` instance for interacting with the `/v1/reports/ID_PLACEHOLDER` endpoint.
315+
316+
### rooms()
317+
318+
This method returns a `Resource` instance for interacting with the `/v1/rooms/ID_PLACEHOLDER` endpoint.
319+
320+
### roomsReports()
321+
322+
This method returns a `Resource` instance for interacting with the `/v1/rooms/ID_PLACEHOLDER/reports` endpoint.
323+
324+
### roomsSessions()
325+
326+
This method returns a `Resource` instance for interacting with the `/v1/rooms/ID_PLACEHOLDER/sessions` endpoint.
327+
328+
### sessions()
329+
330+
This method returns a `Resource` instance for interacting with the `/v1/sessions/ID_PLACEHOLDER` endpoint.
331+
332+
### templates()
333+
334+
This method returns a `Resource` instance for interacting with the `/v1/templates/ID_PLACEHOLDER` endpoint.
335+
233336
Putting it all together
234337
----------------------------
235338

236-
See the examples directory...
339+
See examples:
237340

238-
Instantiate a Private API Client
239-
--------------------------------
341+
<https://github.com/Crowdhandler/crowdhandler-javascript-sdk/tree/main/examples>
240342

241-
_coming soon..._
242343

243344
More information
244345
----------------

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "crowdhandler-sdk",
3-
"version": "1.1.1-beta.1",
3+
"version": "1.2.2-beta.1",
44
"description": "",
55
"homepage": "https://github.com/Crowdhandler/crowdhandler-javascript-sdk#readme",
66
"repository": {

src/client/private_client.ts

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
import { Client } from "./client";
2+
import { Resource } from "./resource";
3+
4+
export class PrivateClient extends Client {
5+
constructor(
6+
key: string,
7+
options: { timeout?: number; debug?: boolean; api_url?: string } = {}
8+
) {
9+
const {
10+
timeout = 5000,
11+
debug = false,
12+
api_url = "https://api.crowdhandler.com",
13+
} = options ?? {};
14+
super(api_url, key, options);
15+
}
16+
17+
account() {
18+
return new Resource(this.key, "/v1/account/", {
19+
timeout: this.timeout,
20+
debug: this.debug,
21+
api_url: this.api_url,
22+
});
23+
}
24+
25+
accountPlan() {
26+
return new Resource(this.key, "/v1/account/plan", {
27+
timeout: this.timeout,
28+
debug: this.debug,
29+
api_url: this.api_url,
30+
});
31+
}
32+
33+
codes() {
34+
return new Resource(this.key, "/v1/codes/ID_PLACEHOLDER", {
35+
timeout: this.timeout,
36+
debug: this.debug,
37+
api_url: this.api_url,
38+
});
39+
}
40+
41+
domains() {
42+
return new Resource(this.key, "/v1/domains/ID_PLACEHOLDER", {
43+
timeout: this.timeout,
44+
debug: this.debug,
45+
api_url: this.api_url,
46+
});
47+
}
48+
49+
domainsIPs() {
50+
return new Resource(this.key, "/v1/domains/ID_PLACEHOLDER/ips", {
51+
timeout: this.timeout,
52+
debug: this.debug,
53+
api_url: this.api_url,
54+
});
55+
}
56+
57+
domainsReports() {
58+
return new Resource(this.key, "/v1/domains/ID_PLACEHOLDER/reports", {
59+
timeout: this.timeout,
60+
debug: this.debug,
61+
api_url: this.api_url,
62+
});
63+
}
64+
65+
domainsRequests() {
66+
return new Resource(this.key, "/v1/domains/ID_PLACEHOLDER/requests", {
67+
timeout: this.timeout,
68+
debug: this.debug,
69+
api_url: this.api_url,
70+
});
71+
}
72+
73+
domainsRooms() {
74+
return new Resource(this.key, "/v1/domains/ID_PLACEHOLDER/rooms", {
75+
timeout: this.timeout,
76+
debug: this.debug,
77+
api_url: this.api_url,
78+
});
79+
}
80+
81+
domainsURLs() {
82+
return new Resource(this.key, "/v1/domains/ID_PLACEHOLDER/urls", {
83+
timeout: this.timeout,
84+
debug: this.debug,
85+
api_url: this.api_url,
86+
});
87+
}
88+
89+
groups() {
90+
return new Resource(this.key, "/v1/groups/ID_PLACEHOLDER", {
91+
timeout: this.timeout,
92+
debug: this.debug,
93+
api_url: this.api_url,
94+
});
95+
}
96+
97+
groupsBatch() {
98+
return new Resource(this.key, "/v1/groups/ID_PLACEHOLDER/batch", {
99+
timeout: this.timeout,
100+
debug: this.debug,
101+
api_url: this.api_url,
102+
});
103+
}
104+
105+
groupsCodes() {
106+
return new Resource(this.key, "/v1/groups/ID_PLACEHOLDER/codes", {
107+
timeout: this.timeout,
108+
debug: this.debug,
109+
api_url: this.api_url,
110+
});
111+
}
112+
113+
ips() {
114+
return new Resource(this.key, "/v1/ips/ID_PLACEHOLDER", {
115+
timeout: this.timeout,
116+
debug: this.debug,
117+
api_url: this.api_url,
118+
});
119+
}
120+
121+
reports() {
122+
return new Resource(this.key, "/v1/reports/ID_PLACEHOLDER", {
123+
timeout: this.timeout,
124+
debug: this.debug,
125+
api_url: this.api_url,
126+
});
127+
}
128+
129+
rooms() {
130+
return new Resource(this.key, "/v1/rooms/ID_PLACEHOLDER", {
131+
timeout: this.timeout,
132+
debug: this.debug,
133+
api_url: this.api_url,
134+
});
135+
}
136+
137+
roomsReports() {
138+
return new Resource(this.key, "/v1/rooms/ID_PLACEHOLDER/reports", {
139+
timeout: this.timeout,
140+
debug: this.debug,
141+
api_url: this.api_url,
142+
});
143+
}
144+
145+
roomsSessions() {
146+
return new Resource(this.key, "/v1/rooms/ID_PLACEHOLDER/sessions", {
147+
timeout: this.timeout,
148+
debug: this.debug,
149+
api_url: this.api_url,
150+
});
151+
}
152+
153+
sessions() {
154+
return new Resource(this.key, "/v1/sessions/ID_PLACEHOLDER", {
155+
timeout: this.timeout,
156+
debug: this.debug,
157+
api_url: this.api_url,
158+
});
159+
}
160+
161+
templates() {
162+
return new Resource(this.key, "/v1/templates/ID_PLACEHOLDER", {
163+
timeout: this.timeout,
164+
debug: this.debug,
165+
api_url: this.api_url,
166+
});
167+
}
168+
}

src/client/public_client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ export class PublicClient extends Client {
1212
}
1313

1414
requests() {
15-
return new Resource(this.key, "/v1/requests/", { timeout: this.timeout, debug: this.debug, api_url: this.api_url });
15+
return new Resource(this.key, "/v1/requests/ID_PLACEHOLDER", { timeout: this.timeout, debug: this.debug, api_url: this.api_url });
1616
}
1717

1818
responses() {
19-
return new Resource(this.key, "/v1/responses/", { timeout: this.timeout, debug: this.debug, api_url: this.api_url });
19+
return new Resource(this.key, "/v1/responses/ID_PLACEHOLDER", { timeout: this.timeout, debug: this.debug, api_url: this.api_url });
2020
}
2121

2222
rooms() {

src/client/resource.ts

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,51 @@ export class Resource extends Client {
77
path: string,
88
options: { timeout?: number; debug?: boolean; api_url?: string } = {}
99
) {
10-
const { timeout = 5000, debug = false, api_url = "https://api.crowdhandler.com" } =
11-
options ?? {};
10+
const {
11+
timeout = 5000,
12+
debug = false,
13+
api_url = "https://api.crowdhandler.com",
14+
} = options ?? {};
1215
super(api_url, key, options);
1316
this.path = path;
1417
}
1518

19+
private formatPath(path: string, id: string) {
20+
// If id is not provided, replace it with an empty string.
21+
id = id || "";
22+
23+
//this.path may contain a placeholder for the id. replace it with the actual id.
24+
path = path.replace("ID_PLACEHOLDER", id);
25+
26+
return path;
27+
}
28+
1629
delete(id: string, body: object) {
17-
return super.httpDELETE(this.path + id, body);
30+
this.path = this.formatPath(this.path, id);
31+
32+
return super.httpDELETE(this.path, body);
1833
}
1934

2035
get(id?: string, params?: object) {
21-
if (id === undefined) {
36+
//Handle id being an optional parameter
37+
if (!id) {
2238
id = "";
2339
}
2440

25-
return super.httpGET(this.path + id, params);
41+
this.path = this.formatPath(this.path, id);
42+
43+
return super.httpGET(this.path, params);
2644
}
2745

2846
post(body: object) {
47+
this.path = this.formatPath(this.path, "");
48+
2949
return super.httpPOST(this.path, body);
3050
}
3151

3252
put(id: string, body: object) {
33-
return super.httpPUT(this.path + id, body);
53+
this.path = this.formatPath(this.path, id);
54+
55+
return super.httpPUT(this.path, body);
3456
}
35-
}
57+
}

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export { Gatekeeper } from './gatekeeper/gatekeeper';
2+
export { PrivateClient } from './client/private_client';
23
export { PublicClient } from './client/public_client';
34
export { RequestContext } from './request/requestContext';

0 commit comments

Comments
 (0)