From e178aec20496880c40b43541f804e06b2f530a93 Mon Sep 17 00:00:00 2001 From: Phoenix181 <40687700+Phoenix181@users.noreply.github.com> Date: Sun, 22 Dec 2019 00:30:49 +0530 Subject: [PATCH] Initialized snoowrap and can get Reddit posts from a username --- .eslintrc | 6 +++++- .gitignore | 4 ++++ Reddit.js | 11 +++++++++++ config.js | 10 ++++++++++ index.js | 3 +++ sample.config.json | 6 ++++++ 6 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 Reddit.js create mode 100644 config.js create mode 100644 sample.config.json diff --git a/.eslintrc b/.eslintrc index 44cbe88..3f2568d 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,3 +1,7 @@ { - "extends": "airbnb" + "extends": "airbnb", + "indent": ["error", "4"], + "new - cap": ["error", { + "newIsCap": false + }] } \ No newline at end of file diff --git a/.gitignore b/.gitignore index 9b9ca9e..2b87c3b 100644 --- a/.gitignore +++ b/.gitignore @@ -105,3 +105,7 @@ dist # Stores VSCode versions used for testing VSCode extensions .vscode-test + + +#config +config.json \ No newline at end of file diff --git a/Reddit.js b/Reddit.js new file mode 100644 index 0000000..5ae7151 --- /dev/null +++ b/Reddit.js @@ -0,0 +1,11 @@ +const Snoowrap = require('snoowrap'); +const config = require('./config'); + +const Reddit = new Snoowrap({ + userAgent: config.userAgent, + clientId: config.clientId, + clientSecret: config.clientSecret, + refreshToken: config.refreshToken, +}); + +module.exports = Reddit; \ No newline at end of file diff --git a/config.js b/config.js new file mode 100644 index 0000000..2038005 --- /dev/null +++ b/config.js @@ -0,0 +1,10 @@ +const configJson = require('./config.json'); + +const config = { + userAgent: configJson.userAgent, + clientId: configJson.clientId, + clientSecret: configJson.clientSecret, + refreshToken: configJson.refreshToken, +}; + +module.exports = config; diff --git a/index.js b/index.js index e69de29..24bac65 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,3 @@ +const Reddit = require('./Reddit'); + +Reddit.getHot().map(post => post.title).then(console.log) \ No newline at end of file diff --git a/sample.config.json b/sample.config.json new file mode 100644 index 0000000..3f28b85 --- /dev/null +++ b/sample.config.json @@ -0,0 +1,6 @@ +{ + "userAgent": "/* Put user Agent here */", + "clientId": "/* Put your Client Id here */", + "clientSecret": "/* Put your Client Secret here */", + "refreshToken": "/* Put refreshToken here. For more information on getting credentials, see here: https://github.com/not-an-aardvark/reddit-oauth-helper */" +} \ No newline at end of file