Socket
Socket
Sign inDemoInstall

stackexchange

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stackexchange - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

lib/methods/answers.js

2

lib/config.js

@@ -8,3 +8,3 @@ 'use strict';

api: 'api.stackexchange.com'
, protocol: 'http:'
, protocol: 'https:'
, site: 'stackoverflow'

@@ -11,0 +11,0 @@ , version: 2.2

@@ -7,2 +7,3 @@ 'use strict';

var query = require('../query')
, post = require('../post')
, Logger = require('devnull')

@@ -38,4 +39,42 @@ , log = new Logger({ timestamp: false });

/**
* upvote - Casts an upvote on the selected question
*
* @param {Object} criteria contains server key and valid access_token
* @param {Integer} id ID of a question
* @param {Function} callback return results
* @param {Boolean} undo Undo the upvote cast
* @api public
*/
function upvote(criteria, id, callback, undo) {
// Key and Access Token are needed in criteria
if(!criteria['key'] || !criteria['access_token']) {
return log.error('questions.upvote lacks key and/or access token as criteria');
}
undo = undo? "/undo" : "";
post('questions/' + id.toString() + '/upvote' + undo, criteria, callback);
}
/**
* downvote - Casts a downvote on the selected question
*
* @param {Object} criteria contains server key and valid access_token
* @param {Integer} id ID of a question
* @param {Function} callback return results
* @param {Boolean} undo Undo the downvote cast
* @api public
*/
function downvote(criteria, id, callback, undo) {
// Key and Access Token are needed in criteria
if(!criteria['key'] || !criteria['access_token']) {
return log.error('questions.upvote lacks key and/or access token as criteria');
}
undo = undo? "/undo" : "";
post('questions/' + id.toString() + '/downvote' + undo, criteria, callback);
}
// Expose commands.
module.exports.questions = questions;
module.exports.answers = answers;
module.exports.upvote = upvote;
module.exports.downvote = downvote;
'use strict';
var config = require('./config')
, parser = require('./parser')
, request = require('request')
, url = require('url')
, zlib = require('zlib')
, Logger = require('devnull')

@@ -11,20 +11,2 @@ , log = new Logger({ timestamp: false });

/**
* Parse the buffer, StackExchange promises to always deliver zipped content,
* but since JSON parsing is required just wrap it in a try/catch.
*
* @param {Buffer} buffer response content
* @param {Function} callback return results
* @api private
*/
function parseBody (buffer, callback) {
zlib.unzip(buffer, function Unzipped (error, body) {
try {
callback(error, JSON.parse(body.toString()));
} catch (error) {
callback(error);
}
});
}
/**
* Execute a query after checkign if criteria are available.

@@ -56,4 +38,4 @@ *

}
else {
parseBody.call(this, res.body, callback);
else {
parser.parseBody.call(this, res.body, callback);
}

@@ -60,0 +42,0 @@ }

@@ -7,2 +7,3 @@ 'use strict';

, questions = require('./methods/questions')
, answers = require('./methods/answers')
, users = require('./methods/users');

@@ -27,3 +28,4 @@

this.questions = questions;
this.answers = answers;
this.users = users;
};
{
"name": "stackexchange",
"version": "0.1.0",
"version": "0.2.0",
"description": "Node.js implementation of the stackexchange/stackoverflow API",

@@ -5,0 +5,0 @@ "main": "./lib/stackexchange",

@@ -23,3 +23,3 @@ /*global expect*/

it('has default protocol', function () {
expect(config.get('protocol')).to.equal('http:');
expect(config.get('protocol')).to.equal('https:');
});

@@ -26,0 +26,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc