node package manager

strawpoll

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.