add `before` property to CommentSearchOptions (#1)
Fix types (#2) Co-authored-by: Raphaël MORTIER <rmortier@centralpay.eu>
Update package.json bump to 1.0.2
@@ -1,6 +1,6 @@
|
|
1 |
{
|
2 |
"name": "snooshift",
|
3 |
-
"version": "1.0.
|
4 |
"description": "A JavaScript wrapper for Reddit Pushshift API based on Snoowrap",
|
5 |
"scripts": {
|
6 |
"start": "node dist/",
|
1 |
{
|
2 |
"name": "snooshift",
|
3 |
+
"version": "1.0.2",
|
4 |
"description": "A JavaScript wrapper for Reddit Pushshift API based on Snoowrap",
|
5 |
"scripts": {
|
6 |
"start": "node dist/",
|
@@ -7,7 +7,8 @@ export declare interface CommentSearchOptions {
|
|
7 |
aggs?: string[];
|
8 |
author?: string;
|
9 |
subreddit?: string;
|
10 |
-
after?: number;
|
|
|
11 |
frequency?: string;
|
12 |
metadata?: boolean;
|
13 |
}
|
@@ -22,21 +23,21 @@ export declare interface SubmissionSearchOptions {
|
|
22 |
"selftext:not"?: string;
|
23 |
size?: number;
|
24 |
fields?: string;
|
25 |
-
sort?:
|
26 |
-
sort_type?:
|
27 |
aggs?: string;
|
28 |
author?: string;
|
29 |
subreddit?: string;
|
30 |
-
after?: number;
|
31 |
-
before?: number;
|
32 |
-
score?: number;
|
33 |
-
num_comments?: number;
|
34 |
over_18?: boolean;
|
35 |
is_video?: boolean;
|
36 |
locked?: boolean;
|
37 |
stickied?: boolean;
|
38 |
spoiler?: boolean;
|
39 |
contest_mode?: boolean;
|
40 |
-
frequency?:
|
41 |
metadata?: boolean;
|
42 |
}
|
7 |
aggs?: string[];
|
8 |
author?: string;
|
9 |
subreddit?: string;
|
10 |
+
after?: number | string;
|
11 |
+
before?: number | string;
|
12 |
frequency?: string;
|
13 |
metadata?: boolean;
|
14 |
}
|
23 |
"selftext:not"?: string;
|
24 |
size?: number;
|
25 |
fields?: string;
|
26 |
+
sort?: "asc" | "desc";
|
27 |
+
sort_type?: "score" | "num_comments" | "created_utc";
|
28 |
aggs?: string;
|
29 |
author?: string;
|
30 |
subreddit?: string;
|
31 |
+
after?: number | string;
|
32 |
+
before?: number | string;
|
33 |
+
score?: number | string;
|
34 |
+
num_comments?: number | string;
|
35 |
over_18?: boolean;
|
36 |
is_video?: boolean;
|
37 |
locked?: boolean;
|
38 |
stickied?: boolean;
|
39 |
spoiler?: boolean;
|
40 |
contest_mode?: boolean;
|
41 |
+
frequency?: "second" | "minute" | "hour" | "day";
|
42 |
metadata?: boolean;
|
43 |
}
|
JavaScript wrapper library for Pushshift with Snoowrap support.
npm i -S snooshift
import { SnooShift } from "snooshift";
// create new object
const snoo = new SnooShift();
// search parameters
// https://github.com/pushshift/api#search-parameters-for-comments
// search comments by author
const searchParams = {
author: "eben0",
};
// send request
snoo.searchComments(searchParams).then((comments) => {
console.log(comments);
});
// get single comment by id
snoo.getComment("gof4uys").then((comment) => {
console.log(comment);
});
// search parameters
// https://github.com/pushshift/api#search-parameters-for-submissions
// search submissions by author
const searchParams = {
author: "eben0",
};
snoo.searchSubmissions(searchParams).then((comments) => {
console.log(comments);
});
// get single submission by id
snoo.searchSubmissions("lrufxe").then((submission) => {
console.log(submission);
});
You can reply, upvote and interact with reddit using Snoowrap
object.
You must set up your reddit api credentials to do so.
import { SnooShift } from "snooshift";
// list of supported credentials:
// https://github.com/not-an-aardvark/snoowrap#examples
const credentials = {
userAgent: "put your user-agent string here",
clientId: "put your client id here",
clientSecret: "put your client secret here",
refreshToken: "put your refresh token here",
};
const snoo = new SnooShift(credentials);
// get comment and reply/upvote/etc...
snoo.getComment("gof4uys").then((comment) => {
comment.reply("My awesome reply").then(value);
comment.upvote().then(value);
comment.delete().then(value);
});
You can directly query the elasticsearch server if you are familiar with syntax.
import { SnooShift } from "snooshift";
const snoo = new SnooShift();
// elasticsearch query
// this query searches for all author's data ordered by created_utc
const query = {
query: {
term: { author: "eben0" },
},
sort: {
created_utc: "desc",
}
};
// searches for author's comments
snoo.elasticComments(query).then((result) => {
console.log(result.hits.hits[0]._source);
});
// searches for author's submissions
snoo.elasticSubmissions(query).then((result) => {
console.log(result.hits.hits[0]._source);
});