Class: Codebot::Shortener::Github
- Inherits:
-
Object
- Object
- Codebot::Shortener::Github
- Defined in:
- lib/codebot/shortener.rb
Overview
Shortens URLs using Github shortener
Instance Method Summary collapse
-
#shorten_url(url) ⇒ String
Shortens a URL with GitHub’s git.io URL shortener.
Instance Method Details
#shorten_url(url) ⇒ String
Shortens a URL with GitHub’s git.io URL shortener. The domain must belong to GitHub.
13 14 15 16 17 18 19 20 21 |
# File 'lib/codebot/shortener.rb', line 13 def shorten_url(url) return url if url.to_s.empty? uri = URI('https://git.io') res = Net::HTTP.post_form uri, 'url' => url.to_s res['location'] || url.to_s rescue StandardError url.to_s end |