Add gallery() unified interface. Add Main(), Subreddit() and Memes().
flowchartsman
Branch: alaska/go-imgur:master
Branch: liamstask/go-imgur:master
Merged
Merged pull request
Merged in walkeraj/go-imgur (pull request #2)
Merged in walkeraj/go-imgur (pull request #2)
Created new generic call gallery(), which handles URL building for most routes that share similar functionality. Modified Main() to use this functionality and added Subreddit() and Memes() that use it as well. Also made Search() use gallery(). Random() remains because the random route is different and only needs a page number.
Added tests for all new methods with responses abbreviated from actual Imgur responses as of today.
NOTES
No effort is made to protect the user from making invalid calls. We don't ensure that the sort/section/etc are valid for that route; we just make the URL according to the rules and rely on the user not to just throw away err.
Page must always be specified, even if it's zero. Could potentially make this optional through the use of variadics. A liiiiitle wonky, especially considering additional ints would be allowed, but thrown away.
Is this complicated enough to use a search struct? That would still be fairly simple and would clean up the calls to all methods. Would allow us to start doing validity checking for sort/section etc, and could even allow compile-time checking with consts like:
type gallerySort int; const ( srtTime = iota srtViral srtTop )
This would break API, though.