Class: RDF::Util::File::FaradayAdapter

Inherits:
HttpAdapter show all
Defined in:
vendor/bundler/ruby/2.5.0/bundler/gems/rdf-1b20f426c35b/lib/rdf/util/file.rb

Overview

Use Faraday for retrieving resources

Since:

  • 1.2

Class Method Summary collapse

Methods inherited from HttpAdapter

default_accept_header, headers

Class Method Details

.connObject

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

Since:

  • 1.2



179
180
181
182
183
184
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-1b20f426c35b/lib/rdf/util/file.rb', line 179

def conn
  @conn ||= Faraday.new do |conn|
    conn.use FaradayMiddleware::FollowRedirects
    conn.adapter Faraday.default_adapter
  end
end

.conn=(conn) ⇒ Object

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

Since:

  • 1.2



172
173
174
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-1b20f426c35b/lib/rdf/util/file.rb', line 172

def conn= conn
  @conn = conn
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)

    HTTP Proxy to use for requests.

  • headers (Array, String)

    ({}) HTTP Request headers

  • verify_none (Boolean)

    (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



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-1b20f426c35b/lib/rdf/util/file.rb', line 188

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
    }

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