ensembledata 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +135 -0
- package/package.json +28 -0
- package/src/client.js +1010 -0
- package/src/index.js +1 -0
- package/src/requester.js +85 -0
- package/src/utils.js +36 -0
- package/types/client.d.ts +612 -0
- package/types/client.d.ts.map +1 -0
- package/types/index.d.ts +2 -0
- package/types/index.d.ts.map +1 -0
- package/types/requester.d.ts +35 -0
- package/types/requester.d.ts.map +1 -0
- package/types/utils.d.ts +11 -0
- package/types/utils.d.ts.map +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# EnsembleData NodeJS API
|
|
2
|
+
|
|
3
|
+
## Documentation
|
|
4
|
+
|
|
5
|
+
Check out the [API docs](https://ensembledata.com/apis/docs) to see which endpoints are available for each social media and for detailed descriptions of their parameters and functionality.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Install the package with npm, pnpm or yarn.
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install ensembledata
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
yarn add ensembledata
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pnpm add ensembledata
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Requirements
|
|
24
|
+
|
|
25
|
+
- The package requires Node 18 or above.
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
[Register](https://dashboard.ensembledata.com/register) to get your free API token.
|
|
30
|
+
|
|
31
|
+
```javascript
|
|
32
|
+
import { EDClient } from "ensembledata";
|
|
33
|
+
|
|
34
|
+
const client = EDClient({ token: "API-TOKEN" });
|
|
35
|
+
const result = await client.tiktok.userInfoFromUsername({
|
|
36
|
+
username: "daviddobrik",
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
console.log("Data: ", result.data);
|
|
40
|
+
console.log("Units charged:", result.unitsCharged);
|
|
41
|
+
|
|
42
|
+
// Other Examples:
|
|
43
|
+
// const result = await client.instagram.userInfo({ username: "daviddobrik" })
|
|
44
|
+
// const result = await client.youtube.channel_subscribers({ channelId: "UCnQghMm3Z164JFhScQYFTBw" })
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
<br>
|
|
48
|
+
<br>
|
|
49
|
+
|
|
50
|
+
### Missing Endpoints / Parameters
|
|
51
|
+
|
|
52
|
+
If you find that one of the endpoints from our [API docs](https://ensembledata.com/apis/docs) is not yet available in this package, you can use the `EDClient.request` method to specify the endpoint manually in the meantime.
|
|
53
|
+
|
|
54
|
+
```javascript
|
|
55
|
+
import { EDClient } from "ensembledata";
|
|
56
|
+
|
|
57
|
+
const client = EDClient({ token: "API-TOKEN" });
|
|
58
|
+
const result = await client.request("/instagram/example", {
|
|
59
|
+
foo: "...",
|
|
60
|
+
bar: "...",
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
If you find that one the parameters to an existing endpoint is missing, you can still send this parameter via the `extraParams` object which is available on all endpoint methods as the second parameter. See the example below:
|
|
65
|
+
|
|
66
|
+
```javascript
|
|
67
|
+
import { EDClient } from "ensembledata";
|
|
68
|
+
|
|
69
|
+
const client = EDClient({ token: "API-TOKEN" });
|
|
70
|
+
const result = await client.instagram.userInfo(
|
|
71
|
+
{ username: "..." },
|
|
72
|
+
{ baz: "..." },
|
|
73
|
+
);
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
<br>
|
|
77
|
+
<br>
|
|
78
|
+
|
|
79
|
+
### Handling Errors
|
|
80
|
+
|
|
81
|
+
In the [API docs](https://ensembledata.com/apis/docs), each endpoint lists a handful of possible errors the API may respond with. You can handle these errors by catching the `EDError` exception.
|
|
82
|
+
|
|
83
|
+
```javascript
|
|
84
|
+
import { EDClient } from "ensembledata";
|
|
85
|
+
|
|
86
|
+
const client = EDClient({ token: "API-TOKEN" });
|
|
87
|
+
try {
|
|
88
|
+
const result = await client.tiktok.userInfoFromUsername({
|
|
89
|
+
username: "daviddobrik",
|
|
90
|
+
});
|
|
91
|
+
} catch (error) {
|
|
92
|
+
switch (error.status_code) {
|
|
93
|
+
// Rate limit exceeded...
|
|
94
|
+
case 429:
|
|
95
|
+
console.log(error.detail);
|
|
96
|
+
break;
|
|
97
|
+
|
|
98
|
+
// Subscription expired...
|
|
99
|
+
case 493:
|
|
100
|
+
console.log(error.detail);
|
|
101
|
+
break;
|
|
102
|
+
|
|
103
|
+
// Some other error occurred, unrelated to the EnsembleData API
|
|
104
|
+
default:
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
<br>
|
|
111
|
+
<br>
|
|
112
|
+
|
|
113
|
+
### Using Promises
|
|
114
|
+
|
|
115
|
+
Every endpoint method returns a promise. You can use the `.then()` and `.catch()` methods to handle the result and errors respectively.
|
|
116
|
+
|
|
117
|
+
```javascript
|
|
118
|
+
import { EDClient } from "ensembledata";
|
|
119
|
+
|
|
120
|
+
const client = EDClient({ token: "API-TOKEN" });
|
|
121
|
+
client.tiktok
|
|
122
|
+
.userInfoFromUsername({ username: "daviddobrik" })
|
|
123
|
+
.then((result) => {
|
|
124
|
+
console.log("Data: ", result.data);
|
|
125
|
+
console.log("Units charged:", result.unitsCharged);
|
|
126
|
+
})
|
|
127
|
+
.catch((error) => {
|
|
128
|
+
console.log("Error: ", error);
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Types
|
|
133
|
+
|
|
134
|
+
This package provides TypeScript types for all the endpoints and their parameters. You can use these types to get autocompletion and type checking in your IDE.
|
|
135
|
+
Internally the package uses JSDoc comments to provide these types. If you experience any typing problems, please let us know by creating an issue.
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ensembledata",
|
|
3
|
+
"description": "Node.js bindings for the EnsembleData API",
|
|
4
|
+
"author": "EnsembleData <hello@ensembledata.com>",
|
|
5
|
+
"contributors": [
|
|
6
|
+
"Fayd Speare <fayd@ensembledata.com>"
|
|
7
|
+
],
|
|
8
|
+
"homepage": "https://ensembledata.com",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git://github.com/ensembledata/ensembledata-node.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": "https://github.com/ensembledata/ensembledata-node/issues",
|
|
14
|
+
"scripts": {},
|
|
15
|
+
"version": "0.0.3",
|
|
16
|
+
"type": "module",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"main": "src/index.js",
|
|
19
|
+
"types": "types/index.d.ts",
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@eslint/js": "^9.8.0",
|
|
22
|
+
"eslint-config-prettier": "^9.1.0",
|
|
23
|
+
"nunjucks": "^3.2.4",
|
|
24
|
+
"prettier": "3.3.3",
|
|
25
|
+
"prettier-plugin-jsdoc": "^1.3.0",
|
|
26
|
+
"typescript": "^5.5.4"
|
|
27
|
+
}
|
|
28
|
+
}
|