README.md in accept_headers-0.0.7 vs README.md in accept_headers-0.0.8
- old
+ new
@@ -63,34 +63,31 @@
AcceptHeaders::MediaType.new('text', 'html', q: 0.4, extensions: { 'level' => '2' }),
AcceptHeaders::MediaType.new('text', '*', q: 0.3)
]
```
-`#negotiate` takes an array of media range strings supported (by your API or route/controller) and returns a hash where the `supported` key contains the array element matched and the `matched` key containing a `MediaType` that was matched in the `Negotiator`s internal list.
+`#negotiate` takes an array of media range strings supported (by your API or route/controller) and returns the best supported `MediaType` and the `extensions` params from the matching internal media type.
This will first check the available list for any matching media types with a `q` of 0 and skip any matches. It does this because the RFC specifies that if the `q` value is 0, then content with this parameter is `not acceptable`. Then it'll look to the highest `q` values and look for matches in descending `q` value order and return the first match (accounting for wildcards). Finally, if there are no matches, it returns `nil`.
```ruby
# The same media_types variable as above
media_types.negotiate(['text/html', 'text/plain'])
-# Returns:
+# Returns this equivalent:
-{
- supported: 'text/html',
- matched: AcceptHeaders::MediaType.new('text', 'html', q: 1, extensions: { 'level' => '1' })
-}
+AcceptHeader::MediaType.new('text', 'html', extensions: { 'level' => '1' })
```
It returns the matching `MediaType`, so you can see which one matched and also access the `extensions` params. For example, if you wanted to put your API version in the extensions, you could then retrieve the value.
```ruby
versions_header = 'Accept: application/json;version=2,application/json;version=1;q=0.8'
media_types = AcceptHeaders::MediaType::Negotiator.new(versions_header)
m = media_types.negotiate('application/json')
-puts m[:match].extensions['version'] # returns '2'
+puts m.extensions['version'] # returns '2'
```
`#accept?`:
```ruby
@@ -119,16 +116,13 @@
`#negotiate`:
```ruby
encodings.negotiate(['gzip', 'compress'])
-# Returns:
+# Returns this equivalent:
-{
- supported: 'gzip',
- matched: AcceptHeaders::Encoding.new('gzip'))
-}
+AcceptHeader::Encoding.new('gzip')
```
`#accept?`:
```ruby
@@ -161,15 +155,12 @@
`#negotiate`:
```ruby
languages.negotiate(['en-us', 'zh-Hant'])
-# Returns:
+# Returns this equivalent:
-{
- supported: 'en-us',
- matched: AcceptHeaders::Language.new('en', 'us'))
-}
+AcceptHeaders::Language.new('en', 'us')
```
`#accept?`:
```ruby