Update Utopian.Rocks API wrapper for Node.js, New Features v0.1.6

Words
159
Reading
1 min
Listen
Play
8y

Repository

https://github.com/gigatoride/node-utopian-rocks

utopian_mascot.png

Intro image source edited by gigatoride

New Features

  • Replace old aliases like utopian.getModerators to utopian.stats.getModeratorsByDate
  • Advanced statistics methods
  • Moderator Checker
  • New Endpoints

New method aliases

// Retrive moderators list
utopian.getModerators()

// Check if moderator username is valid
utopian.isModerator(param)

// Retrive all time moderators statistics
utopian.stats.getModerators(params)

// Retrive all time projects statistics
utopian.stats.getProjects(params)

// Retrive all time contributors statistics
utopian.stats.getContributors(params)

// Retrive all moderators by date
utopian.stats.getModeratorsByDate(param)

// Retrive all projects by date
utopian.stats.getProjectsByDate(param)

// Retrive all staff picks by date
utopian.stats.getStaffPicksByDate(param)

// Retrive all staff categories by date
utopian.stats.getCategoriesByDate(param)

// Retrive all tasks requests by date
utopian.stats.getTasksRequestsByDate(param)

Improve API Test

Test using jest in this commit I've improved the testing:

npm test

Results:
jest

New Endpoints and Improve API

this commit I've made general improvements and removed old endpoints like in the switch statment and replaced it with:

let endpoints = {
  stats: require('./lib/stats')
}; // JS object for API endpoints. 

I've also added moderator checker isModerator() as a new endpoint

endpoints.isModerator = (username) => axios.get(API_URL + '/moderators') // Requesting moderators endpoint
  .then(function (response) {
    return response.data.includes(username) // Returns true or false.
  })
  .catch(function (error) {
    return error; // Returns an error of something wrong with response.
  });

More statistics

In this commit I've created a file for stats that will be exported to api.js

For example I've created the following algorithm to count the total reviewed contribtuions by all moderators with descending order.

      response.data.filter(body => {
        // tests whether at least one moderator in the array passes the test implemented by the provided function.
        if (moderators.some(obj => obj.moderator === body.moderator)) {
          // returns the index of the first moderator in the array that satisfies the provided testing function. Otherwise -1 is returned.
          let objIndex = moderators.findIndex(
            obj => obj.moderator == body.moderator //  If moderator already exist in the array of objects
          );
          moderators[objIndex].reviewed++; // Count reviewed contributions by moderator
        } else
          // If not exist push it into the array.
          return moderator.push({
            moderator: body.moderator, // Moderator username
            reviewed: 1 // Number of reviewed contributions
          });
      });
      return moderators.sort((a, b) => b.reviewed - a.reviewed); // Sort moderators descendingly by number of reviews.

I also created similar algorthim in utopian.stats.getContributors() and utopian.stats.getProjects() with different options, usage.

README.md

In this README.md commit is the current documention for usage, however, I'm currently preparing doc directory that will has a more detailed usage for all method aliases.

GitHub Account

https://github.com/gigatoride

Update Utopian.Rocks API wrapper for Node.js, New Features v0.1.6 | Ecency