Skip to content

Instantly share code, notes, and snippets.

@jugyo
Forked from ryumu/bitly.rb
Created April 7, 2011 02:29

Revisions

  1. 十行 revised this gist Apr 26, 2011. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions bitly.rb
    Original file line number Diff line number Diff line change
    @@ -2,8 +2,8 @@
    # shorten url using bit.ly if text is over 140
    Earthquake.init do
    config[:bitly] ||= {}
    config[:bitly][:username] ||= ''
    config[:bitly][:api_key] ||= ''
    config[:bitly][:username] ||= 'earthquakegem'
    config[:bitly][:api_key] ||= 'R_22e702353baf49751d053660e4c71a30'
    config[:bitly][:domain] ||= 'j.mp'

    input_filter do |text|
  2. 十行 revised this gist Apr 7, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bitly.rb
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@
    config[:bitly][:domain] ||= 'j.mp'

    input_filter do |text|
    if text =~ /^(:update|:reply)/ && text.size > 140
    if text =~ /^:(update|reply|retweet|message)/ && text.size > 140
    puts "shortening urls...".c(:info)
    text.gsub(URI.regexp(['http','https'])) do |url|
    query = "domain=#{config[:bitly][:domain]}&longUrl=#{URI.encode(url)}&login=#{config[:bitly][:username]}&apiKey=#{config[:bitly][:api_key]}"
  3. 十行 revised this gist Apr 7, 2011. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions bitly.rb
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,14 @@
    # earthquake.gem plugin
    # shorten url using bit.ly

    # shorten url using bit.ly if text is over 140
    Earthquake.init do
    config[:bitly] ||= {}
    config[:bitly][:username] ||= ''
    config[:bitly][:api_key] ||= ''
    config[:bitly][:domain] ||= 'j.mp'

    input_filter do |text|
    if text =~ %r|^:update|
    if text =~ /^(:update|:reply)/ && text.size > 140
    puts "shortening urls...".c(:info)
    text.gsub(URI.regexp(['http','https'])) do |url|
    query = "domain=#{config[:bitly][:domain]}&longUrl=#{URI.encode(url)}&login=#{config[:bitly][:username]}&apiKey=#{config[:bitly][:api_key]}"
    result = JSON.parse(Net::HTTP.get("api.bit.ly", "/v3/shorten?#{query}"))
    @@ -22,4 +22,4 @@
    text
    end
    end
    end
    end
  4. @ryumu ryumu revised this gist Apr 6, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bitly.rb
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@
    config[:bitly][:domain] ||= 'j.mp'

    input_filter do |text|
    if text =~ %r|^:|
    if text =~ %r|^:update|
    text.gsub(URI.regexp(['http','https'])) do |url|
    query = "domain=#{config[:bitly][:domain]}&longUrl=#{URI.encode(url)}&login=#{config[:bitly][:username]}&apiKey=#{config[:bitly][:api_key]}"
    result = JSON.parse(Net::HTTP.get("api.bit.ly", "/v3/shorten?#{query}"))
  5. @ryumu ryumu created this gist Apr 6, 2011.
    25 changes: 25 additions & 0 deletions bitly.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    # earthquake.gem plugin
    # shorten url using bit.ly

    Earthquake.init do
    config[:bitly] ||= {}
    config[:bitly][:username] ||= ''
    config[:bitly][:api_key] ||= ''
    config[:bitly][:domain] ||= 'j.mp'

    input_filter do |text|
    if text =~ %r|^:|
    text.gsub(URI.regexp(['http','https'])) do |url|
    query = "domain=#{config[:bitly][:domain]}&longUrl=#{URI.encode(url)}&login=#{config[:bitly][:username]}&apiKey=#{config[:bitly][:api_key]}"
    result = JSON.parse(Net::HTTP.get("api.bit.ly", "/v3/shorten?#{query}"))
    if result['status_code'] == 200
    result['data']['url']
    else
    url
    end
    end
    else
    text
    end
    end
    end