Skip to content

Commit

Permalink
add support for requesting popular videos
Browse files Browse the repository at this point in the history
Signed-off-by: George Lemon <[email protected]>
  • Loading branch information
georgelemon committed Sep 15, 2024
1 parent b7e9c4d commit 543c848
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/pexels/video.nim
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,28 @@ proc `$`*(videoResponse: PexelsVideoPicture): string =
## Convert `PexelsVideoPicture` object to JSON
videoResponse.toJson()

proc videos*(pexels: Pexels, query: string): Future[PexelsVideosResponse] {.async.} =
#
# Public procs
#
proc videos*(px: Pexels, query: string): Future[PexelsVideosResponse] {.async.} =
## Search for videos by `query`
pexels.query["query"] = query
let res: AsyncResponse = await pexels.httpGet(PexelsEndpoint.epSearchVideos)
px.query["query"] = query
let res: AsyncResponse = await px.httpGet(PexelsEndpoint.epSearchVideos)
let body = await res.body
result = fromJson(body, PexelsVideosResponse)
pexels.client.close()
px.client.close()

proc popular*(px: Pexels): Future[PexelsVideosResponse] {.async.} =
## Retrieve the current popular Pexels videos
# todo filtering
let res: AsyncResponse = await px.httpGet(PexelsEndpoint.epPopularVideos)
let body = await res.body
result = fromJson(body, PexelsVideosResponse)
px.client.close()

#
# Iterators
#
iterator items*(videosResponse: PexelsVideosResponse): PexelsVideoResponse =
for v in videosResponse.videos:
yield v

0 comments on commit 543c848

Please sign in to comment.