Module: URI

Defined in:
lib/epitools/core_ext/misc.rb

Instance Method Summary collapse

Instance Method Details

#get(headers = {}, redirect_limit = 10) ⇒ Object

Get this URI using Net::HTTP


155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/epitools/core_ext/misc.rb', line 155

def get(headers={}, redirect_limit=10)
  raise "Sorry, URI can't get from #{scheme.inspect} URIs yet" unless scheme =~ /^https?$/
  raise 'Too many HTTP redirections' if redirect_limit == 0

  # headers['User-Agent'] ||= USER_AGENT

  # response = Net::HTTP.start(host, port) do |http|
  #   # the_path = path.empty? ? "/" : path
  #   req = Net::HTTP::Get.new(self, headers)
  #   http.request(req)
  # end

  response = Net::HTTP.get_response(self)

  case response
  when Net::HTTPSuccess
    response
  when Net::HTTPRedirection
    # puts "redirect: #{response['location']}"
    URI(response['location']).get(headers, redirect_limit-1)
  else
    response.error!
  end
end

#paramsObject

Return a Hash of the variables in the query string


136
137
138
# File 'lib/epitools/core_ext/misc.rb', line 136

def params
  query ? query.to_params : {}
end

#to_strObject

URIs are strings, dammit!


143
144
145
# File 'lib/epitools/core_ext/misc.rb', line 143

def to_str
  to_s
end