Class: IsGd

Inherits:
Object
  • Object
show all
Defined in:
lib/urlshort.rb

Class Method Summary collapse

Class Method Details

.shorten(link) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/urlshort.rb', line 38

def self.shorten(link)
    err = 0
    clnt = HTTPClient.new
    resp = clnt.get('http://is.gd/create.php', 
             {:format => 'simple', :url => link} )#.content
    begin
        case resp.status_code
        when 200
            return resp.content
        when 400
            raise BadRequest.new(resp.content)
        when 406
            raise NotAcceptable.new(resp.content)
        when 502
            raise BadGateway.new(resp.content)
        when 503
            raise ServiceUnavailable.new(resp.content)
        end
    rescue BadRequest
        err = 1
    rescue NotAcceptable
        err = 1
    rescue BadGateway
        err = 1
    rescue ServiceUnavailable
        err = 1
    end
    return err
end