altmetric / embiggen

A Ruby library to expand shortened URLs
https://rubygems.org/gems/embiggen
MIT License
124 stars 6 forks source link

Remove expand! in favour of EmbiggenedURIs #8

Closed mudge closed 9 years ago

mudge commented 9 years ago

GitHub: https://github.com/altmetric/embiggen/issues/1

As discussed in #1, rather than having two expansion methods (one gracefully handling errors but not communicating any information about them and one eagerly raising exceptions), consistently return a sum type from expand that both encapsulates exceptions and communicates success:

uri = Embiggen::URI('http://examp.le/badlink').expand
#=> #<Embiggen::EmbiggenedURI http://examp.le/badlink>
uri.success?
#=> true or false
uri.error
#=> #<Embiggen::BadShortenedURI ...>
uri.to_s
#=> 'http://examp.le/badlink'

Embiggen::EmbiggenedURI delegates to an internal Addresssable::URI but does so explicitly through Forwardable rather than SimpleDelegator: some methods are delegated (e.g. host, inferred_port, request_uri) but only for convenience and the true way to get a URI instance is to use Embiggen::EmbiggenedURI#uri.

mudge commented 9 years ago

Some questions for reviewers:

mudge commented 9 years ago

Discussed in a group: