async
(params, auths) => {
}
const config = {
url: `https://oauth.reddit.com/subreddits/mine/${params.where}`,
params: {
after: params.after,
before: params.before,
count: params.count,
include_categories: params.include_categories,
limit: params.limit,
show: params.show,
sr_detail: params.sr_detail,
},
headers: {
Authorization: `Bearer ${auths.reddit.oauth_access_token}`,
"User-Agent": "pipedream:v0.0.1 (by /r/pipedream)",
},
}
return await require("@pipedreamhq/platform").axios(this, config)
auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps) => {
}
const axios = require("axios");
// simplify things a bit
let mysubs = steps.get_subreddits_mine_where.$return_value.data.children.map(s => {
return s.data;
})
// title, displayName
let promises = [];
mysubs.forEach(sub => {
let url = 'https://engtbib844m2yqb.m.pipedream.net?subreddit='+sub.display_name;
promises.push(axios({method:'get', url}));
});
let result = await Promise.all(promises);
// global post array we can sort in a bit
this.posts = [];
for(let i=0;i<result.length;i++) {
this.posts = this.posts.concat(result[i].data.result.slice(0,10));
}
auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps) => {
}
let dotLeft = function(s, len) {
if(s.length < len) return s;
return s.substring(0, len)+'...';
};
let lastSub = '';
this.subject = `Daily Reddit Report`;
this.body = `
<h1>Daily New Posts for Your Reddit Subscriptions</h1>
<p/>
`;
steps.get_and_sort.posts.forEach(p => {
// only show thumbnails when they aren't "self","default","nswf" - or more broadly, not a url
if(p.thumbnail.indexOf('http') === -1) delete p.thumbnail;
let text = '';
if(p.is_self) text = dotLeft(p.selftext,200);
if(p.subreddit !== lastSub) {
this.body += `<hr/><h2>${p.subreddit}</h2>`;
lastSub = p.subreddit;
}
this.body += `
<p>
${ p.thumbnail ? '<img src="'+p.thumbnail+'" align="left" style="margin-right:10px">':''}
<b>Title: ${p.title}</b><br/>
URL: <a href="${p.url}">${p.url}</a><br/>
Reddit URL: <a href="https://www.reddit.com${p.permalink}">https://www.reddit.com${p.permalink}</a><br/>
Author: ${p.author}<br/>
<br clear="left">
${text}
</p>
`
});
async
params => {
}
const options = {
subject: params.subject,
text: params.text,
}
if (params.html) {
options.html = params.html
}
if (params.include_collaborators) {
options.include_collaborators = params.include_collaborators
}
$send.email(options)