Skip to content

Commit

Permalink
Update HackerNews.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulkp220 committed Mar 14, 2018
1 parent ee7bdfe commit 9db54fd
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/HackerNews.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ module HackerNews
using HTTP
using JSON

# Abstract Type
abstract type HNApiRoute end

# HNApiRoute Subtypes
type MaxItem <: HNApiRoute end
type TopStories <: HNApiRoute end
type NewStories <: HNApiRoute end
Expand All @@ -15,6 +17,7 @@ type ShowStories <: HNApiRoute end
type JobStories <: HNApiRoute end
type Updates <: HNApiRoute end

# Declaring the values
hn_route_string(::Type{MaxItem}) = "maxitem"
hn_route_string(::Type{TopStories}) = "topstories"
hn_route_string(::Type{NewStories}) = "newstories"
Expand Down Expand Up @@ -100,16 +103,25 @@ type HNUser
submitted= get(data, "submitted", nothing)) = new(data, id, delay, created, karma, about, submitted)
end

"""
Parse response for updates
"""
function parse_hn_response(::Type{Updates}, response, hn)
info("fetching updates..")
JSON.parse(convert(String, response.body))[hn.user_related ? "profiles":"items"]
end

"""
Parse response for maxitem
"""
function parse_hn_response(::Type{MaxItem}, response, hn)
info("fetching maxitem..")
parse(convert(String, response.body))
end

"""
Parse response
"""
function parse_hn_response(story, response, hn)
info("fetching $(story)...")
eval(parse(convert(String, response.body)))[1:hn.nposts]
Expand Down

0 comments on commit 9db54fd

Please sign in to comment.