Skip to content

Instantly share code, notes, and snippets.

@CarolineMeeks
Forked from jehiah/bitly.rb
Created December 23, 2013 23:19
Show Gist options
  • Select an option

  • Save CarolineMeeks/8106516 to your computer and use it in GitHub Desktop.

Select an option

Save CarolineMeeks/8106516 to your computer and use it in GitHub Desktop.

Revisions

  1. @jehiah jehiah revised this gist Feb 25, 2011. 1 changed file with 13 additions and 5 deletions.
    18 changes: 13 additions & 5 deletions lib/bitly.rb
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,25 @@
    # Bit.ly API implementation - thanks to Richard Johansso http://gist.github.com/112191
    require 'httparty'

    class Api::Bitly
    include HTTParty
    base_uri 'api.bit.ly'
    basic_auth 'username', 'password'
    format :json

    # Usage: Bitly.shorten("http://example.com")
    def self.shorten(url)
    response = get('/shorten', :query => required_params.merge(:longUrl => url))
    response['results'][url]['shortUrl']
    response = get('/v3/shorten', :query => required_params.merge(:longUrl => url ))
    response['data']["url"]
    end

    # Usage: Bitly.stats("http://bit.ly/18LNRV")
    def self.clicks(url)
    response = get('/v3/clicks', :query => required_params.merge(:shortUrl => url))
    response['data']['clicks'][0]['user_clicks']
    end

    # your bit.ly api key can be found at http://bit.ly/a/your_api_key
    def self.required_params
    {:version => "2.0.1"}
    {:version => "2.0.1", :login => "LOGIN", :apiKey => 'API_KEY'}
    end
    end
  2. richardjohansson renamed this gist Jul 3, 2009. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. richardjohansson renamed this gist Jul 3, 2009. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. richardjohansson created this gist May 15, 2009.
    17 changes: 17 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    require 'httparty'

    class Api::Bitly
    include HTTParty
    base_uri 'api.bit.ly'
    basic_auth 'username', 'password'
    format :json

    def self.shorten(url)
    response = get('/shorten', :query => required_params.merge(:longUrl => url))
    response['results'][url]['shortUrl']
    end

    def self.required_params
    {:version => "2.0.1"}
    end
    end