rack-linkeddata 0.3.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/CREDITS ADDED
File without changes
data/README CHANGED
@@ -57,6 +57,13 @@ Examples
57
57
 
58
58
  use Rack::LinkedData::ContentNegotiation, :default => "text/turtle"
59
59
 
60
+ Options are also passed to the writer, which can allow options to be shared among the application
61
+ and different components.
62
+
63
+ shared_options = {:default => "text/turtle", :standard_prefixes => true, }
64
+ use Rack::LinkedData::ContentNegotiation, shared_options
65
+ run MyApplication, shared_options
66
+
60
67
  ### Testing Linked Data content negotiation using `rackup` and `curl`
61
68
 
62
69
  $ rackup doc/examples/hello.ru
@@ -81,7 +88,7 @@ client requested and understands.
81
88
  The middleware queries [RDF.rb][] for the MIME content types of known RDF
82
89
  serialization formats, so it will work with whatever serialization plugins
83
90
  that are currently available for RDF.rb. (At present, this includes support
84
- for N-Triples, Turtle, RDF/XML, RDF/JSON and TriX.)
91
+ for N-Triples, N-Quads, Turtle, RDF/XML, RDF/JSON, JSON-LD, RDFa, TriG and TriX.)
85
92
 
86
93
  Documentation
87
94
  -------------
@@ -94,8 +101,8 @@ Documentation
94
101
  Dependencies
95
102
  ------------
96
103
 
97
- * [Rack](http://rubygems.org/gems/rack) (>= 1.0.0)
98
- * [Linked Data](http://rubygems.org/gems/linkeddata) (>= 0.3.0)
104
+ * [Rack](http://rubygems.org/gems/rack) (>= 1.4.4)
105
+ * [Linked Data](http://rubygems.org/gems/linkeddata) (>= 1.0)
99
106
 
100
107
  Installation
101
108
  ------------
@@ -110,12 +117,12 @@ Download
110
117
 
111
118
  To get a local working copy of the development repository, do:
112
119
 
113
- % git clone git://github.com/datagraph/rack-linkeddata.git
120
+ % git clone git://github.com/ruby-rdf/rack-linkeddata.git
114
121
 
115
122
  Alternatively, download the latest development version as a tarball as
116
123
  follows:
117
124
 
118
- % wget http://github.com/datagraph/rack-linkeddata/tarball/master
125
+ % wget http://github.com/ruby-rdf/rack-linkeddata/tarball/master
119
126
 
120
127
  References
121
128
  ----------
@@ -138,7 +145,7 @@ License
138
145
  This is free and unencumbered public domain software. For more information,
139
146
  see <http://unlicense.org/> or the accompanying {file:UNLICENSE} file.
140
147
 
141
- [Rack]: http://rack.rubyforge.org/
142
- [RDF.rb]: http://rdf.rubyforge.org/
148
+ [Rack]: http://rack.github.com/
149
+ [RDF.rb]: http://ruby-rdf.github.com/rdf/
143
150
  [Linked Data]: http://linkeddata.org/
144
151
  [conneg]: http://en.wikipedia.org/wiki/Content_negotiation
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 1.0.0
@@ -2,6 +2,20 @@ module Rack; module LinkedData
2
2
  ##
3
3
  # Rack middleware for Linked Data content negotiation.
4
4
  #
5
+ # Uses HTTP Content Negotiation to find an appropriate RDF
6
+ # format to serialize any result with a body being `RDF::Enumerable`.
7
+ #
8
+ # Override content negotiation by setting the :format option to
9
+ # {#initialize}.
10
+ #
11
+ # Add a :default option to set a content type to use when nothing else
12
+ # is found.
13
+ #
14
+ # @example
15
+ # use Rack::LinkedData::ContentNegotation, :format => :ttl
16
+ # use Rack::LinkedData::ContentNegotiation, :format => RDF::NTriples::Format
17
+ # use Rack::LinkedData::ContentNegotiation, :default => 'application/rdf+xml'
18
+ #
5
19
  # @see http://www4.wiwiss.fu-berlin.de/bizer/pub/LinkedDataTutorial/
6
20
  class ContentNegotiation
7
21
  DEFAULT_CONTENT_TYPE = "text/plain" # N-Triples
@@ -16,9 +30,11 @@ module Rack; module LinkedData
16
30
  ##
17
31
  # @param [#call] app
18
32
  # @param [Hash{Symbol => Object}] options
19
- # @option options [String] :default (DEFAULT_CONTENT_TYPE)
33
+ # Other options passed to writer.
34
+ # @option options [String] :default (DEFAULT_CONTENT_TYPE) Specific content type
35
+ # @option options [RDF::Format, #to_sym] :format Specific RDF writer format to use
20
36
  def initialize(app, options = {})
21
- @app, @options = app, options.to_hash.dup
37
+ @app, @options = app, options
22
38
  @options[:default] = (@options[:default] || DEFAULT_CONTENT_TYPE).to_s
23
39
  end
24
40
 
@@ -30,20 +46,18 @@ module Rack; module LinkedData
30
46
  # @see http://rack.rubyforge.org/doc/SPEC.html
31
47
  def call(env)
32
48
  response = app.call(env)
33
- case env['REQUEST_METHOD'].to_sym
34
- when :GET, :HEAD
35
- case response[2] # the body
36
- when RDF::Enumerable
37
- serialize(env, *response)
38
- else response
39
- end
49
+ body = response[2].respond_to?(:body) ? response[2].body : response[2]
50
+ case body
51
+ when RDF::Enumerable
52
+ response[2] = body # Put it back in the response, it might have been a proxy
53
+ serialize(env, *response)
40
54
  else response
41
55
  end
42
56
  end
43
57
 
44
58
  ##
45
59
  # Serializes an `RDF::Enumerable` response into a Rack protocol
46
- # response using HTTP content negotiation rules.
60
+ # response using HTTP content negotiation rules or a specified Content-Type.
47
61
  #
48
62
  # @param [Hash{String => String}] env
49
63
  # @param [Integer] status
@@ -52,10 +66,11 @@ module Rack; module LinkedData
52
66
  # @return [Array(Integer, Hash, #each)]
53
67
  def serialize(env, status, headers, body)
54
68
  begin
55
- writer, content_type = find_writer(env)
69
+ writer, content_type = find_writer(env, headers)
56
70
  if writer
57
- headers = headers.merge(VARY).merge('Content-Type' => content_type) # FIXME: don't overwrite existing Vary headers
58
- [status, headers, [writer.dump(body)]]
71
+ # FIXME: don't overwrite existing Vary headers
72
+ headers = headers.merge(VARY).merge('Content-Type' => content_type)
73
+ [status, headers, [writer.dump(body, nil, @options)]]
59
74
  else
60
75
  not_acceptable
61
76
  end
@@ -67,21 +82,30 @@ module Rack; module LinkedData
67
82
  ##
68
83
  # Returns an `RDF::Writer` class for the given `env`.
69
84
  #
85
+ # If options contain a `:format` key, it identifies the specific format to use;
86
+ # otherwise, if the environment has an HTTP_ACCEPT header, use it to find a writer;
87
+ # otherwise, use the default content type
88
+ #
70
89
  # @param [Hash{String => String}] env
90
+ # @param [Hash{String => Object}] headers
71
91
  # @return [Array(Class, String)]
72
92
  # @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
73
- def find_writer(env)
74
- unless env.has_key?('HTTP_ACCEPT')
75
- # HTTP/1.1 §14.1: "If no Accept header field is present, then it is
76
- # assumed that the client accepts all media types"
77
- find_writer_for_content_type(options[:default])
78
- else
93
+ def find_writer(env, headers)
94
+ if @options[:format]
95
+ format = @options[:format]
96
+ writer = RDF::Writer.for(format.to_sym) unless format.is_a?(RDF::Format)
97
+ return [writer, writer.format.content_type.first] if writer
98
+ elsif env.has_key?('HTTP_ACCEPT')
79
99
  content_types = parse_accept_header(env['HTTP_ACCEPT'])
80
100
  content_types.each do |content_type|
81
101
  writer, content_type = find_writer_for_content_type(content_type)
82
102
  return [writer, content_type] if writer
83
103
  end
84
104
  return nil
105
+ else
106
+ # HTTP/1.1 §14.1: "If no Accept header field is present, then it is
107
+ # assumed that the client accepts all media types"
108
+ find_writer_for_content_type(options[:default])
85
109
  end
86
110
  end
87
111
 
@@ -1,9 +1,7 @@
1
1
  module Rack; module LinkedData
2
2
  module VERSION
3
- MAJOR = 0
4
- MINOR = 3
5
- TINY = 0
6
- EXTRA = nil
3
+ VERSION_FILE = ::File.expand_path("../../../../VERSION", __FILE__)
4
+ MAJOR, MINOR, TINY, EXTRA = ::File.read(VERSION_FILE).chomp.split(".")
7
5
 
8
6
  STRING = [MAJOR, MINOR, TINY, EXTRA].compact.join('.')
9
7
 
@@ -14,9 +14,14 @@ module Rack
14
14
  # @return [void]
15
15
  def self.register_mime_types!(options = {})
16
16
  if defined?(Rack::Mime::MIME_TYPES)
17
- RDF::Format.file_extensions.each do |file_ext, content_type|
17
+ RDF::Format.each do |format|
18
+ if !Rack::Mime::MIME_TYPES.has_key?(file_ext = ".#{format.to_sym}") || options[: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|
18
23
  if !Rack::Mime::MIME_TYPES.has_key?(file_ext = ".#{file_ext}") || options[:overwrite]
19
- Rack::Mime::MIME_TYPES.merge!(file_ext => content_type.to_s)
24
+ Rack::Mime::MIME_TYPES.merge!(file_ext => formats.first.content_type.first)
20
25
  end
21
26
  end
22
27
  end
metadata CHANGED
@@ -1,138 +1,134 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rack-linkeddata
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 3
8
- - 0
9
- version: 0.3.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
12
- - Datagraph
7
+ authors:
8
+ - Arto Bendiken
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2010-12-28 00:00:00 +01:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: yard
12
+ date: 2013-01-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: linkeddata
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
22
23
  prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- - 6
30
- - 0
31
- version: 0.6.0
32
- type: :development
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: rspec
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rack
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 1.4.4
38
+ type: :runtime
36
39
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- segments:
42
- - 2
43
- - 1
44
- - 0
45
- version: 2.1.0
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.4.4
46
+ - !ruby/object:Gem::Dependency
47
+ name: yard
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 0.8.3
46
54
  type: :development
47
- version_requirements: *id002
48
- - !ruby/object:Gem::Dependency
49
- name: rack-test
50
55
  prerelease: false
51
- requirement: &id003 !ruby/object:Gem::Requirement
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- segments:
56
- - 0
57
- - 5
58
- - 6
59
- version: 0.5.6
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.3
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: 2.12.0
60
70
  type: :development
61
- version_requirements: *id003
62
- - !ruby/object:Gem::Dependency
63
- name: linkeddata
64
71
  prerelease: false
65
- requirement: &id004 !ruby/object:Gem::Requirement
66
- requirements:
67
- - - ~>
68
- - !ruby/object:Gem::Version
69
- segments:
70
- - 0
71
- - 3
72
- - 0
73
- version: 0.3.0
74
- type: :runtime
75
- version_requirements: *id004
76
- - !ruby/object:Gem::Dependency
77
- name: rack
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 2.12.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: rack-test
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: 0.6.2
86
+ type: :development
78
87
  prerelease: false
79
- requirement: &id005 !ruby/object:Gem::Requirement
80
- requirements:
81
- - - ">="
82
- - !ruby/object:Gem::Version
83
- segments:
84
- - 1
85
- - 0
86
- version: "1.0"
87
- type: :runtime
88
- version_requirements: *id005
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 0.6.2
89
94
  description: Rack middleware for Linked Data content negotiation.
90
- email: datagraph@googlegroups.com
95
+ email: public-rdf-ruby@w3.org
91
96
  executables: []
92
-
93
97
  extensions: []
94
-
95
98
  extra_rdoc_files: []
96
-
97
- files:
99
+ files:
98
100
  - AUTHORS
101
+ - CREDITS
99
102
  - README
100
103
  - UNLICENSE
101
104
  - VERSION
102
105
  - lib/rack/linkeddata/conneg.rb
103
106
  - lib/rack/linkeddata/version.rb
104
107
  - lib/rack/linkeddata.rb
105
- has_rdoc: false
106
- homepage: http://github.com/datagraph
107
- licenses:
108
+ homepage: http://ruby-rdf.github.com/rack-linkeddata
109
+ licenses:
108
110
  - Public Domain
109
111
  post_install_message:
110
112
  rdoc_options: []
111
-
112
- require_paths:
113
+ require_paths:
113
114
  - lib
114
- required_ruby_version: !ruby/object:Gem::Requirement
115
- requirements:
116
- - - ">="
117
- - !ruby/object:Gem::Version
118
- segments:
119
- - 1
120
- - 8
121
- - 1
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
122
120
  version: 1.8.1
123
- required_rubygems_version: !ruby/object:Gem::Requirement
124
- requirements:
125
- - - ">="
126
- - !ruby/object:Gem::Version
127
- segments:
128
- - 0
129
- version: "0"
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
130
127
  requirements: []
131
-
132
128
  rubyforge_project: datagraph
133
- rubygems_version: 1.3.6
129
+ rubygems_version: 1.8.24
134
130
  signing_key:
135
131
  specification_version: 3
136
132
  summary: Linked Data content negotiation for Rack applications.
137
133
  test_files: []
138
-
134
+ has_rdoc: false