Class: Twitorious::URL::Bitly
- Inherits:
-
Object
- Object
- Twitorious::URL::Bitly
- Defined in:
- lib/twitorious/url/bitly.rb
Instance Method Summary collapse
-
#initialize(user, pass) ⇒ Bitly
constructor
A new instance of Bitly.
- #shorten(url) ⇒ Object
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 |