class DwcaHunter::Url

Attributes

header[R]
net_http[R]
path[R]

Public Class Methods

new(url) click to toggle source
# File lib/dwca_hunter/url.rb, line 6
def initialize(url)
  @url = url
  @parsed_url = URI.parse(url.strip)
  @path = @parsed_url.path == '' ? '/' : @parsed_url.path
  @net_http = Net::HTTP.new(@parsed_url.host, @parsed_url.port)
  @header = get_header
end

Public Instance Methods

content_length() click to toggle source
# File lib/dwca_hunter/url.rb, line 19
def content_length
  header ? header.content_length : nil
end
valid?() click to toggle source

confirm that the passed in URL is valid and responses with a proper code

# File lib/dwca_hunter/url.rb, line 15
def valid?
    @header && ['200','301','302'].include?(@header.code)
end

Private Instance Methods

get_header() click to toggle source
# File lib/dwca_hunter/url.rb, line 25
def get_header
  begin
    return @net_http.head(@path)
  rescue SocketError
    return nil
  end
end