Coder Social home page Coder Social logo

npm's Introduction

utopian-api

This is the official npm package for the utopian api.

Build Status

Installation

To install this libary run: npm i utopian-api --save

Running Tests

For running tests locally run: npm test

Tests

  • Standard(Code Quality)
  • Chai & Mocha(API tests)

To fix small code quality issues

  • Check if standard is installed globally. If not, then run npm install -g standard

  • Type standard --fix

Methods

getModerators() : returns array of utopian moderators

getSponsors() : returns array of utopian sponsors

getModerator(username) : returns array with informations if username is an utopian moderator otherwise the array is empty

getSponsor(username) : returns array with informations if username is an utopian sponsor otherwise the array is empty

getPosts(options) : returns array of posts. Use options to apply filters.

getPostsByGithubProject(repoName, options) : returns array of posts related to github repositry. Use options (optionally) to apply filters.

getPendingPosts() : alias to get pending posts

getPendingPostsByModeratorAndCategory(moderator, category) : alias to get pending posts for the given moderator in the given category

getPendingPostsByModerator(moderator) : alias to get pending posts for the given moderator

getPendingPostsCount() : get total pending posts count

getTotalPostCount() : get total posts count

getStats() : get utopian statistics

Examples

Get all moderators and log their names:

const utopian = require('utopian-api');

utopian.getModerators().then((moderators) => {
    for (i = 0; i < moderators.results.length; i++) {
        console.log(moderators.results[i].account)
    }
});

Get all sponsors and log their names:

const utopian = require('utopian-api');

utopian.getSponsors().then((sponsors) => {
    for (i = 0; i < sponsors.results.length; i++) {
        console.log(sponsors.results[i].account)
    }
});

Check wether a user is a utopian.io mod:

const utopian = require('./api');
utopian.getModerator("wehmoen").then((result) => {
    console.log(result);
}); // returns [{_id: '5a4bf....}]
utopian.getModerator("ned").then((result) => {
    console.log(result);
}); //returns []

Get posts for the development category:

const utopian = require('utopian-api');

utopian.getPosts({
    sortBy: 'created',
    type: 'development'
}).then((posts) => {
    console.log(posts.results); //get the first 50 posts
});

utopian.getPosts({
    sortBy: 'created',
    type: 'development',
    skip: 50
}).then((posts) => {
    console.log(posts.results); //get the next 50 posts
});

Limit the number of results:

const utopian = require('utopian-api');

utopian.getPosts({
    sortBy: 'created',
    type: 'development',
    limit: 5
}).then((posts) => {
    console.log(posts.results); //get the first 5 posts
});

Get pending posts count:

const utopian = require('utopian-api');

utopian.getPendingPostsCount().then((count) => {
    console.log("There are " + count + " pending posts.");
})

Get total posts count:

const utopian = require('utopian-api');

utopian.getTotalPostCount().then((count) => {
    console.log("There are " + count + " posts on utopian.io. AMAZING!");
})

Get posts of utopian-io/utopian-api-npm project hosted on github:

const utopian = require('utopian-api');

utopian.getPostsByGithubProject('utopian-io/utopian-api-npm', {
    type: 'development'
}).then(response => {
    console.log("There are " + response.total + " posts on utopian-io/utopian-api-npm project. AMAZING!");
})
const utopian = require('utopian-api');

utopian.getStats().then((data) => {
  console.log(data);
})
let utopian = require('utopian-api');

utopian.getTopProjects({
    limit: 5,
    start_date: '2017-12-08',
    end_date: '2018-01-20',
    sort_by: 'contributions',   // contributions or rewards
    retrieve_by: 'projects',    // projects or contributions
    only_new: false
}).then((data) => {
    console.log(data); 
});

Get an Individual Post

let utopian = require('utopian-api');

utopian.getPost('ms10398','add-tests-ci-and-standard-code-quality-checks-in-npm-package').then((data) => {
    	console.log(data);
  	}
);

Get Post URL

let utopian = require('utopian-api');

utopian.getPostURL('26763950').then((data) => {
    	console.log(data);
  	}
);

Get Post By Author

let utopian = require('utopian-api');

utopian.getPostByAuthor('ms10398').then((data) => {
    	console.log(data);
  	}
);

Contribution

If you want to contribute to this package create a fork, make your changes and create a pull request.

npm's People

Contributors

adasq avatar codingdefined avatar espoem avatar hsyndeniz avatar jayserdny avatar ms10398 avatar

Watchers

 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.