rack-linkeddata 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -18,7 +18,28 @@ Features
18
18
  Examples
19
19
  --------
20
20
 
21
- ### Adding Linked Data content negotiation to a Rack application
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 client
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 works by querying [RDF.rb][] for the MIME content types of
59
- known RDF serialization formats, so it will work with whatever serialization
60
- plugins that are currently available for RDF.rb. (At present, this includes
61
- support for N-Triples, Turtle, RDF/XML, RDF/JSON and TriX.)
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.0
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
- writer ? [status, headers.merge('Content-Type' => content_type), [writer.dump(body)]] : not_acceptable
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
  ##
@@ -2,7 +2,7 @@ module Rack; module LinkedData
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 0
5
+ TINY = 1
6
6
  EXTRA = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
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-26 00:00:00 +02:00
17
+ date: 2010-05-27 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency