Giter VIP home page Giter VIP logo

strawpoll's Introduction

strawpoll

Build Status Dependency Status

Create and get polls on Straw Poll.

Example

Here's an example using concat-stream:

var concat = require('concat-stream');
var strawpoll = require('strawpoll');

var stream = strawpoll({
  title: 'My first poll',
  options: [
    'wow',
    'awesome',
    'amazing',
    'nice'
  ],
  multi: false,
  permissive: true
});

stream.pipe(concat(function(poll) {
  poll = JSON.parse(poll);
  // poll.id is your poll's id
  // check out your poll at strawpoll.me/id
}));

Add JSONStream and you don't even have to use JSON.parse yourself!

var concat = require('concat-stream');
var JSONStream = require('JSONStream');
var strawpoll = require('strawpoll');

var stream = strawpoll({
  title: 'My first poll',
  options: [
    'wow',
    'awesome',
    'amazing',
    'nice'
  ],
  multi: false,
  permissive: true
})
  .pipe(JSONStream.parse('id'))
  .pipe(concat(function(id) {
    // `id` is a Buffer here
    // `id.toString()` is your poll's id
  }));

An example of getting a poll with concat-stream:

var concat = require('concat-stream');
var strawpoll = require('strawpoll');

var stream = strawpoll.get(1)
  .pipe(concat(function(poll) {
    poll = JSON.parse(poll);
    // poll.id is the id you requested
    // poll.title is the title of the poll
  }));

The JSON parsed response will match examples from the Straw Poll API.

Installation

$ npm install strawpoll

API

var strawpoll = require('strawpoll');

strawpoll(options)

Returns a hyperquest stream which is POSTing to Straw Poll in order to create your poll.

options:

  • title (String)
  • options (Array)
  • multi (Boolean)
  • permissive (Boolean)

strawpoll.create(options)

Alias of just strawpoll(options).

strawpoll.get(id)

Returns a hyperquest stream which is GETing poll information from Straw Poll based on Number id.

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.