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 newest*(): Episode =
|
proc newEpisodeFromNode(data: json.JsonNode): Episode =
|
||||||
var
|
Episode(name: data["name"].getStr,
|
||||||
data = getJson("/newest")["episode"]
|
|
||||||
ep = Episode(name: data["name"].getStr,
|
|
||||||
air_date: data["air_date"].getNum.int,
|
air_date: data["air_date"].getNum.int,
|
||||||
season: data["season"].getNum.int,
|
season: data["season"].getNum.int,
|
||||||
episode: data["episode"].getNum.int,
|
episode: data["episode"].getNum.int,
|
||||||
is_movie: data["is_movie"].getBVal)
|
is_movie: data["is_movie"].getBVal)
|
||||||
|
|
||||||
return ep
|
proc newest*(): Episode =
|
||||||
|
getJson("/newest")["episode"].newEpisodeFromNode
|
||||||
|
|
||||||
proc `$`*(ep: Episode): string =
|
proc random*(): Episode =
|
||||||
return "Episode:: name:" & ep.name & " season:" & $ep.season & " episode:" & $ep.episode & " air_date:" & $ep.air_date & " is_movie:" & $ep.is_movie
|
getJson("/random")["episode"].newEpisodeFromNode
|
||||||
|
|
||||||
|
proc get_episode*(season, episode: int): Episode =
|
||||||
|
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