async
(params, auths) => {
}
const config = {
url: `https://oauth.reddit.com/r/${params.subreddit}/new`,
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) => {
}
/*
Date.now is ms, for reddit posts, created_utc is seconds, so convert our value to seconds
*/
const now = Date.now()/1000;
// and 24 hours in seconds then is 24 * 60 * 60
const maxtime = 24 * 60 * 60;
let result = steps.get_new.$return_value.data.children.filter(p => {
let diff = now - p.data.created_utc;
return diff < maxtime;
}).map(p => {
return p.data;
});
$respond({
status: 200,
body: { result }, // This can be any string, object, or Buffer
});