Class: Mush::Services::Bitly

Inherits:
AuthenticatedService show all
Defined in:
lib/mush/services/bitly.rb

Overview

bit.ly and j.mp login=bitlyapidemo apiKey=R_0da49e0a9118ff35f52f629d2d71bf07 longUrl=http%3A%2F%2Fbetaworks.com%2F format=json domain=j.mp

Instance Attribute Summary

Attributes inherited from AuthenticatedService

#apikey, #login

Instance Method Summary collapse

Methods inherited from AuthenticatedService

#authorize, #initialize

Methods inherited from Mush::Service

#authorize, #get, #post

Constructor Details

This class inherits a constructor from Mush::AuthenticatedService

Instance Method Details

#shorten(url) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/mush/services/bitly.rb', line 15

def shorten(url)
  invalid_uri_msg = "Please provide a valid URI, including http://"
  invalid_auth_msg = "Invalid Authorization Data, please provide both login and apikey"
  
  raise InvalidURI.new invalid_uri_msg if url.empty?
  raise InvalidAuthorizationData.new(invalid_auth_msg) if .empty? or apikey.empty?
  
  options = {}
  options[:query] = {:login => self., :apiKey => self.apikey, :longUrl => url}
  
  response = get('/shorten', options)
  
  response["status_code"] == 200 ? response["data"]["url"].chomp : response["status_txt"]
end