Remove unused profile API

This commit is contained in:
Zed 2022-01-05 22:17:14 +01:00
parent ab0c487778
commit d726894555
3 changed files with 11 additions and 39 deletions

View file

@ -3,12 +3,6 @@ import asyncdispatch, httpclient, uri, strutils
import packedjson import packedjson
import types, query, formatters, consts, apiutils, parser import types, query, formatters, consts, apiutils, parser
proc getGraphProfile*(username: string): Future[Profile] {.async.} =
let
variables = %*{"screen_name": username, "withHighlightedLabel": true}
js = await fetch(graphUser ? {"variables": $variables})
result = parseGraphProfile(js, username)
proc getGraphListBySlug*(name, list: string): Future[List] {.async.} = proc getGraphListBySlug*(name, list: string): Future[List] {.async.} =
let let
variables = %*{"screenName": name, "listSlug": list, "withHighlightedLabel": false} variables = %*{"screenName": name, "listSlug": list, "withHighlightedLabel": false}
@ -38,14 +32,14 @@ proc getListMembers*(list: List; after=""): Future[Result[Profile]] {.async.} =
proc getProfile*(username: string): Future[Profile] {.async.} = proc getProfile*(username: string): Future[Profile] {.async.} =
let let
ps = genParams({"screen_name": username}) ps = genParams({"screen_name": username})
url = userShow ? ps js = await fetch(userShow ? ps, oldApi=true)
result = parseUserShow(await fetch(url, oldApi=true), username) result = parseUserShow(js, username=username)
proc getProfileById*(userId: string): Future[Profile] {.async.} = proc getProfileById*(userId: string): Future[Profile] {.async.} =
let let
ps = genParams({"user_id": userId}) ps = genParams({"user_id": userId})
url = userShow ? ps js = await fetch(userShow ? ps, oldApi=true)
result = parseUserShowId(await fetch(url, oldApi=true), userId) result = parseUserShow(js, id=userId)
proc getTimeline*(id: string; after=""; replies=false): Future[Timeline] {.async.} = proc getTimeline*(id: string; after=""; replies=false): Future[Timeline] {.async.} =
let let

View file

@ -13,13 +13,12 @@ const
search* = api / "2/search/adaptive.json" search* = api / "2/search/adaptive.json"
timelineApi = api / "2/timeline" timelineApi = api / "2/timeline"
tweet* = timelineApi / "conversation"
timeline* = timelineApi / "profile" timeline* = timelineApi / "profile"
mediaTimeline* = timelineApi / "media" mediaTimeline* = timelineApi / "media"
listTimeline* = timelineApi / "list.json" listTimeline* = timelineApi / "list.json"
tweet* = timelineApi / "conversation"
graphql = api / "graphql" graphql = api / "graphql"
graphUser* = graphql / "E4iSsd6gypGFWx2eUhSC1g/UserByScreenName"
graphList* = graphql / "ErWsz9cObLel1BF-HjuBlA/ListBySlug" graphList* = graphql / "ErWsz9cObLel1BF-HjuBlA/ListBySlug"
graphListId* = graphql / "JADTh6cjebfgetzvF3tQvQ/List" graphListId* = graphql / "JADTh6cjebfgetzvF3tQvQ/List"

View file

@ -26,41 +26,20 @@ proc parseProfile(js: JsonNode; id=""): Profile =
result.expandProfileEntities(js) result.expandProfileEntities(js)
proc parseUserShow*(js: JsonNode; username: string): Profile = proc parseUserShow*(js: JsonNode; username=""; id=""): Profile =
if js.isNull: if id.len > 0:
return Profile(username: username) result = Profile(id: id)
else:
with error, js{"errors"}:
result = Profile(username: username) result = Profile(username: username)
if error.getError == suspended:
result.suspended = true
return
result = parseProfile(js)
proc parseUserShowId*(js: JsonNode; userId: string): Profile =
if js.isNull:
return Profile(id: userId)
with error, js{"errors"}:
result = Profile(id: userId)
if error.getError == suspended:
result.suspended = true
return
result = parseProfile(js)
proc parseGraphProfile*(js: JsonNode; username: string): Profile =
if js.isNull: return if js.isNull: return
with error, js{"errors"}: with error, js{"errors"}:
result = Profile(username: username)
if error.getError == suspended: if error.getError == suspended:
result.suspended = true result.suspended = true
return return
let user = js{"data", "user", "legacy"} result = parseProfile(js)
let id = js{"data", "user", "rest_id"}.getStr
result = parseProfile(user, id)
proc parseGraphList*(js: JsonNode): List = proc parseGraphList*(js: JsonNode): List =
if js.isNull: return if js.isNull: return