GithubHelp home page GithubHelp logo

reddit-api's Introduction

Welcome!

This is a project to wrap and make the Reddit API easily accessible to your node.js applications.

See the Reddit API documentation for details on what to do.

Please note, this is not finished. I will be developing it as I go He didn't. I am working on my own projects to leverage the reddit API, so I started the effort. Pull requests are very welcome!

Documentation

Go to the documentation!

Example

Please don't mind the coffeescript example for the time being. Again, this is a work in prorgess. :) This is not a work in progress.

You would launch this like: user=foo password=bar coffee test.coffee

Immediate mode (default):

Reddit = require 'reddit-api'

reddit = new Reddit 'cutebot v0.1 by /u/YOUR_REDDIT_USERNAME_HERE'

# Enable logging.
reddit.setIsLogging true

# Login operation.
{user, password} = process.env
reddit.login user, password, (error) ->

    throw error if error?

	# Check the user's inbox.
	reddit.messages (error, messages) ->

		throw error if error?

		console.log messages

Deferred (burst) mode:

Reddit = require 'reddit-api'

reddit = new Reddit 'cutebot v0.1 by /u/YOUR_REDDIT_USERNAME_HERE'

# Enable logging.
reddit.setIsLogging true

# Login operation.
{user, password} = process.env
reddit.login user, password, (error) ->

    throw error if error?

	# Deferred dispatching.
	reddit.setDispatchMode 'deferred'

	# Check the user's inbox.
	reddit.messages (error, messages) ->

		throw error if error?

		console.log messages

	console.log 'Chilling for 2 seconds before the burst!'
	setTimeout(
		-> reddit.burst()
		2000
	)

Rate-limited mode:

Reddit = require 'reddit-api'

reddit = new Reddit 'cutebot v0.1 by /u/YOUR_REDDIT_USERNAME_HERE'

# Enable logging.
reddit.setIsLogging true

# Rate-limited dispatching.
reddit.setDispatchMode 'limited'

# Login operation.
{user, password} = process.env
reddit.login user, password, (error) ->

    throw error if error?

# Check the user's inbox.
reddit.messages (error, messages) ->

	throw error if error?

	console.log messages

# Notification when all queued operations are complete.
reddit.on 'drain', ->

    # Shut it down.
    reddit.setDispatchMode 'immediate'

TODO

  • Obviously, implement more of the API including OAuth

reddit-api's People

Contributors

michaelowens avatar cha0s avatar

Watchers

 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.