
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
reddit-wrapper-v2
Advanced tools
Simple Reddit API framework for nodejs. Replacing the no longer updated reddit-snooper. Relying more on promises rather than callbacks.
Reddit-Wrapper is designed to be a simple to user reddit API wrapper, while also providing robust error handling and retry capabilities. Every function returns a promise. Allowing the user to easily handle errors in the catch, and results in the then.
reddit.api.get("/subreddits/mine/subscriber", {
limit: 2,
})
.then(function(response) {
let responseCode = response[0];
let responseData = response[1];
console.log("Received response (" + responseCode + "): ", responseData);
})
.catch(function(err) {
});
npm install reddit-wrapper-v2 --save
var RedditAPI = require('reddit-wrapper');
var redditConn = new RedditAPI(
{
// credential information is not needed for snooper.watcher
// Required values:
username: 'reddit_username',
password: 'reddit password',
app_id: 'reddit api app id',
api_secret: 'reddit api secret',
// Optional values
user_agent: 'user agent for your bot',
// Retry on Wait tells the API Wrapper that whenever reddit replies with the message
// "You are doing this too much, try again". To sleep the process until the second
// after reddit will allow posting, and then post again. (This is a hard sleep).
retry_on_wait: true, // Default: false
// Retry on Server Error tells the wrapper to retry making requests a certain amount
// of times, if a reddit server error is encountered (Ie. "Ow. Please try again.").
// Specifying 5 times will attempt the request a MAXIMUM of 6 times.
retry_on_server_error: 5, // Default: 0
// Retry Delay specifies the delay between server error retries. The unit is seconds.
retry_delay: 1, // Default: 5 seconds.
})
All you need to get up and running is obtain an api_id and an api_secret. Both can be created on the Reddit app console
Reddit Wrappers api component is an agnostic wrapper around Reddit's rest API that handles retries, and Reddit's different response codes.
In order to use the api head over to the Reddit API Documentation. All of the api methods use one of the 5 HTTP methods (GET, POST, PATCH, PUT, DELETE) which map to the 5 different snooper.api methods.
// endpoint: api endpoint ex: 'api/v1/me' or '/api/v1/me/karma/' (listed on api documentation)
// data: JSON data, dependent on the request which is specified in the docs
// NOTE: the function .get is used for api calls that use HTTP GET, you can find the method each api endpiont uses on (you guessed it) the reddit api docs
// HTTP GET
redditWrapper.api.get(endpoint, data)
.then(function(response) {
let responseCode = response[0];
let responseData = response[1];
console.log("Received response (" + responseCode + "): ", responseData);
})
.catch(function(err) {
return console.error("api request failed: " + err)
});
// HTTP POST
redditWrapper.api.post(endpoint, data)
.then(function(response) {})
.catch(function(err) {})
// HTTP PATCH
redditWrapper.api.patch(endpoint, data)
.then(function(response) {})
.catch(function(err) {})
// HTTP PUT
redditWrapper.api.put(endpoint, data)
.then(function(response) {})
.catch(function(err) {})
// HTTP DELETE
redditWrapper.api.delete(endpoint, data)
.then(function(response) {})
.catch(function(err) {})
// gets an api token
redditWrapper.api.get_token()
.then(function(token) {})
.catch(function(err) {})
Note: new accounts get little to no posting privileges (1 comment or post per 5 minutes or more) if you dont have any karma. If you just want to play around with the api I recommend using an active account. Note: the response from any HTTP methods will be an array containing [responseCode, data].
check how much karma your bot has
redditWrapper.api.get('api/v1/me/karma', {})
.then(function(resp) {
let responseCode = response[0];
let responseData = response[1];
console.log("I have " + responseData.karma + " karma")
})
.catch(function(err) {
console.log("Error getting karma: ", err);
})
post a comment
redditWrapper.api.post("/api/comment", {
api_type: "json",
text: "Hello World"
thing_id: comment.data.name
})
.then(function(resp) {
let responseCode = response[0];
let responseData = response[1];
console.log("Posted comment!");
})
.catch(function(err) {
console.log("Error posting comment: ", err);
})
FAQs
Simple Reddit API framework for nodejs. Replacing the no longer updated reddit-snooper. Relying more on promises rather than callbacks. Nicely handles multiple reddit errors.
The npm package reddit-wrapper-v2 receives a total of 12 weekly downloads. As such, reddit-wrapper-v2 popularity was classified as not popular.
We found that reddit-wrapper-v2 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.