class RDF::Util::File::RestClientAdapter
If the [Rest Client](rubygems.org/gems/rest-client) gem is included, it will be used for retrieving resources allowing for sophisticated HTTP caching using [REST Client Components](rubygems.org/gems/rest-client-components) allowing the use of `Rack::Cache` to avoid network access. @since 1.2
Public Class Methods
open_url(base_uri, options)
click to toggle source
@see RDF::Util::File::HttpAdapter.open_url @param [String] base_uri to open @param [Hash{Symbol => Object}] options @return [RemoteDocument, Object] A {RemoteDocument}. If a block is given, the result of evaluating the block is returned. @raise [IOError] if not found
# File lib/rdf/util/file.rb, line 89 def self.open_url(base_uri, options) ssl_verify = options[:verify_none] ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER # If RestClient is loaded, prefer it RestClient.proxy = options[:proxy].to_s if options[:proxy] client = RestClient::Resource.new(base_uri, verify_ssl: ssl_verify) client.get(headers(options)) do |response, request, res, &blk| case response.code 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, base_uri)), code: response.code.to_i, headers: response.headers } remote_document = RemoteDocument.new(response.body, document_options) when 300..399 # Document base is redirected location # Location may be relative base_uri = ::URI.join(base_uri, response.headers[:location].to_s).to_s response.follow_redirection(request, res, &blk) else raise IOError, "<#{base_uri}>: #{response.code}" end end end