From d7268945558827ad436663b2d0bae0f93b1b235e Mon Sep 17 00:00:00 2001 From: Zed Date: Wed, 5 Jan 2022 22:17:14 +0100 Subject: [PATCH] Remove unused profile API --- src/api.nim | 14 ++++---------- src/consts.nim | 3 +-- src/parser.nim | 33 ++++++--------------------------- 3 files changed, 11 insertions(+), 39 deletions(-) diff --git a/src/api.nim b/src/api.nim index 779b3e4..260435e 100644 --- a/src/api.nim +++ b/src/api.nim @@ -3,12 +3,6 @@ import asyncdispatch, httpclient, uri, strutils import packedjson 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.} = let 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.} = let ps = genParams({"screen_name": username}) - url = userShow ? ps - result = parseUserShow(await fetch(url, oldApi=true), username) + js = await fetch(userShow ? ps, oldApi=true) + result = parseUserShow(js, username=username) proc getProfileById*(userId: string): Future[Profile] {.async.} = let ps = genParams({"user_id": userId}) - url = userShow ? ps - result = parseUserShowId(await fetch(url, oldApi=true), userId) + js = await fetch(userShow ? ps, oldApi=true) + result = parseUserShow(js, id=userId) proc getTimeline*(id: string; after=""; replies=false): Future[Timeline] {.async.} = let diff --git a/src/consts.nim b/src/consts.nim index d1822ce..c7651b4 100644 --- a/src/consts.nim +++ b/src/consts.nim @@ -13,13 +13,12 @@ const search* = api / "2/search/adaptive.json" timelineApi = api / "2/timeline" - tweet* = timelineApi / "conversation" timeline* = timelineApi / "profile" mediaTimeline* = timelineApi / "media" listTimeline* = timelineApi / "list.json" + tweet* = timelineApi / "conversation" graphql = api / "graphql" - graphUser* = graphql / "E4iSsd6gypGFWx2eUhSC1g/UserByScreenName" graphList* = graphql / "ErWsz9cObLel1BF-HjuBlA/ListBySlug" graphListId* = graphql / "JADTh6cjebfgetzvF3tQvQ/List" diff --git a/src/parser.nim b/src/parser.nim index 75f4d12..25778ed 100644 --- a/src/parser.nim +++ b/src/parser.nim @@ -26,41 +26,20 @@ proc parseProfile(js: JsonNode; id=""): Profile = result.expandProfileEntities(js) -proc parseUserShow*(js: JsonNode; username: string): Profile = - if js.isNull: - return Profile(username: username) - - with error, js{"errors"}: +proc parseUserShow*(js: JsonNode; username=""; id=""): Profile = + if id.len > 0: + result = Profile(id: id) + else: 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 + with error, js{"errors"}: - result = Profile(username: username) if error.getError == suspended: result.suspended = true return - let user = js{"data", "user", "legacy"} - let id = js{"data", "user", "rest_id"}.getStr - result = parseProfile(user, id) + result = parseProfile(js) proc parseGraphList*(js: JsonNode): List = if js.isNull: return