class Udongo::Redirects::Response

Public Class Methods

new(response) click to toggle source
# File lib/udongo/redirects/response.rb, line 3
def initialize(response)
  @response = response
end

Public Instance Methods

endpoint_matches?(destination) click to toggle source
# File lib/udongo/redirects/response.rb, line 7
def endpoint_matches?(destination)
  sanitize_destination(destination) == headers['Location']
end
headers() click to toggle source

Apparently Curb does not provide parsed headers… A bit sad. TODO: Handle multiple location headers so endpoint_matches? can succeed. For now, the last location header is returned as a value.

# File lib/udongo/redirects/response.rb, line 14
def headers
  list = @response.header_str.split(/[\r\n]+/).map(&:strip)
  Hash[list.flat_map{ |s| s.scan(/^(\S+): (.+)/) }.map { |pair|
    [pair.first.to_s.camelcase, pair.second]
  }]
end
raw() click to toggle source
# File lib/udongo/redirects/response.rb, line 21
def raw
  @response
end
sanitize_destination(destination) click to toggle source
# File lib/udongo/redirects/response.rb, line 25
def sanitize_destination(destination)
  destination.to_s
             .gsub('/?', '?')
             .chomp('/')
end
success?() click to toggle source
# File lib/udongo/redirects/response.rb, line 31
def success?
  ['200 OK', '301 Moved Permanently'].include?(@response.status)
end