reddit-api-generator

Generates the Reddit API into various formats

npm install reddit-api-generator
16 downloads in the last week
23 downloads in the last month

reddit-api-generator

Transforms the auto generated Reddit API into various formats for consumption by anyone looking to write a wrapper for the Reddit API.

The dist/ folder contains the various outputs.

Supported formats

  • JSON
  • Node.js
  • AMD

Install

You can clone this repository, or use one of the following package managers:

npm

npm install reddit-api-generator

bower

npm install reddit-api-generator

Usage

You can clone the repository and pull out files you wish to use, or use the appropriate include for your platform:

node

var redditApi = require('reddit-api-generator');

AMD

requirejs(['reddit-api-generator'], function(redditApi) {

});

Data Format (JSON example)

The JSON follows the format that the API does. Given:

/api/v1/me

The JSON path would be:

api.v1.me

Information returned (JSON example)

Every endpoint has enough data with it to create an call to the Reddit API. Here is [/r/subreddit]/new (More endpoint examples can be found in the ./dist folder):

{
    "oauth": [
        "read"
    ],
    "extensions": [
        ".json",
        ".xml"
    ],
    "method": "GET",
    "path": "/r/$subreddit/new",
    "url": {
        "oauth": "https://oauth.reddit.com/r/$subreddit/new",
        "standard": "http://www.reddit.com/r/$subreddit/new"
    },
    "describe": "This endpoint is a listing.",
    "args": {
        "after": {
            "describe": "fullname of a thing"
        },
        "before": {
            "describe": "fullname of a thing"
        },
        "count": {
            "describe": "a positive integer (default: 0)"
        },
        "limit": {
            "describe": "the maximum number of items desired (default: 25, maximum: 100)"
        },
        "show": {
            "describe": "(optional) the string all"
        }
    }
}

Url parameters (JSON example)

Sometimes there are parameters in the url. These are represented with a "$" prepending the name of the variable. Given this path:

/api/multi/{multipath}/r/{srname}

The JSON path would be:

api.multi.$multipath.r.$srname

Misc.

url's: standard vs. oauth

There is a lack of documentation (?) on which endpoints can work with either OAuth / Login / Anonymously.

Take [/r/subreddit]/new for example:

"url": {
    "oauth": "https://oauth.reddit.com/r/$subreddit/new",
    "standard": "http://www.reddit.com/r/$subreddit/new"
},

This endpoint can be called with OAuth, with a simple login, or anonymously. Other endpoints that require OAuth can't be called with anything but OAuth.

Because of this, both oauth & standard url routes are provided when the endpoint supports some form of OAuth. Later versions may address this issue.

Test

If you wish to generate a new version of the API, make sure the tests still pass:

npm test

Building

Run the command ./buildApi -h to get started. The buildAll.sh script will automatically generate every variation provided.

npm loves you