Turned out that the old code was wrong. I'm not sure why it used to work.

`response.body` properly resolves to an async proc defined in the httpclient
module with the following signature:

proc body*(response: AsyncResponse): Future[string] {.async.}

Perhaps the old code was somehow matching the body field of the `AsyncResponse`
object, which is marked as private.
This commit is contained in:
Zahary Karadjov 2017-04-28 19:09:11 +03:00
commit 9107e551f1

View file

@ -29,17 +29,19 @@ proc newBountySource(team, token: string): BountySource =
result.client.headers["Referer"] = "https://salt.bountysource.com/teams/nim/admin/supporters" result.client.headers["Referer"] = "https://salt.bountysource.com/teams/nim/admin/supporters"
result.client.headers["Origin"] = "https://salt.bountysource.com/" result.client.headers["Origin"] = "https://salt.bountysource.com/"
import typetraits
proc getSupporters(self: BountySource): Future[JsonNode] {.async.} = proc getSupporters(self: BountySource): Future[JsonNode] {.async.} =
let response = await self.client.get(apiUrl & let response = await self.client.get(apiUrl &
"/supporters?order=monthly&per_page=200&team_slug=" & self.team) "/supporters?order=monthly&per_page=200&team_slug=" & self.team)
doAssert response.status.startsWith($Http200) doAssert response.status.startsWith($Http200)
return parseJson(response.body) return parseJson(await response.body)
proc getGithubUser(username: string): Future[JsonNode] {.async.} = proc getGithubUser(username: string): Future[JsonNode] {.async.} =
let client = newAsyncHttpClient() let client = newAsyncHttpClient()
let response = await client.get(githubApiUrl & "/users/" & username) let response = await client.get(githubApiUrl & "/users/" & username)
if response.status.startsWith($Http200): if response.status.startsWith($Http200):
return parseJson(response.body) return parseJson(await response.body)
else: else:
echo("Could not get Github user: ", username, ". ", response.status) echo("Could not get Github user: ", username, ". ", response.status)
return nil return nil