Module: Bitly::API

Defined in:
lib/bitly/api.rb

Constant Summary collapse

VERSION =
'2.0.1'

Class Method Summary collapse

Class Method Details

.expand(url) ⇒ Object


Expand a Bitly::URL




32
33
34
35
# File 'lib/bitly/api.rb', line 32

def self.expand(url)             
  bitly_hash = url.split('/').last
  get('expand','shortUrl' => url)[bitly_hash]['longUrl']
end

.get(action, query = {}) ⇒ Object



7
8
9
10
# File 'lib/bitly/api.rb', line 7

def self.get(action,query={})      
  response = RestClient.get path(action,query) 
  JSON.parse(response)['results']
end

.path(path, query) ⇒ Object



12
13
14
15
# File 'lib/bitly/api.rb', line 12

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(url) ⇒ Object

returns Bitly::URL for given URL currently only works for one url at a time



24
25
26
# File 'lib/bitly/api.rb', line 24

def self.shorten(url)    
  get('shorten','longUrl' => url)[url]
end