feat(api): twitter api router added

This commit is contained in:
kristobalus 2023-08-09 13:25:26 +06:00
parent 20b5cce5dc
commit ef5eaf1bde
5 changed files with 58 additions and 0 deletions

5
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/nitter.iml" filepath="$PROJECT_DIR$/.idea/nitter.iml" />
</modules>
</component>
</project>

12
.idea/nitter.iml Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
<excludeFolder url="file://$MODULE_DIR$/temp" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@ -0,0 +1,27 @@
# SPDX-License-Identifier: AGPL-3.0-only
import jester
import router_utils
import json
import ".."/[types, redis_cache, formatters, query, api]
proc getUserProfileJson*(username: string): JsonNode {.async.} =
let user = await getGraphUser(username)
return %*{ "user": user }
proc getUserTweetsJson*(id: string): JsonNode {.async.} =
let tweets = await getGraphUserTweets(id, TimelineKind.tweets)
let replies = await getGraphUserTweets(id, TimelineKind.replies)
let media = await getGraphUserTweets(id, TimelineKind.media)
return %*{ "tweets": tweets, "replies": replies, "media": media }
proc createTwitterApiRouter*(cfg: Config) =
router debug:
get "/api/user/@username":
let username = @"username"
let response = await getUserProfileJson(username)
resp Http200, {"Content-Type": "application/json"}, response
get "/api/user/@id/tweets":
let id = @"id"
let response = await getUserTweetsJson(id)
resp Http200, {"Content-Type": "application/json"}, response