module ShortURL
Constants
- CREDENTIALS_PATH
- SERVICES
Hash table of all the supported services. The key is a symbol representing the service (usually the hostname minus the .com, .net, etc.) The value is an instance of
Service
with all the parameters set so that wheninstance
.call is invoked, the shortened URL is returned.- VERSION
Public Class Methods
credentials()
click to toggle source
# File lib/shorturl.rb 13 def self.credentials 14 @credentials ||= begin 15 if File.file?(CREDENTIALS_PATH) 16 YAML.load_file(CREDENTIALS_PATH) 17 else 18 {} 19 end 20 end 21 end
credentials_for(service)
click to toggle source
# File lib/shorturl.rb 23 def self.credentials_for(service) 24 credentials.fetch(service,{}) 25 end
shorten("http://mypage.com") → Uses TinyURL
click to toggle source
shorten("http://mypage.com", :bitly)
Main method of ShortURL
, its usage is quite simple, just give an url to shorten and an optional service. If no service is selected, RubyURL.com will be used. An invalid service symbol will raise an ArgumentError exception
Valid service
values:
-
:tinyurl
-
:shorl
-
:snipurl
-
:metamark
-
:makeashorterlink
-
:skinnylink
-
:linktrim
-
:shorterlink
-
:minlink
-
:lns
-
:fyad
-
:d62
-
:shiturl
-
:littlink
-
:clipurl
-
:shortify
-
:orz
# File lib/shorturl.rb 127 def self.shorten(url, service = :tinyurl) 128 if SERVICES.has_key?(service) 129 SERVICES[service].call(url) 130 else 131 raise InvalidService 132 end 133 end
valid_services()
click to toggle source
Array containing symbols representing all the implemented URL shortening services
# File lib/shorturl.rb 95 def self.valid_services 96 SERVICES.keys 97 end