rdf 1.1.10 → 1.1.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c527ab8ceef6cc215b7b30f603e3a51d3a0ee403
4
- data.tar.gz: 9c47a7510c2f8b4e0ff6dd6048167c32055de5d3
3
+ metadata.gz: a7d765dce315d0c9f719adae387e1cec7f945958
4
+ data.tar.gz: 9446ae5e871f78abf5a43e783e4a90d193160984
5
5
  SHA512:
6
- metadata.gz: d9a8dc1d4eec0baab67d6407b677f1a72825149a525c37b6ce8a34fba96d76814be3824a776d1e456f10af088c667bf28c27f7c528e4fd02a0dc90fd16c1d1b3
7
- data.tar.gz: d26dac7f54707765751e32a249eb244862e86abdcdad12c83dcd81a0356ad902c46b0302f1734dfbc93c31b9477303cec3456dd3bc281f69f1ca89e5f2602693
6
+ metadata.gz: 0b9b5e08ba70b4574a955c30154bc4702ba0ca5767b734aafdeb2d1919da2fe961ab93c74122d1ab89e023bb710943e5dbfc5a2072141db5f219a4d9756f91ca
7
+ data.tar.gz: 1dd2bae743a05599b83ddaa860817aa9afd2a4bc1e47dc6606a79aaf9b01e87583ef61ac3e9c0cba89fc0fbd31bd4c78be85e8c2e3c3bab9b260f72d75e8a83e
data/README CHANGED
@@ -321,6 +321,15 @@ from BNode identity (i.e., they each entail the other)
321
321
  ### RDF Vocabularies
322
322
 
323
323
  * {RDF} - Resource Description Framework (RDF)
324
+ * {RDF::OWL} - Web Ontology Language (OWL)
325
+ * {RDF::RDFS} - RDF Schema (RDFS)
326
+ * {RDF::RDFV} - RDF Vocabulary (RDFV)
327
+ * {RDF::XSD} - XML Schema (XSD)
328
+
329
+ #### Deprecated Vocabularies
330
+
331
+ The following vocabularies will be deprecated in RDF.rb 2.0 and moved to the rdf-vocab gem.
332
+
324
333
  * {RDF::CC} - Creative Commons (CC)
325
334
  * {RDF::CERT} - W3 Authentication Certificate (CERT)
326
335
  * {RDF::DC} - Dublin Core (DC)
@@ -335,10 +344,7 @@ from BNode identity (i.e., they each entail the other)
335
344
  * {RDF::MA} - Media Resources (MA)
336
345
  * {RDF::MO} - Music Ontology (MO)
337
346
  * {RDF::OG} - Open Graph protocol (OG)
338
- * {RDF::OWL} - Web Ontology Language (OWL)
339
347
  * {RDF::PROV} - Provenance on the web (PROV)
340
- * {RDF::RDFS} - RDF Schema (RDFS)
341
- * {RDF::RDFV} - RDF Vocabulary (RDFV)
342
348
  * {RDF::RSA} - W3 RSA Keys (RSA)
343
349
  * {RDF::RSS} - RDF Site Summary (RSS)
344
350
  * {RDF::SCHEMA} - Schema.org (SCHEMA)
@@ -354,7 +360,6 @@ from BNode identity (i.e., they each entail the other)
354
360
  * {RDF::WOT} - Web of Trust (WOT)
355
361
  * {RDF::XHTML} - Extensible HyperText Markup Language (XHTML)
356
362
  * {RDF::XHV} - XHTML Vocabulary (XHV)
357
- * {RDF::XSD} - XML Schema (XSD)
358
363
 
359
364
  ## Dependencies
360
365
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.10
1
+ 1.1.11
@@ -16,7 +16,7 @@ module RDF
16
16
  # Defines the maximum number of interned Node references that can be held
17
17
  # cached in memory at any one time.
18
18
  #
19
- # Note that caching interned nodes means that two different invocations using the same symbol will result in the same node, which may not be appropriate depending on the context from which it is used. RDF requires that bnodes with the same label are, in fact, different bnodes, unless they are used wihin the same document.
19
+ # Note that caching interned nodes means that two different invocations using the same symbol will result in the same node, which may not be appropriate depending on the context from which it is used. RDF requires that bnodes with the same label are, in fact, different bnodes, unless they are used within the same document.
20
20
  CACHE_SIZE = -1 # unlimited by default
21
21
 
22
22
  ##
data/lib/rdf/util/file.rb CHANGED
@@ -4,19 +4,270 @@ require 'time'
4
4
 
5
5
  module RDF; module Util
6
6
  ##
7
- # Wrapper for Net::HTTP. This allows implementations to override
8
- # for more sophisticated behavior.
9
- #
7
+ # Wrapper for retrieving RDF resources from HTTP(S) and file: scheme locations.
8
+ #
9
+ # By default, HTTP(S) resources are retrieved using Net::HTTP. However,
10
10
  # If the [Rest Client](https://rubygems.org/gems/rest-client) gem is included,
11
- # it will be used for retrieving resources allowing for
11
+ # it will be used for retrieving resources, allowing for
12
12
  # sophisticated HTTP caching using [REST Client Components](https://rubygems.org/gems/rest-client-components)
13
13
  # allowing the use of `Rack::Cache` to avoid network access.
14
14
  #
15
+ # To use other HTTP clients, consumers can subclass
16
+ # {RDF::Util::File::HttpAdapter} and set the {RDF::Util::File.http_adapter}.
17
+ #
15
18
  # Also supports the file: scheme for access to local files.
16
19
  #
17
20
  #
18
21
  # @since 0.2.4
19
22
  module File
23
+
24
+ ##
25
+ # @abstract Subclass and override {.open_url} to implement a custom adapter
26
+ # @since 1.2
27
+ class HttpAdapter
28
+ ##
29
+ # @param [Hash{Symbol => Object}] options
30
+ # @option options [Array, String] :headers
31
+ # HTTP Request headers
32
+ # @return [Hash] A hash of HTTP request headers
33
+ def self.headers options
34
+ headers = options.fetch(:headers, {})
35
+ headers['Accept'] ||= default_accept_header
36
+ headers
37
+ end
38
+
39
+ ##
40
+ # @return [String] the value for an Accept header
41
+ def self.default_accept_header
42
+ # Receive text/html and text/plain at a lower priority than other formats
43
+ reader_types = RDF::Format.reader_types.map do |t|
44
+ case t.to_s
45
+ when /text\/(?:plain|html)/
46
+ "#{t};q=0.5"
47
+ when /application\/xhtml\+xml/
48
+ "#{t};q=0.7"
49
+ else
50
+ t
51
+ end
52
+ end
53
+
54
+ (reader_types + %w(*/*;q=0.1)).join(", ")
55
+ end
56
+
57
+ ##
58
+ # @abstract
59
+ # @param [String] base_uri to open
60
+ # @param [Hash{Symbol => Object}] options
61
+ # options are ignored in this implementation. Applications are encouraged
62
+ # to override this implementation to provide more control over HTTP
63
+ # headers and redirect following.
64
+ # @option options [String] :proxy
65
+ # HTTP Proxy to use for requests.
66
+ # @option options [Array, String] :headers
67
+ # HTTP Request headers
68
+ # @option options [Boolean] :verify_none (false)
69
+ # Don't verify SSL certificates
70
+ # @return [RemoteDocument, Object] A {RemoteDocument}. If a block is given, the result of evaluating the block is returned.
71
+ def self.open_url base_uri, options
72
+ raise NoMethodError.new("#{self.inspect} does not implement required method `open_url` for ", "open_url")
73
+ end
74
+ end
75
+
76
+ ##
77
+ # If the [Rest Client](https://rubygems.org/gems/rest-client) gem is included,
78
+ # it will be used for retrieving resources allowing for
79
+ # sophisticated HTTP caching using [REST Client Components](https://rubygems.org/gems/rest-client-components)
80
+ # allowing the use of `Rack::Cache` to avoid network access.
81
+ # @since 1.2
82
+ class RestClientAdapter < HttpAdapter
83
+ # @see HttpAdapter.open_url
84
+ # @param [String] base_uri to open
85
+ # @param [Hash{Symbol => Object}] options
86
+ # @return [RemoteDocument, Object] A {RemoteDocument}. If a block is given, the result of evaluating the block is returned.
87
+ def self.open_url base_uri, options
88
+ ssl_verify = options[:verify_none] ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER
89
+
90
+ # If RestClient is loaded, prefer it
91
+ RestClient.proxy = options[:proxy].to_s if options[:proxy]
92
+ client = RestClient::Resource.new(base_uri, verify_ssl: ssl_verify)
93
+ client.get(headers(options)) do |response, request, res, &blk|
94
+ case response.code
95
+ when 200..299
96
+ # found object
97
+
98
+ # If a Location is returned, it defines the base resource for this file, not it's actual ending location
99
+ document_options = {
100
+ base_uri: RDF::URI(response.headers.fetch(:location, base_uri)),
101
+ charset: Encoding::UTF_8,
102
+ code: response.code.to_i,
103
+ headers: response.headers
104
+ }
105
+
106
+ remote_document = RemoteDocument.new(response.body, document_options)
107
+ when 300..399
108
+ # Document base is redirected location
109
+ base_uri = response.headers[:location].to_s
110
+ response.follow_redirection(request, res, &blk)
111
+ else
112
+ raise IOError, "<#{base_uri}>: #{response.code}"
113
+ end
114
+ end
115
+ end
116
+ end
117
+
118
+ ##
119
+ # Net::HTTP adapter to retrieve resources without additional dependencies
120
+ # @since 1.2
121
+ class NetHttpAdapter < HttpAdapter
122
+ # @see HttpAdapter.open_url
123
+ # @param [String] base_uri to open
124
+ # @param [Hash{Symbol => Object}] options
125
+ # @return [RemoteDocument, Object] A {RemoteDocument}. If a block is given, the result of evaluating the block is returned.
126
+ def self.open_url base_uri, options
127
+ ssl_verify = options[:verify_none] ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER
128
+
129
+ redirect_count = 0
130
+ max_redirects = 5
131
+ parsed_url = ::URI.parse(base_uri)
132
+ parsed_proxy = ::URI.parse(options[:proxy].to_s)
133
+ base_uri = parsed_url.to_s
134
+ remote_document = nil
135
+
136
+ until remote_document do
137
+ Net::HTTP::start(parsed_url.host, parsed_url.port,
138
+ parsed_proxy.host, parsed_proxy.port,
139
+ open_timeout: 60 * 1000,
140
+ use_ssl: parsed_url.scheme == 'https',
141
+ verify_mode: ssl_verify
142
+ ) do |http|
143
+ request = Net::HTTP::Get.new(parsed_url.request_uri, headers(options))
144
+ http.request(request) do |response|
145
+ case response
146
+ when Net::HTTPSuccess
147
+ # found object
148
+
149
+ # Normalize headers using symbols
150
+ response_headers = response.to_hash.inject({}) do |out, (key, value)|
151
+ out[key.gsub(/-/, '_').downcase.to_sym] = %w{ set-cookie }.include?(key.downcase) ? value : value.first
152
+ out
153
+ end
154
+
155
+ # If a Location is returned, it defines the base resource for this file, not it's actual ending location
156
+ document_options = {
157
+ base_uri: RDF::URI(response["Location"] ? response["Location"] : base_uri),
158
+ charset: Encoding::UTF_8,
159
+ code: response.code.to_i,
160
+ content_type: response.content_type,
161
+ headers: response_headers
162
+ }.merge(response.type_params)
163
+ document_options[:last_modified] = DateTime.parse(response["Last-Modified"]) if response["Last-Modified"]
164
+
165
+ remote_document = RemoteDocument.new(response.body, document_options)
166
+ when Net::HTTPRedirection
167
+ # Follow redirection
168
+ raise IOError, "Too many redirects" if (redirect_count += 1) > max_redirects
169
+
170
+ parsed_url = ::URI.parse(response["Location"])
171
+
172
+ base_uri = parsed_url.to_s
173
+ else
174
+ raise IOError, "<#{parsed_url}>: #{response.message}(#{response.code})"
175
+ end
176
+ end
177
+ end
178
+ end
179
+ remote_document
180
+ end
181
+ end
182
+
183
+ ##
184
+ # Use Faraday for retrieving resources
185
+ # @since 1.2
186
+ class FaradayAdapter < HttpAdapter
187
+ class <<self
188
+ ##
189
+ # Set the Faraday::Connection to use for retrieving RDF resources
190
+ def conn= conn
191
+ @conn = conn
192
+ end
193
+
194
+ ##
195
+ # Get the Faraday::Connection to use for retrieving RDF resources,
196
+ # or a default connect that follows redirects.
197
+ def conn
198
+ @conn ||= Faraday.new do |conn|
199
+ conn.use FaradayMiddleware::FollowRedirects
200
+ conn.adapter Faraday.default_adapter
201
+ end
202
+ end
203
+ end
204
+
205
+ # @see HttpAdapter.open_url
206
+ # @param [String] base_uri to open
207
+ # @param [Hash{Symbol => Object}] options
208
+ # @return [RemoteDocument, Object] A {RemoteDocument}.
209
+ def self.open_url base_uri, options
210
+ response = conn.get do |req|
211
+ req.url base_uri
212
+ headers(options).each do |k,v|
213
+ req.headers[k] = v
214
+ end
215
+ end
216
+
217
+ case response.status
218
+ when 200..299
219
+ # found object
220
+
221
+ # If a Location is returned, it defines the base resource for this file, not it's actual ending location
222
+ document_options = {
223
+ base_uri: RDF::URI(response.headers.fetch(:location, response.env.url)),
224
+ charset: Encoding::UTF_8,
225
+ code: response.status,
226
+ headers: response.headers
227
+ }
228
+
229
+ remote_document = RemoteDocument.new(response.body, document_options)
230
+ else
231
+ raise IOError, "<#{base_uri}>: #{response.code}"
232
+ end
233
+ end
234
+ end
235
+
236
+ class <<self
237
+ ##
238
+ # Set the HTTP adapter
239
+ # @see .http_adapter
240
+ # @param [HttpAdapter] http_adapter
241
+ # @return [HttpAdapter]
242
+ # @since 1.2
243
+ def http_adapter= http_adapter
244
+ @http_adapter = http_adapter
245
+ end
246
+
247
+ ##
248
+ # Get current HTTP adapter. If no adapter has been explicitly set,
249
+ # use RestClientAdapter (if RestClient is loaded), or the NetHttpAdapter
250
+ #
251
+ # @param [Boolean] use_net_http use the NetHttpAdapter, even if other
252
+ # adapters have been configured
253
+ # @return [HttpAdapter]
254
+ # @since 1.2
255
+ def http_adapter use_net_http = false
256
+ if use_net_http
257
+ NetHttpAdapter
258
+ else
259
+ @http_adapter ||= begin
260
+ # Otherwise, fallback to Net::HTTP
261
+ if defined?(RestClient)
262
+ RestClientAdapter
263
+ else
264
+ NetHttpAdapter
265
+ end
266
+ end
267
+ end
268
+ end
269
+ end
270
+
20
271
  ##
21
272
  # Open the file, returning or yielding {RemoteDocument}.
22
273
  #
@@ -59,94 +310,9 @@ module RDF; module Util
59
310
  remote_document = nil
60
311
 
61
312
  if filename_or_url.to_s =~ /^https?/
62
- # Open as a URL with Net::HTTP
63
- headers = options.fetch(:headers, {})
64
- # Receive text/html and text/plain at a lower priority than other formats
65
- reader_types = RDF::Format.reader_types.map do |t|
66
- t.to_s =~ /text\/(?:plain|html)/ ? "#{t};q=0.5" : t
67
- end
68
- headers['Accept'] ||= (reader_types + %w(*/*;q=0.1)).join(", ")
69
-
70
313
  base_uri = filename_or_url.to_s
71
- ssl_verify = options[:verify_none] ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER
72
314
 
73
- if defined?(RestClient) && !options[:use_net_http]
74
- # If RestClient is loaded, prefer it
75
- RestClient.proxy = options[:proxy].to_s if options[:proxy]
76
- client = RestClient::Resource.new(base_uri, verify_ssl: ssl_verify)
77
- client.get(headers) do |response, request, res, &blk|
78
- case response.code
79
- when 200..299
80
- # found object
81
-
82
- # If a Location is returned, it defines the base resource for this file, not it's actual ending location
83
- document_options = {
84
- base_uri: RDF::URI(response.headers.fetch(:location, base_uri)),
85
- charset: Encoding::UTF_8,
86
- code: response.code.to_i,
87
- headers: response.headers
88
- }
89
-
90
- remote_document = RemoteDocument.new(response.body, document_options)
91
- when 300..399
92
- # Document base is redirected location
93
- base_uri = response.headers[:location].to_s
94
- response.follow_redirection(request, res, &blk)
95
- else
96
- raise IOError, "<#{base_uri}>: #{response.code}"
97
- end
98
- end
99
- else
100
- # Otherwise, fallback to Net::HTTP
101
- redirect_count = 0
102
- max_redirects = 5
103
- parsed_url = ::URI.parse(filename_or_url.to_s)
104
- parsed_proxy = ::URI.parse(options[:proxy].to_s)
105
- base_uri = parsed_url.to_s
106
- until remote_document do
107
- Net::HTTP::start(parsed_url.host, parsed_url.port,
108
- parsed_proxy.host, parsed_proxy.port,
109
- open_timeout: 60 * 1000,
110
- use_ssl: parsed_url.scheme == 'https',
111
- verify_mode: ssl_verify
112
- ) do |http|
113
- request = Net::HTTP::Get.new(parsed_url.request_uri, headers)
114
- http.request(request) do |response|
115
- case response
116
- when Net::HTTPSuccess
117
- # found object
118
-
119
- # Normalize headers using symbols
120
- response_headers = response.to_hash.inject({}) do |out, (key, value)|
121
- out[key.gsub(/-/, '_').downcase.to_sym] = %w{ set-cookie }.include?(key.downcase) ? value : value.first
122
- out
123
- end
124
-
125
- # If a Location is returned, it defines the base resource for this file, not it's actual ending location
126
- document_options = {
127
- base_uri: RDF::URI(response["Location"] ? response["Location"] : base_uri),
128
- charset: Encoding::UTF_8,
129
- code: response.code.to_i,
130
- content_type: response.content_type,
131
- headers: response_headers
132
- }.merge(response.type_params)
133
- document_options[:last_modified] = DateTime.parse(response["Last-Modified"]) if response["Last-Modified"]
134
-
135
- remote_document = RemoteDocument.new(response.body, document_options)
136
- when Net::HTTPRedirection
137
- # Follow redirection
138
- raise IOError, "Too many redirects" if (redirect_count += 1) > max_redirects
139
-
140
- parsed_url = ::URI.parse(response["Location"])
141
-
142
- base_uri = parsed_url.to_s
143
- else
144
- raise IOError, "<#{parsed_url}>: #{response.message}(#{response.code})"
145
- end
146
- end
147
- end
148
- end
149
- end
315
+ remote_document = self.http_adapter(!!options[:use_net_http]).open_url(base_uri, options)
150
316
  else
151
317
  # Fake content type based on found format
152
318
  format = RDF::Format.for(filename_or_url.to_s)
data/lib/rdf/vocab/cc.rb CHANGED
@@ -2,6 +2,7 @@
2
2
  # This file generated automatically using vocab-fetch from http://creativecommons.org/ns#
3
3
  require 'rdf'
4
4
  module RDF
5
+ # @deprecated Please use `RDF::Vocab::CC` from the rdf-vocab gem instead
5
6
  class CC < RDF::StrictVocabulary("http://creativecommons.org/ns#")
6
7
 
7
8
  # Class definitions
@@ -39,7 +40,7 @@ module RDF
39
40
  property :deprecatedOn,
40
41
  domain: "cc:License".freeze,
41
42
  label: "deprecatedOn".freeze,
42
- range: "http://www.w3.org/2001/XMLSchema-datatypes#date".freeze,
43
+ range: "xsd:date".freeze,
43
44
  type: "rdf:Property".freeze
44
45
  property :jurisdiction,
45
46
  domain: "cc:License".freeze,
@@ -2,6 +2,7 @@
2
2
  # This file generated automatically using vocab-fetch from http://www.w3.org/ns/auth/cert#
3
3
  require 'rdf'
4
4
  module RDF
5
+ # @deprecated Please use `RDF::Vocab::CERT` from the rdf-vocab gem instead
5
6
  class CERT < RDF::StrictVocabulary("http://www.w3.org/ns/auth/cert#")
6
7
 
7
8
  # Class definitions
@@ -132,7 +133,7 @@ module RDF
132
133
  <p>The only difference is that the octet string is then encoded using either xsd:base64Binary or xsd:hexBinary. Currently for all usages of this relation, the xsd:hexBinary datatype should be used until the SPARQL working group specifies specifies in its <a href="http://www.w3.org/TR/sparql11-entailment/#DEntRegime">D-Entailment</a> that those two types are equivalent.</p>
133
134
  <p>It would have been better had there been a hexInteger datatype that was standard and supported by all tools.</p>
134
135
  ).freeze,
135
- domain: ["cert:DSAKey".freeze, "cert:RSAKey".freeze],
136
+ domain: ["cert:RSAKey".freeze],
136
137
  label: "modulus".freeze,
137
138
  range: ["xsd:base64Binary".freeze, "xsd:hexBinary".freeze],
138
139
  "rdfs:isDefinedBy" => %(cert:).freeze,
@@ -145,7 +146,7 @@ module RDF
145
146
  public_exponent*private_exponent = 1 modulo totient\(p*q\)
146
147
  The private exponent is often named 'd'
147
148
  ).freeze,
148
- domain: "cert:RSAPrivateKey".freeze,
149
+ domain: "cert:PrivateKey".freeze,
149
150
  label: "private".freeze,
150
151
  range: "xsd:nonNegativeInteger".freeze,
151
152
  "rdfs:isDefinedBy" => %(cert:).freeze,