The challenge was to implement an enhanced HackerNews top stories API. This resource should provide a list and a detail endpoint.
/stories/
/stores/:id
Return a JSON covering a list of HackerNews top story objects.
- count (default: 10) -- limit the number of top stories returned
- order (options: title, by, score) -- sort the retrieved stories by the specified key
You will need to retrieve the list of Top Stories (/v0/topstories
), then retrieve the Item object for each top story ID.
Example (/stories/?count=2
):
[
{
"by": "foo",
"descendants": 2,
"id": 42,
"kids": [111, 222],
"score": 99,
"time": 1175714200,
"title": "Example 1",
"type": "story",
"url": "http://www.google.com/1"
},
{
"by": "bar",
"descendants": 3,
"id": 43,
"kids": [333, 444, 555],
"score": 80,
"time": 1175714200,
"title": "Example 2",
"type": "story",
"url": "http://www.google.com/2"
}
]
Return JSON response covering a single HackerNews story.
- count (default: 10) -- limit the number of comments included in comments
The endpoint returns an individual top story Item object with its associated comments.
Add the new comments array to the story detail response. This array should contain up to N (N=count
) total comment Items. For each included comment, retrieve the comment object by its ID, represented under the original kids array for the story.
Example (/stories/43/?count=2
)
{
"by": "bar",
"descendants": 3,
"id": 43,
"kids": [333, 444, 555],
"comments": [{
"by": "baz",
"id": 2921983,
"kids": [],
"parent": 43,
"text": "Hello, world",
"time": 1314211127,
"type": "comment"
},
{
"by": "baz",
"id": 2921983,
"kids": [45],
"parent": 44,
"text": "Hello, world",
"time": 1314211127,
"type": "comment"
}
],
"score": 80,
"time": 1175714200,
"title": "Example 2",
"type": "story",
"url": "http://www.google.com/2"
}
run: bundle exec rspec
run: bundle install
to install the gems
and rails s
to start the server