docs: expand JavaScript SDK documentation

This commit is contained in:
Mo Elzubeir
2026-05-29 13:35:09 -05:00
parent 252ea713b1
commit c860cf6d88
11 changed files with 850 additions and 116 deletions
+29
View File
@@ -0,0 +1,29 @@
import { SocialhoseClient, SocialhoseError } from '@socialhose/api';
const socialhose = new SocialhoseClient({
apiKey: process.env.SOCIALHOSE_API_KEY!,
});
try {
const campaigns = await socialhose.getCampaigns();
const campaignId = campaigns[0]?.id;
const mentions = await socialhose.getMentions({
campaign_ids: campaignId,
content_search: 'hospital',
ordering: '-published_at',
});
console.log({
campaigns: campaigns.length,
mentionCount: mentions.count,
firstMention: mentions.results[0]?.url,
});
} catch (error) {
if (error instanceof SocialhoseError) {
console.error({ status: error.status, path: error.path, body: error.body });
process.exitCode = 1;
} else {
throw error;
}
}
@@ -0,0 +1,26 @@
import { SocialhoseClient } from '@socialhose/api';
const socialhose = new SocialhoseClient({
apiKey: process.env.SOCIALHOSE_API_KEY!,
cacheTtlMs: 15 * 60 * 1000,
});
const campaignId = process.argv[2];
const term = process.argv[3] ?? 'RSF';
const stats = await socialhose.getEntityStats(term, campaignId, {
revalidateSeconds: 15 * 60,
});
console.log(JSON.stringify({
term: stats.term,
total: stats.total,
exact: stats.exact,
sentiment: stats.sentiment,
platformMix: stats.platformMix,
recent7d: stats.recent7d,
prev7d: stats.prev7d,
momentumPct: stats.momentumPct,
sparkline: stats.sparkline,
topUrls: stats.sample.slice(0, 5).map((m) => m.url),
}, null, 2));