Class: RDF::Util::File::FaradayAdapter
- Inherits:
-
HttpAdapter
- Object
- HttpAdapter
- RDF::Util::File::FaradayAdapter
- Defined in:
- lib/rdf/util/file.rb
Overview
Use Faraday for retrieving resources
Class Method Summary collapse
-
.conn ⇒ Object
Get the Faraday::Connection to use for retrieving RDF resources, or a default connect that follows redirects.
-
.conn=(conn) ⇒ Object
Set the Faraday::Connection to use for retrieving RDF resources.
- .open_url(base_uri, proxy: nil, headers: {}, verify_none: false, **options) ⇒ RemoteDocument, Object abstract
Methods inherited from HttpAdapter
default_accept_header, default_user_agent, headers
Class Method Details
.conn ⇒ Object
Get the Faraday::Connection to use for retrieving RDF resources, or a default connect that follows redirects.
190 191 192 193 194 195 |
# 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) ⇒ Object
Set the Faraday::Connection to use for retrieving RDF resources
183 184 185 |
# 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) ⇒ RemoteDocument, Object
This method is abstract.
Returns A RemoteDocument. If a block is given, the result of evaluating the block is returned.
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/rdf/util/file.rb', line 199 def self.open_url(base_uri, proxy: nil, headers: {}, verify_none: false, **) 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 = { base_uri: RDF::URI(response.headers.fetch(:location, response.env.url)), code: response.status, headers: response.headers } RemoteDocument.new(response.body, ) else raise IOError, "<#{base_uri}>: #{response.status}" end end |