mynyml-rack-accept-media-types 0.5 → 0.5.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 +25 -0
- data/Rakefile +1 -1
- data/examples.rb +38 -0
- data/lib/rack/accept_media_types.rb +1 -1
- data/rack-accept-media-types.gemspec +3 -2
- metadata +3 -2
data/README
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
===== Sumarry
|
2
|
+
|
3
|
+
Rack convenience middleware for simplified handling of Accept header
|
4
|
+
(env['HTTP_ACCEPT']). Allows ordering of its values (accepted media types)
|
5
|
+
according to their "quality" (preference level).
|
6
|
+
|
7
|
+
This wrapper is typically used to determine the request's prefered media
|
8
|
+
type (see example below).
|
9
|
+
|
10
|
+
===== Install
|
11
|
+
|
12
|
+
gem install mynyml-rack-accept-media-types --source=http://gems.github.com/
|
13
|
+
|
14
|
+
===== Examples
|
15
|
+
|
16
|
+
env['HTTP_ACCEPT'] #=> 'application/xml;q=0.8,text/html,text/plain;q=0.9'
|
17
|
+
|
18
|
+
types = Rack::AcceptMediaTypes.new(env['HTTP_ACCEPT'])
|
19
|
+
types #=> ['text/html', 'text/plain', 'application/xml']
|
20
|
+
types.prefered #=> 'text/html'
|
21
|
+
|
22
|
+
===== Links
|
23
|
+
|
24
|
+
source:: http://github.com/mynyml/rack-accept-media-types
|
25
|
+
rdocs:: http://docs.github.com/mynyml/rack-accept-media-types
|
data/Rakefile
CHANGED
@@ -22,7 +22,7 @@ end
|
|
22
22
|
|
23
23
|
spec = Gem::Specification.new do |s|
|
24
24
|
s.name = 'rack-accept-media-types'
|
25
|
-
s.version = '0.5'
|
25
|
+
s.version = '0.5.1'
|
26
26
|
s.summary = "Rack convenience middleware for simplified handling of Accept header."
|
27
27
|
s.description = "Rack convenience middleware for simplified handling of Accept header."
|
28
28
|
s.author = "Martin Aumont"
|
data/examples.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rack'
|
4
|
+
require 'simple_example' # gem install mynyml-simple_example
|
5
|
+
|
6
|
+
root = Pathname(__FILE__).dirname.expand_path
|
7
|
+
require root + 'lib/rack/accept_media_types'
|
8
|
+
|
9
|
+
include SimpleExample
|
10
|
+
puts SimpleExample::Format.separator = '-'*10
|
11
|
+
|
12
|
+
|
13
|
+
# simple
|
14
|
+
env = {'HTTP_ACCEPT' => 'text/html,text/plain'}
|
15
|
+
example do
|
16
|
+
types = Rack::AcceptMediaTypes.new(env['HTTP_ACCEPT'])
|
17
|
+
#=> ["text/html", "text/plain"]
|
18
|
+
types.prefered
|
19
|
+
#=> "text/html"
|
20
|
+
end
|
21
|
+
|
22
|
+
# with quality values
|
23
|
+
env = {'HTTP_ACCEPT' => 'text/html;q=0.5,text/plain;q=0.9'}
|
24
|
+
example do
|
25
|
+
types = Rack::AcceptMediaTypes.new(env['HTTP_ACCEPT'])
|
26
|
+
#=> ["text/plain", "text/html"]
|
27
|
+
types.prefered
|
28
|
+
#=> "text/plain"
|
29
|
+
end
|
30
|
+
|
31
|
+
# rejects types with invalid quality values
|
32
|
+
env = {'HTTP_ACCEPT' => 'text/html;q=0,text/plain;q=1.1,application/xml'}
|
33
|
+
example do
|
34
|
+
types = Rack::AcceptMediaTypes.new(env['HTTP_ACCEPT'])
|
35
|
+
#=> ["application/xml"]
|
36
|
+
types.prefered
|
37
|
+
#=> "application/xml"
|
38
|
+
end
|
@@ -10,7 +10,7 @@ module Rack
|
|
10
10
|
#
|
11
11
|
# ===== Examples
|
12
12
|
#
|
13
|
-
# env['HTTP_ACCEPT'] #=> '
|
13
|
+
# env['HTTP_ACCEPT'] #=> 'application/xml;q=0.8,text/html,text/plain;q=0.9'
|
14
14
|
#
|
15
15
|
# types = Rack::AcceptMediaTypes.new(env['HTTP_ACCEPT'])
|
16
16
|
# types #=> ['text/html', 'text/plain', 'application/xml']
|
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-accept-media-types
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Aumont
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-06-
|
12
|
+
date: 2009-06-06 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -31,6 +31,7 @@ files:
|
|
31
31
|
- lib/rack
|
32
32
|
- lib/rack/accept_media_types.rb
|
33
33
|
- LICENSE
|
34
|
+
- examples.rb
|
34
35
|
- README
|
35
36
|
has_rdoc: true
|
36
37
|
homepage: ""
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mynyml-rack-accept-media-types
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Aumont
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-06-
|
12
|
+
date: 2009-06-05 21:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -31,6 +31,7 @@ files:
|
|
31
31
|
- lib/rack
|
32
32
|
- lib/rack/accept_media_types.rb
|
33
33
|
- LICENSE
|
34
|
+
- examples.rb
|
34
35
|
- README
|
35
36
|
has_rdoc: true
|
36
37
|
homepage: ""
|