Code Monkey home page Code Monkey logo

node-potato's Introduction

Node Potato

Status GitHub Issues GitHub Pull Requests License


Table of Contents


About

Node Potato is a JavaScript API wrapper for Opinion Potato. It provides a simple and easy-to-use interface for interacting with the Opinion Potato API, allowing you to easily add Opinion Potato functionality to your own applications.

An API key and API identifier is required to use this API wrapper. To obtain an API Key, you must first contact: [email protected] asking for a key, stating what you will use it for, and how you will interact with it.

If your application is successful, an API key and API identifier key will be sent to you via email.

API Key = This is your secure key for authenticating with the API. You should never share this with anyone. If you need a new key, contact [email protected]

API Identifier = This is a unique number assigned to you which will allow you to query your own polls separately from the public list. This is mainly used when interacting with Private polls that you have created


Installing

For Installation With NPM

npm i node-potato

Usage

Below is the basic usage of Node Potato

Create Potato

Creating the potato object

const { potato } = require("node-potato");

//Creates a new potato object
let Potato = new potato({apiKey: "API_KEY", apiIdentifier: API_IDENTIFIER});

Note: API_IDENTIFIER must be passed as an int

Get Poll

Get a poll

//Get an opinion potato poll with the Id 626288817
Potato.getPoll(626288817).then((value) =>{

    console.log(value);

});

/*expected output:{
  pollId: 626288817,
  question: 'Which political system do you believe in',
  topic: 'politics',
  optionA: 'Democracy',
  optionB: 'Socialism',
  optionAVotes: 2,
  optionBVotes: 141,
  CreatedOn: '2023-07-30T23:19:39.228Z',
  archived: false,
  visibility: 'Public',
  pollSlug: 'which-political-system-do-you-believe-in-democracy-or-socialism'
}*/

Get All Polls

Gets all public polls listed on opinion potato

//Gets all public polls
Potato.getAllPolls().then((value) =>{

    console.log(value);

});

/*expected output:[
    {
        pollId: 626288817,
        question: 'Which political system do you believe in',
        topic: 'politics',
        optionA: 'Democracy',
        optionB: 'Socialism',
        optionAVotes: 2,
        optionBVotes: 141,
        CreatedOn: '2023-07-30T23:19:39.228Z',
        archived: false,
        visibility: 'Public',
        pollSlug: 'which-political-system-do-you-believe-in-democracy-or-socialism'
    },
    ...
]*/

Get Private Poll

Get a poll you have created that is private

//Gets the private poll with the Id 644304039
Potato.getPrivatePoll(644304039).then((value) =>{

    console.log(value);

});

/*expected output:{
        pollId: 626288817,
        question: 'Which political system do you believe in',
        topic: 'politics',
        optionA: 'Democracy',
        optionB: 'Socialism',
        optionAVotes: 2,
        optionBVotes: 141,
        CreatedOn: '2023-07-30T23:19:39.228Z',
        archived: false,
        visibility: 'Private',
        pollSlug: 'which-political-system-do-you-believe-in-democracy-or-socialism'
    }*/

Vote Poll

Vote on a poll

//Votes on the poll with and Id of 992659119 option A
Potato.submitVote(992659119, "A").then((value) =>{

    console.log(value);
    
});
//expected output: { Message: 'Vote applied successfully', optionA: 5, optionB: 0 }


//Votes on the poll with and Id of 992659119 option B
Potato.submitVote(992659119, "B").then((value) =>{

    console.log(value);
    
});
//expected output: { Message: 'Vote applied successfully', optionA: 5, optionB: 1 }

Create Poll

Creates a public poll on Opinion Potato

//Create the options for the poll
const options = {
    "question":"test poll for the api wrapper",
    "optionA":"optionA",
    "optionB":"optionB",
    "topic":"science-technology",
    "visibility":"Public"
}

//Submit poll to Opinion Potato
Potato.createPoll(options).then((value) =>{

    console.log(value)

})

//expected output: { pollId: 133486009 }


//Create the options for the poll
const options = {
    "question":"test private poll for the api wrapper",
    "optionA":"optionA",
    "optionB":"optionB",
    "topic":"science-technology",
    "visibility":"Private"
}

//Submit a private poll to Opinion Potato
Potato.createPoll(options).then((value) =>{

    console.log(value)

})

//expected output: { pollId: 133486036 }

Note:

  • The question should not include a question mark (?)
  • A poll must not already exist with the same question and answer combination
  • Topic must include one of the following:
    • music
    • arts-crafts
    • religion
    • politics
    • sport
    • food-drink
    • literature
    • science-technology
    • education
    • nature-environment
    • fashion
    • history
    • lifestyle
    • climate
    • celebrities
    • society
    • health
    • countries
    • war
    • space
    • culture
    • travel
    • beliefs
    • gaming
    • money

Authors

node-potato's People

Contributors

yoloftw avatar

Stargazers

 avatar

Watchers

 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.