Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit 37cfc70fee2d3e1c8c12b6f723a8c79cb2f21578 0 parents
@caseypt authored
1  .gitignore
@@ -0,0 +1 @@
+node_modules
11 README.md
@@ -0,0 +1,11 @@
+# node-pollster
+
+A small Node.js wrapper for the [Huffington Post Pollster API](http://elections.huffingtonpost.com/pollster/api).
+
+## Installation
+
+npm install pollster
+
+## Getting Started
+
+ var pollster = require('pollster')
1  index.js
@@ -0,0 +1 @@
+module.exports = require('./lib/pollster');
BIN  lib/.DS_Store
Binary file not shown
48 lib/pollster.js
@@ -0,0 +1,48 @@
+exports.version = '0.0.1';
+
+var request = require('request');
+
+(function(pollster) {
+
+ var config = {
+ 'API_SERVER' : 'elections.huffingtonpost.com',
+ 'API_BASE': '/pollster/api'
+ };
+
+ _buildRequestUrl = function(path, params) {
+ var url = 'http://' + config.API_SERVER + config.API_BASE + '/' + path;
+
+ return url;
+ };
+
+ _invoke = function(path, params, callback) {
+ var url = _buildRequestUrl(path, params);
+
+ request(url, {qs: params}, function (error, response, body) {
+ if (!error && response.statusCode == 200) {
+ callback(JSON.parse(body));
+ } else {
+ console.log(body);
+ }
+ });
+ };
+
+ pollster.charts = function(params, callback) {
+ _invoke('charts', params, function(result){
+ callback(result);
+ });
+ };
+
+ pollster.chart = function(slug, callback) {
+ _invoke('charts/' + slug, {}, function(result){
+ callback(result);
+ });
+ };
+
+ pollster.polls = function(params, callback) {
+ _invoke('polls/', params, function(result){
+ callback(result);
+ });
+ };
+
+}(typeof module == 'object' ? module.exports : window.pollster = {}));
17 package.json
@@ -0,0 +1,17 @@
+{
+ "name": "pollster",
+ "description": "A thin wrapper for the Huffington Post Pollster API",
+ "author": "Casey Thomas <c@cpt.ph>",
+ "version": "0.0.1",
+ "main": "lib/pollster",
+ "repository": {
+ "type": "git",
+ "url": "http://github.com/caseypt/node-pollster.git"
+ },
+ "dependencies": {
+ "request": ">=2.11.1"
+ },
+ "engines": {
+ "node": "0.8.x"
+ }
+}
13 test/test.js
@@ -0,0 +1,13 @@
+var pollster = require('../lib/pollster');
+
+/*pollster.charts({'state': 'PA'}, function(result){
+ console.log(result);
+});
+
+pollster.chart('2012-pennsylvania-gop-primary', function(result){
+ console.log(result);
+});*/
+
+pollster.polls({'state': 'PA', 'topic': '2012-house'}, function(result){
+ console.log(result);
+});
Please sign in to comment.
Something went wrong with that request. Please try again.