Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added method to shorten url.

  • Loading branch information...
commit 39dc0719fe13153d234ee0fa421db86f02fcbea5 1 parent ff53ccb
@techmaniack authored
Showing with 14 additions and 3 deletions.
  1. +5 −1 bin/lmgtfy
  2. +9 −2 lib/lmgtfy/runner.rb
View
6 bin/lmgtfy
@@ -3,4 +3,8 @@
require 'lmgtfy/runner'
-STDOUT.puts Lmgtfy::Runner.new.generate_lmgtfy_url
+lmgt = Lmgtfy::Runner.new.generate_lmgtfy_url
+shrt = Lmgtfy::Runner.new.generate_short_url
+
+puts "lmgtfy_url => #{lmgt}"
+puts "short_url => #{shrt}"
View
11 lib/lmgtfy/runner.rb
@@ -1,9 +1,9 @@
+require 'json'
+require 'net/http'
require 'uri'
module Lmgtfy
-
class Runner
-
attr_reader :query
def initialize
@@ -14,6 +14,13 @@ def generate_lmgtfy_url
"http://lmgtfy.com/?#{@query}"
end
+ def generate_short_url
+ base_url = "http://is.gd/create.php?format=json&url="
+ string = "http://lmgtfy.com/?#{@query}"
+ response = Net::HTTP.get_response(URI.parse(base_url + string))
+ JSON.parse(response.body)["shorturl"]
+ end
+
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.