Sha256: 5f2e004b3fd0e45844611722a753072942876384d9b14ac88fa620a8c29338d3

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

module Bitly
  module API
    
    LOGIN = 'concerthash'
    KEY = 'R_0fd8ec1ba81bee526dc9043f443eafb1'
    
    VERSION = '2.0.1'
    
    def self.get(action,query={})      
      response = RestClient.get path(action,query) 
      JSON.parse(response)['results']
    end                                   
    
    def self.path(path,query)        
      query_string = query.inject('') { |string,array| string.concat("&#{array[0]}=#{array[1]}")  }
      "http://api.bit.ly/#{path}?version=#{VERSION}#{query_string}&login=#{LOGIN}&apiKey=#{KEY}"
    end  
    
    
    #--------------------------------------------------------------------------
    # Shorten a URL
    #--------------------------------------------------------------------------
    
    # returns Bitly::URL for given URL
    # currently only works for one url at a time
    def self.shorten(url)    
      get('shorten','longUrl' => url)[url]
    end
    
    #--------------------------------------------------------------------------
    # Expand a Bitly::URL
    #--------------------------------------------------------------------------
    
    def self.expand(url)             
      bitly_hash = url.split('/').last
      get('expand','shortUrl' => url)[bitly_hash]['longUrl']
    end 
    

    
  end
end  
 

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
glasner-bitly-0.1.2 lib/bitly/api.rb