graphql.nim 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. import options
  2. import jsony
  3. import user, ../types/[graphuser, graphlistmembers]
  4. from ../../types import User, Result, Query, QueryKind
  5. proc parseGraphUser*(json: string): User =
  6. let raw = json.fromJson(GraphUser)
  7. if raw.data.user.result.reason.get("") == "Suspended":
  8. return User(suspended: true)
  9. result = toUser raw.data.user.result.legacy
  10. result.id = raw.data.user.result.restId
  11. result.verified = result.verified or raw.data.user.result.isBlueVerified
  12. proc parseGraphListMembers*(json, cursor: string): Result[User] =
  13. result = Result[User](
  14. beginning: cursor.len == 0,
  15. query: Query(kind: userList)
  16. )
  17. let raw = json.fromJson(GraphListMembers)
  18. for instruction in raw.data.list.membersTimeline.timeline.instructions:
  19. if instruction.kind == "TimelineAddEntries":
  20. for entry in instruction.entries:
  21. case entry.content.entryType
  22. of TimelineTimelineItem:
  23. let userResult = entry.content.itemContent.userResults.result
  24. if userResult.restId.len > 0:
  25. result.content.add toUser userResult.legacy
  26. of TimelineTimelineCursor:
  27. if entry.content.cursorType == "Bottom":
  28. result.bottom = entry.content.value