Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@orbit-love/reddit

Package Overview
Dependencies
Maintainers
4
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@orbit-love/reddit - npm Package Compare versions

Comparing version 0.3.2 to 0.3.3

.env.sample

3

package.json
{
"name": "@orbit-love/reddit",
"version": "0.3.2",
"version": "0.3.3",
"description": "Integrate Reddit interactions into Orbit workspaces",

@@ -34,2 +34,3 @@ "main": "./src/index.js",

"@orbit-love/activities": "^0.1.1",
"dotenv": "^10.0.0",
"moment": "^2.29.1",

@@ -36,0 +37,0 @@ "snoowrap": "^1.23.0",

@@ -12,4 +12,4 @@ # Reddit to Orbit Workspace

|<p align="left">:sparkles:</p> This is a *community project*. The Orbit team does its best to maintain it and keep it up to date with any recent API changes.<br/><br/>We welcome community contributions to make sure that it stays current. <p align="right">:sparkles:</p>|
|-----------------------------------------|
| <p align="left">:sparkles:</p> This is a _community project_. The Orbit team does its best to maintain it and keep it up to date with any recent API changes.<br/><br/>We welcome community contributions to make sure that it stays current. <p align="right">:sparkles:</p> |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

@@ -22,7 +22,7 @@ ![There are three ways to use this integration. Install package - build and run your own applications. Run the CLI - run on-demand directly from your terminal. Schedule an automation with GitHub - get started in minutes - no coding required](docs/ways-to-use.png)

2. Create a new app with the following settings:
1. Name: `orbit-community-integration`
2. Type: `script`
3. Description: `orbit.love community integration`
4. About URL: `https://github.com/orbit-love/community-js-reddit-orbit`
5. Redirect URI: `https://orbit.love`
1. Name: `orbit-community-integration`
2. Type: `script`
3. Description: `orbit.love community integration`
4. About URL: `https://github.com/orbit-love/community-js-reddit-orbit`
5. Redirect URI: `https://orbit.love`
3. Take note of your `Client ID` which is just below your app name, and your `Client Secret`.

@@ -34,11 +34,17 @@

| Variable | Description | More Info
|---|---|--|
| `REDDIT_CLIENT_ID` | Client ID for your Reddit App | Follow the guide above
| `REDDIT_CLIENT_SECRET` | Client Secret for your Reddit App | Follow the guide above
| `REDDIT_USERNAME` | Your Reddit username | Your account credentials
| `REDDIT_PASSWORD` | Your Reddit password | Your account credentials
| `ORBIT_API_KEY` | API key for Orbit | Found in `Account Settings` in your Orbit workspace
| `ORBIT_WORKSPACE_ID` | ID for your Orbit workspace | Last part of the Orbit workspace URL, i.e. `https://app.orbit.love/my-workspace`, the ID is `my-workspace`
| Variable | Description | More Info |
| ---------------------- | --------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| `REDDIT_CLIENT_ID` | Client ID for your Reddit App | Follow the guide above |
| `REDDIT_CLIENT_SECRET` | Client Secret for your Reddit App | Follow the guide above |
| `REDDIT_USERNAME` | Your Reddit username\* | Your account credentials |
| `REDDIT_PASSWORD` | Your Reddit password | Your account credentials |
| `ORBIT_API_KEY` | API key for Orbit | Found in `Account Settings` in your Orbit workspace |
| `ORBIT_WORKSPACE_ID` | ID for your Orbit workspace | Last part of the Orbit workspace URL, i.e. `https://app.orbit.love/my-workspace`, the ID is `my-workspace` |
### Username cannot have 2FA
\**PLEASE NOTE: For this to work, your Reddit account should have 2FA disabled AND needs to have a password set.
- If you used your Google or Apple account to sign up to Reddit and don't have an account, you could disconnect it, and then you'll be able to set an account (and reconnect your Google or Apple account after).
- If you want 2FA enabled on your main Reddit account (you probably should): create an additional account to set up this integration and don't use your main account.
## Package Usage

@@ -55,4 +61,11 @@

```js
const OrbitReddit = require('@orbit-love/reddit')
const orbitReddit = new OrbitReddit('orbitWorkspaceId', 'orbitApiKey', 'redditClientId', 'redditClientSecret', 'redditUsername', 'redditPassword')
const OrbitReddit = require("@orbit-love/reddit");
const orbitReddit = new OrbitReddit(
"orbitWorkspaceId",
"orbitApiKey",
"redditClientId",
"redditClientSecret",
"redditUsername",
"redditPassword"
);
```

@@ -63,4 +76,4 @@

```js
const OrbitReddit = require('@orbit-love/reddit')
const orbitReddit = new OrbitReddit()
const OrbitReddit = require("@orbit-love/reddit");
const orbitReddit = new OrbitReddit();
```

@@ -71,10 +84,10 @@

```js
const OrbitReddit = require('@orbit-love/reddit')
const orbitReddit = new OrbitReddit()
const OrbitReddit = require("@orbit-love/reddit");
const orbitReddit = new OrbitReddit();
// Allows you to go back a number of hours and only get posts in that timeframe
const posts = await orbitReddit.getPosts({ subreddit: 'javascript', hours: 24 })
const prepared = await orbitReddit.preparePosts(posts)
const summary = await orbitReddit.addActivities(prepared)
console.log(summary)
const posts = await orbitReddit.getPosts({ subreddit: "javascript", hours: 24 });
const prepared = await orbitReddit.preparePosts(posts);
const summary = await orbitReddit.addActivities(prepared);
console.log(summary);
```

@@ -85,10 +98,10 @@

```js
const OrbitReddit = require('@orbit-love/reddit')
const orbitReddit = new OrbitReddit()
const OrbitReddit = require("@orbit-love/reddit");
const orbitReddit = new OrbitReddit();
// Allows you to go back a number of hours and only get posts in that timeframe
const comments = await orbitReddit.getComments({ subreddit: 'javascript', hours: 24 })
const prepared = await orbitReddit.prepareComments(comments)
const summary = await orbitReddit.addActivities(prepared)
console.log(summary)
const comments = await orbitReddit.getComments({ subreddit: "javascript", hours: 24 });
const prepared = await orbitReddit.prepareComments(comments);
const summary = await orbitReddit.addActivities(prepared);
console.log(summary);
```

@@ -117,5 +130,9 @@

* For posts this will match if the post title, url or body text contain the term.
* For comments this will match if it was left on a post with a title containing the term, or the comment itself contains the term.
- For posts this will match if the post title, url or body text contain the term.
- For comments this will match if it was left on a post with a title containing the term, or the comment itself contains the term.
### Performing a Historical Import
You may want to perform a one-time historical import to fetch all your previous Reddit interactions and bring them into your Orbit workspace. To do so, set the hours tag to 720 for 30 days of import.
## GitHub Actions Automation Setup

@@ -122,0 +139,0 @@

#!/usr/bin/env node
const OrbitReddit = require('./index.js')
const args = require('yargs').argv
const OrbitReddit = require("./index.js");
const args = require("yargs").argv;
require("dotenv").config();
async function main() {
if((!args.posts && !args.comments) || !args.subreddit || !process.env.ORBIT_WORKSPACE_ID || !process.env.ORBIT_API_KEY || !process.env.REDDIT_CLIENT_ID || !process.env.REDDIT_CLIENT_SECRET || !process.env.REDDIT_USERNAME || !process.env.REDDIT_PASSWORD) {
return console.error(`
if (
(!args.posts && !args.comments) ||
!args.subreddit ||
!process.env.ORBIT_WORKSPACE_ID ||
!process.env.ORBIT_API_KEY ||
!process.env.REDDIT_CLIENT_ID ||
!process.env.REDDIT_CLIENT_SECRET ||
!process.env.REDDIT_USERNAME ||
!process.env.REDDIT_PASSWORD
) {
return console.error(`
You must run this command as follows:

@@ -15,44 +25,45 @@ npx @orbit-love/reddit --posts|comments --subreddit=subreddit-name --hours=24

You must also have ORBIT_WORKSPACE_ID, ORBIT_API_KEY, REDDIT_CLIENT_ID, REDDIT_CLIENT_SECRET, REDDIT_USERNAME, and REDDIT_PASSWORD environment variables set.
`)
}
`);
}
const orbitReddit = new OrbitReddit()
const orbitReddit = new OrbitReddit();
let hours
if(!args.hours) hours = 24
else if(Number.isNaN(+args.hours)) return console.error(`${args.hours} is not a number`)
else hours = args.hours
let hours;
if (!args.hours) hours = 24;
else if (Number.isNaN(+args.hours)) return console.error(`${args.hours} is not a number`);
else hours = args.hours;
if(args.posts) {
let posts = await orbitReddit.getPosts({ subreddit: args.subreddit, hours })
if(args.filter) posts = posts.filter(p => {
const inTitle = p.title.toLowerCase().includes(args.filter.toLowerCase())
const inBody = p.selftext.toLowerCase().includes(args.filter.toLowerCase())
const inUrl = p.url.toLowerCase().includes(args.filter.toLowerCase())
return inTitle || inBody || inUrl
})
console.log(`Fetched ${posts.length} posts from the provided timeframe`)
const prepared = await orbitReddit.preparePosts(posts)
console.log(`Posts are prepared as Orbit activities. Sending them off now...`)
const response = await orbitReddit.addActivities(prepared)
console.log(response) // "Added n activities to the workspace-id Orbit workspace"
}
if (args.posts) {
let posts = await orbitReddit.getPosts({ subreddit: args.subreddit, hours });
if (args.filter)
posts = posts.filter((p) => {
const inTitle = p.title.toLowerCase().includes(args.filter.toLowerCase());
const inBody = p.selftext.toLowerCase().includes(args.filter.toLowerCase());
const inUrl = p.url.toLowerCase().includes(args.filter.toLowerCase());
return inTitle || inBody || inUrl;
});
console.log(`Fetched ${posts.length} posts from the provided timeframe`);
const prepared = await orbitReddit.preparePosts(posts);
console.log(`Posts are prepared as Orbit activities. Sending them off now...`);
const response = await orbitReddit.addActivities(prepared);
console.log(response); // "Added n activities to the workspace-id Orbit workspace"
}
if(args.comments) {
let comments = await orbitReddit.getComments({ subreddit: args.subreddit, hours })
if(args.filter) {
comments = comments.filter(c => {
const inTitle = c.link_title.toLowerCase().includes(args.filter.toLowerCase())
const inBody = c.body.toLowerCase().includes(args.filter.toLowerCase())
return inTitle || inBody
})
}
console.log(`Fetched ${comments.length} comments from the provided timeframe`)
const prepared = await orbitReddit.prepareComments(comments)
console.log(`Comments are prepared as Orbit activities. Sending them off now...`)
const response = await orbitReddit.addActivities(prepared)
console.log(response) // "Added n activities to the workspace-id Orbit workspace"
if (args.comments) {
let comments = await orbitReddit.getComments({ subreddit: args.subreddit, hours });
if (args.filter) {
comments = comments.filter((c) => {
const inTitle = c.link_title.toLowerCase().includes(args.filter.toLowerCase());
const inBody = c.body.toLowerCase().includes(args.filter.toLowerCase());
return inTitle || inBody;
});
}
console.log(`Fetched ${comments.length} comments from the provided timeframe`);
const prepared = await orbitReddit.prepareComments(comments);
console.log(`Comments are prepared as Orbit activities. Sending them off now...`);
const response = await orbitReddit.addActivities(prepared);
console.log(response); // "Added n activities to the workspace-id Orbit workspace"
}
}
main()
main();

@@ -1,80 +0,102 @@

const pkg = require('../package.json')
const posts = require('./posts')
const comments = require('./comments')
const snoowrap = require('snoowrap')
const OrbitActivities = require('@orbit-love/activities')
const pkg = require("../package.json");
const posts = require("./posts");
const comments = require("./comments");
const snoowrap = require("snoowrap");
const OrbitActivities = require("@orbit-love/activities");
class OrbitReddit {
constructor(orbitWorkspaceId, orbitApiKey, redditClientId, redditClientSecret, redditUsername, redditPassword) {
this.credentials = this.checkCredentials(orbitWorkspaceId, orbitApiKey, redditClientId, redditClientSecret, redditUsername, redditPassword)
this.orbit = new OrbitActivities(this.credentials.orbitWorkspaceId, this.credentials.orbitApiKey, `community-js-reddit-orbit/${pkg.version}`)
this.reddit = new snoowrap({
userAgent: `orbit.love community integration run by ${this.credentials.redditUsername}`,
clientId: this.credentials.redditClientId,
clientSecret: this.credentials.redditClientSecret,
username: this.credentials.redditUsername,
password: this.credentials.redditPassword
})
}
constructor(orbitWorkspaceId, orbitApiKey, redditClientId, redditClientSecret, redditUsername, redditPassword) {
this.credentials = this.checkCredentials(
orbitWorkspaceId,
orbitApiKey,
redditClientId,
redditClientSecret,
redditUsername,
redditPassword
);
this.orbit = new OrbitActivities(
this.credentials.orbitWorkspaceId,
this.credentials.orbitApiKey,
`community-js-reddit-orbit/${pkg.version}`
);
this.reddit = new snoowrap({
userAgent: `orbit.love community integration run by ${this.credentials.redditUsername}`,
clientId: this.credentials.redditClientId,
clientSecret: this.credentials.redditClientSecret,
username: this.credentials.redditUsername,
password: this.credentials.redditPassword,
});
}
checkCredentials(OrbitWorkspaceId, OrbitApiKey, RedditClientId, RedditClientSecret, RedditUsername, RedditPassword) {
const orbitWorkspaceId = OrbitWorkspaceId || process.env.ORBIT_WORKSPACE_ID
const orbitApiKey = OrbitApiKey || process.env.ORBIT_API_KEY
const redditClientId = RedditClientId || process.env.REDDIT_CLIENT_ID
const redditClientSecret = RedditClientSecret || process.env.REDDIT_CLIENT_SECRET
const redditUsername = RedditUsername || process.env.REDDIT_USERNAME
const redditPassword = RedditPassword || process.env.REDDIT_PASSWORD
checkCredentials(OrbitWorkspaceId, OrbitApiKey, RedditClientId, RedditClientSecret, RedditUsername, RedditPassword) {
const orbitWorkspaceId = OrbitWorkspaceId || process.env.ORBIT_WORKSPACE_ID;
const orbitApiKey = OrbitApiKey || process.env.ORBIT_API_KEY;
const redditClientId = RedditClientId || process.env.REDDIT_CLIENT_ID;
const redditClientSecret = RedditClientSecret || process.env.REDDIT_CLIENT_SECRET;
const redditUsername = RedditUsername || process.env.REDDIT_USERNAME;
const redditPassword = RedditPassword || process.env.REDDIT_PASSWORD;
if(!orbitWorkspaceId || !orbitApiKey || !redditClientId || !redditClientSecret || !redditUsername || !redditPassword) {
throw new Error('You must initialize the OrbitReddit package with: orbitWorkspaceId, orbitApiKey, redditClientId, redditClientSecret, redditUsername, redditPassword')
} else {
return { orbitWorkspaceId, orbitApiKey, redditClientId, redditClientSecret, redditUsername, redditPassword }
}
if (
!orbitWorkspaceId ||
!orbitApiKey ||
!redditClientId ||
!redditClientSecret ||
!redditUsername ||
!redditPassword
) {
throw new Error(
"You must initialize the OrbitReddit package with: orbitWorkspaceId, orbitApiKey, redditClientId, redditClientSecret, redditUsername, redditPassword"
);
} else {
return { orbitWorkspaceId, orbitApiKey, redditClientId, redditClientSecret, redditUsername, redditPassword };
}
}
getPosts(options) {
if(!options) throw new Error('You must provide an options object')
if(!options.hours) throw new Error('You must provide an hours property')
if(!options.subreddit) throw new Error('You must provide a subreddit property')
return posts.get(this.reddit, options)
}
getPosts(options) {
if (!options) throw new Error("You must provide an options object");
if (!options.hours) throw new Error("You must provide an hours property");
if (!options.subreddit) throw new Error("You must provide a subreddit property");
return posts.get(this.reddit, options);
}
preparePosts(list) {
return posts.prepare(list)
}
preparePosts(list) {
return posts.prepare(list);
}
getComments(options) {
if(!options) throw new Error('You must provide an options object')
if(!options.hours) throw new Error('You must provide an hours property')
if(!options.subreddit) throw new Error('You must provide a subreddit property')
return comments.get(this.reddit, options)
}
getComments(options) {
if (!options) throw new Error("You must provide an options object");
if (!options.hours) throw new Error("You must provide an hours property");
if (!options.subreddit) throw new Error("You must provide a subreddit property");
return comments.get(this.reddit, options);
}
prepareComments(list) {
return comments.prepare(list)
}
prepareComments(list) {
return comments.prepare(list);
}
addActivities(activities) {
return new Promise(async (resolve, reject) => {
try {
let stats = { added: 0, duplicates: 0, errors: [] }
for(let activity of activities) {
await this.orbit.createActivity(activity)
.then(() => { stats.added++ })
.catch(err => {
if(err.errors.key) stats.duplicates++
else { errors.push(err) }
})
}
resolve(stats)
} catch(error) {
reject(error)
}
})
}
addActivities(activities) {
return new Promise(async (resolve, reject) => {
try {
let stats = { added: 0, duplicates: 0, errors: [] };
for (let activity of activities) {
await this.orbit
.createActivity(activity)
.then(() => {
stats.added++;
})
.catch((err) => {
if (err.errors && err.errors.key) stats.duplicates++;
else {
stats.errors.push(err);
}
});
}
resolve(stats);
} catch (error) {
reject(error);
}
});
}
}
module.exports = OrbitReddit
module.exports = OrbitReddit;
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