2 ms·
> Are there clients that don't break when you change the API the client works with? Pretty smart clients. Yes, you can write clients for GitHub's API that work
by steveklabnik 14y ago
> Are there clients that don't break when you change the API the client works with? Pretty smart clients.
Yes, you can write clients for GitHub's API that works that way, for example.
Here, I whipped you up one: https://gist.github.com/steveklabnik/5282209/e48b100d95ff77fcfef4c02364e584725043c777 https://gist.github.com/steveklabnik/5282209/e48b100d95ff77f...
This client will return you information about the first gist on the second page of the public list. It does this by fetching the list of gists from the root, then using the pagination to walk forward. GitHub can change all of this, and it'll still work.
$ ruby fetch_gists.rb
DATA:
ID: 5282131
URL: https://api.github.com/gists/5282131
USER: sparksp
Bonus: here's a slightly refactored version. The logic is more clear when you move things into helpers. https://gist.github.com/steveklabnik/5282209/52ed62366586838cdf987682dde7fd05eb1848e7 https://gist.github.com/steveklabnik/5282209/52ed62366586838...
- barkmadley 14y agoIf I may, the goal seems a bit incorrectly specified for hypermedia. For instance, if github decided to change the number of results they return per page, then your script would not break, but it would have a different meaning. I would suggest a better goal to be "get the 11th public gist". Although that still isn't perfect since it doesn't mention how the collection would be sorted (I presume by date).
- steveklabnik 14y agoAbsolutely, this goal is bad. I was just trying to show off the mechanics, and that clients don't have to be complex.