Add the missing API calls, save searching
This commit is contained in:
parent
170595579d
commit
0f608fcb5a
|
@ -26,6 +26,13 @@ proc newEpisodeFromNode(data: json.JsonNode): Episode =
|
|||
episode: data["episode"].getNum.int,
|
||||
is_movie: data["is_movie"].getBVal)
|
||||
|
||||
proc newEpisodeListFromNode(data: json.JsonNode): seq[Episode] =
|
||||
var ret: seq[Episode]
|
||||
for item in data.items():
|
||||
ret = ret & item.newEpisodeFromNode
|
||||
|
||||
return ret
|
||||
|
||||
proc newest*(): Episode =
|
||||
getJson("/newest")["episode"].newEpisodeFromNode
|
||||
|
||||
|
@ -35,9 +42,17 @@ proc random*(): Episode =
|
|||
proc get_episode*(season, episode: int): Episode =
|
||||
getJson("/season/" & $season & "/episode/" & $episode)["episode"].newEpisodeFromNode
|
||||
|
||||
proc all_episodes*(): seq[Episode] =
|
||||
getJson("/all")["episodes"].newEpisodeListFromNode
|
||||
|
||||
proc get_season*(season: int): seq[Episode] =
|
||||
getJson("/season/" & $season)["episodes"].newEpisodeListFromNode
|
||||
|
||||
when isMainModule:
|
||||
import unittest
|
||||
|
||||
echo "Running API tests"
|
||||
|
||||
suite "ponyapi tests":
|
||||
var ep: Episode
|
||||
|
||||
|
@ -58,3 +73,22 @@ when isMainModule:
|
|||
test "get episode":
|
||||
var myEp = get_episode(2, 14) # best episode
|
||||
assert myEp.name == "The Last Roundup"
|
||||
|
||||
test "get all episodes":
|
||||
try:
|
||||
var all = all_episodes()
|
||||
assert all.len > 100
|
||||
|
||||
except:
|
||||
echo getCurrentExceptionMsg()
|
||||
fail
|
||||
|
||||
test "get information on season 1":
|
||||
try:
|
||||
var eps = get_season(1)
|
||||
|
||||
assert eps.len == 26
|
||||
|
||||
except:
|
||||
echo getCurrentExceptionMsg()
|
||||
fail
|
||||
|
|
Loading…
Reference in New Issue