http_headers-accept 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +75 -74
- data/http_headers-accept.gemspec +1 -1
- data/lib/http_headers/accept/version.rb +7 -0
- data/lib/http_headers/accept.rb +2 -4
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c28ca05fb7b45da5f0ebc52844a87b9ad9a01c7c22dd9aa39ef5bb54a84a39fa
|
4
|
+
data.tar.gz: cbe42ac16917768c46fc099effe815e858e1469f137267c08f4b8fbae21b09e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a57dde7ea3370f0c99473bc0d2d93d51942c76e87f87d54c7d5ba00fc63db1ca15ee2f73ca13f14428ef2e547a5e4a015f87ef2ab42447dde948719689dbff76
|
7
|
+
data.tar.gz: 3cf92680ff04d73c942ad5d8d5ff2bc8d14d6957459a68cd6932bdd7be1eb489adca052e0d355eaf76ee4c37563d050a9a0ff4a219fee4b378711451053f0327
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,74 +1,75 @@
|
|
1
|
-
# HttpHeaders::Accept
|
2
|
-
|
3
|
-
[![Build Status: master](https://travis-ci.com/XPBytes/http_headers-accept.svg)](https://travis-ci.com/XPBytes/http_headers-accept)
|
4
|
-
[![Gem Version](https://badge.fury.io/rb/http_headers-accept.svg)](https://badge.fury.io/rb/http_headers-accept)
|
5
|
-
[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)
|
6
|
-
|
7
|
-
:nut_and_bolt: Utility to parse and sort the "Accept" HTTP Header
|
8
|
-
|
9
|
-
## Installation
|
10
|
-
|
11
|
-
Add this line to your application's Gemfile:
|
12
|
-
|
13
|
-
```ruby
|
14
|
-
gem 'http_headers-accept'
|
15
|
-
```
|
16
|
-
|
17
|
-
And then execute:
|
18
|
-
|
19
|
-
$ bundle
|
20
|
-
|
21
|
-
Or install it yourself as:
|
22
|
-
|
23
|
-
$ gem install http_headers-accept
|
24
|
-
|
25
|
-
## Usage
|
26
|
-
|
27
|
-
You can parse the "Accept" header. As per the RFCs, you should really have one (delimited) value but the current
|
28
|
-
implementation accepts an array of values.
|
29
|
-
|
30
|
-
```ruby
|
31
|
-
require 'http_headers/accept'
|
32
|
-
|
33
|
-
parsed = HttpHeaders::Accept.new('application/json, text/html; q=0.8')
|
34
|
-
parsed.first.to_s
|
35
|
-
# => 'application/json'
|
36
|
-
parsed.last.q
|
37
|
-
# => 0.8
|
38
|
-
|
39
|
-
|
40
|
-
parsed = HttpHeaders::Accept.new([
|
41
|
-
'*/*; q=0.1',
|
42
|
-
'application/json; foo=bar, text/html; q=0.8'
|
43
|
-
])
|
44
|
-
parsed.first[:foo]
|
45
|
-
# => bar
|
46
|
-
parsed.last.to_s
|
47
|
-
# => '*/*; q=0.1'
|
48
|
-
```
|
49
|
-
|
50
|
-
Each parsed entry exposes the following methods:
|
51
|
-
- `media_type`: the parsed media_type
|
52
|
-
- `q`: the quality parameter as float, or 1.0
|
53
|
-
- `[](parameter)`: accessor for the parameter; throws if it does not exist
|
54
|
-
- `to_s`: encode back to an entry to be used in a `Accept` header
|
55
|
-
|
56
|
-
## Related
|
57
|
-
|
58
|
-
- [HttpHeaders::Utils](https://github.com/XPBytes/http_headers-utils): :nut_and_bolt: Utility belt for the HttpHeader libraries
|
59
|
-
- [HttpHeaders::AcceptLanguage](https://github.com/XPBytes/http_headers-accept_language): :nut_and_bolt: Utility to parse and sort the "Accept-Language" HTTP Header
|
60
|
-
- [HttpHeaders::ContentType](https://github.com/XPBytes/http_headers-content_type): :nut_and_bolt: Utility to parse and sort the "Content-Type" HTTP Header
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
1
|
+
# HttpHeaders::Accept
|
2
|
+
|
3
|
+
[![Build Status: master](https://travis-ci.com/XPBytes/http_headers-accept.svg)](https://travis-ci.com/XPBytes/http_headers-accept)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/http_headers-accept.svg)](https://badge.fury.io/rb/http_headers-accept)
|
5
|
+
[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)
|
6
|
+
|
7
|
+
:nut_and_bolt: Utility to parse and sort the "Accept" HTTP Header
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'http_headers-accept'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install http_headers-accept
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
You can parse the "Accept" header. As per the RFCs, you should really have one (delimited) value but the current
|
28
|
+
implementation accepts an array of values.
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
require 'http_headers/accept'
|
32
|
+
|
33
|
+
parsed = HttpHeaders::Accept.new('application/json, text/html; q=0.8')
|
34
|
+
parsed.first.to_s
|
35
|
+
# => 'application/json'
|
36
|
+
parsed.last.q
|
37
|
+
# => 0.8
|
38
|
+
|
39
|
+
|
40
|
+
parsed = HttpHeaders::Accept.new([
|
41
|
+
'*/*; q=0.1',
|
42
|
+
'application/json; foo=bar, text/html; q=0.8'
|
43
|
+
])
|
44
|
+
parsed.first[:foo]
|
45
|
+
# => bar
|
46
|
+
parsed.last.to_s
|
47
|
+
# => '*/*; q=0.1'
|
48
|
+
```
|
49
|
+
|
50
|
+
Each parsed entry exposes the following methods:
|
51
|
+
- `media_type`: the parsed media_type
|
52
|
+
- `q`: the quality parameter as float, or 1.0
|
53
|
+
- `[](parameter)`: accessor for the parameter; throws if it does not exist
|
54
|
+
- `to_s`: encode back to an entry to be used in a `Accept` header
|
55
|
+
|
56
|
+
## Related
|
57
|
+
|
58
|
+
- [HttpHeaders::Utils](https://github.com/XPBytes/http_headers-utils): :nut_and_bolt: Utility belt for the HttpHeader libraries
|
59
|
+
- [HttpHeaders::AcceptLanguage](https://github.com/XPBytes/http_headers-accept_language): :nut_and_bolt: Utility to parse and sort the "Accept-Language" HTTP Header
|
60
|
+
- [HttpHeaders::ContentType](https://github.com/XPBytes/http_headers-content_type): :nut_and_bolt: Utility to parse and sort the "Content-Type" HTTP Header
|
61
|
+
- [HttpHeaders::Link](https://github.com/XPBytes/http_headers-link): :nut_and_bolt: Utility to parse and sort the "Link" HTTP Header
|
62
|
+
|
63
|
+
|
64
|
+
## Development
|
65
|
+
|
66
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can
|
67
|
+
also run `bin/console` for an interactive prompt that will allow you to experiment.
|
68
|
+
|
69
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
|
70
|
+
version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version,
|
71
|
+
push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
72
|
+
|
73
|
+
## Contributing
|
74
|
+
|
75
|
+
Bug reports and pull requests are welcome on GitHub at [XPBytes/http_headers-accept](https://github.com/XPBytes/http_headers-accept).
|
data/http_headers-accept.gemspec
CHANGED
data/lib/http_headers/accept.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
|
+
require 'http_headers/accept/version'
|
1
2
|
require 'http_headers/utils/list'
|
2
|
-
require 'delegate'
|
3
3
|
|
4
4
|
module HttpHeaders
|
5
|
-
class Accept < DelegateClass(Array)
|
6
|
-
VERSION = "0.2.0"
|
7
|
-
|
5
|
+
class Accept # < DelegateClass(Array) determined by version
|
8
6
|
def initialize(value)
|
9
7
|
__setobj__ HttpHeaders::Utils::List.new(value, entry_klazz: Accept::Entry)
|
10
8
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http_headers-accept
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derk-Jan Karrenbeld
|
@@ -99,6 +99,7 @@ files:
|
|
99
99
|
- bin/setup
|
100
100
|
- http_headers-accept.gemspec
|
101
101
|
- lib/http_headers/accept.rb
|
102
|
+
- lib/http_headers/accept/version.rb
|
102
103
|
homepage: https://github.com/XPBytes/http_headers-accept
|
103
104
|
licenses:
|
104
105
|
- MIT
|