diff --git a/client/nim/.gitignore b/client/nim/.gitignore new file mode 100644 index 0000000..82c4fa6 --- /dev/null +++ b/client/nim/.gitignore @@ -0,0 +1,2 @@ +ponyapi +nimcache diff --git a/client/nim/ponyapi.nim b/client/nim/ponyapi.nim new file mode 100644 index 0000000..c953a51 --- /dev/null +++ b/client/nim/ponyapi.nim @@ -0,0 +1,51 @@ +import httpclient +import json + +type + Episode* = object of RootObj + name: string + air_date: int + season: int + episode: int + is_movie: bool + +const + API_ENDPOINT: string = "http://ponyapi.apps.xeserv.us" + +proc getJson(endpoint: string): json.JsonNode = + var + data = httpclient.getContent(API_ENDPOINT & "/" & endpoint) + jsonTable = json.parseJson data + + return jsonTable + +proc newest*(): Episode = + var + data = getJson("/newest")["episode"] + ep = Episode(name: data["name"].getStr, + air_date: data["air_date"].getNum.int, + season: data["season"].getNum.int, + episode: data["episode"].getNum.int, + is_movie: data["is_movie"].getBVal) + + return ep + +proc `$`*(ep: Episode): string = + return "Episode:: name:" & ep.name & " season:" & $ep.season & " episode:" & $ep.episode & " air_date:" & $ep.air_date & " is_movie:" & $ep.is_movie + +when isMainModule: + import unittest + + suite "ponyapi tests": + var ep: Episode + + test "Newest episode lookup": + try: + ep = newest() + + except: + echo getCurrentExceptionMsg() + fail + + test "stringify episode": + echo ep diff --git a/ponyapi.nimble b/ponyapi.nimble new file mode 100644 index 0000000..83b9ad6 --- /dev/null +++ b/ponyapi.nimble @@ -0,0 +1,10 @@ +[Package] +name = "ponyapi" +version = "0.1.0" +author = "Christine Dodrill " +description = "PonyAPI client https://github.com/Xe/PonyAPI" +license = "MIT" +srcDir = "client/nim" + +[Deps] +Requires: "nim >= 0.10.0"