rack-linkeddata 3.1.0 → 3.1.1

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
  SHA256:
3
- metadata.gz: 966d05516d9e34419506a0fdaa47a04e61ba51b18630f98f2590fc7d82c1a00b
4
- data.tar.gz: 2a616206491f89c318b16beb61a35688965958271dce37b5a0ce412a17568507
3
+ metadata.gz: f4916ce1f8a73781907fee891b1a7ea31a1c1ff950a79087df54a7aa01abdf9a
4
+ data.tar.gz: 5c4bd1edde8f839fa980abc2d55050727587b2525fe870434b47d500c82dd74c
5
5
  SHA512:
6
- metadata.gz: 86a3666ae1e6e3e0ef7bc0bb730883ccce7063ebe1f7053eead450ad7498dff6aecf9cd2fdadd00f3da9ab5d3acef68696899feb045e8c139c8e1342fcd5e8bc
7
- data.tar.gz: e98c08daae3e76e3b3c7c8037b718b5be537be1e1e74578d36f2addaa99d38ec1a1aeb1dcd94eb3c566823d700d13023aad107cd28613663ed263ae8f6c55d8c
6
+ metadata.gz: 7b879aaf4e1dde88deae05cf38d8f775673274e9a90ba314fba2b686215ce2fce8efdecbab3ad7fd47e51673b38204202b04c13b3e8e401eeb3ad5b3751464f0
7
+ data.tar.gz: ba38a8c789cdb8e266e6319a406cbb83ba1900292aabed3e1e08056a9f0dceac83e3585a90c0f485e1b86c04775a24dac8f48eff10b05cf2c99e7c37c066fdef
data/README.md CHANGED
@@ -5,15 +5,15 @@ negotiation for Rack applications. You can use `Rack::LinkedData` with any
5
5
  Ruby web framework based on Rack, including with Ruby on Rails 3.0 and with
6
6
  Sinatra.
7
7
 
8
- * <http://github.com/datagraph/rack-linkeddata>
8
+ * <https://github.com/ruby-rdf/rack-linkeddata>
9
9
 
10
- [![Gem Version](https://badge.fury.io/rb/rack-linkeddata.png)](http://badge.fury.io/rb/rack-linkeddata)
11
- [![Build Status](https://travis-ci.org/ruby-rdf/rack-linkeddata.png?branch=master)](http://travis-ci.org/ruby-rdf/rack-linkeddata)
10
+ [![Gem Version](https://badge.fury.io/rb/rack-linkeddata.png)](https://badge.fury.io/rb/rack-linkeddata)
11
+ [![Build Status](https://travis-ci.org/ruby-rdf/rack-linkeddata.png?branch=master)](https://travis-ci.org/ruby-rdf/rack-linkeddata)
12
12
 
13
13
  ## Features
14
14
 
15
15
  * Implements [HTTP content negotiation][conneg] for RDF content types.
16
- * Supports all [RDF.rb][]-compatible serialization formats.
16
+ * Supports all [RDF.rb][] compatible serialization formats.
17
17
  * Compatible with any Rack application and any Rack-based framework.
18
18
 
19
19
  ## Examples
@@ -91,19 +91,19 @@ for N-Triples, N-Quads, Turtle, RDF/XML, RDF/JSON, JSON-LD, RDFa, TriG and TriX.
91
91
 
92
92
  ##Documentation
93
93
 
94
- <http://http://rubydoc.info/github/ruby-rdf/rack-linkeddata/>
94
+ <https://rubydoc.info/github/ruby-rdf/rack-linkeddata/>
95
95
 
96
96
  * {Rack::LinkedData}
97
97
  * {Rack::LinkedData::ContentNegotiation}
98
98
 
99
99
  ## Dependencies
100
100
 
101
- * [Rack](http://rubygems.org/gems/rack) (~> 2.0)
102
- * [Linked Data](http://rubygems.org/gems/linkeddata) (~> 3.1)
101
+ * [Rack](https://rubygems.org/gems/rack) (~> 2.0)
102
+ * [Linked Data](https://rubygems.org/gems/linkeddata) (~> 3.1)
103
103
 
104
104
  ## Installation
105
105
 
106
- The recommended installation method is via [RubyGems](http://rubygems.org/).
106
+ The recommended installation method is via [RubyGems](https://rubygems.org/).
107
107
  To install the latest official release of the gem, do:
108
108
 
109
109
  % [sudo] gem install rack-linkeddata
@@ -117,7 +117,7 @@ To get a local working copy of the development repository, do:
117
117
  Alternatively, download the latest development version as a tarball as
118
118
  follows:
119
119
 
120
- % wget http://github.com/ruby-rdf/rack-linkeddata/tarball/master
120
+ % wget https://github.com/ruby-rdf/rack-linkeddata/tarball/master
121
121
 
122
122
  ## Contributing
123
123
  This repository uses [Git Flow](https://github.com/nvie/gitflow) to mange development and release activity. All submissions _must_ be on a feature branch based on the _develop_ branch to ease staging and integration.
@@ -136,27 +136,27 @@ This repository uses [Git Flow](https://github.com/nvie/gitflow) to mange develo
136
136
 
137
137
  ## References
138
138
 
139
- * <http://www.w3.org/DesignIssues/LinkedData.html>
140
- * <http://linkeddata.org/docs/how-to-publish>
141
- * <http://linkeddata.org/conneg-303-redirect-code-samples>
142
- * <http://www.w3.org/TR/cooluris/>
143
- * <http://www.w3.org/TR/swbp-vocab-pub/>
144
- * <http://patterns.dataincubator.org/book/publishing-patterns.html>
139
+ * <https://www.w3.org/DesignIssues/LinkedData.html>
140
+ * <https://linkeddata.org/docs/how-to-publish>
141
+ * <https://linkeddata.org/conneg-303-redirect-code-samples>
142
+ * <https://www.w3.org/TR/cooluris/>
143
+ * <https://www.w3.org/TR/swbp-vocab-pub/>
144
+ * <https://patterns.dataincubator.org/book/publishing-patterns.html>
145
145
 
146
146
  ## Authors
147
147
 
148
- * [Arto Bendiken](http://github.com/bendiken) - <http://ar.to/>
149
- * [Gregg Kellogg](http://github.com/gkellogg) - <http://greggkellogg.net/>
148
+ * [Arto Bendiken](https://github.com/artob) - <https://ar.to/>
149
+ * [Gregg Kellogg](https://github.com/gkellogg) - <https://greggkellogg.net/>
150
150
 
151
151
  ## License
152
152
 
153
153
  This is free and unencumbered public domain software. For more information,
154
- see <http://unlicense.org/> or the accompanying {file:UNLICENSE} file.
155
-
156
- [Rack]: http://rack.github.com/
157
- [RDF.rb]: http://ruby-rdf.github.com/rdf/
158
- [Linked Data]: http://linkeddata.org/
159
- [conneg]: http://en.wikipedia.org/wiki/Content_negotiation
160
- [YARD]: http://yardoc.org/
161
- [YARD-GS]: http://rubydoc.info/docs/yard/file/docs/GettingStarted.md
162
- [PDD]: http://unlicense.org/#unlicensing-contributions
154
+ see <https://unlicense.org/> or the accompanying {file:UNLICENSE} file.
155
+
156
+ [Rack]: https://rack.github.com/
157
+ [RDF.rb]: https://ruby-rdf.github.com/rdf/
158
+ [Linked Data]: https://linkeddata.org/
159
+ [conneg]: https://en.wikipedia.org/wiki/Content_negotiation
160
+ [YARD]: https://yardoc.org/
161
+ [YARD-GS]: https://rubydoc.info/docs/yard/file/docs/GettingStarted.md
162
+ [PDD]: https://unlicense.org/#unlicensing-contributions
data/UNLICENSE CHANGED
@@ -21,4 +21,4 @@ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
21
  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
22
  OTHER DEALINGS IN THE SOFTWARE.
23
23
 
24
- For more information, please refer to <http://unlicense.org/>
24
+ For more information, please refer to <https://unlicense.org/>
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.1.0
1
+ 3.1.1
@@ -1,4 +1,4 @@
1
- require 'rack'
1
+ require 'rack/rdf'
2
2
  require 'linkeddata'
3
3
 
4
4
  module Rack
@@ -9,22 +9,11 @@ module Rack
9
9
  ##
10
10
  # Registers all known RDF formats with Rack's MIME types registry.
11
11
  #
12
- # @param [Boolean] :overwrite (false)
12
+ # @param [Boolean] overwrite (false)
13
13
  # @param [Hash{Symbol => Object}] options
14
14
  # @return [void]
15
15
  def self.register_mime_types!(overwrite: false, **options)
16
- if defined?(Rack::Mime::MIME_TYPES)
17
- RDF::Format.each do |format|
18
- if !Rack::Mime::MIME_TYPES.has_key?(file_ext = ".#{format.to_sym}") || overwrite
19
- Rack::Mime::MIME_TYPES.merge!(file_ext => format.content_type.first)
20
- end
21
- end
22
- RDF::Format.file_extensions.each do |file_ext, formats|
23
- if !Rack::Mime::MIME_TYPES.has_key?(file_ext = ".#{file_ext}") || overwrite
24
- Rack::Mime::MIME_TYPES.merge!(file_ext => formats.first.content_type.first)
25
- end
26
- end
27
- end
16
+ Rack::RDF.register_mime_types!(overwrite: overwrite, **options)
28
17
  end
29
18
  end
30
19
  end
@@ -6,7 +6,7 @@ module Rack; module LinkedData
6
6
  # format to serialize any result with a body being `RDF::Enumerable`.
7
7
  #
8
8
  # Override content negotiation by setting the :format option to
9
- # {#initialize}.
9
+ # `#initialize`.
10
10
  #
11
11
  # Add a :default option to set a content type to use when nothing else
12
12
  # is found.
@@ -18,222 +18,6 @@ module Rack; module LinkedData
18
18
  #
19
19
  # @see http://www4.wiwiss.fu-berlin.de/bizer/pub/LinkedDataTutorial/
20
20
  # @see https://www.rubydoc.info/github/rack/rack/master/file/SPEC
21
- class ContentNegotiation
22
- DEFAULT_CONTENT_TYPE = "application/n-triples" # N-Triples
23
- VARY = {'Vary' => 'Accept'}.freeze
24
-
25
- # @return [#call]
26
- attr_reader :app
27
-
28
- # @return [Hash{Symbol => Object}]
29
- attr_reader :options
30
-
31
- ##
32
- # @param [#call] app
33
- # @param [Hash{Symbol => Object}] options
34
- # Other options passed to writer.
35
- # @param [String] :default (DEFAULT_CONTENT_TYPE) Specific content type
36
- # @option options [RDF::Format, #to_sym] :format Specific RDF writer format to use
37
- def initialize(app, options)
38
- @app, @options = app, options
39
- @options[:default] = (@options[:default] || DEFAULT_CONTENT_TYPE).to_s
40
- end
41
-
42
- ##
43
- # Handles a Rack protocol request.
44
- # Parses Accept header to find appropriate mime-type and sets content_type accordingly.
45
- #
46
- # Inserts ordered content types into the environment as `ORDERED_CONTENT_TYPES` if an Accept header is present
47
- #
48
- # @param [Hash{String => String}] env
49
- # @return [Array(Integer, Hash, #each)] Status, Headers and Body
50
- # @see http://rack.rubyforge.org/doc/SPEC.html
51
- def call(env)
52
- env['ORDERED_CONTENT_TYPES'] = parse_accept_header(env['HTTP_ACCEPT']) if env.has_key?('HTTP_ACCEPT')
53
- response = app.call(env)
54
- body = response[2].respond_to?(:body) ? response[2].body : response[2]
55
- case body
56
- when RDF::Enumerable
57
- response[2] = body # Put it back in the response, it might have been a proxy
58
- serialize(env, *response)
59
- else response
60
- end
61
- end
62
-
63
- ##
64
- # Serializes an `RDF::Enumerable` response into a Rack protocol
65
- # response using HTTP content negotiation rules or a specified Content-Type.
66
- #
67
- # Passes parameters from Accept header, and Link header to writer.
68
- #
69
- # @param [Hash{String => String}] env
70
- # @param [Integer] status
71
- # @param [Hash{String => Object}] headers
72
- # @param [RDF::Enumerable] body
73
- # @return [Array(Integer, Hash, #each)] Status, Headers and Body
74
- def serialize(env, status, headers, body)
75
- result, content_type = nil, nil
76
- find_writer(env, headers) do |writer, ct, accept_params = {}|
77
- begin
78
- # Passes content_type as writer option to allow parameters to be extracted.
79
- writer_options = @options.merge(
80
- accept_params: accept_params,
81
- link: env['HTTP_LINK']
82
- )
83
- result, content_type = writer.dump(body, nil, **writer_options), ct.split(';').first
84
- break
85
- rescue RDF::WriterError
86
- # Continue to next writer
87
- ct
88
- rescue
89
- ct
90
- end
91
- end
92
-
93
- if result
94
- headers = headers.merge(VARY).merge('Content-Type' => content_type)
95
- [status, headers, [result]]
96
- else
97
- not_acceptable
98
- end
99
- end
100
-
101
- protected
102
- ##
103
- # Yields an `RDF::Writer` class for the given `env`.
104
- #
105
- # If options contain a `:format` key, it identifies the specific format to use;
106
- # otherwise, if the environment has an HTTP_ACCEPT header, use it to find a writer;
107
- # otherwise, use the default content type
108
- #
109
- # @param [Hash{String => String}] env
110
- # @param [Hash{String => Object}] headers
111
- # @yield |writer, content_type|
112
- # @yield_param [RDF::Writer] writer
113
- # @yield_param [String] content_type from accept media-range without parameters
114
- # @yield_param [Hash{Symbol => String}] accept_params from accept media-range
115
- # @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
116
- def find_writer(env, headers)
117
- if @options[:format]
118
- format = @options[:format]
119
- writer = RDF::Writer.for(format.to_sym)
120
- yield(writer, writer.format.content_type.first) if writer
121
- elsif env.has_key?('HTTP_ACCEPT')
122
- content_types = parse_accept_header(env['HTTP_ACCEPT'])
123
- content_types.each do |content_type|
124
- find_writer_for_content_type(content_type) do |writer, ct, accept_params|
125
- # Yields content type with parameters
126
- yield(writer, ct, accept_params)
127
- end
128
- end
129
- else
130
- # HTTP/1.1 §14.1: "If no Accept header field is present, then it is
131
- # assumed that the client accepts all media types"
132
- find_writer_for_content_type(options[:default]) do |writer, ct|
133
- # Yields content type with parameters
134
- yield(writer, ct)
135
- end
136
- end
137
- end
138
-
139
- ##
140
- # Yields an `RDF::Writer` class for the given `content_type`.
141
- #
142
- # Calls `Writer#accept?(content_type)` for matched content type to allow writers to further discriminate on how if to accept content-type with specified parameters.
143
- #
144
- # @param [String, #to_s] content_type
145
- # @yield |writer, content_type|
146
- # @yield_param [RDF::Writer] writer
147
- # @yield_param [String] content_type (including media-type parameters)
148
- def find_writer_for_content_type(content_type)
149
- ct, *params = content_type.split(';').map(&:strip)
150
- accept_params = params.inject({}) do |memo, pv|
151
- p, v = pv.split('=').map(&:strip)
152
- memo.merge(p.downcase.to_sym => v.sub(/^["']?([^"']*)["']?$/, '\1'))
153
- end
154
- formats = RDF::Format.each(content_type: ct, has_writer: true).to_a.reverse
155
- formats.each do |format|
156
- yield format.writer, (ct || format.content_type.first), accept_params if
157
- format.writer.accept?(accept_params)
158
- end
159
- end
160
-
161
- ##
162
- # Parses an HTTP `Accept` header, returning an array of MIME content
163
- # types ordered by the precedence rules defined in HTTP/1.1 §14.1.
164
- #
165
- # @param [String, #to_s] header
166
- # @return [Array<String>]
167
- # @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
168
- def parse_accept_header(header)
169
- entries = header.to_s.split(',')
170
- entries = entries.map { |e| accept_entry(e) }.sort_by(&:last).map(&:first)
171
- entries.map { |e| find_content_type_for_media_range(e) }.flatten
172
- end
173
-
174
- # Returns pair of content_type (including non-'q' parameters)
175
- # and array of quality, number of '*' in content-type, and number of non-'q' parameters
176
- def accept_entry(entry)
177
- type, *options = entry.split(';').map(&:strip)
178
- quality = 0 # we sort smallest first
179
- options.delete_if { |e| quality = 1 - e[2..-1].to_f if e.start_with? 'q=' }
180
- [options.unshift(type).join(';'), [quality, type.count('*'), 1 - options.size]]
181
- end
182
-
183
- ##
184
- # Returns a content type appropriate for the given `media_range`,
185
- # returns `nil` if `media_range` contains a wildcard subtype
186
- # that is not mapped.
187
- #
188
- # @param [String, #to_s] media_range
189
- # @return [String, nil]
190
- def find_content_type_for_media_range(media_range)
191
- case media_range.to_s
192
- when '*/*'
193
- options[:default]
194
- when 'text/*'
195
- 'text/turtle'
196
- when 'application/*'
197
- 'application/ld+json'
198
- when 'application/json'
199
- 'application/ld+json'
200
- when 'application/xml'
201
- 'application/rdf+xml'
202
- when /^([^\/]+)\/\*$/
203
- nil
204
- else
205
- media_range.to_s
206
- end
207
- end
208
-
209
- ##
210
- # Outputs an HTTP `406 Not Acceptable` response.
211
- #
212
- # @param [String, #to_s] message
213
- # @return [Array(Integer, Hash, #each)]
214
- def not_acceptable(message = nil)
215
- http_error(406, message, VARY)
216
- end
217
-
218
- ##
219
- # Outputs an HTTP `4xx` or `5xx` response.
220
- #
221
- # @param [Integer, #to_i] code
222
- # @param [String, #to_s] message
223
- # @param [Hash{String => String}] headers
224
- # @return [Array(Integer, Hash, #each)]
225
- def http_error(code, message = nil, headers = {})
226
- message = http_status(code) + (message.nil? ? "\n" : " (#{message})\n")
227
- [code, {'Content-Type' => "text/plain"}.merge(headers), [message]]
228
- end
229
-
230
- ##
231
- # Returns the standard HTTP status message for the given status `code`.
232
- #
233
- # @param [Integer, #to_i] code
234
- # @return [String]
235
- def http_status(code)
236
- [code, Rack::Utils::HTTP_STATUS_CODES[code]].join(' ')
237
- end
21
+ class ContentNegotiation < Rack::RDF::ContentNegotiation
238
22
  end # class ContentNegotiation
239
23
  end; end # module Rack::LinkedData
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-linkeddata
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arto Bendiken
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-12-16 00:00:00.000000000 Z
12
+ date: 2020-05-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: linkeddata
@@ -18,6 +18,9 @@ dependencies:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
20
  version: '3.1'
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 3.1.2
21
24
  type: :runtime
22
25
  prerelease: false
23
26
  version_requirements: !ruby/object:Gem::Requirement
@@ -25,8 +28,11 @@ dependencies:
25
28
  - - "~>"
26
29
  - !ruby/object:Gem::Version
27
30
  version: '3.1'
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 3.1.2
28
34
  - !ruby/object:Gem::Dependency
29
- name: rdf
35
+ name: rack-rdf
30
36
  requirement: !ruby/object:Gem::Requirement
31
37
  requirements:
32
38
  - - "~>"
@@ -45,28 +51,28 @@ dependencies:
45
51
  requirements:
46
52
  - - "~>"
47
53
  - !ruby/object:Gem::Version
48
- version: '2.0'
54
+ version: '2.1'
49
55
  type: :runtime
50
56
  prerelease: false
51
57
  version_requirements: !ruby/object:Gem::Requirement
52
58
  requirements:
53
59
  - - "~>"
54
60
  - !ruby/object:Gem::Version
55
- version: '2.0'
61
+ version: '2.1'
56
62
  - !ruby/object:Gem::Dependency
57
63
  name: yard
58
64
  requirement: !ruby/object:Gem::Requirement
59
65
  requirements:
60
66
  - - "~>"
61
67
  - !ruby/object:Gem::Version
62
- version: 0.9.20
68
+ version: '0.9'
63
69
  type: :development
64
70
  prerelease: false
65
71
  version_requirements: !ruby/object:Gem::Requirement
66
72
  requirements:
67
73
  - - "~>"
68
74
  - !ruby/object:Gem::Version
69
- version: 0.9.20
75
+ version: '0.9'
70
76
  - !ruby/object:Gem::Dependency
71
77
  name: rspec
72
78
  requirement: !ruby/object:Gem::Requirement
@@ -109,7 +115,7 @@ files:
109
115
  - lib/rack/linkeddata.rb
110
116
  - lib/rack/linkeddata/conneg.rb
111
117
  - lib/rack/linkeddata/version.rb
112
- homepage: http://ruby-rdf.github.com/rack-linkeddata
118
+ homepage: https://github.com/ruby-rdf/rack-linkeddata
113
119
  licenses:
114
120
  - Unlicense
115
121
  metadata: {}
@@ -128,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
134
  - !ruby/object:Gem::Version
129
135
  version: '0'
130
136
  requirements: []
131
- rubygems_version: 3.0.6
137
+ rubygems_version: 3.1.3
132
138
  signing_key:
133
139
  specification_version: 4
134
140
  summary: Linked Data content negotiation for Rack applications.