Socket
Socket
Sign inDemoInstall

snoowrap

Package Overview
Dependencies
56
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.8.0 to 0.9.0

lib/request_handler.js

5

lib/constants.js

@@ -28,3 +28,4 @@ module.exports = {

LiveUpdateEvent: 'LiveThread',
LiveUpdate: 'LiveUpdate'
LiveUpdate: 'LiveUpdate',
LabeledMulti: 'MultiReddit'
},

@@ -34,3 +35,3 @@ USERNAME_REGEX: /^[\w-]{1,20}$/,

LIVETHREAD_PERMISSIONS: ['update', 'edit', 'manage'],
HTTP_VERBS: ['get', 'head', 'post', 'put', 'delete', 'trace', 'options', 'connect', 'patch']
HTTP_VERBS: ['del', 'get', 'head', 'patch', 'post', 'put']
};

4

lib/errors.js

@@ -10,3 +10,3 @@ /* eslint-disable max-len */

this.name = 'RateLimitError';
this.message = `${ constants.MODULE_NAME }.errors.${ this.name }: ${ constants.MODULE_NAME } refused to continue because reddit's ratelimit was exceeded. For more information about reddit's ratelimit, please consult reddit's API rules at ${ constants.API_RULES_LINK }. To avoid hitting the ratelimit again, you should probably wait at least ${ expiry_time_from_now } seconds before making any more requests.`;
this.message = `${ constants.MODULE_NAME }.errors.${ this.name }: ${ constants.MODULE_NAME } refused to continue because reddit's ratelimit was exceeded. For more information about reddit's ratelimit, please consult reddit's API rules at ${ constants.API_RULES_LINK }. To avoid hitting the ratelimit again, you should probably wait at least ${ expiry_time_from_now } milliseconds before making any more requests.`;
}

@@ -28,3 +28,3 @@ },

},
RateLimitWarning: time_until_reset => `Warning: ${ constants.MODULE_NAME } temporarily stopped sending requests because reddit's ratelimit was exceeded. The request you attempted to send was queued, and will be sent to reddit when the current ratelimit period expires in ${ time_until_reset } seconds.`,
RateLimitWarning: time_until_reset => `Warning: ${ constants.MODULE_NAME } temporarily stopped sending requests because reddit's ratelimit was exceeded. The request you attempted to send was queued, and will be sent to reddit when the current ratelimit period expires in ${ time_until_reset } milliseconds.`,
NoCredentialsError: class extends Error {

@@ -31,0 +31,0 @@ constructor() {

{
"name": "snoowrap",
"version": "0.8.0",
"version": "0.9.0",
"license": "MIT",

@@ -11,4 +11,4 @@ "description": "A Node.js wrapper for the reddit API",

"pretest": "npm run lint && npm run compile",
"test": "mocha --harmony_proxies --compilers js:babel-core/register",
"docs": "jsdoc lib/snoowrap.js -c jsdoc.conf.json"
"test": "mocha --harmony-proxies --compilers js:babel-core/register",
"docs": "npm run compile && jsdoc -c jsdoc.conf.json lib/snoowrap.js lib/objects/RedditContent.js lib/objects/ReplyableContent.js lib/objects/VoteableContent.js lib/objects/Comment.js lib/objects/RedditUser.js lib/objects/Submission.js lib/objects/LiveThread.js lib/objects/PrivateMessage.js lib/objects/Subreddit.js lib/objects/MultiReddit.js lib/objects/WikiPage.js lib/objects/Listing.js"
},

@@ -43,3 +43,3 @@ "repository": {

"moment": "^2.11.2",
"promise-chains": "^0.2.4",
"promise-chains": "^0.2.6",
"request-promise": "^2.0.1",

@@ -59,3 +59,3 @@ "ws": "^1.0.1"

"eslint-plugin-babel": "^3.1.0",
"ink-docstrap": "^1.1.3",
"ink-docstrap": "^1.1.4",
"jsdoc": "^3.4.0",

@@ -62,0 +62,0 @@ "mocha": "^2.4.5"

@@ -7,7 +7,10 @@ # snoowrap [![Build Status](https://travis-ci.org/not-an-aardvark/snoowrap.svg?branch=master)](https://travis-ci.org/not-an-aardvark/snoowrap)

* If you've used [PRAW](https://praw.readthedocs.org/en/stable/), you'll probably find a lot of snoowrap's syntax to be familiar. However, aside from being written in a different language, there are a few important differences.
* For example, unlike PRAW, snoowrap is non-blocking; all API calls are async and return bluebird Promises. This means that you can handle asynchronous events however you want, and you can use snoowrap as part of a larger process without it holding everything back.
snoowrap supports every API endpoint, and provides a simple interface to access each of them. The method to get a user profile is just `get_user()`, and the method to upvote something is just `upvote()`. There's no need to look up REST endpoints or deal with low-level HTTP requests.
If you've used [PRAW](https://praw.readthedocs.org/en/stable/), you'll probably find a lot of snoowrap's syntax to be familiar. However, aside from being written in a different language, there are a few important differences:
* Unlike PRAW, snoowrap is non-blocking; all API calls are async and return bluebird Promises. This means that you can handle asynchronous events however you want, and you can use snoowrap as part of a larger process without it holding everything back.
* Each snoowrap object is completely independent. If you want, you can have scripts from separate accounts make requests at the same time.
* snoowrap's objects are structured to keep the syntax as simple as possible. So the following expression:
snoowrap's objects are structured to keep the syntax as simple as possible. So the following expression:
```javascript

@@ -40,3 +43,3 @@ r.get_submission('2np694').body

* snoowrap handles many API interactions such as authentication, ratelimiting, error correction, and HTTP requests internally, so that you can write less boilerplate code and focus more on doing what you want to do.
snoowrap handles all API interactions such as authentication, ratelimiting, error correction, and HTTP requests under the hood. That way, you can write less boilerplate code and focus more on doing what you actually want to do.
* After you provide a token once, snoowrap will refresh it on its own from then on -- you won't have to worry about authentication again.

@@ -49,4 +52,6 @@ * snoowrap uses lazy objects, so it never fetches more than it needs to.

### Quick example file
---
### Simple example file
```javascript

@@ -100,2 +105,5 @@ 'use strict';

// Printing the content of a wiki page
r.get_subreddit('AskReddit').get_wiki_page('bestof').content_md.then(console.log);
```

@@ -105,7 +113,42 @@

### To include in a project:
### Live threads
Reddit's [live threads](https://www.reddit.com/r/live/wiki/index) are different from most other content, in that messages are distributed through websockets instead of a RESTful API. snoowrap fully supports this protocol under the hood, and it represents the content stream as an [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter). For example, the following code will stream all livethread updates to the console as they appear:
```javascript
r.get_livethread('whrdxo8dg9n0').stream.on('update', console.log);
```
For more information, see snoowrap's [LiveThread documentation page](https://not-an-aardvark.github.io/snoowrap/LiveThread.html).
---
### Important note regarding ES6
snoowrap uses the `Proxy` object introduced in ES6. Since this is not yet included in Node by default, you will need to run your project with the `--harmony-proxies` runtime flag, e.g. `node --harmony-proxies yourProject.js`. With regard to running code in browsers, as of February 2016 the only browsers that support Proxies are Chrome 49+ and Microsoft Edge.
If you *can't* use that node flag for some reason, or your code is running in a non-supporting browser, snoowrap will still function. However, method chaining as described above won't work, so your syntax will need to be a bit heavier.
For example:
```javascript
// This works when run with node's --harmony-proxies flag, or with a browser that supports Proxies.
// However, it fails if Proxies are not available.
r.get_submission('47v7tm').comments[0].upvote();
// ----------
// This is equivalent and works on all platforms, but the syntax isn't as nice.
// Note: .get() and .call() are the standard bluebird utility methods.
r.get_submission('47v7tm').fetch().get('comments').get(0).call('upvote');
```
---
### To include in a project
1. `npm install snoowrap --save`
1. `var snoowrap = require('snoowrap');`
### To build/run the tests independently:
### To build/run the tests independently
1. `git clone https://github.com/not-an-aardvark/snoowrap.git`

@@ -118,4 +161,2 @@ 1. `cd snoowrap`

Note: snoowrap uses the `Proxy` object introduced in ES6. Since this is not yet included in Node by default, you will need to run your project with the `--harmony-proxies` flag. E.g. `node --harmony-proxies yourProject.js`
snoowrap is currently in active development; while it provides shortcuts for a large number of API endpoints, it is not yet feature-complete. See [here](https://not-an-aardvark.github.io/snoowrap) for full documentation.

Sorry, the diff of this file is too big to display

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