Class: RDF::Util::File::HttpAdapter Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/rdf/util/file.rb

Overview

This class is abstract.

Subclass and override HttpAdapter.open_url to implement a custom adapter

Since:

  • 1.2

Direct Known Subclasses

FaradayAdapter, NetHttpAdapter, RestClientAdapter

Class Method Summary collapse

Class Method Details

.default_accept_headerString

Returns the value for an Accept header.

Returns:

  • (String)

    the value for an Accept header

Since:

  • 1.2



41
42
43
# File 'lib/rdf/util/file.rb', line 41

def self.default_accept_header
  (RDF::Format.accept_types + %w(*/*;q=0.1)).join(", ")
end

.default_user_agentString

Returns the default User-Agent used when fetching resources.

Returns:

  • (String)

    the default User-Agent used when fetching resources.

Since:

  • 1.2



47
48
49
# File 'lib/rdf/util/file.rb', line 47

def self.default_user_agent
  "Ruby RDF.rb/#{RDF::VERSION}"
end

.headers(headers: {}) ⇒ Hash

Returns A hash of HTTP request headers.

Parameters:

  • headers (Array, String) (defaults to: {})

    HTTP Request headers

Returns:

  • (Hash)

    A hash of HTTP request headers

Since:

  • 1.2



33
34
35
36
37
# File 'lib/rdf/util/file.rb', line 33

def self.headers headers: {}
  headers['Accept'] ||= default_accept_header
  headers['User-Agent'] ||= default_user_agent
  headers
end

.open_url(base_uri, proxy: nil, headers: {}, verify_none: false, **options) ⇒ RemoteDocument, Object

This method is abstract.

Returns A RemoteDocument. If a block is given, the result of evaluating the block is returned.

Parameters:

  • base_uri (String)

    to open

  • proxy (String) (defaults to: nil)

    HTTP Proxy to use for requests.

  • headers (Array, String) (defaults to: {})

    ({}) HTTP Request headers

    Defaults ‘Accept` header based on available reader content types to allow for content negotiation based on available readers.

    Defaults ‘User-Agent` header, unless one is specified.

  • verify_none (Boolean) (defaults to: false)

    (false) Don’t verify SSL certificates

  • options (Hash{Symbol => Object})

    options are ignored in this implementation. Applications are encouraged to override this implementation to provide more control over HTTP headers and redirect following.

Returns:

Raises:

  • (IOError)

    if not found

Since:

  • 1.2



70
71
72
# File 'lib/rdf/util/file.rb', line 70

def self.open_url(base_uri, proxy: nil, headers: {}, verify_none: false, **options)
  raise NoMethodError.new("#{self.inspect} does not implement required method `open_url` for ", "open_url")
end