Module: ISGD
- Defined in:
- lib/isgd.rb
Class Method Summary collapse
-
.lookup(url) ⇒ String
Looks up a short URL's original long URL.
-
.shorten(url, short = nil) ⇒ String
Shortens a URL using ISGD.
Instance Method Summary collapse
-
#lookup(url) ⇒ String
private
Looks up a short URL's original long URL.
-
#shorten(url, short = nil) ⇒ String
private
Shortens a URL using ISGD.
Class Method Details
.lookup(url) ⇒ String
Looks up a short URL's original long URL.
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/isgd.rb', line 36 def lookup(url) params = { format: 'json', shorturl: url } @client = HTTPClient.new if @client.nil? response = JSON.parse(@client.get(URI.parse('https://is.gd/forward.php'), params).body) return response['errormessage'] if response.key?('errormessage') response['url'] end |
.shorten(url, short = nil) ⇒ String
Shortens a URL using ISGD.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/isgd.rb', line 15 def shorten(url, short = nil) params = { format: 'json', url: url } params[:shorturl] = short if !short.nil? && 30 < short.length < 5 @client = HTTPClient.new if @client.nil? response = JSON.parse(@client.get(URI.parse('https://is.gd/create.php'), params).body) return response['errormessage'] if response.key?('errormessage') response['shorturl'] end |
Instance Method Details
#lookup(url) ⇒ String (private)
Looks up a short URL's original long URL.
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/isgd.rb', line 36 def lookup(url) params = { format: 'json', shorturl: url } @client = HTTPClient.new if @client.nil? response = JSON.parse(@client.get(URI.parse('https://is.gd/forward.php'), params).body) return response['errormessage'] if response.key?('errormessage') response['url'] end |
#shorten(url, short = nil) ⇒ String (private)
Shortens a URL using ISGD.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/isgd.rb', line 15 def shorten(url, short = nil) params = { format: 'json', url: url } params[:shorturl] = short if !short.nil? && 30 < short.length < 5 @client = HTTPClient.new if @client.nil? response = JSON.parse(@client.get(URI.parse('https://is.gd/create.php'), params).body) return response['errormessage'] if response.key?('errormessage') response['shorturl'] end |