Giter Club home page Giter Club logo

rereddit's Introduction

broadcaster logo

About

Rereddit is a NodeJS wrapper for interfacing with reddit.com's API. It is built around superagent with a few extentions to its Request object for convenience. This extension allows for requests to be made like so:

rereddit.read('funny').limit(25).after('t3_a515a')
    .end(function(err, posts) {
        // Do something with posts.
    });

Rereddit also allows for accessing protected content, returning a user object from a successful call to login that can be stored within a session and passed back to the module when needed.

rereddit.login('username', 'password').end(function(err, user) {
    rereddit.me().as(user)
        .end(function(err, details) {
            // Now we have the user's details. 
        });
});

Usage

Install via NPM.

$ npm install rereddit

Then simply require within your application.

var rereddit = require('rereddit');

API

read([item])

The read function takes an optional string as an argument, matching either a reddit thing id36, or subreddit name. If no argument is present, rereddit assumes you wish to grab the front page posts of reddit.com.

login(username, password)

Login generates the initial post request and attaches the users credentials. Calling end on a login request will return a user object containing the cookie to be set, as well as a data object holding the generated modhash and cookie details like so:

{
    cookie: String,
    data: {
        modhash: String,
        cookie: String
    }
}

me()

A call to me generates an initialized request to grab the user's details. A call to me must be followed by a call to as (documented below) to pass along the required credentials with the request.

reddits()

Initializes a request to retrieve a list of subreddits from reddit.com.

comments(thread)

Initializes a request to fetch the comments for a thread (thread may be the fullname of a reddit thing, or just a things id only).

comment(parent, text), reply(parent, text)

Initializes a request to post a comment to the specified parent thread with the given text. An alias is provided as reply to allow for flavor. The parent id is expected to be in proper id36 format.

vote(id, dir)

Initializes a request to cast a vote on the specified id in the given direction dir, which is a string (equal to up or down), or integer (1 or -1). The id is expected to be in proper id36 format.

inbox()

Returns the messages stored in a user's inbox. The user is provided with a chained call to me.

unread()

Returns only the unread messages from a user's inbox. The user is provided with a chained call to me.

sent()

Returns messages that the user has previously sent. The user is provided with a chained call to me.

moreChildren(id, children)

Initializes a request to retrieve hidden comments. children may be supplied as an array of strings or comma-delimited strings. The chidlren are expected to be in proper id36 format.

Rereddit exposes superagent's Request object with a few additional convenience methods attached to each instance.

as(user)

The additional as method attached to the Request prototype simply fits the object with credentials to pass along to the reddit.com API.

limit(num)

Limit, as may be expected, is used for limiting the amount of results returned via a request geneerated by a call to read.

after(id)

As with limit, after simply tells the request that all results returned from a read request should follow after the specified id. The id is expected to be in proper id36 format.

Release v0.1.0

rereddit's People

Contributors

chuckpreslar avatar zfogg avatar

Watchers

Andre Steenveld avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.