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, options) ⇒ RemoteDocument, Object
Methods inherited from HttpAdapter
default_accept_header, headers
Class Method Details
.conn ⇒ Object
Get the Faraday::Connection to use for retrieving RDF resources, or a default connect that follows redirects.
200 201 202 203 204 205 |
# File 'lib/rdf/util/file.rb', line 200 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
193 194 195 |
# File 'lib/rdf/util/file.rb', line 193 def conn= conn @conn = conn end |
.open_url(base_uri, options) ⇒ RemoteDocument, Object
Returns A RemoteDocument.
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/rdf/util/file.rb', line 212 def self.open_url(base_uri, ) response = conn.get do |req| req.url base_uri 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 } remote_document = RemoteDocument.new(response.body, ) else raise IOError, "<#{base_uri}>: #{response.status}" end end |