rack-linkeddata 1.0.0 → 1.1.0

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.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. data/CREDITS +1 -0
  3. data/README +36 -25
  4. data/VERSION +1 -1
  5. data/lib/rack/linkeddata/conneg.rb +15 -15
  6. metadata +28 -40
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ef1ed257caa8575b95b77ab988a37176800c97e0
4
+ data.tar.gz: 91b82de5a9f3a9fe4124c08ad25b3e0d652915b8
5
+ SHA512:
6
+ metadata.gz: 1aa999f9f66ff6bfede6a67939c32239e2125dd16ce778bb2f550a9332f15ac283f60d186e4620c95d6bb35b1d2fa7bbb3191cb6ccc5c45c1ab2923622b2b2ee
7
+ data.tar.gz: e5cf29db93b0337275de272e3c40e50f367ef68b7f11c1209c05e5cf177abaa53110f3e3594da9974ee82e83bd3ce5f352bb2698bf0baefee59919a481ecd3b5
data/CREDITS CHANGED
@@ -0,0 +1 @@
1
+ * Gregg Kellogg <gregg@greggkellogg.net>
data/README CHANGED
@@ -1,5 +1,4 @@
1
- Linked Data Content Negotiation for Rack Applications
2
- =====================================================
1
+ # Linked Data Content Negotiation for Rack Applications
3
2
 
4
3
  This is [Rack][] middleware that provides [Linked Data][] content
5
4
  negotiation for Rack applications. You can use `Rack::LinkedData` with any
@@ -8,15 +7,16 @@ Sinatra.
8
7
 
9
8
  * <http://github.com/datagraph/rack-linkeddata>
10
9
 
11
- Features
12
- --------
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)
12
+
13
+ ## Features
13
14
 
14
15
  * Implements [HTTP content negotiation][conneg] for RDF content types.
15
16
  * Supports all [RDF.rb][]-compatible serialization formats.
16
17
  * Compatible with any Rack application and any Rack-based framework.
17
18
 
18
- Examples
19
- --------
19
+ ## Examples
20
20
 
21
21
  ### Adding Linked Data content negotiation to a Rails 3.x application
22
22
 
@@ -75,8 +75,7 @@ and different components.
75
75
  $ curl -iH "Accept: application/trix" http://localhost:9292/hello
76
76
  $ curl -iH "Accept: */*" http://localhost:9292/hello
77
77
 
78
- Description
79
- -----------
78
+ ## Description
80
79
 
81
80
  `Rack::LinkedData` implements content negotiation for any [Rack][] response
82
81
  object that implements the `RDF::Enumerable` mixin. You would typically
@@ -90,30 +89,26 @@ serialization formats, so it will work with whatever serialization plugins
90
89
  that are currently available for RDF.rb. (At present, this includes support
91
90
  for N-Triples, N-Quads, Turtle, RDF/XML, RDF/JSON, JSON-LD, RDFa, TriG and TriX.)
92
91
 
93
- Documentation
94
- -------------
92
+ ##Documentation
95
93
 
96
- <http://datagraph.rubyforge.org/rack-linkeddata/>
94
+ <http://http://rubydoc.info/github/ruby-rdf/rack-linkeddata/>
97
95
 
98
96
  * {Rack::LinkedData}
99
97
  * {Rack::LinkedData::ContentNegotiation}
100
98
 
101
- Dependencies
102
- ------------
99
+ ## Dependencies
103
100
 
104
- * [Rack](http://rubygems.org/gems/rack) (>= 1.4.4)
105
- * [Linked Data](http://rubygems.org/gems/linkeddata) (>= 1.0)
101
+ * [Rack](http://rubygems.org/gems/rack) (>= 1.5.2)
102
+ * [Linked Data](http://rubygems.org/gems/linkeddata) (>= 1.1)
106
103
 
107
- Installation
108
- ------------
104
+ ## Installation
109
105
 
110
106
  The recommended installation method is via [RubyGems](http://rubygems.org/).
111
107
  To install the latest official release of the gem, do:
112
108
 
113
109
  % [sudo] gem install rack-linkeddata
114
110
 
115
- Download
116
- --------
111
+ ## Download
117
112
 
118
113
  To get a local working copy of the development repository, do:
119
114
 
@@ -124,8 +119,22 @@ follows:
124
119
 
125
120
  % wget http://github.com/ruby-rdf/rack-linkeddata/tarball/master
126
121
 
127
- References
128
- ----------
122
+ ## Contributing
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.
124
+
125
+ * Do your best to adhere to the existing coding conventions and idioms.
126
+ * Don't use hard tabs, and don't leave trailing whitespace on any line.
127
+ * Do document every method you add using [YARD][] annotations. Read the
128
+ [tutorial][YARD-GS] or just look at the existing code for examples.
129
+ * Don't touch the `.gemspec`, `VERSION` or `AUTHORS` files. If you need to
130
+ change them, do so on your private branch only.
131
+ * Do feel free to add yourself to the `CREDITS` file and the corresponding
132
+ list in the the `README`. Alphabetical order applies.
133
+ * Do note that in order for us to merge any non-trivial changes (as a rule
134
+ of thumb, additions larger than about 15 lines of code), we need an
135
+ explicit [public domain dedication][PDD] on record from you.
136
+
137
+ ## References
129
138
 
130
139
  * <http://www.w3.org/DesignIssues/LinkedData.html>
131
140
  * <http://linkeddata.org/docs/how-to-publish>
@@ -134,13 +143,12 @@ References
134
143
  * <http://www.w3.org/TR/swbp-vocab-pub/>
135
144
  * <http://patterns.dataincubator.org/book/publishing-patterns.html>
136
145
 
137
- Authors
138
- -------
146
+ ## Authors
139
147
 
140
148
  * [Arto Bendiken](http://github.com/bendiken) - <http://ar.to/>
149
+ * [Gregg Kellogg](http://github.com/gkellogg) - <http://greggkellogg.net/>
141
150
 
142
- License
143
- -------
151
+ ## License
144
152
 
145
153
  This is free and unencumbered public domain software. For more information,
146
154
  see <http://unlicense.org/> or the accompanying {file:UNLICENSE} file.
@@ -149,3 +157,6 @@ see <http://unlicense.org/> or the accompanying {file:UNLICENSE} file.
149
157
  [RDF.rb]: http://ruby-rdf.github.com/rdf/
150
158
  [Linked Data]: http://linkeddata.org/
151
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
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.0
@@ -18,7 +18,7 @@ module Rack; module LinkedData
18
18
  #
19
19
  # @see http://www4.wiwiss.fu-berlin.de/bizer/pub/LinkedDataTutorial/
20
20
  class ContentNegotiation
21
- DEFAULT_CONTENT_TYPE = "text/plain" # N-Triples
21
+ DEFAULT_CONTENT_TYPE = "application/n-triples" # N-Triples
22
22
  VARY = {'Vary' => 'Accept'}.freeze
23
23
 
24
24
  # @return [#call]
@@ -40,11 +40,15 @@ module Rack; module LinkedData
40
40
 
41
41
  ##
42
42
  # Handles a Rack protocol request.
43
+ # Parses Accept header to find appropriate mime-type and sets content_type accordingly.
44
+ #
45
+ # Inserts ordered content types into the environment as `ORDERED_CONTENT_TYPES` if an Accept header is present
43
46
  #
44
47
  # @param [Hash{String => String}] env
45
48
  # @return [Array(Integer, Hash, #each)]
46
49
  # @see http://rack.rubyforge.org/doc/SPEC.html
47
50
  def call(env)
51
+ env['ORDERED_CONTENT_TYPES'] = parse_accept_header(env['HTTP_ACCEPT']) if env.has_key?('HTTP_ACCEPT')
48
52
  response = app.call(env)
49
53
  body = response[2].respond_to?(:body) ? response[2].body : response[2]
50
54
  case body
@@ -136,19 +140,15 @@ module Rack; module LinkedData
136
140
  # @return [Array<String>]
137
141
  # @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
138
142
  def parse_accept_header(header)
139
- content_types = header.to_s.split(',').map do |content_type_and_weight|
140
- content_type_and_weight.strip!
141
- case content_type_and_weight
142
- when /^([^;]+);\s*q=(\d+\.\d+)$/
143
- [[1.0, $2.to_f].min, $1, content_type_and_weight]
144
- when /(\S+)/
145
- [1.0, $1, content_type_and_weight]
146
- else nil
147
- end
148
- end
149
- content_types.compact! # remove nils
150
- content_types = content_types.sort_by { |elem| [elem[0], elem[2].size] }
151
- content_types.reverse.map { |elem| elem[1] }
143
+ entries = header.to_s.split(',')
144
+ entries.map { |e| accept_entry(e) }.sort_by(&:last).map(&:first)
145
+ end
146
+
147
+ def accept_entry(entry)
148
+ type, *options = entry.delete(' ').split(';')
149
+ quality = 0 # we sort smallest first
150
+ options.delete_if { |e| quality = 1 - e[2..-1].to_f if e.start_with? 'q=' }
151
+ [type, [quality, type.count('*'), 1 - options.size]]
152
152
  end
153
153
 
154
154
  ##
@@ -169,7 +169,7 @@ module Rack; module LinkedData
169
169
  # @return [Array(Integer, Hash, #each)]
170
170
  def http_error(code, message = nil, headers = {})
171
171
  message = http_status(code) + (message.nil? ? "\n" : " (#{message})\n")
172
- [code, {'Content-Type' => 'text/plain; charset=utf-8'}.merge(headers), [message]]
172
+ [code, {'Content-Type' => "#{DEFAULT_CONTENT_TYPE}; charset=utf-8"}.merge(headers), [message]]
173
173
  end
174
174
 
175
175
  ##
metadata CHANGED
@@ -1,96 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-linkeddata
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
5
- prerelease:
4
+ version: 1.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Arto Bendiken
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-01-20 00:00:00.000000000 Z
11
+ date: 2013-11-14 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: linkeddata
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
- version: '1.0'
19
+ version: 1.1.0
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
- version: '1.0'
26
+ version: 1.1.0
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rack
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
- version: 1.4.4
33
+ version: '1.4'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
- version: 1.4.4
40
+ version: '1.4'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: yard
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
- version: 0.8.3
47
+ version: '0.8'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
- version: 0.8.3
54
+ version: '0.8'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rspec
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
- version: 2.12.0
61
+ version: '2.14'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
- version: 2.12.0
68
+ version: '2.14'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rack-test
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
- version: 0.6.2
75
+ version: '0.6'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - '>='
92
81
  - !ruby/object:Gem::Version
93
- version: 0.6.2
82
+ version: '0.6'
94
83
  description: Rack middleware for Linked Data content negotiation.
95
84
  email: public-rdf-ruby@w3.org
96
85
  executables: []
@@ -108,27 +97,26 @@ files:
108
97
  homepage: http://ruby-rdf.github.com/rack-linkeddata
109
98
  licenses:
110
99
  - Public Domain
100
+ metadata: {}
111
101
  post_install_message:
112
102
  rdoc_options: []
113
103
  require_paths:
114
104
  - lib
115
105
  required_ruby_version: !ruby/object:Gem::Requirement
116
- none: false
117
106
  requirements:
118
- - - ! '>='
107
+ - - '>='
119
108
  - !ruby/object:Gem::Version
120
- version: 1.8.1
109
+ version: 1.9.2
121
110
  required_rubygems_version: !ruby/object:Gem::Requirement
122
- none: false
123
111
  requirements:
124
- - - ! '>='
112
+ - - '>='
125
113
  - !ruby/object:Gem::Version
126
114
  version: '0'
127
115
  requirements: []
128
116
  rubyforge_project: datagraph
129
- rubygems_version: 1.8.24
117
+ rubygems_version: 2.1.11
130
118
  signing_key:
131
- specification_version: 3
119
+ specification_version: 4
132
120
  summary: Linked Data content negotiation for Rack applications.
133
121
  test_files: []
134
122
  has_rdoc: false