Socket
Socket
Sign inDemoInstall

redwrap

Package Overview
Dependencies
6
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.2 to 0.0.3

LICENSE.md

12

package.json
{
"name": "redwrap",
"version": "0.0.2",
"version": "0.0.3",
"description": "Redwrap simplifies Reddit API requests by providing an easy to use wrapper with jQuery style chaining.",

@@ -9,5 +9,9 @@ "main": "redwrap.js",

},
"devDependencies": {},
"devDependencies": {
"mocha": "~1.4.1",
"chai": "~1.2.0",
"sinon": "~1.4.2"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "./node_modules/mocha/bin/mocha"
},

@@ -26,4 +30,4 @@ "repository": {

"author": "Stephen Whatley",
"license": "BSD",
"license": "MIT",
"readmeFilename": "README.md"
}

@@ -15,11 +15,13 @@ #redwrap

This gives us access to 3 types of requests.
This gives us access to 3 types of requests. Each of these request types must be provided with a callback function. The arguments for the callback function are error, data, and response.
* error - will return any errors encountered during the request
* data - returns an object created by parsing the JSON in the response body
* response - returns the raw response from Reddit, including the body in JSON form.
###1.The basic user request
Redwrap uses the request module to issue requests behind the scenes. If you are familiar with request, you will notice the arguments for all of our callbacks in redwrap are the same.
```javascript
reddit.user('username', function(err, res, body){
console.log(body); //outputs json for the requested username
reddit.user('username', function(err, data, res){
console.log(data); //outputs a parsed javascript object represeting
});

@@ -32,4 +34,4 @@ ```

```javascript
reddit.r('WTF', function(err, res, body){
console.log(body); //outputs json for first page of WTF subreddit
reddit.r('WTF', function(err, data, res){
console.log(data); //outputs object representing first page of WTF subreddit
});

@@ -43,4 +45,4 @@ ```

```javascript
reddit.list('hot', function(err, res, body){
console.log(body); //json for the front page of reddit w/ 'hot' filter
reddit.list('hot', function(err, data, res){
console.log(data); //object representing the front page of reddit w/ 'hot' filter
});

@@ -52,4 +54,4 @@ ```

```javascript
reddit.list().hot().exe(function(err, res, body){
console.log(body);
reddit.list().hot().exe(function(err, data, res){
console.log(data);
});

@@ -87,4 +89,4 @@ ```

```javascript
reddit.user('username').sort('top').from('year').limit(100, function(err, res, body){
console.log(body); //top 100 comments this year for username
reddit.user('username').sort('top').from('year').limit(100, function(err, data, res){
console.log(data); //top 100 comments this year for username
});

@@ -91,0 +93,0 @@ ```

@@ -16,8 +16,3 @@ /*====================================

var parseJSON = function(myJSON, cb){
var parsed = JSON.parse(myJSON);
cb(parsed);
};
/*========== CONSTRUCTOR ==========*/

@@ -27,3 +22,3 @@

this.ee = new EventEmitter();
this.path = path || '';
this.path = path || '/';
this.filter = '';

@@ -33,3 +28,3 @@ this.url = {

, host: 'www.reddit.com'
, pathname : path + '/.json'
, pathname : path + '.json'
, query: {}

@@ -47,3 +42,14 @@ };

request(reqUrl, cb);
request.get(reqUrl, function(err, res, body){
try {
parsedBody = JSON.parse(body);
}
catch (parseError) {
return cb(parseError, null);
}
cb(err, parsedBody, res);
});
console.log('Requested URL: ' + reqUrl);

@@ -75,3 +81,3 @@ };

request(reqUrl, function(error, res, body){
request.get(reqUrl, function(error, res, body){
if (error) {

@@ -78,0 +84,0 @@ that.ee.emit('error', error);

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc