Skip to content

Commit 24cde1d

Browse files
committed
Update Javascript samples w/ XDK
1 parent f812d83 commit 24cde1d

File tree

118 files changed

+3866
-6195
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+3866
-6195
lines changed

javascript/bookmarks/bookmarks-lookup-js-sdk.js

Lines changed: 0 additions & 92 deletions
This file was deleted.

javascript/bookmarks/create-bookmark-js-sdk.js

Lines changed: 0 additions & 93 deletions
This file was deleted.

javascript/bookmarks/delete-bookmark-js-sdk.js

Lines changed: 0 additions & 91 deletions
This file was deleted.

javascript/compliance/create_compliance_job.js renamed to javascript/compliance/create_jobs.js

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,23 @@
1-
const needle = require('needle');
1+
const { Client } = require('@xdevplatform/xdk');
22

33
// The code below sets the bearer token from your environment variables
44
// To set environment variables on macOS or Linux, run the export command below from the terminal:
55
// export BEARER_TOKEN='YOUR-TOKEN'
66
const token = process.env.BEARER_TOKEN;
7-
8-
const endpointUrl = 'https://api.x.com/2/compliance/jobs'
7+
const client = new Client({ bearerToken: token });
98

109
// For User Compliance Job, replace type value with users instead of tweets
1110
// Also replace the name value with your desired job name
1211
const data = {
13-
"type": "tweets",
14-
"name": 'my_batch_compliance_job'
15-
}
16-
17-
async function makeRequest() {
18-
19-
const res = await needle.post(endpointUrl, {
20-
json: data,
21-
headers: {
22-
"User-Agent": "v2BatchComplianceJS",
23-
"authorization": `Bearer ${token}`
24-
}
25-
})
26-
27-
if (res.body) {
28-
return res.body;
29-
} else {
30-
throw new Error('Unsuccessful request');
31-
}
32-
}
12+
type: "tweets",
13+
name: 'my_batch_compliance_job'
14+
};
3315

3416
(async () => {
3517
try {
3618
// Make request
37-
const response = await makeRequest();
19+
const response = await client.compliance.createJobs(data);
20+
3821
console.dir(response, {
3922
depth: null
4023
});

javascript/compliance/download_compliance_results.js renamed to javascript/compliance/download_results.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
const needle = require('needle');
2-
31
// Replace with your job download_url
42
downloadUrl = ''
53

64
async function getRequest() {
5+
const res = await fetch(downloadUrl, {
6+
headers: {
7+
'Accept-Encoding': 'gzip, deflate, br'
8+
}
9+
})
710

8-
const res = await needle('get', downloadUrl, { compressed: true })
9-
10-
if (res.body) {
11-
return res.body.toString('utf8');
11+
if (res.ok) {
12+
return await res.text();
1213
} else {
1314
throw new Error('Unsuccessful request');
1415
}
@@ -28,4 +29,4 @@ async function getRequest() {
2829
process.exit(-1);
2930
}
3031
process.exit();
31-
})();
32+
})();

0 commit comments

Comments
 (0)