Skip to content

Instantly share code, notes, and snippets.

@kayakaya
Created March 2, 2011 13:14
Show Gist options
  • Save kayakaya/850906 to your computer and use it in GitHub Desktop.
Save kayakaya/850906 to your computer and use it in GitHub Desktop.
diff of bitly.rb
diff --git a/plugin/bitly.rb b/plugin/bitly.rb
index c296d24..e07e131 100644
--- a/plugin/bitly.rb
+++ b/plugin/bitly.rb
@@ -13,7 +13,7 @@
#
require 'json'
-require 'open-uri'
+require 'net/http'
def bitly( long_url )
return nil if !long_url or long_url.empty?
@@ -26,7 +26,9 @@ def bitly( long_url )
query = "/v3/shorten?longUrl=#{CGI::escape long_url}&login=#{login}&apiKey=#{key}&format=json"
begin
- @bitly_cache[long_url] = JSON::parse( open( "http://api.bit.ly#{query}", &:read ) )['data']['url']
+ Net::HTTP.version_1_2
+ res = Net::HTTP.get("api.bit.ly", "#{query}")
+ @bitly_cache[long_url] = JSON::parse( res, &:read )['data']['url']
rescue TypeError # biy.ly returns an error.
nil
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment