-
Notifications
You must be signed in to change notification settings - Fork 3
Issue #8 - API Method Chaining #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
… additional tags and before option. Work in progress.
…ixtures.json. Small fix for setHitsPerPage function
|
Awesome work, I know you put a ton of time and work into this. I like the way that this looks, will you bump the version to 2.0.0? :) In the future I'd like to change |
|
Thanks! Version bumped and merge done. Want me to make the release? So basically like what chai does with should and expect? That is definitely cleaner. |
|
You could use getters for this and have minimal code changes. For example, to make this work for hn.story or hn.comment you can simply change line 170 to: Object.defineProperty(module.exports, fName, {enumerable: true, get: function () {However, this has the problem that .story() and .story(id) no longer works because in javascript it has to either be a getter or a function, it can't be both. However, this can be fixed by adding an ".id(id)" function so you could do .story.id ... that would be more coding work though. |
|
Sorry about the late response. So the getter approach as you both mentioned works, but we run into a hitch with story (as @euank mentioned), top, and recent. That is, all 3 have a single optional param, and they can’t be both a getter and a function (as @euank also mentioned). So here’s a suggestion, have hn.comment.story.top.execute(cb);
hn.comment.story_id(id).search(query).execute(cb);So that means that methods like search, just become What do you think? Is there a better way to do it? |
|
Any thoughts? :) |
|
Sorry, I've been super busy these past few weeks. What if |
|
No worries! Yeah that works, sounds good. |
- As discussed in #9 - Does not enforce correct usage currently (id without story) - Doesn't handle id before story
|
So are we cool with the I'm asking because I'm thinking that its probably best to do this change first (switch to getters + execute()) before completing the other open issues. |
Methods
Callback only
getComments(cb)=comment().top(cb)getLastComments(cb)=comment().recent(cb)getPolls(cb)=poll().top(cb)getLastPolls(cb)=poll.recent(cb)getPosts(cb)=story().poll().top(cb)getLastPosts(cb)=story().poll().recent(cb)getStories(cb)=story().top(cb)getLastStories(cb)=story.recent(cb)String(s) and callback
getCommentsSince(since, cb)=comment().since(marker, cb)getPollsSince(since, cb)=poll().since(marker, cb)getPostsSince(since, cb)=story().poll().since(marker, cb)getStoriesSince(since, cb)=story().since(marker, cb)getItem(id, cb)=item(id, cb)getUser(username, cb)=user(username, cb)getUserComments(username, cb)=author(username).comment().top(cb)getLastUserComments(username, cb)=author(username).comment().recent(cb)getUserCommentsSince(username, since, cb)=author(username).comment().since(marker, cb)getUserPolls(username, cb)=author(username).poll().top(cb)getLastUserPolls(username, cb)=author(username).poll().recent(cb)getUserPollsSince(username, since, cb)=author(username).poll().since(marker, cb)getUserPosts(username, cb)=author(username).story().poll().top(cb)getLastUserPosts(username, cb)=author(username).story().poll().recent(cb)getUserPostsSince(username, since, cb)=author(username).story().poll().since(marker, cb)getUserStories(username, cb)=author(username).story().top(cb)getLastUserStories(username, cb)=author(username).story().recent(cb)getUserStoriesSince(username, since, cb)=author(username).story().since(marker, cb)searchComments(query, cb)=comment().top().search(query, cb)searchLastComments(query, cb)=comment().recent().search(query, cb)searchCommentsSince(query, since, cb)=comment().search(query).since(marker, cb)searchPolls(query, cb)=poll().top().search(query, cb)searchLastPolls(query, cb)=poll().recent().search(query, cb)searchPollsSince(query, since, cb)=poll().search(query).since(marker, cb)searchPosts(query, cb)=story().poll().top().search(query, cb)searchLastPosts(query, cb)=story().poll().recent().search(query, cb)searchPostsSince(query, since, cb)=story().poll().search(query).since(marker, cb)searchStories(query, cb)=story().top().search(query, cb)searchLastStories(query, cb)=story().recent().search(query, cb)searchStoriesSince(query, since, cb)=story().search(query).since(marker, cb)Object and callback
search(obj, cb)= Chain of any tags & page settings +search(query, cb)searchLast(obj, cb)= Chain of any tags & page settings +recent().search(query, cb)searchSince(obj, since, cb)= Chain of any tags & page settings +since().search(query, cb)