class RDF::Util::File::FaradayAdapter

Use Faraday for retrieving resources @since 1.2

Public Class Methods

conn() click to toggle source

Get the Faraday::Connection to use for retrieving RDF resources, or a default connect that follows redirects.

# File lib/rdf/util/file.rb, line 190
def conn
  @conn ||= Faraday.new do |conn|
    conn.use FaradayMiddleware::FollowRedirects
    conn.adapter Faraday.default_adapter
  end
end
conn=(conn) click to toggle source

Set the Faraday::Connection to use for retrieving RDF resources

# File lib/rdf/util/file.rb, line 183
def conn= conn
  @conn = conn
end
open_url(base_uri, proxy: nil, headers: {}, verify_none: false, **options) click to toggle source

(see HttpAdapter.open_url)

# File lib/rdf/util/file.rb, line 199
def self.open_url(base_uri, proxy: nil, headers: {}, verify_none: false, **options)
  response = conn.get do |req|
    req.url base_uri
    headers(headers: headers).each do |k,v|
      req.headers[k] = v
    end
  end

  case response.status
  when 200..299
    # found object

    # If a Location is returned, it defines the base resource for this file, not it's actual ending location
    document_options = {
      base_uri:     RDF::URI(response.headers.fetch(:location, response.env.url)),
      code:         response.status,
      headers:      response.headers
    }

    RemoteDocument.new(response.body, document_options)
  else
    raise IOError, "<#{base_uri}>: #{response.status}"
  end
end