70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/urlshort.rb', line 70
def self.shorten(link)
err = 0
clnt = HTTPClient.new
resp = clnt.get('http://v.gd/create.php',
{:format => 'simple', :url => link} ) 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
|