Skip to content

Instantly share code, notes, and snippets.

@danielevans
Created August 14, 2012 19:31
Show Gist options
  • Select an option

  • Save danielevans/3352015 to your computer and use it in GitHub Desktop.

Select an option

Save danielevans/3352015 to your computer and use it in GitHub Desktop.
Weechat helper
def yourls_shorten(url)
# use yourls shortener
# need to provide url config option
require 'rubygems'
require 'json/pure'
params = ['action=shorturl']
params << 'format=simple'
params << 'url=' + URI.encode(url)
yourls_url = Weechat.config_get_plugin('yourls_url')
api_url = [yourls_url, params.join('&')].join(yourls_url.include?('?') ? '&' : '?')
begin
body_txt = fetch(api_url)
rescue Exception => ex
return "Failure yourls shortening url: " + ex.to_s
end
body_txt
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment