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.

strawpoll's People

Contributors

kenany avatar probableprime avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

strawpoll's Issues

Voting

Would be cool to have the ability to vote on existing polls.

multi

multi: false
doesn't work for me.

Image of Yaktocat

Consider just using jsonist

Responses are so small that JSONStream is not really necessary at all. I think users will 99% of the time just end up concat-streaming the strawpoll stream so perhaps we might as well just turn this module into a callback API and perform GETs and POSTs with jsonist so that users don't need to use any module besides this one just to do simple stuff? This would be akin to something like backpack.tf.

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.