nimcatapi/internal

Internal procs

These procs are used internally. Only manually call them if you know what you are doing! :)

Types

RequestType = enum
  imageSearch = "/images/search", breedSearch = "/breeds"

Procs

proc buildRequest(api, requestType, request): string {....raises: [ValueError],
    tags: [].}

Builds an url string from request data, that can be sent to the API.

Should not be called manually, used internally.

proc errorLog(msg: string) {....raises: [IOError], tags: [WriteIOEffect].}
Very basic error handler/debugger:
proc getBreedsFromApiBreeds[A, B](api: AnimalApi; response: JsonNode): seq[B]
proc getImagesFromResponse(response: JsonNode): seq[string] {....raises: [IOError],
    tags: [WriteIOEffect].}
Converts response to Response object and returns only images:
proc getImagesFromResponse(response: seq[Re]): seq[string] {....raises: [],
    tags: [].}
proc getImagesFromResponseRawJsonNode(response: JsonNode): seq[string] {.
    ...raises: [IOError, KeyError, IOError], tags: [WriteIOEffect].}

Loops over response json and pick "url" field from objects.

(old implementation)

proc sendRequest(api, requestType; request = Request()): JsonNode {....raises: [
    Exception, ValueError, OSError, IOError, OSError, Exception, ValueError,
    JsonParsingError],
    tags: [RootEffect, TimeEffect, ReadIOEffect, WriteIOEffect].}

Get raw json result from the API.

Should not be called manually just to get images. Use requestImageUrl() and requestImageUrls() instead!

See https://developers.thecatapi.com/ for information on how data is structured.