Class: Twitorious::URL::Bitly

Inherits:
Object
  • Object
show all
Defined in:
lib/twitorious/url/bitly.rb

Instance Method Summary collapse

Constructor Details

#initialize(user, pass) ⇒ Bitly

Returns a new instance of Bitly.



6
7
8
9
# File 'lib/twitorious/url/bitly.rb', line 6

def initialize(user, pass)
  @auth = Twitorious::Auth::Basic.new(user, pass)
  @host = URI.parse("http://api.bit.ly")
end

Instance Method Details

#shorten(url) ⇒ Object



11
12
13
14
15
16
# File 'lib/twitorious/url/bitly.rb', line 11

def shorten(url)
  path = "/shorten?version=2.0.1&longUrl=#{CGI.escape(url)}"
  body = @auth.get(@host, path)
  json = JSON.parse(body)
  return json["results"][url]["shortUrl"]
end