Class: Codebot::Shortener::Custom
- Inherits:
-
Object
- Object
- Codebot::Shortener::Custom
- Defined in:
- lib/codebot/shortener.rb
Overview
Shortens URLs using a custom shortener
Instance Method Summary collapse
-
#initialize(shortener_url, shortener_secret) ⇒ Custom
constructor
A new instance of Custom.
- #shorten_url(url) ⇒ Object
Constructor Details
#initialize(shortener_url, shortener_secret) ⇒ Custom
Returns a new instance of Custom.
26 27 28 29 |
# File 'lib/codebot/shortener.rb', line 26 def initialize(shortener_url, shortener_secret) @shortener_url = URI(shortener_url) @shortener_secret = shortener_secret end |
Instance Method Details
#shorten_url(url) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/codebot/shortener.rb', line 31 def shorten_url(url) return url if url.to_s.empty? res = Net::HTTP.post_form @shortener_url, 'url' => url.to_s, 'secret' => @shortener_secret res.body.strip || url.to_s rescue StandardError url.to_s end |