Add more features to the nim client
This commit is contained in:
parent
4ad4b4f997
commit
170595579d
|
@ -19,19 +19,21 @@ proc getJson(endpoint: string): json.JsonNode =
|
||||||
|
|
||||||
return jsonTable
|
return jsonTable
|
||||||
|
|
||||||
|
proc newEpisodeFromNode(data: json.JsonNode): Episode =
|
||||||
|
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)
|
||||||
|
|
||||||
proc newest*(): Episode =
|
proc newest*(): Episode =
|
||||||
var
|
getJson("/newest")["episode"].newEpisodeFromNode
|
||||||
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 random*(): Episode =
|
||||||
|
getJson("/random")["episode"].newEpisodeFromNode
|
||||||
|
|
||||||
proc `$`*(ep: Episode): string =
|
proc get_episode*(season, episode: int): Episode =
|
||||||
return "Episode:: name:" & ep.name & " season:" & $ep.season & " episode:" & $ep.episode & " air_date:" & $ep.air_date & " is_movie:" & $ep.is_movie
|
getJson("/season/" & $season & "/episode/" & $episode)["episode"].newEpisodeFromNode
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
import unittest
|
import unittest
|
||||||
|
@ -49,3 +51,10 @@ when isMainModule:
|
||||||
|
|
||||||
test "stringify episode":
|
test "stringify episode":
|
||||||
echo ep
|
echo ep
|
||||||
|
|
||||||
|
test "random episode":
|
||||||
|
echo random()
|
||||||
|
|
||||||
|
test "get episode":
|
||||||
|
var myEp = get_episode(2, 14) # best episode
|
||||||
|
assert myEp.name == "The Last Roundup"
|
||||||
|
|
Loading…
Reference in New Issue