This topic was automatically generated from Slack. You can find the original thread here.
Dylan Sather (Pipedream) : re: Reddit, go ahead and start on the New Link in a Subreddit source. That source should accept the subreddit name as a prop, similar to the action.
Here’s how I’d get started:
- In the
componentsdirectory of your fork, create a new
This is a simple example of the structure of a directory for an app. First, you’ll need to create an “app file” -
reddit.app.js- which contains basic metadata about the app and shared props and methods. Here, the app name should be
app: "reddit"). The
propDefinitionssection should contain props that are shared across multiple sources. Adding them in the app file allows you to reuse the props across sources. So when you add the
subredditprop, I’d recommend keeping it here. The
methodssection contains shared methods that can also be used across sources, as well.
- A note on auth. In workflows, the user’s connected account details for Reddit are accessible at
auths.reddit. In sources, that auth data is exposed at
this.$auth. So to reference the OAuth access token, for example, you’d use
- When you create a specific source, create a
sourcessubdirectory within the
- The structure of the source itself is defined by the component API. Here’s one example source, but you’ll find many more in the
componentsdir under the relevant apps, so I’d recommend taking a look there for examples.
- Reddit doesn’t support webhooks, so you’ll need to poll the API endpoint on a schedule, looking for new items added since the last new post that was returned from the API. Luckily, this endpoint supports an
afterparameter that should allow you to fetch new items since a specific item ID. A lot of our sources operate in the same way: 1) pull first set of items, 2) store the last item / last time the source ran in
this.db(see docs), 3) the next time the source runs, pull the last item ID from
this.dband fetch new items added since then. Take a look at similar sources here, here, and here.
Let me know if that helps get you started, or if you have any other questions.