devrant

    0.0.11 • Public • Published

    devRant

    NPM Version Build Status

    Unofficial wrapper for the public devRant API.

    devRant

    Requirements

    You need node version 6 or greater.

    Installation

    npm i -S devrant

    Interface

    This module exposes methods to fetch rants (posts) from devRant and to fetch the profile of a devRant user by username.

    devRant Display Requirements

    When displaying the contents of a rant fetched from the devRant API, it is required to credit the author of a rant by displaying their devRant username.

    Syntax

    devRant
      .rants()
      .then()
      .catch();

    Methods

    After requiring the module, the following methods can be used:

    METHOD ARGUMENTS RETURNS DESCRIPTION
    rant Yes Promise Retrieve a single rant from devRant. Use this method to retrieve a rant with its full text and comments. The retrieved rant is a Full Rant Object.
    rants Optional Promise Retrieve rants from devRant. The retrieved rants are Simple Rant Objects.
    search Yes Promise Retrieve rants from devRant that match a specific search term. The retrieved rants are Simple Rant Objects.
    profile Yes Promise Retrieve the profile of a devRant user by username. The retrieved profile is a Profile Object.

    .rant(id)

    Retrieve a single rant from devRant. Use this method to retrieve a rant with its full text and comments.

    The retrieved rant is a Full Rant Object.

    Arguments
    NAME TYPE DESCRIPTION
    id Number The rant id. For example 43511.
    Returns

    Promise.

    .rants(options)

    Retrieve rants from devRant.

    By providing an options Object as an argument, it's possible to sort by algo, recent and top rants. As well as limiting and skipping the amount of rants to be fetched.

    The retrieved rants are Simple Rant Objects.

    Arguments
    NAME TYPE DESCRIPTION
    options Object Optional. The options to control the rants to be fetched. When omitted, 50 rants of type algo will be fetched and 0 rants will be skipped.
    Options
    OPTIONS KEY TYPE DESCRIPTION
    sort String Optional. The type of rants to be fetched. Must be algo, recent or top. When omitted, it defaults to algo.
    limit Number Optional. The amount of rants to be fetched. When omitted, it defaults to 50.
    skip Number Optional. The amount of rants to be skipped. When omitted, it defaults to 0.
    Returns

    Promise.

    .search(term)

    Retrieve rants from devRant that match a specific search term.

    The retrieved rants are Simple Rant Objects.

    Arguments
    NAME TYPE DESCRIPTION
    term String The search term used to match specific rants. For example javascript, xcode, wk2, devrant, etc.
    Returns

    Promise.

    .profile(username)

    Retrieve the profile of a devRant user by username.

    The retrieved profile is a Profile Object.

    Arguments
    NAME TYPE DESCRIPTION
    username String The devRant username. For example danillouz, dfox, localhost, etc.
    Returns

    Promise.

    Rant Object Simple

    {
      "id": 43511,
      "text": "when people think you know everything...",
      "num_upvotes": 38,
      "num_downvotes": 1,
      "score": 37,
      "created_time": 1464610498,
      "attached_image": {
        "url": "https://d1fvlyhrbsf219.cloudfront.net/devrant/rant/r_43511_uQDW4.jpg",
        "width": 600,
        "height": 300
      },
      "num_comments": 5,
      "tags": [ ],
      "vote_state": 0,
      "user_id": 15601,
      "user_username": "Mung00se",
      "user_score": 272
    }

    Rant Object Full

    {
      "rant": {
        "id": 43511,
        "text": "when people think you know everything...",
        "num_upvotes": 39,
        "num_downvotes": 1,
        "score": 38,
        "created_time": 1464610498,
        "attached_image": {
          "url": "https://d1fvlyhrbsf219.cloudfront.net/devrant/rant/r_43511_uQDW4.jpg",
          "width": 600,
          "height": 300
        },
        "num_comments": 5,
        "tags": [ ],
        "vote_state": 0,
        "user_id": 15601,
        "user_username": "Mung00se",
        "user_score": 273
      },
      "comments": [
        {
          "id": 43529,
          "rant_id": 43511,
          "body": "But at some point we all do it.",
          "num_upvotes": 2,
          "num_downvotes": 0,
          "score": 2,
          "created_time": 1464611516,
          "vote_state": 0,
          "user_id": 505,
          "user_username": "Jumpshot44",
          "user_score": 2233
        }
      ],
      "success": true
    }

    Profile Object

    {
      "username": "danillouz",
      "score": 207,
      "about": "I spend too much time tweaking my terminal and color schemes..",
      "location": "The Netherlands",
      "created_time": 1463432703,
      "skills": "Node.js, JavaScript, mongoDB, GraphQL, ObjectiveC, Go",
      "github": "danillouz",
      "content": {
        "content": {
          "rants": [
            {
              "id": 38898,
              "text": "Me and my team are working on a system where we depend on a component that was built by a different dev team and hasn't been integration tested yet, because it's that new. This is how it's going..",
              "num_upvotes": 35,
              "num_downvotes": 0,
              "score": 35,
              "created_time": 1464211080,
              "attached_image": {
                "url": "https://d1fvlyhrbsf219.cloudfront.net/devrant/rant/r_38898_Z93E9.gif",
                "width": 380,
                "height": 230
              },
              "num_comments": 2,
              "tags": [
                "teams",
                "integration-testing",
                "dependencies"
              ],
              "vote_state": 0,
              "user_id": 27942,
              "user_username": "danillouz",
              "user_score": 207
            }
          ],
          "upvoted": [
            {
              "id": 42586,
              "text": "My office desk",
              "num_upvotes": 65,
              "num_downvotes": 0,
              "score": 65,
              "created_time": 1464530939,
              "attached_image": {
                "url": "https://d1fvlyhrbsf219.cloudfront.net/devrant/rant/r_42586_9jWtu.jpg",
                "width": 800,
                "height": 600
              },
              "num_comments": 18,
              "tags": [
                "mydesk"
              ],
              "vote_state": 0,
              "user_id": 13541,
              "user_username": "dvlpr",
              "user_score": 104
            }
          ],
          "comments": [
            {
              "id": 41422,
              "rant_id": 41065,
              "body": "@xroad Hodor",
              "num_upvotes": 3,
              "num_downvotes": 0,
              "score": 3,
              "created_time": 1464425475,
              "vote_state": 0,
              "user_id": 27942,
              "user_username": "danillouz",
              "user_score": 207
            }
          ]
        },
        "counts": {
          "rants": 5,
          "upvoted": 37,
          "comments": 16
        }
      }
    }

    Examples

    Fetch rant with id 43511

    'use strict';
     
    const devRant = require('devrant');
     
    devRant
      .rant(43511)
      .then(function receiveRant(rant) {
        console.log('rant: ', rant);
      })
      .catch(function errorHandler(err) {
        console.log('err: ', err.message);
      });

    Fetch 10 rants of type top and skip the first 10

    const devRant = require('devrant');
     
    devRant
      .rants({
        sort: 'top',
        limit: 10,
        skip: 10
      })
      .then(function receiveRants(rants) {
        console.log('rants: ', rants);
      })
      .catch(function errorHandler(err) {
        console.log('err: ', err.message);
      });

    Fetch 50 rants of type algo and skip 0 by using default behavior

    'use strict';
     
    const devRant = require('devrant');
    const co = require('co');
     
    function algoRants() {
      return co(function *fetchRants() {   
        const rants = yield devRant.rants();
     
        console.log(`rants: ${rants}`);
      });
    }
     
    algoRants();

    Fetch all rants that match the search term javascript

    'use strict';
     
    const devRant = require('devrant');
    const co = require('co');
     
    function search(term) {
      return co(function *searchRants() {   
        const rants = yield devRant.search(term);
     
        console.log(`rants: ${rants}`);
      });
    }
     
    search('javascript');

    Fetch the profile of the devRant user with username dfox

    'use strict';
     
    const devRant = require('devrant');
    const co = require('co');
     
    function getProfile(username) {
      return co(function *fetchProfile() {   
        const profile = yield devRant.profile(username);
     
        console.log(`profile: ${profile}`);
      });
    }
     
    getProfile('dfox');

    Install

    npm i devrant

    DownloadsWeekly Downloads

    1

    Version

    0.0.11

    License

    Apache-2.0

    Unpacked Size

    151 kB

    Total Files

    18

    Last publish

    Collaborators

    • danillouz