mirror of https://github.com/zedeus/nitter
feat(api): twitter api router added
This commit is contained in:
parent
20b5cce5dc
commit
ef5eaf1bde
|
@ -0,0 +1,5 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
|
@ -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>
|
|
@ -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>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
|
@ -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
|
Loading…
Reference in New Issue