Created
August 14, 2012 19:31
-
-
Save danielevans/3352015 to your computer and use it in GitHub Desktop.
Weechat helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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