Add gallery() unified interface. Add Main(), Subreddit() and Memes().

Merged
#2 · Created  · Last updated

Merged pull request

Merged in walkeraj/go-imgur (pull request #2)

77ae416·Author: ·Closed by: ·2014-07-13

Description

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.

0 attachments

0 comments

Loading commits...