scrapebadger 0.7.0 → 0.8.1
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 +1 -0
- package/dist/index.d.cts +1347 -9
- package/dist/index.d.ts +1347 -9
- package/dist/index.js +641 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +637 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -3275,6 +3275,639 @@ var GoogleClient = class {
|
|
|
3275
3275
|
}
|
|
3276
3276
|
};
|
|
3277
3277
|
|
|
3278
|
+
// src/reddit/search.ts
|
|
3279
|
+
var SearchClient3 = class {
|
|
3280
|
+
client;
|
|
3281
|
+
constructor(client) {
|
|
3282
|
+
this.client = client;
|
|
3283
|
+
}
|
|
3284
|
+
/**
|
|
3285
|
+
* Search Reddit posts.
|
|
3286
|
+
*
|
|
3287
|
+
* @param options - Search parameters.
|
|
3288
|
+
* @param options.query - Search query string.
|
|
3289
|
+
* @param options.subreddit - Restrict search to a specific subreddit.
|
|
3290
|
+
* @param options.sort - Sort order (relevance, hot, top, new, comments).
|
|
3291
|
+
* @param options.time - Time filter (hour, day, week, month, year, all).
|
|
3292
|
+
* @param options.after - Pagination cursor for the next page.
|
|
3293
|
+
* @param options.limit - Number of results to return (max 100).
|
|
3294
|
+
* @returns Search results with posts and pagination metadata.
|
|
3295
|
+
* @throws AuthenticationError - If the API key is invalid.
|
|
3296
|
+
* @throws ValidationError - If the search parameters are invalid.
|
|
3297
|
+
*
|
|
3298
|
+
* @example
|
|
3299
|
+
* ```typescript
|
|
3300
|
+
* const results = await client.reddit.search.posts({
|
|
3301
|
+
* query: "best practices",
|
|
3302
|
+
* subreddit: "programming",
|
|
3303
|
+
* sort: "top",
|
|
3304
|
+
* time: "month",
|
|
3305
|
+
* limit: 25,
|
|
3306
|
+
* });
|
|
3307
|
+
* console.log(`Found ${results.posts.length} posts`);
|
|
3308
|
+
* ```
|
|
3309
|
+
*/
|
|
3310
|
+
async posts(options) {
|
|
3311
|
+
return this.client.request("/v1/reddit/search/posts", {
|
|
3312
|
+
params: {
|
|
3313
|
+
query: options.query,
|
|
3314
|
+
subreddit: options.subreddit,
|
|
3315
|
+
sort: options.sort,
|
|
3316
|
+
time: options.time,
|
|
3317
|
+
after: options.after,
|
|
3318
|
+
limit: options.limit
|
|
3319
|
+
}
|
|
3320
|
+
});
|
|
3321
|
+
}
|
|
3322
|
+
/**
|
|
3323
|
+
* Search Reddit subreddits.
|
|
3324
|
+
*
|
|
3325
|
+
* @param options - Search parameters.
|
|
3326
|
+
* @param options.query - Search query string.
|
|
3327
|
+
* @param options.after - Pagination cursor for the next page.
|
|
3328
|
+
* @param options.limit - Number of results to return (max 100).
|
|
3329
|
+
* @returns Matching subreddits with pagination metadata.
|
|
3330
|
+
* @throws AuthenticationError - If the API key is invalid.
|
|
3331
|
+
* @throws ValidationError - If the search parameters are invalid.
|
|
3332
|
+
*
|
|
3333
|
+
* @example
|
|
3334
|
+
* ```typescript
|
|
3335
|
+
* const results = await client.reddit.search.subreddits({
|
|
3336
|
+
* query: "javascript",
|
|
3337
|
+
* limit: 10,
|
|
3338
|
+
* });
|
|
3339
|
+
* for (const sub of results.subreddits) {
|
|
3340
|
+
* console.log(`r/${sub.display_name}: ${sub.subscribers.toLocaleString()} subscribers`);
|
|
3341
|
+
* }
|
|
3342
|
+
* ```
|
|
3343
|
+
*/
|
|
3344
|
+
async subreddits(options) {
|
|
3345
|
+
return this.client.request(
|
|
3346
|
+
"/v1/reddit/search/subreddits",
|
|
3347
|
+
{
|
|
3348
|
+
params: {
|
|
3349
|
+
query: options.query,
|
|
3350
|
+
after: options.after,
|
|
3351
|
+
limit: options.limit
|
|
3352
|
+
}
|
|
3353
|
+
}
|
|
3354
|
+
);
|
|
3355
|
+
}
|
|
3356
|
+
/**
|
|
3357
|
+
* Search Reddit users.
|
|
3358
|
+
*
|
|
3359
|
+
* @param options - Search parameters.
|
|
3360
|
+
* @param options.query - Search query string.
|
|
3361
|
+
* @param options.after - Pagination cursor for the next page.
|
|
3362
|
+
* @param options.limit - Number of results to return (max 100).
|
|
3363
|
+
* @returns Matching users with pagination metadata.
|
|
3364
|
+
* @throws AuthenticationError - If the API key is invalid.
|
|
3365
|
+
* @throws ValidationError - If the search parameters are invalid.
|
|
3366
|
+
*
|
|
3367
|
+
* @example
|
|
3368
|
+
* ```typescript
|
|
3369
|
+
* const results = await client.reddit.search.users({
|
|
3370
|
+
* query: "john",
|
|
3371
|
+
* limit: 20,
|
|
3372
|
+
* });
|
|
3373
|
+
* for (const user of results.users) {
|
|
3374
|
+
* console.log(`u/${user.name}: ${user.total_karma.toLocaleString()} karma`);
|
|
3375
|
+
* }
|
|
3376
|
+
* ```
|
|
3377
|
+
*/
|
|
3378
|
+
async users(options) {
|
|
3379
|
+
return this.client.request(
|
|
3380
|
+
"/v1/reddit/search/users",
|
|
3381
|
+
{
|
|
3382
|
+
params: {
|
|
3383
|
+
query: options.query,
|
|
3384
|
+
after: options.after,
|
|
3385
|
+
limit: options.limit
|
|
3386
|
+
}
|
|
3387
|
+
}
|
|
3388
|
+
);
|
|
3389
|
+
}
|
|
3390
|
+
/**
|
|
3391
|
+
* Get Reddit posts linking to a specific domain.
|
|
3392
|
+
*
|
|
3393
|
+
* @param options - Request parameters.
|
|
3394
|
+
* @param options.domain - Domain name to search for (e.g. "github.com").
|
|
3395
|
+
* @param options.sort - Sort order (hot, new, top, rising).
|
|
3396
|
+
* @param options.time - Time filter for top sort (hour, day, week, month, year, all).
|
|
3397
|
+
* @param options.after - Pagination cursor for the next page.
|
|
3398
|
+
* @param options.limit - Number of results to return (max 100).
|
|
3399
|
+
* @returns Posts linking to the domain with pagination metadata.
|
|
3400
|
+
* @throws AuthenticationError - If the API key is invalid.
|
|
3401
|
+
* @throws ValidationError - If the parameters are invalid.
|
|
3402
|
+
*
|
|
3403
|
+
* @example
|
|
3404
|
+
* ```typescript
|
|
3405
|
+
* const results = await client.reddit.search.domainPosts({
|
|
3406
|
+
* domain: "github.com",
|
|
3407
|
+
* sort: "top",
|
|
3408
|
+
* time: "week",
|
|
3409
|
+
* limit: 25,
|
|
3410
|
+
* });
|
|
3411
|
+
* for (const post of results.posts) {
|
|
3412
|
+
* console.log(`r/${post.subreddit}: ${post.title}`);
|
|
3413
|
+
* }
|
|
3414
|
+
* ```
|
|
3415
|
+
*/
|
|
3416
|
+
async domainPosts(options) {
|
|
3417
|
+
return this.client.request(
|
|
3418
|
+
"/v1/reddit/search/domain",
|
|
3419
|
+
{
|
|
3420
|
+
params: {
|
|
3421
|
+
domain: options.domain,
|
|
3422
|
+
sort: options.sort,
|
|
3423
|
+
time: options.time,
|
|
3424
|
+
after: options.after,
|
|
3425
|
+
limit: options.limit
|
|
3426
|
+
}
|
|
3427
|
+
}
|
|
3428
|
+
);
|
|
3429
|
+
}
|
|
3430
|
+
};
|
|
3431
|
+
|
|
3432
|
+
// src/reddit/posts.ts
|
|
3433
|
+
var PostsClient = class {
|
|
3434
|
+
client;
|
|
3435
|
+
constructor(client) {
|
|
3436
|
+
this.client = client;
|
|
3437
|
+
}
|
|
3438
|
+
/**
|
|
3439
|
+
* Get trending/hot posts from Reddit or a specific subreddit.
|
|
3440
|
+
*
|
|
3441
|
+
* @param options - Request parameters.
|
|
3442
|
+
* @param options.subreddit - Subreddit name (without r/). If omitted, returns site-wide posts.
|
|
3443
|
+
* @param options.sort - Sort order (hot, new, top, rising, controversial).
|
|
3444
|
+
* @param options.time - Time filter for top/controversial (hour, day, week, month, year, all).
|
|
3445
|
+
* @param options.after - Pagination cursor for the next page.
|
|
3446
|
+
* @param options.limit - Number of results to return (max 100).
|
|
3447
|
+
* @returns Trending posts with pagination metadata.
|
|
3448
|
+
* @throws AuthenticationError - If the API key is invalid.
|
|
3449
|
+
*
|
|
3450
|
+
* @example
|
|
3451
|
+
* ```typescript
|
|
3452
|
+
* const results = await client.reddit.posts.trending({
|
|
3453
|
+
* subreddit: "worldnews",
|
|
3454
|
+
* sort: "hot",
|
|
3455
|
+
* limit: 25,
|
|
3456
|
+
* });
|
|
3457
|
+
* for (const post of results.posts) {
|
|
3458
|
+
* console.log(`${post.title} (${post.num_comments} comments)`);
|
|
3459
|
+
* }
|
|
3460
|
+
* ```
|
|
3461
|
+
*/
|
|
3462
|
+
async trending(options = {}) {
|
|
3463
|
+
return this.client.request("/v1/reddit/posts", {
|
|
3464
|
+
params: {
|
|
3465
|
+
subreddit: options.subreddit,
|
|
3466
|
+
sort: options.sort,
|
|
3467
|
+
time: options.time,
|
|
3468
|
+
after: options.after,
|
|
3469
|
+
limit: options.limit
|
|
3470
|
+
}
|
|
3471
|
+
});
|
|
3472
|
+
}
|
|
3473
|
+
/**
|
|
3474
|
+
* Get full details of a single Reddit post.
|
|
3475
|
+
*
|
|
3476
|
+
* @param postId - The Reddit post ID (e.g. "abc123" or "t3_abc123").
|
|
3477
|
+
* @param options - Optional parameters.
|
|
3478
|
+
* @param options.subreddit - Subreddit name (helps resolve the post URL).
|
|
3479
|
+
* @returns Full post details.
|
|
3480
|
+
* @throws NotFoundError - If the post doesn't exist.
|
|
3481
|
+
* @throws AuthenticationError - If the API key is invalid.
|
|
3482
|
+
*
|
|
3483
|
+
* @example
|
|
3484
|
+
* ```typescript
|
|
3485
|
+
* const response = await client.reddit.posts.get("abc123", { subreddit: "programming" });
|
|
3486
|
+
* const { post } = response;
|
|
3487
|
+
* console.log(`${post.title} by u/${post.author}`);
|
|
3488
|
+
* console.log(`Score: ${post.score}, Comments: ${post.num_comments}`);
|
|
3489
|
+
* ```
|
|
3490
|
+
*/
|
|
3491
|
+
async get(postId, options = {}) {
|
|
3492
|
+
return this.client.request(
|
|
3493
|
+
`/v1/reddit/posts/${postId}`,
|
|
3494
|
+
{ params: { subreddit: options.subreddit } }
|
|
3495
|
+
);
|
|
3496
|
+
}
|
|
3497
|
+
/**
|
|
3498
|
+
* Get comments for a Reddit post.
|
|
3499
|
+
*
|
|
3500
|
+
* @param postId - The Reddit post ID (e.g. "abc123" or "t3_abc123").
|
|
3501
|
+
* @param options - Optional parameters.
|
|
3502
|
+
* @param options.subreddit - Subreddit name (helps resolve the post URL).
|
|
3503
|
+
* @param options.sort - Comment sort order (confidence, top, new, controversial, old, qa).
|
|
3504
|
+
* @param options.depth - Maximum comment tree depth.
|
|
3505
|
+
* @param options.limit - Number of top-level comments to return.
|
|
3506
|
+
* @returns Post details and nested comment tree.
|
|
3507
|
+
* @throws NotFoundError - If the post doesn't exist.
|
|
3508
|
+
* @throws AuthenticationError - If the API key is invalid.
|
|
3509
|
+
*
|
|
3510
|
+
* @example
|
|
3511
|
+
* ```typescript
|
|
3512
|
+
* const response = await client.reddit.posts.comments("abc123", {
|
|
3513
|
+
* subreddit: "programming",
|
|
3514
|
+
* sort: "top",
|
|
3515
|
+
* limit: 50,
|
|
3516
|
+
* });
|
|
3517
|
+
* for (const comment of response.comments) {
|
|
3518
|
+
* console.log(`u/${comment.author}: ${comment.body.slice(0, 100)}`);
|
|
3519
|
+
* }
|
|
3520
|
+
* ```
|
|
3521
|
+
*/
|
|
3522
|
+
async comments(postId, options = {}) {
|
|
3523
|
+
return this.client.request(
|
|
3524
|
+
`/v1/reddit/posts/${postId}/comments`,
|
|
3525
|
+
{
|
|
3526
|
+
params: {
|
|
3527
|
+
subreddit: options.subreddit,
|
|
3528
|
+
sort: options.sort,
|
|
3529
|
+
depth: options.depth,
|
|
3530
|
+
limit: options.limit
|
|
3531
|
+
}
|
|
3532
|
+
}
|
|
3533
|
+
);
|
|
3534
|
+
}
|
|
3535
|
+
/**
|
|
3536
|
+
* Get cross-posts and duplicate submissions of a Reddit post.
|
|
3537
|
+
*
|
|
3538
|
+
* @param postId - The Reddit post ID (e.g. "abc123" or "t3_abc123").
|
|
3539
|
+
* @param options - Optional parameters.
|
|
3540
|
+
* @param options.after - Pagination cursor for the next page.
|
|
3541
|
+
* @param options.limit - Number of results to return (max 100).
|
|
3542
|
+
* @returns The original post and its duplicate submissions.
|
|
3543
|
+
* @throws NotFoundError - If the post doesn't exist.
|
|
3544
|
+
* @throws AuthenticationError - If the API key is invalid.
|
|
3545
|
+
*
|
|
3546
|
+
* @example
|
|
3547
|
+
* ```typescript
|
|
3548
|
+
* const response = await client.reddit.posts.duplicates("abc123");
|
|
3549
|
+
* console.log(`Original: ${response.post.title}`);
|
|
3550
|
+
* console.log(`Cross-posted ${response.duplicates.length} times`);
|
|
3551
|
+
* for (const dupe of response.duplicates) {
|
|
3552
|
+
* console.log(` r/${dupe.subreddit}: ${dupe.score} points`);
|
|
3553
|
+
* }
|
|
3554
|
+
* ```
|
|
3555
|
+
*/
|
|
3556
|
+
async duplicates(postId, options = {}) {
|
|
3557
|
+
return this.client.request(
|
|
3558
|
+
`/v1/reddit/posts/${postId}/duplicates`,
|
|
3559
|
+
{
|
|
3560
|
+
params: {
|
|
3561
|
+
after: options.after,
|
|
3562
|
+
limit: options.limit
|
|
3563
|
+
}
|
|
3564
|
+
}
|
|
3565
|
+
);
|
|
3566
|
+
}
|
|
3567
|
+
};
|
|
3568
|
+
|
|
3569
|
+
// src/reddit/subreddits.ts
|
|
3570
|
+
var SubredditsClient = class {
|
|
3571
|
+
client;
|
|
3572
|
+
constructor(client) {
|
|
3573
|
+
this.client = client;
|
|
3574
|
+
}
|
|
3575
|
+
/**
|
|
3576
|
+
* Get a subreddit's full details and metadata.
|
|
3577
|
+
*
|
|
3578
|
+
* @param subreddit - Subreddit name (without r/ prefix).
|
|
3579
|
+
* @returns Full subreddit details.
|
|
3580
|
+
* @throws NotFoundError - If the subreddit doesn't exist.
|
|
3581
|
+
* @throws AuthenticationError - If the API key is invalid.
|
|
3582
|
+
*
|
|
3583
|
+
* @example
|
|
3584
|
+
* ```typescript
|
|
3585
|
+
* const response = await client.reddit.subreddits.get("javascript");
|
|
3586
|
+
* const { subreddit } = response;
|
|
3587
|
+
* console.log(`${subreddit.title}: ${subreddit.subscribers.toLocaleString()} members`);
|
|
3588
|
+
* console.log(`Description: ${subreddit.public_description}`);
|
|
3589
|
+
* ```
|
|
3590
|
+
*/
|
|
3591
|
+
async get(subreddit) {
|
|
3592
|
+
return this.client.request(`/v1/reddit/subreddits/${subreddit}`);
|
|
3593
|
+
}
|
|
3594
|
+
/**
|
|
3595
|
+
* Get posts from a subreddit.
|
|
3596
|
+
*
|
|
3597
|
+
* @param subreddit - Subreddit name (without r/ prefix).
|
|
3598
|
+
* @param options - Optional parameters.
|
|
3599
|
+
* @param options.sort - Sort order (hot, new, top, rising, controversial).
|
|
3600
|
+
* @param options.time - Time filter for top/controversial (hour, day, week, month, year, all).
|
|
3601
|
+
* @param options.after - Pagination cursor for the next page.
|
|
3602
|
+
* @param options.limit - Number of results to return (max 100).
|
|
3603
|
+
* @returns Subreddit posts with pagination metadata.
|
|
3604
|
+
* @throws NotFoundError - If the subreddit doesn't exist.
|
|
3605
|
+
* @throws AuthenticationError - If the API key is invalid.
|
|
3606
|
+
*
|
|
3607
|
+
* @example
|
|
3608
|
+
* ```typescript
|
|
3609
|
+
* const response = await client.reddit.subreddits.posts("typescript", {
|
|
3610
|
+
* sort: "top",
|
|
3611
|
+
* time: "week",
|
|
3612
|
+
* limit: 25,
|
|
3613
|
+
* });
|
|
3614
|
+
* for (const post of response.posts) {
|
|
3615
|
+
* console.log(`${post.title} — ${post.score} pts`);
|
|
3616
|
+
* }
|
|
3617
|
+
* ```
|
|
3618
|
+
*/
|
|
3619
|
+
async posts(subreddit, options = {}) {
|
|
3620
|
+
return this.client.request(`/v1/reddit/subreddits/${subreddit}/posts`, {
|
|
3621
|
+
params: {
|
|
3622
|
+
sort: options.sort,
|
|
3623
|
+
time: options.time,
|
|
3624
|
+
after: options.after,
|
|
3625
|
+
limit: options.limit
|
|
3626
|
+
}
|
|
3627
|
+
});
|
|
3628
|
+
}
|
|
3629
|
+
/**
|
|
3630
|
+
* Get the rules for a subreddit.
|
|
3631
|
+
*
|
|
3632
|
+
* @param subreddit - Subreddit name (without r/ prefix).
|
|
3633
|
+
* @returns List of subreddit rules.
|
|
3634
|
+
* @throws NotFoundError - If the subreddit doesn't exist.
|
|
3635
|
+
* @throws AuthenticationError - If the API key is invalid.
|
|
3636
|
+
*
|
|
3637
|
+
* @example
|
|
3638
|
+
* ```typescript
|
|
3639
|
+
* const response = await client.reddit.subreddits.rules("AskReddit");
|
|
3640
|
+
* for (const rule of response.rules) {
|
|
3641
|
+
* console.log(`${rule.priority}. ${rule.short_name}`);
|
|
3642
|
+
* console.log(` ${rule.description}`);
|
|
3643
|
+
* }
|
|
3644
|
+
* ```
|
|
3645
|
+
*/
|
|
3646
|
+
async rules(subreddit) {
|
|
3647
|
+
return this.client.request(`/v1/reddit/subreddits/${subreddit}/rules`);
|
|
3648
|
+
}
|
|
3649
|
+
/**
|
|
3650
|
+
* List all wiki pages in a subreddit.
|
|
3651
|
+
*
|
|
3652
|
+
* @param subreddit - Subreddit name (without r/ prefix).
|
|
3653
|
+
* @returns List of wiki page slugs.
|
|
3654
|
+
* @throws NotFoundError - If the subreddit doesn't exist.
|
|
3655
|
+
* @throws AuthenticationError - If the API key is invalid.
|
|
3656
|
+
*
|
|
3657
|
+
* @example
|
|
3658
|
+
* ```typescript
|
|
3659
|
+
* const response = await client.reddit.subreddits.wikiPages("rust");
|
|
3660
|
+
* for (const page of response.pages) {
|
|
3661
|
+
* console.log(`/r/rust/wiki/${page}`);
|
|
3662
|
+
* }
|
|
3663
|
+
* ```
|
|
3664
|
+
*/
|
|
3665
|
+
async wikiPages(subreddit) {
|
|
3666
|
+
return this.client.request(
|
|
3667
|
+
`/v1/reddit/subreddits/${subreddit}/wiki`
|
|
3668
|
+
);
|
|
3669
|
+
}
|
|
3670
|
+
/**
|
|
3671
|
+
* Get the content of a specific wiki page in a subreddit.
|
|
3672
|
+
*
|
|
3673
|
+
* @param subreddit - Subreddit name (without r/ prefix).
|
|
3674
|
+
* @param page - Wiki page slug (e.g. "index", "faq").
|
|
3675
|
+
* @returns Wiki page content and metadata.
|
|
3676
|
+
* @throws NotFoundError - If the subreddit or wiki page doesn't exist.
|
|
3677
|
+
* @throws AuthenticationError - If the API key is invalid.
|
|
3678
|
+
*
|
|
3679
|
+
* @example
|
|
3680
|
+
* ```typescript
|
|
3681
|
+
* const response = await client.reddit.subreddits.wikiPage("learnprogramming", "faq");
|
|
3682
|
+
* console.log(`Last edited by: u/${response.page.revision_by}`);
|
|
3683
|
+
* console.log(response.page.content_md);
|
|
3684
|
+
* ```
|
|
3685
|
+
*/
|
|
3686
|
+
async wikiPage(subreddit, page) {
|
|
3687
|
+
return this.client.request(`/v1/reddit/subreddits/${subreddit}/wiki/${page}`);
|
|
3688
|
+
}
|
|
3689
|
+
/**
|
|
3690
|
+
* Get the most popular subreddits on Reddit.
|
|
3691
|
+
*
|
|
3692
|
+
* @param options - Optional parameters.
|
|
3693
|
+
* @param options.after - Pagination cursor for the next page.
|
|
3694
|
+
* @param options.limit - Number of results to return (max 100).
|
|
3695
|
+
* @returns Popular subreddits with pagination metadata.
|
|
3696
|
+
* @throws AuthenticationError - If the API key is invalid.
|
|
3697
|
+
*
|
|
3698
|
+
* @example
|
|
3699
|
+
* ```typescript
|
|
3700
|
+
* const response = await client.reddit.subreddits.popular({ limit: 20 });
|
|
3701
|
+
* for (const sub of response.subreddits) {
|
|
3702
|
+
* console.log(`r/${sub.display_name}: ${sub.subscribers.toLocaleString()} subscribers`);
|
|
3703
|
+
* }
|
|
3704
|
+
* ```
|
|
3705
|
+
*/
|
|
3706
|
+
async popular(options = {}) {
|
|
3707
|
+
return this.client.request("/v1/reddit/subreddits/popular", {
|
|
3708
|
+
params: {
|
|
3709
|
+
after: options.after,
|
|
3710
|
+
limit: options.limit
|
|
3711
|
+
}
|
|
3712
|
+
});
|
|
3713
|
+
}
|
|
3714
|
+
/**
|
|
3715
|
+
* Get newly created subreddits on Reddit.
|
|
3716
|
+
*
|
|
3717
|
+
* @param options - Optional parameters.
|
|
3718
|
+
* @param options.after - Pagination cursor for the next page.
|
|
3719
|
+
* @param options.limit - Number of results to return (max 100).
|
|
3720
|
+
* @returns New subreddits with pagination metadata.
|
|
3721
|
+
* @throws AuthenticationError - If the API key is invalid.
|
|
3722
|
+
*
|
|
3723
|
+
* @example
|
|
3724
|
+
* ```typescript
|
|
3725
|
+
* const response = await client.reddit.subreddits.newSubreddits({ limit: 20 });
|
|
3726
|
+
* for (const sub of response.subreddits) {
|
|
3727
|
+
* console.log(`r/${sub.display_name} (created: ${new Date(sub.created_utc * 1000).toLocaleDateString()})`);
|
|
3728
|
+
* }
|
|
3729
|
+
* ```
|
|
3730
|
+
*/
|
|
3731
|
+
async newSubreddits(options = {}) {
|
|
3732
|
+
return this.client.request("/v1/reddit/subreddits/new", {
|
|
3733
|
+
params: {
|
|
3734
|
+
after: options.after,
|
|
3735
|
+
limit: options.limit
|
|
3736
|
+
}
|
|
3737
|
+
});
|
|
3738
|
+
}
|
|
3739
|
+
};
|
|
3740
|
+
|
|
3741
|
+
// src/reddit/users.ts
|
|
3742
|
+
var UsersClient3 = class {
|
|
3743
|
+
client;
|
|
3744
|
+
constructor(client) {
|
|
3745
|
+
this.client = client;
|
|
3746
|
+
}
|
|
3747
|
+
/**
|
|
3748
|
+
* Get a Reddit user's profile.
|
|
3749
|
+
*
|
|
3750
|
+
* @param username - The Reddit username (without u/ prefix).
|
|
3751
|
+
* @returns The user profile response.
|
|
3752
|
+
* @throws NotFoundError - If the user doesn't exist or is suspended.
|
|
3753
|
+
* @throws AuthenticationError - If the API key is invalid.
|
|
3754
|
+
*
|
|
3755
|
+
* @example
|
|
3756
|
+
* ```typescript
|
|
3757
|
+
* const response = await client.reddit.users.get("spez");
|
|
3758
|
+
* const { user } = response;
|
|
3759
|
+
* console.log(`u/${user.name}`);
|
|
3760
|
+
* console.log(`Karma: ${user.total_karma.toLocaleString()} (${user.link_karma} post, ${user.comment_karma} comment)`);
|
|
3761
|
+
* console.log(`Account age: ${new Date(user.created_utc * 1000).toLocaleDateString()}`);
|
|
3762
|
+
* ```
|
|
3763
|
+
*/
|
|
3764
|
+
async get(username) {
|
|
3765
|
+
return this.client.request(
|
|
3766
|
+
`/v1/reddit/users/${username}`
|
|
3767
|
+
);
|
|
3768
|
+
}
|
|
3769
|
+
/**
|
|
3770
|
+
* Get posts submitted by a Reddit user.
|
|
3771
|
+
*
|
|
3772
|
+
* @param username - The Reddit username (without u/ prefix).
|
|
3773
|
+
* @param options - Optional parameters.
|
|
3774
|
+
* @param options.sort - Sort order (hot, new, top, controversial).
|
|
3775
|
+
* @param options.time - Time filter for top/controversial (hour, day, week, month, year, all).
|
|
3776
|
+
* @param options.after - Pagination cursor for the next page.
|
|
3777
|
+
* @param options.limit - Number of results to return (max 100).
|
|
3778
|
+
* @returns The user's posts with pagination metadata.
|
|
3779
|
+
* @throws NotFoundError - If the user doesn't exist.
|
|
3780
|
+
* @throws AuthenticationError - If the API key is invalid.
|
|
3781
|
+
*
|
|
3782
|
+
* @example
|
|
3783
|
+
* ```typescript
|
|
3784
|
+
* const response = await client.reddit.users.posts("spez", {
|
|
3785
|
+
* sort: "top",
|
|
3786
|
+
* time: "all",
|
|
3787
|
+
* limit: 25,
|
|
3788
|
+
* });
|
|
3789
|
+
* for (const post of response.posts) {
|
|
3790
|
+
* console.log(`r/${post.subreddit}: ${post.title} (${post.score} pts)`);
|
|
3791
|
+
* }
|
|
3792
|
+
* ```
|
|
3793
|
+
*/
|
|
3794
|
+
async posts(username, options = {}) {
|
|
3795
|
+
return this.client.request(
|
|
3796
|
+
`/v1/reddit/users/${username}/posts`,
|
|
3797
|
+
{
|
|
3798
|
+
params: {
|
|
3799
|
+
sort: options.sort,
|
|
3800
|
+
time: options.time,
|
|
3801
|
+
after: options.after,
|
|
3802
|
+
limit: options.limit
|
|
3803
|
+
}
|
|
3804
|
+
}
|
|
3805
|
+
);
|
|
3806
|
+
}
|
|
3807
|
+
/**
|
|
3808
|
+
* Get comments made by a Reddit user.
|
|
3809
|
+
*
|
|
3810
|
+
* @param username - The Reddit username (without u/ prefix).
|
|
3811
|
+
* @param options - Optional parameters.
|
|
3812
|
+
* @param options.sort - Sort order (hot, new, top, controversial).
|
|
3813
|
+
* @param options.time - Time filter for top/controversial (hour, day, week, month, year, all).
|
|
3814
|
+
* @param options.after - Pagination cursor for the next page.
|
|
3815
|
+
* @param options.limit - Number of results to return (max 100).
|
|
3816
|
+
* @returns The user's comments with pagination metadata.
|
|
3817
|
+
* @throws NotFoundError - If the user doesn't exist.
|
|
3818
|
+
* @throws AuthenticationError - If the API key is invalid.
|
|
3819
|
+
*
|
|
3820
|
+
* @example
|
|
3821
|
+
* ```typescript
|
|
3822
|
+
* const response = await client.reddit.users.comments("spez", {
|
|
3823
|
+
* sort: "new",
|
|
3824
|
+
* limit: 50,
|
|
3825
|
+
* });
|
|
3826
|
+
* for (const comment of response.comments) {
|
|
3827
|
+
* console.log(`r/${comment.subreddit}: ${comment.body.slice(0, 80)}`);
|
|
3828
|
+
* }
|
|
3829
|
+
* ```
|
|
3830
|
+
*/
|
|
3831
|
+
async comments(username, options = {}) {
|
|
3832
|
+
return this.client.request(
|
|
3833
|
+
`/v1/reddit/users/${username}/comments`,
|
|
3834
|
+
{
|
|
3835
|
+
params: {
|
|
3836
|
+
sort: options.sort,
|
|
3837
|
+
time: options.time,
|
|
3838
|
+
after: options.after,
|
|
3839
|
+
limit: options.limit
|
|
3840
|
+
}
|
|
3841
|
+
}
|
|
3842
|
+
);
|
|
3843
|
+
}
|
|
3844
|
+
/**
|
|
3845
|
+
* Get subreddits moderated by a Reddit user.
|
|
3846
|
+
*
|
|
3847
|
+
* @param username - The Reddit username (without u/ prefix).
|
|
3848
|
+
* @returns Subreddits moderated by the user.
|
|
3849
|
+
* @throws NotFoundError - If the user doesn't exist.
|
|
3850
|
+
* @throws AuthenticationError - If the API key is invalid.
|
|
3851
|
+
*
|
|
3852
|
+
* @example
|
|
3853
|
+
* ```typescript
|
|
3854
|
+
* const response = await client.reddit.users.moderated("spez");
|
|
3855
|
+
* for (const sub of response.subreddits) {
|
|
3856
|
+
* console.log(`r/${sub.display_name}: ${sub.subscribers.toLocaleString()} subscribers`);
|
|
3857
|
+
* }
|
|
3858
|
+
* ```
|
|
3859
|
+
*/
|
|
3860
|
+
async moderated(username) {
|
|
3861
|
+
return this.client.request(
|
|
3862
|
+
`/v1/reddit/users/${username}/moderated`
|
|
3863
|
+
);
|
|
3864
|
+
}
|
|
3865
|
+
/**
|
|
3866
|
+
* Get trophies awarded to a Reddit user.
|
|
3867
|
+
*
|
|
3868
|
+
* @param username - The Reddit username (without u/ prefix).
|
|
3869
|
+
* @returns List of trophies awarded to the user.
|
|
3870
|
+
* @throws NotFoundError - If the user doesn't exist.
|
|
3871
|
+
* @throws AuthenticationError - If the API key is invalid.
|
|
3872
|
+
*
|
|
3873
|
+
* @example
|
|
3874
|
+
* ```typescript
|
|
3875
|
+
* const response = await client.reddit.users.trophies("spez");
|
|
3876
|
+
* for (const trophy of response.trophies) {
|
|
3877
|
+
* console.log(`${trophy.name}${trophy.description ? `: ${trophy.description}` : ""}`);
|
|
3878
|
+
* }
|
|
3879
|
+
* ```
|
|
3880
|
+
*/
|
|
3881
|
+
async trophies(username) {
|
|
3882
|
+
return this.client.request(
|
|
3883
|
+
`/v1/reddit/users/${username}/trophies`
|
|
3884
|
+
);
|
|
3885
|
+
}
|
|
3886
|
+
};
|
|
3887
|
+
|
|
3888
|
+
// src/reddit/client.ts
|
|
3889
|
+
var RedditClient = class {
|
|
3890
|
+
/** Client for search operations (posts, subreddits, users, domain posts) */
|
|
3891
|
+
search;
|
|
3892
|
+
/** Client for post operations (trending, details, comments, duplicates) */
|
|
3893
|
+
posts;
|
|
3894
|
+
/** Client for subreddit operations (details, posts, rules, moderators, wiki) */
|
|
3895
|
+
subreddits;
|
|
3896
|
+
/** Client for user operations (profile, posts, comments, moderated, trophies) */
|
|
3897
|
+
users;
|
|
3898
|
+
/**
|
|
3899
|
+
* Create a new Reddit client.
|
|
3900
|
+
*
|
|
3901
|
+
* @param client - The base HTTP client for making requests.
|
|
3902
|
+
*/
|
|
3903
|
+
constructor(client) {
|
|
3904
|
+
this.search = new SearchClient3(client);
|
|
3905
|
+
this.posts = new PostsClient(client);
|
|
3906
|
+
this.subreddits = new SubredditsClient(client);
|
|
3907
|
+
this.users = new UsersClient3(client);
|
|
3908
|
+
}
|
|
3909
|
+
};
|
|
3910
|
+
|
|
3278
3911
|
// src/client.ts
|
|
3279
3912
|
var ScrapeBadger = class {
|
|
3280
3913
|
baseClient;
|
|
@@ -3286,6 +3919,8 @@ var ScrapeBadger = class {
|
|
|
3286
3919
|
vinted;
|
|
3287
3920
|
/** Google Scraper API client — 19 Google product APIs */
|
|
3288
3921
|
google;
|
|
3922
|
+
/** Reddit scraper API client */
|
|
3923
|
+
reddit;
|
|
3289
3924
|
/**
|
|
3290
3925
|
* Create a new ScrapeBadger client.
|
|
3291
3926
|
*
|
|
@@ -3324,6 +3959,7 @@ var ScrapeBadger = class {
|
|
|
3324
3959
|
this.web = new WebClient(this.baseClient);
|
|
3325
3960
|
this.vinted = new VintedClient(this.baseClient);
|
|
3326
3961
|
this.google = new GoogleClient(this.baseClient);
|
|
3962
|
+
this.reddit = new RedditClient(this.baseClient);
|
|
3327
3963
|
}
|
|
3328
3964
|
};
|
|
3329
3965
|
|
|
@@ -3355,6 +3991,11 @@ exports.InsufficientCreditsError = InsufficientCreditsError;
|
|
|
3355
3991
|
exports.ListsClient = ListsClient;
|
|
3356
3992
|
exports.NotFoundError = NotFoundError;
|
|
3357
3993
|
exports.RateLimitError = RateLimitError;
|
|
3994
|
+
exports.RedditClient = RedditClient;
|
|
3995
|
+
exports.RedditPostsClient = PostsClient;
|
|
3996
|
+
exports.RedditSearchClient = SearchClient3;
|
|
3997
|
+
exports.RedditSubredditsClient = SubredditsClient;
|
|
3998
|
+
exports.RedditUsersClient = UsersClient3;
|
|
3358
3999
|
exports.ScrapeBadger = ScrapeBadger;
|
|
3359
4000
|
exports.ScrapeBadgerError = ScrapeBadgerError;
|
|
3360
4001
|
exports.ServerError = ServerError;
|