From 91f42c4c948efa6bd13aedeef1868c35bc81e0f4 Mon Sep 17 00:00:00 2001 From: Zed Date: Wed, 17 Jun 2020 20:46:45 +0200 Subject: [PATCH] Nevermind. --- src/api.nim | 4 ++-- src/consts.nim | 2 +- src/parser.nim | 13 ++++++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/api.nim b/src/api.nim index 33dc505..07465da 100644 --- a/src/api.nim +++ b/src/api.nim @@ -36,8 +36,8 @@ proc getListMembers*(list: List; after=""): Future[Result[Profile]] {.async.} = proc getProfile*(username: string): Future[Profile] {.async.} = let ps = genParams({"screen_name": username}) - url = userLookup ? ps - result = parseUserLookup(await fetch(url, oldApi=true), username) + url = userShow ? ps + result = parseUserShow(await fetch(url, oldApi=true), username) proc getTimeline*(id: string; after=""; replies=false): Future[Timeline] {.async.} = let diff --git a/src/consts.nim b/src/consts.nim index 5e8e386..48da4c4 100644 --- a/src/consts.nim +++ b/src/consts.nim @@ -13,7 +13,7 @@ const mediaTimeline* = timelineApi / "media" listTimeline* = timelineApi / "list.json" listMembers* = api / "1.1/lists/members.json" - userLookup* = api / "1.1/users/lookup.json" + userShow* = api / "1.1/users/show.json" photoRail* = api / "1.1/statuses/media_timeline.json" tweet* = timelineApi / "conversation" search* = api / "2/search/adaptive.json" diff --git a/src/parser.nim b/src/parser.nim index f7bdc27..362ecd3 100644 --- a/src/parser.nim +++ b/src/parser.nim @@ -24,10 +24,17 @@ proc parseProfile(js: JsonNode; id=""): Profile = result.expandProfileEntities(js) -proc parseUserLookup*(js: JsonNode; username: string): Profile = - if js.isNull or js.kind == JArray and js.len == 0 or "error" in js: +proc parseUserShow*(js: JsonNode; username: string): Profile = + if js.isNull: return Profile(username: username) - result = parseProfile(js[0]) + + with error, js{"errors"}: + result = Profile(username: username) + if error.getError == suspended: + result.suspended = true + return + + result = parseProfile(js) proc parseGraphProfile*(js: JsonNode; username: string): Profile = if js.isNull: return