Giter VIP home page Giter VIP logo

jaraw's Introduction

Jaraw - just another reddit api wrapper dependencies devDependencies Build Status

So far it only supports bots/personal scripts. Hopefully more options will come.

Installation

npm install jaraw

Usage

As a bot/personal script

Jaraw = require 'jaraw'

options =
  type: 'script'
  login:
    username: 'your username'
    password: 'your password'
  oauth:
    id: 'client id'
    secret: 'client secret'
  user_agent: 'custom useragent'

reddit = new Jaraw options

reddit.loginAsScript ->
  reddit.get '/api/v1/me', doStuff

You can add a "rate_limit" property to the options object that can be as low as 1000. By default, it is 2000.

Logging out

reddit.logout -> console.log "All logged out!"

Note: Due to the fact that refresh tokens are not given to personal scripts, using reddit.get or reddit.post after you've logged out will log you in again.

Anonymous usage:

reddit = new Jaraw "custom useragent"
reddit.get('/r/all.json', doStuff)

Example:

Suppose you're looking at the reddit API's section on submitting a new link.

The method is "POST", the endpoint is "/api/submit" and the oauth scope is "submit". (As of the most current version, the only way to use it is as a personal script, which uses all scopes.)

Then we can do the following, after logging in:

params =
   api_type: 'json'
   kind: 'self'
   sr: 'test'
   text: 'THIS IS A TEST! DO NOT UPVOTE!'
   title: 'testing ... '

reddit.post '/api/submit', params

Building

$ npm install
$ grunt

This creates jaraw.js in the build folder. Alternatively, you can do each of these individually:

grunt coffeelint
grunt mochaTest:tests
grunt coffee
grunt uglify

Running tests

grunt mochaTest:tests

By default, running the above command won't run tests that actually make requests to reddit's servers.

To run those, use grunt mochaTest:integration. Note: this also tests .js files in the build folder, so make sure you build this before running integration tests. Also, you may need to adjust timeout in the gruntfile.

LICENSE

Copyright © 2015 Thimoteus

This work is free. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See the LICENSE file for more details.

jaraw's People

Contributors

thimoteus avatar

Watchers

 avatar  avatar  avatar

jaraw's Issues

JSON.parse sometimes fails

Probably caused by a bad response in trying to get an access token.

SyntaxError: Unexpected token <
    at Object.parse (native)
    at i (.../node_modules/jaraw/build/jaraw.js:1:1565)

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.