Skip to content

Commit 01028bb

Browse files
[DR-382] updated blocks example to devvit web in RedditAPIClient (#63)
<!-- If this pull request closes an issue, please mention the issue number below --> Closes # <!-- Issue # here --> DR-382 ## 💸 TL;DR <!-- What's the three sentence summary of purpose of the PR --> RedditAPIClient had an outdated example in blocks that needed to updated to devvit web. ## 📜 Details [Design Doc](<!-- insert Google Doc link here if applicable -->) [Jira](<!-- insert Jira link if applicable -->) https://reddit.atlassian.net/browse/DR-382?atlOrigin=eyJpIjoiOGMyMjVhOWJmMjFmNDUyNGFiOTc3YjNiOTZhN2VkNGYiLCJwIjoiaiJ9 <!-- Add additional details required for the PR: breaking changes, screenshots, external dependency changes --> ## 🧪 Testing Steps / Validation <!-- add details on how this PR has been tested, include reproductions and screenshots where applicable --> ## ✅ Checks <!-- Make sure your pr passes the CI checks and do check the following fields as needed - --> - [ ] CI tests (if present) are passing - [ ] Adheres to code style for repo - [ ] Contributor License Agreement (CLA) completed if not a Reddit employee
1 parent 6c62fa0 commit 01028bb

2 files changed

Lines changed: 38 additions & 34 deletions

File tree

docs/api/redditapi/RedditAPIClient/classes/RedditAPIClient.md

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,29 @@
66

77
The Reddit API Client
88

9-
To use the Reddit API Client, add it to the plugin configuration at the top of the file.
9+
To use the Reddit API Client, enable the `redditAPI` permission in your `devvit.json` file.
10+
11+
```json title="devvit.json"
12+
{
13+
"permissions": {
14+
"redditAPI": true
15+
}
16+
}
17+
```
1018

1119
## Example
1220

1321
```ts
14-
15-
Devvit.configure({
16-
redditAPI: true,
17-
// other plugins
18-
})
19-
20-
// use within one of our capability handlers e.g. Menu Actions, Triggers, Scheduled Job Type, etc
21-
async (event, context) => {
22-
const subreddit = await context.reddit.getSubredditById(context.subredditId);
23-
context.reddit.submitPost({
24-
subredditName: subreddit.name,
25-
title: 'test post',
26-
text: 'test body',
27-
})
28-
// additional code
29-
}
22+
import { reddit } from '@devvit/web/server';
23+
24+
export const menuActionHandler = async () => {
25+
const subredditName = await reddit.getCurrentSubredditName();
26+
return await reddit.submitPost({
27+
subredditName,
28+
title: 'test post',
29+
text: 'test body',
30+
});
31+
};
3032
```
3133

3234
## Constructors

versioned_docs/version-0.12/api/redditapi/RedditAPIClient/classes/RedditAPIClient.md

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,29 @@
66

77
The Reddit API Client
88

9-
To use the Reddit API Client, add it to the plugin configuration at the top of the file.
9+
To use the Reddit API Client, enable the `redditAPI` permission in your `devvit.json` file.
10+
11+
```json title="devvit.json"
12+
{
13+
"permissions": {
14+
"redditAPI": true
15+
}
16+
}
17+
```
1018

1119
## Example
1220

1321
```ts
14-
15-
Devvit.configure({
16-
redditAPI: true,
17-
// other plugins
18-
})
19-
20-
// use within one of our capability handlers e.g. Menu Actions, Triggers, Scheduled Job Type, etc
21-
async (event, context) => {
22-
const subreddit = await context.reddit.getSubredditById(context.subredditId);
23-
context.reddit.submitPost({
24-
subredditName: subreddit.name,
25-
title: 'test post',
26-
text: 'test body',
27-
})
28-
// additional code
29-
}
22+
import { reddit } from '@devvit/web/server';
23+
24+
export const menuActionHandler = async () => {
25+
const subredditName = await reddit.getCurrentSubredditName();
26+
return await reddit.submitPost({
27+
subredditName,
28+
title: 'test post',
29+
text: 'test body',
30+
});
31+
};
3032
```
3133

3234
## Constructors

0 commit comments

Comments
 (0)