I’d encourage you to reconsider the necessity of the existence of the shorteners class method. It will be a maintenance nightmare.
It still seems valuable to provide a default list of shorteners but to encourage users to supply their own.
The current implementation interrogates Configuration.shorteners with any? and expects to be yielded a series of domains that respond to to_s.
If the interface between Embiggen::URI and Configuration.shorteners was simplified to include? (or something similar) then it would be possible to replace a static list of shorteners with much more powerful options, e.g.
require 'bitly'
class BitlyDomains
extend Forwardable
attr_reader :client
def_delegator :client, :pro?, :include?
def initialize(client)
@client = client
end
end
Bitly.use_api_version_3
Bitly.configure do |config|
config.api_version = 3
config.access_token = ENV.fetch('BITLY_ACCESS_TOKEN')
end
Embiggen.configure do |config|
config.shorteners = BitlyDomains.new(Bitly.client)
end
As raised by @sferik on Twitter:
It still seems valuable to provide a default list of shorteners but to encourage users to supply their own.
The current implementation interrogates
Configuration.shorteners
withany?
and expects to be yielded a series of domains that respond toto_s
.If the interface between
Embiggen::URI
andConfiguration.shorteners
was simplified toinclude?
(or something similar) then it would be possible to replace a static list of shorteners with much more powerful options, e.g.