rack-linkeddata 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +28 -7
- data/VERSION +1 -1
- data/lib/rack/linkeddata/conneg.rb +8 -2
- data/lib/rack/linkeddata/version.rb +1 -1
- metadata +3 -3
data/README
CHANGED
@@ -18,7 +18,28 @@ Features
|
|
18
18
|
Examples
|
19
19
|
--------
|
20
20
|
|
21
|
-
### Adding Linked Data content negotiation to a
|
21
|
+
### Adding Linked Data content negotiation to a Rails 3.x application
|
22
|
+
|
23
|
+
# config/application.rb
|
24
|
+
class Application < Rails::Application
|
25
|
+
config.middleware.use Rack::LinkedData::ContentNegotiation
|
26
|
+
end
|
27
|
+
|
28
|
+
### Adding Linked Data content negotiation to a Sinatra application
|
29
|
+
|
30
|
+
#!/usr/bin/env ruby -rubygems
|
31
|
+
require 'sinatra'
|
32
|
+
require 'rack/linkeddata'
|
33
|
+
|
34
|
+
use Rack::LinkedData::ContentNegotiation
|
35
|
+
|
36
|
+
get '/hello' do
|
37
|
+
RDF::Graph.new do
|
38
|
+
self << [RDF::Node.new, RDF::DC.title, "Hello, world!"]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
### Adding Linked Data content negotiation to a Rackup application
|
22
43
|
|
23
44
|
#!/usr/bin/env rackup
|
24
45
|
require 'rack/linkeddata'
|
@@ -52,13 +73,13 @@ Description
|
|
52
73
|
object that implements the `RDF::Enumerable` mixin. You would typically
|
53
74
|
return an instance of `RDF::Graph` or `RDF::Repository` from your Rack
|
54
75
|
application, and let the `Rack::LinkedData::ContentNegotiation` middleware
|
55
|
-
take care serializing your response into whatever RDF format the HTTP
|
56
|
-
requested and understands.
|
76
|
+
take care of serializing your response into whatever RDF format the HTTP
|
77
|
+
client requested and understands.
|
57
78
|
|
58
|
-
The middleware
|
59
|
-
|
60
|
-
|
61
|
-
|
79
|
+
The middleware queries [RDF.rb][] for the MIME content types of known RDF
|
80
|
+
serialization formats, so it will work with whatever serialization plugins
|
81
|
+
that are currently available for RDF.rb. (At present, this includes support
|
82
|
+
for N-Triples, Turtle, RDF/XML, RDF/JSON and TriX.)
|
62
83
|
|
63
84
|
Documentation
|
64
85
|
-------------
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
@@ -5,6 +5,7 @@ module Rack; module LinkedData
|
|
5
5
|
# @see http://www4.wiwiss.fu-berlin.de/bizer/pub/LinkedDataTutorial/
|
6
6
|
class ContentNegotiation
|
7
7
|
DEFAULT_CONTENT_TYPE = "text/plain" # N-Triples
|
8
|
+
VARY = {'Vary' => 'Accept'}.freeze
|
8
9
|
|
9
10
|
# @return [#call]
|
10
11
|
attr_reader :app
|
@@ -51,7 +52,12 @@ module Rack; module LinkedData
|
|
51
52
|
# @return [Array(Integer, Hash, #each)]
|
52
53
|
def serialize(env, status, headers, body)
|
53
54
|
writer, content_type = find_writer(env)
|
54
|
-
|
55
|
+
if writer
|
56
|
+
headers = headers.merge(VARY).merge('Content-Type' => content_type) # FIXME: don't overwrite existing Vary headers
|
57
|
+
[status, headers, [writer.dump(body)]]
|
58
|
+
else
|
59
|
+
not_acceptable
|
60
|
+
end
|
55
61
|
end
|
56
62
|
|
57
63
|
##
|
@@ -123,7 +129,7 @@ module Rack; module LinkedData
|
|
123
129
|
# @param [String, #to_s] message
|
124
130
|
# @return [Array(Integer, Hash, #each)]
|
125
131
|
def not_acceptable(message = nil)
|
126
|
-
http_error(406, message)
|
132
|
+
http_error(406, message, VARY)
|
127
133
|
end
|
128
134
|
|
129
135
|
##
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Datagraph
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-27 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|