Class: Umatic::HTTPClient
- Inherits:
-
Object
- Object
- Umatic::HTTPClient
- Defined in:
- lib/client.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.instance ⇒ Object
7 8 9 |
# File 'lib/client.rb', line 7 def self.instance @@instance ||= new end |
Instance Method Details
#get(url) ⇒ Object
28 29 30 31 |
# File 'lib/client.rb', line 28 def get(url) uri = open(url) Net::HTTP.get(URI.parse(uri)) end |
#open(uri_str, limit = 2) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/client.rb', line 11 def open(uri_str, limit = 2) raise 'HTTP redirect too deep' if limit == 0 uri = URI.parse(uri_str) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true if uri.scheme == "https" response = http.head(uri.path + '?' + (uri.query ? uri.query : '')) case response when Net::HTTPSuccess then uri_str when Net::HTTPRedirection then open(response['location'], limit - 1) else response.error! end end |