trailer_vote-media_types 0.9.3 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +12 -12
- data/.rubocop.yml +29 -29
- data/.travis.yml +19 -19
- data/CHANGELOG.md +82 -82
- data/Gemfile +6 -6
- data/Gemfile.lock +51 -51
- data/README.md +118 -118
- data/Rakefile +12 -12
- data/bin/console +16 -16
- data/bin/setup +8 -8
- data/lib/trailer_vote/media_types.rb +35 -33
- data/lib/trailer_vote/media_types/audio_fragment.rb +108 -108
- data/lib/trailer_vote/media_types/base_text.rb +22 -22
- data/lib/trailer_vote/media_types/carousel.rb +42 -42
- data/lib/trailer_vote/media_types/client_configuration.rb +35 -35
- data/lib/trailer_vote/media_types/configuration.rb +82 -61
- data/lib/trailer_vote/media_types/errors.rb +31 -31
- data/lib/trailer_vote/media_types/feedback.rb +50 -50
- data/lib/trailer_vote/media_types/feedback_listing.rb +49 -49
- data/lib/trailer_vote/media_types/fingerprint_binary.rb +67 -67
- data/lib/trailer_vote/media_types/interactive_player.rb +33 -33
- data/lib/trailer_vote/media_types/issue.rb +64 -64
- data/lib/trailer_vote/media_types/partials/image_links.rb +30 -30
- data/lib/trailer_vote/media_types/persona.rb +38 -38
- data/lib/trailer_vote/media_types/place.rb +106 -106
- data/lib/trailer_vote/media_types/product.rb +191 -191
- data/lib/trailer_vote/media_types/product_image.rb +96 -96
- data/lib/trailer_vote/media_types/product_lookup.rb +37 -37
- data/lib/trailer_vote/media_types/product_place_link.rb +36 -36
- data/lib/trailer_vote/media_types/product_video.rb +100 -100
- data/lib/trailer_vote/media_types/products_listing.rb +43 -43
- data/lib/trailer_vote/media_types/push_manifest.rb +33 -0
- data/lib/trailer_vote/media_types/push_trivial_campaign.rb +32 -0
- data/lib/trailer_vote/media_types/sentiment_feedback.rb +100 -100
- data/lib/trailer_vote/media_types/types/boolean.rb +15 -15
- data/lib/trailer_vote/media_types/types/formatted_url.rb +51 -51
- data/lib/trailer_vote/media_types/types/http_url.rb +23 -23
- data/lib/trailer_vote/media_types/types/influx_db_connection_url.rb +10 -10
- data/lib/trailer_vote/media_types/types/iso8601.rb +10 -10
- data/lib/trailer_vote/media_types/types/product_data_type.rb +15 -15
- data/lib/trailer_vote/media_types/types/product_image_type.rb +25 -25
- data/lib/trailer_vote/media_types/types/product_movie_handler.rb +16 -16
- data/lib/trailer_vote/media_types/types/product_movie_type.rb +17 -17
- data/lib/trailer_vote/media_types/types/uuid_v4.rb +10 -10
- data/lib/trailer_vote/media_types/types/vote_value.rb +17 -17
- data/lib/trailer_vote/media_types/version.rb +7 -7
- data/trailer_vote-media_types.gemspec +41 -41
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c57c38b2a54615d048b410cbb49059bb08512c2659eb885301decd9a5cb4332f
|
4
|
+
data.tar.gz: 5a3eff968faff84bfe7c68ec0d4626cc0c380593a61ed966b971787652c64852
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b5e311947d3c7e450c2a41ea5670e9661d4e7e4adbd6b2b30f65a59b5fe994f6c5eeb5a36aa6afd7b0ab3b536a8e006b3ab75d9605f98e3b5cdecb1103b655a
|
7
|
+
data.tar.gz: acf04c53066fbf6ba185d065c6914fae105b442335fa72ea6af7fc9b3662ca07e5ed15a3d72e59ba26287a222a1d99730fdd5eba5336e1b651279a8d6c416923
|
data/.gitignore
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
/.bundle/
|
2
|
-
/.yardoc
|
3
|
-
/_yardoc/
|
4
|
-
/coverage/
|
5
|
-
/doc/
|
6
|
-
/pkg/
|
7
|
-
/test/reports/
|
8
|
-
/tmp/
|
9
|
-
|
10
|
-
/.byebug_history
|
11
|
-
/.rakeTasks
|
12
|
-
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/_yardoc/
|
4
|
+
/coverage/
|
5
|
+
/doc/
|
6
|
+
/pkg/
|
7
|
+
/test/reports/
|
8
|
+
/tmp/
|
9
|
+
|
10
|
+
/.byebug_history
|
11
|
+
/.rakeTasks
|
12
|
+
|
data/.rubocop.yml
CHANGED
@@ -1,29 +1,29 @@
|
|
1
|
-
AllCops:
|
2
|
-
Include:
|
3
|
-
- '**/Rakefile'
|
4
|
-
- 'lib/**/*.rb'
|
5
|
-
Exclude:
|
6
|
-
- 'Gemfile'
|
7
|
-
- 'bin/**/*'
|
8
|
-
TargetRubyVersion: 2.4
|
9
|
-
|
10
|
-
Layout/EmptyLinesAroundClassBody:
|
11
|
-
Enabled: false
|
12
|
-
|
13
|
-
Layout/EndOfLine:
|
14
|
-
Enabled: false
|
15
|
-
|
16
|
-
Metrics/LineLength:
|
17
|
-
Max: 120
|
18
|
-
|
19
|
-
Metrics/MethodLength:
|
20
|
-
Max: 15
|
21
|
-
|
22
|
-
Style/Documentation:
|
23
|
-
Enabled: false
|
24
|
-
|
25
|
-
Style/EmptyMethod:
|
26
|
-
EnforcedStyle: expanded
|
27
|
-
|
28
|
-
Style/IfUnlessModifier:
|
29
|
-
Enabled: false
|
1
|
+
AllCops:
|
2
|
+
Include:
|
3
|
+
- '**/Rakefile'
|
4
|
+
- 'lib/**/*.rb'
|
5
|
+
Exclude:
|
6
|
+
- 'Gemfile'
|
7
|
+
- 'bin/**/*'
|
8
|
+
TargetRubyVersion: 2.4
|
9
|
+
|
10
|
+
Layout/EmptyLinesAroundClassBody:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Layout/EndOfLine:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Metrics/LineLength:
|
17
|
+
Max: 120
|
18
|
+
|
19
|
+
Metrics/MethodLength:
|
20
|
+
Max: 15
|
21
|
+
|
22
|
+
Style/Documentation:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Style/EmptyMethod:
|
26
|
+
EnforcedStyle: expanded
|
27
|
+
|
28
|
+
Style/IfUnlessModifier:
|
29
|
+
Enabled: false
|
data/.travis.yml
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
sudo: false
|
2
|
-
language: ruby
|
3
|
-
cache: bundler
|
4
|
-
rvm:
|
5
|
-
- 2.4
|
6
|
-
- 2.5
|
7
|
-
- 2.6
|
8
|
-
- rbx-3
|
9
|
-
- ruby-head
|
10
|
-
matrix:
|
11
|
-
allow_failures:
|
12
|
-
- rvm: ruby-head
|
13
|
-
- rvm: rbx-3
|
14
|
-
- rvm: 2.6
|
15
|
-
before_install:
|
16
|
-
- gem update --system
|
17
|
-
- gem --version
|
18
|
-
install:
|
19
|
-
- bundle install --with development --jobs=3 --retry=3 --path=${BUNDLE_PATH:-vendor/bundle}
|
1
|
+
sudo: false
|
2
|
+
language: ruby
|
3
|
+
cache: bundler
|
4
|
+
rvm:
|
5
|
+
- 2.4
|
6
|
+
- 2.5
|
7
|
+
- 2.6
|
8
|
+
- rbx-3
|
9
|
+
- ruby-head
|
10
|
+
matrix:
|
11
|
+
allow_failures:
|
12
|
+
- rvm: ruby-head
|
13
|
+
- rvm: rbx-3
|
14
|
+
- rvm: 2.6
|
15
|
+
before_install:
|
16
|
+
- gem update --system
|
17
|
+
- gem --version
|
18
|
+
install:
|
19
|
+
- bundle install --with development --jobs=3 --retry=3 --path=${BUNDLE_PATH:-vendor/bundle}
|
data/CHANGELOG.md
CHANGED
@@ -1,82 +1,82 @@
|
|
1
|
-
# Changelog
|
2
|
-
|
3
|
-
## 0.9.2
|
4
|
-
|
5
|
-
- Add vimeo as video handler
|
6
|
-
|
7
|
-
## 0.9.1
|
8
|
-
|
9
|
-
- Allow empty for various `index` and `collection` views
|
10
|
-
|
11
|
-
## 0.9.0
|
12
|
-
|
13
|
-
- Add `issue` media type
|
14
|
-
- Update `trailer_vote-fixtures` to 1.2.0
|
15
|
-
|
16
|
-
## 0.8.1
|
17
|
-
|
18
|
-
- Use external `trailer_vote-fixtures`
|
19
|
-
|
20
|
-
## 0.8.0
|
21
|
-
|
22
|
-
- Add `Issue` media type
|
23
|
-
- Add `issues` link to configuration media type
|
24
|
-
|
25
|
-
## 0.7.6
|
26
|
-
|
27
|
-
- Allow `content_*` to be `nil`
|
28
|
-
|
29
|
-
## 0.7.5
|
30
|
-
|
31
|
-
- Add `content_language` and `content_region` to assets
|
32
|
-
|
33
|
-
## 0.7.4
|
34
|
-
|
35
|
-
- Allow `type` on partial `image_links` (such as sentiment_feedback)
|
36
|
-
|
37
|
-
## 0.7.3
|
38
|
-
|
39
|
-
- Add `type` to image self link
|
40
|
-
- Add `type` to image index links
|
41
|
-
- Add `type` to video self link
|
42
|
-
- Add `type` to video index links
|
43
|
-
|
44
|
-
## 0.7.2
|
45
|
-
|
46
|
-
- Allow for `content_digest` and dimensions on image links (output)
|
47
|
-
|
48
|
-
## 0.7.1
|
49
|
-
|
50
|
-
- Fix version 2 of sentiment feedback not registering
|
51
|
-
- Change default version of sentiment feedback to v2
|
52
|
-
|
53
|
-
## 0.7.0
|
54
|
-
|
55
|
-
- Add `products` link to configuration v1
|
56
|
-
- Add scheme validation for `data` property of products
|
57
|
-
|
58
|
-
## 0.6.3
|
59
|
-
|
60
|
-
- Fix `product_video` create root key
|
61
|
-
|
62
|
-
## 0.6.2
|
63
|
-
|
64
|
-
- Loosen Gem dependency versions to allow any minor update, except for dogfooded gems, which are allowed major updates, until they hit 1.0.0
|
65
|
-
- Add metadata urls for gemspec
|
66
|
-
|
67
|
-
## 0.6.1
|
68
|
-
|
69
|
-
- Allow for http urls because not all services in all environments may operate with TLS enabled.
|
70
|
-
|
71
|
-
## 0.6.0
|
72
|
-
|
73
|
-
- Update `media_types` to `0.6.0` so that the integrations become available downstream.
|
74
|
-
- Rename all `deleted_at` to `expires_at` (#1)
|
75
|
-
- Add `Types::HttpsUrl`, `Types::InfluxDbConnectionUrl`, `Types.makeFormattedUrl`, `Types.Iso8601` to check format of string attributes. (#2)
|
76
|
-
- Add documentation for `updated_at` fields (#4)
|
77
|
-
- Add expected type for `ProductLookup` `identifier` (#5)
|
78
|
-
- Remove optional nil for analytics and metrics url by changing the type (#3)
|
79
|
-
|
80
|
-
## 0.5.0
|
81
|
-
|
82
|
-
:baby: initial public release. Not considered stable until version 1.0.0.
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 0.9.2
|
4
|
+
|
5
|
+
- Add vimeo as video handler
|
6
|
+
|
7
|
+
## 0.9.1
|
8
|
+
|
9
|
+
- Allow empty for various `index` and `collection` views
|
10
|
+
|
11
|
+
## 0.9.0
|
12
|
+
|
13
|
+
- Add `issue` media type
|
14
|
+
- Update `trailer_vote-fixtures` to 1.2.0
|
15
|
+
|
16
|
+
## 0.8.1
|
17
|
+
|
18
|
+
- Use external `trailer_vote-fixtures`
|
19
|
+
|
20
|
+
## 0.8.0
|
21
|
+
|
22
|
+
- Add `Issue` media type
|
23
|
+
- Add `issues` link to configuration media type
|
24
|
+
|
25
|
+
## 0.7.6
|
26
|
+
|
27
|
+
- Allow `content_*` to be `nil`
|
28
|
+
|
29
|
+
## 0.7.5
|
30
|
+
|
31
|
+
- Add `content_language` and `content_region` to assets
|
32
|
+
|
33
|
+
## 0.7.4
|
34
|
+
|
35
|
+
- Allow `type` on partial `image_links` (such as sentiment_feedback)
|
36
|
+
|
37
|
+
## 0.7.3
|
38
|
+
|
39
|
+
- Add `type` to image self link
|
40
|
+
- Add `type` to image index links
|
41
|
+
- Add `type` to video self link
|
42
|
+
- Add `type` to video index links
|
43
|
+
|
44
|
+
## 0.7.2
|
45
|
+
|
46
|
+
- Allow for `content_digest` and dimensions on image links (output)
|
47
|
+
|
48
|
+
## 0.7.1
|
49
|
+
|
50
|
+
- Fix version 2 of sentiment feedback not registering
|
51
|
+
- Change default version of sentiment feedback to v2
|
52
|
+
|
53
|
+
## 0.7.0
|
54
|
+
|
55
|
+
- Add `products` link to configuration v1
|
56
|
+
- Add scheme validation for `data` property of products
|
57
|
+
|
58
|
+
## 0.6.3
|
59
|
+
|
60
|
+
- Fix `product_video` create root key
|
61
|
+
|
62
|
+
## 0.6.2
|
63
|
+
|
64
|
+
- Loosen Gem dependency versions to allow any minor update, except for dogfooded gems, which are allowed major updates, until they hit 1.0.0
|
65
|
+
- Add metadata urls for gemspec
|
66
|
+
|
67
|
+
## 0.6.1
|
68
|
+
|
69
|
+
- Allow for http urls because not all services in all environments may operate with TLS enabled.
|
70
|
+
|
71
|
+
## 0.6.0
|
72
|
+
|
73
|
+
- Update `media_types` to `0.6.0` so that the integrations become available downstream.
|
74
|
+
- Rename all `deleted_at` to `expires_at` (#1)
|
75
|
+
- Add `Types::HttpsUrl`, `Types::InfluxDbConnectionUrl`, `Types.makeFormattedUrl`, `Types.Iso8601` to check format of string attributes. (#2)
|
76
|
+
- Add documentation for `updated_at` fields (#4)
|
77
|
+
- Add expected type for `ProductLookup` `identifier` (#5)
|
78
|
+
- Remove optional nil for analytics and metrics url by changing the type (#3)
|
79
|
+
|
80
|
+
## 0.5.0
|
81
|
+
|
82
|
+
:baby: initial public release. Not considered stable until version 1.0.0.
|
data/Gemfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
|
-
|
5
|
-
# Specify your gem's dependencies in trailer_vote-api.gemspec
|
6
|
-
gemspec
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in trailer_vote-api.gemspec
|
6
|
+
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,51 +1,51 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
trailer_vote-media_types (0.
|
5
|
-
media_types (>= 0.6.0, < 1)
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
ansi (1.5.0)
|
11
|
-
awesome_print (1.8.0)
|
12
|
-
builder (3.2.3)
|
13
|
-
docile (1.3.1)
|
14
|
-
json (2.1.0)
|
15
|
-
media_types (0.6.0)
|
16
|
-
minitest (5.11.3)
|
17
|
-
minitest-ci (3.4.0)
|
18
|
-
minitest (>= 5.0.6)
|
19
|
-
minitest-reporters (1.3.
|
20
|
-
ansi
|
21
|
-
builder
|
22
|
-
minitest (>= 5.0)
|
23
|
-
ruby-progressbar
|
24
|
-
oj (3.7.
|
25
|
-
rake (10.5.0)
|
26
|
-
ruby-progressbar (1.10.0)
|
27
|
-
simplecov (0.16.1)
|
28
|
-
docile (~> 1.1)
|
29
|
-
json (>= 1.8, < 3)
|
30
|
-
simplecov-html (~> 0.10.0)
|
31
|
-
simplecov-html (0.10.2)
|
32
|
-
trailer_vote-fixtures (1.
|
33
|
-
|
34
|
-
PLATFORMS
|
35
|
-
ruby
|
36
|
-
x64-mingw32
|
37
|
-
|
38
|
-
DEPENDENCIES
|
39
|
-
awesome_print
|
40
|
-
bundler (~> 1.16)
|
41
|
-
minitest (~> 5.0)
|
42
|
-
minitest-ci (~> 3.4)
|
43
|
-
minitest-reporters (~> 1.3)
|
44
|
-
oj (~> 3.6)
|
45
|
-
rake (~> 10.0)
|
46
|
-
simplecov (~> 0.16)
|
47
|
-
trailer_vote-fixtures (~> 1.
|
48
|
-
trailer_vote-media_types!
|
49
|
-
|
50
|
-
BUNDLED WITH
|
51
|
-
1.17.3
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
trailer_vote-media_types (0.10.0)
|
5
|
+
media_types (>= 0.6.0, < 1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ansi (1.5.0)
|
11
|
+
awesome_print (1.8.0)
|
12
|
+
builder (3.2.3)
|
13
|
+
docile (1.3.1)
|
14
|
+
json (2.1.0)
|
15
|
+
media_types (0.6.0)
|
16
|
+
minitest (5.11.3)
|
17
|
+
minitest-ci (3.4.0)
|
18
|
+
minitest (>= 5.0.6)
|
19
|
+
minitest-reporters (1.3.6)
|
20
|
+
ansi
|
21
|
+
builder
|
22
|
+
minitest (>= 5.0)
|
23
|
+
ruby-progressbar
|
24
|
+
oj (3.7.8)
|
25
|
+
rake (10.5.0)
|
26
|
+
ruby-progressbar (1.10.0)
|
27
|
+
simplecov (0.16.1)
|
28
|
+
docile (~> 1.1)
|
29
|
+
json (>= 1.8, < 3)
|
30
|
+
simplecov-html (~> 0.10.0)
|
31
|
+
simplecov-html (0.10.2)
|
32
|
+
trailer_vote-fixtures (1.3.1)
|
33
|
+
|
34
|
+
PLATFORMS
|
35
|
+
ruby
|
36
|
+
x64-mingw32
|
37
|
+
|
38
|
+
DEPENDENCIES
|
39
|
+
awesome_print
|
40
|
+
bundler (~> 1.16)
|
41
|
+
minitest (~> 5.0)
|
42
|
+
minitest-ci (~> 3.4)
|
43
|
+
minitest-reporters (~> 1.3)
|
44
|
+
oj (~> 3.6)
|
45
|
+
rake (~> 10.0)
|
46
|
+
simplecov (~> 0.16)
|
47
|
+
trailer_vote-fixtures (~> 1.3)
|
48
|
+
trailer_vote-media_types!
|
49
|
+
|
50
|
+
BUNDLED WITH
|
51
|
+
1.17.3
|
data/README.md
CHANGED
@@ -1,118 +1,118 @@
|
|
1
|
-
# TrailerVote::MediaTypes
|
2
|
-
[![Build Status](https://travis-ci.com/TrailerVote/trailervote-media-types.svg?branch=master)](https://travis-ci.com/TrailerVote/trailervote-media-types)
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/trailer_vote-media_types.svg)](https://badge.fury.io/rb/trailer_vote-media_types)
|
4
|
-
[![Maintainability](https://api.codeclimate.com/v1/badges/f5ea339bc868a4e3c362/maintainability)](https://codeclimate.com/github/TrailerVote/trailervote-media-types/maintainability)
|
5
|
-
|
6
|
-
## Installation
|
7
|
-
|
8
|
-
Add this line to your application's Gemfile:
|
9
|
-
|
10
|
-
```ruby
|
11
|
-
gem 'trailer_vote-media_types'
|
12
|
-
```
|
13
|
-
|
14
|
-
And then execute:
|
15
|
-
|
16
|
-
$ bundle
|
17
|
-
|
18
|
-
Or install it yourself as:
|
19
|
-
|
20
|
-
$ gem install trailer_vote-media_types
|
21
|
-
|
22
|
-
## Notes
|
23
|
-
|
24
|
-
### `updated_at` vs `Last-Modified` headers
|
25
|
-
|
26
|
-
When this is used in conjunction with a TrailerVote service, the `updated_at` attributes inside the body of a response will take precedence over any `Last-Modified` header. The `updated_at` value **SHOULD** reflect the last time the resource was updated, whereas the `Last-Modified` value may change when the representation is updated.
|
27
|
-
|
28
|
-
### Are ids missing?
|
29
|
-
|
30
|
-
No, the `id` or `uuid` attributes are not missing. As per the [TrailerVote API considerations](https://docs.trailervote.com/reference) clients **SHOULD** not need to construct URLs. Both internally and externally, where possible, we refer to resources by their fully qualified URL which _is_ their identifier, instead of something like a UUID.
|
31
|
-
|
32
|
-
## Usage
|
33
|
-
|
34
|
-
This gem is based on [`media_types`](https://github.com/SleeplessByte/media-types-ruby), and inherits all the functionality from that gem. In general, you can use `trailer_vote-media_types` in the following ways:
|
35
|
-
|
36
|
-
### `Accept` and `Content-Type` construction
|
37
|
-
|
38
|
-
All the media types can be turned into a header value, both acceptable for the `Accept` and `Content-Type` headers:
|
39
|
-
|
40
|
-
```ruby
|
41
|
-
TrailerVote::MediaTypes::Configuration.to_constructable.version(2).to_s
|
42
|
-
# => "application/vnd.trailervote.configuration.v2+json"
|
43
|
-
```
|
44
|
-
|
45
|
-
The [`Constructable`](https://www.rubydoc.info/gems/media_types/MediaTypes/Constructable) result of `#to_constructable` allows for chaining the various options in our media types, namely `view` (e.g. `index`, `create`) and `version`. The default `suffix` is none for binary types and `json` for text type, as we don't support XML at the moment.
|
46
|
-
|
47
|
-
It is **recommended** to always include `.version(n)`, otherwise you will get the newest version, which might not be what you support in the code.
|
48
|
-
|
49
|
-
### `Accept` with quality parameter
|
50
|
-
|
51
|
-
If you want to have multiple `Accept` values, but with different priorities, `Constructable#to_s` accepts an additional parameter to set this. For example, if you want to make a fully qualified `Accept` header and you prefer product version 2, but accept version 1 as well:
|
52
|
-
|
53
|
-
```ruby
|
54
|
-
[
|
55
|
-
TrailerVote::MediaTypes::Product.to_constructable.version(2).to_s,
|
56
|
-
TrailerVote::MediaTypes::Product.to_constructable.version(1).to_s(0.9),
|
57
|
-
TrailerVote::MediaTypes::Errors.to_constructable.version(1).to_s(0.1)
|
58
|
-
].join(', ')
|
59
|
-
# => "application/vnd.trailervote.configuration.product.v2+json,
|
60
|
-
# application/vnd.trailervote.configuration.product.v1+json; q=0.9,
|
61
|
-
# application/vnd.trailervote.errors.v1+json; q=0.1"
|
62
|
-
```
|
63
|
-
|
64
|
-
### Data validation
|
65
|
-
|
66
|
-
All the media types come equipped with validations, for most known / expected permutations of views and versions. Validations are based on [`Scheme`](https://www.rubydoc.info/gems/media_types/MediaTypes/Scheme) from the [`media_types`](https://github.com/SleeplessByte/media-types-ruby) gem.
|
67
|
-
|
68
|
-
```ruby
|
69
|
-
media_type = TrailerVote::MediaTypes::ClientConfiguration.to_constructable.version(1)
|
70
|
-
# => application/vnd.trailervote.client_configuration.v1+json
|
71
|
-
|
72
|
-
media_type.valid?(
|
73
|
-
configuration: {
|
74
|
-
place: "https://fake.trailervote.com/api/places/435ec0b8-100d-4e92-8a17-04bc77e90880",
|
75
|
-
persona: "https://fake.trailervote.com/api/persona/e03a1c72-8bce-408c-a6e4-de215e73dd92"
|
76
|
-
}
|
77
|
-
)
|
78
|
-
# => true
|
79
|
-
|
80
|
-
media_type.validate!(
|
81
|
-
configuration: {
|
82
|
-
place: "https://fake.trailervote.com/api/places/435ec0b8-100d-4e92-8a17-04bc77e90880",
|
83
|
-
}
|
84
|
-
)
|
85
|
-
# => raises MediaTypes::Scheme::ExhaustedOutputError: Missing keys in output: [:persona] at [.->configuration]
|
86
|
-
```
|
87
|
-
|
88
|
-
### `Mime::Type` registration
|
89
|
-
|
90
|
-
In case you use `action_dispatch/http/mime_type`, you may register the TrailerVote Media Types into the `Mime::Type` registry like so:
|
91
|
-
```ruby
|
92
|
-
TrailerVote::MediaTypes::Persona.register
|
93
|
-
# => [...] # Array of registered types, each version, each suffix permutation, all aliases
|
94
|
-
```
|
95
|
-
|
96
|
-
You can now look them up in the registry:
|
97
|
-
|
98
|
-
```ruby
|
99
|
-
media_type = TrailerVote::MediaTypes::Persona.to_constructable.version(1).to_s
|
100
|
-
# => "application/vnd.trailervote.persona.v1+json"
|
101
|
-
|
102
|
-
Mime::Type.lookup(media_type)
|
103
|
-
# => Mime::Type entry
|
104
|
-
```
|
105
|
-
|
106
|
-
## Development
|
107
|
-
|
108
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can
|
109
|
-
also run `bin/console` for an interactive prompt that will allow you to experiment.
|
110
|
-
|
111
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
|
112
|
-
version number in `version.rb`, and then run `bundle update trailer_vote-media_types` in any repository that depends on
|
113
|
-
this gem. If you have permissions, you may call `bundle exec rake release` to create a new git tag, push
|
114
|
-
git commits and tags, and push the `.gem` file to the rubygems gem server.
|
115
|
-
|
116
|
-
## Contributing
|
117
|
-
|
118
|
-
Bug reports and pull requests are welcome on GitHub at [TrailerVote/trailervote-media-types](https://github.com/TrailerVote/trailervote-media-types)
|
1
|
+
# TrailerVote::MediaTypes
|
2
|
+
[![Build Status](https://travis-ci.com/TrailerVote/trailervote-media-types.svg?branch=master)](https://travis-ci.com/TrailerVote/trailervote-media-types)
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/trailer_vote-media_types.svg)](https://badge.fury.io/rb/trailer_vote-media_types)
|
4
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/f5ea339bc868a4e3c362/maintainability)](https://codeclimate.com/github/TrailerVote/trailervote-media-types/maintainability)
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'trailer_vote-media_types'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install trailer_vote-media_types
|
21
|
+
|
22
|
+
## Notes
|
23
|
+
|
24
|
+
### `updated_at` vs `Last-Modified` headers
|
25
|
+
|
26
|
+
When this is used in conjunction with a TrailerVote service, the `updated_at` attributes inside the body of a response will take precedence over any `Last-Modified` header. The `updated_at` value **SHOULD** reflect the last time the resource was updated, whereas the `Last-Modified` value may change when the representation is updated.
|
27
|
+
|
28
|
+
### Are ids missing?
|
29
|
+
|
30
|
+
No, the `id` or `uuid` attributes are not missing. As per the [TrailerVote API considerations](https://docs.trailervote.com/reference) clients **SHOULD** not need to construct URLs. Both internally and externally, where possible, we refer to resources by their fully qualified URL which _is_ their identifier, instead of something like a UUID.
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
This gem is based on [`media_types`](https://github.com/SleeplessByte/media-types-ruby), and inherits all the functionality from that gem. In general, you can use `trailer_vote-media_types` in the following ways:
|
35
|
+
|
36
|
+
### `Accept` and `Content-Type` construction
|
37
|
+
|
38
|
+
All the media types can be turned into a header value, both acceptable for the `Accept` and `Content-Type` headers:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
TrailerVote::MediaTypes::Configuration.to_constructable.version(2).to_s
|
42
|
+
# => "application/vnd.trailervote.configuration.v2+json"
|
43
|
+
```
|
44
|
+
|
45
|
+
The [`Constructable`](https://www.rubydoc.info/gems/media_types/MediaTypes/Constructable) result of `#to_constructable` allows for chaining the various options in our media types, namely `view` (e.g. `index`, `create`) and `version`. The default `suffix` is none for binary types and `json` for text type, as we don't support XML at the moment.
|
46
|
+
|
47
|
+
It is **recommended** to always include `.version(n)`, otherwise you will get the newest version, which might not be what you support in the code.
|
48
|
+
|
49
|
+
### `Accept` with quality parameter
|
50
|
+
|
51
|
+
If you want to have multiple `Accept` values, but with different priorities, `Constructable#to_s` accepts an additional parameter to set this. For example, if you want to make a fully qualified `Accept` header and you prefer product version 2, but accept version 1 as well:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
[
|
55
|
+
TrailerVote::MediaTypes::Product.to_constructable.version(2).to_s,
|
56
|
+
TrailerVote::MediaTypes::Product.to_constructable.version(1).to_s(0.9),
|
57
|
+
TrailerVote::MediaTypes::Errors.to_constructable.version(1).to_s(0.1)
|
58
|
+
].join(', ')
|
59
|
+
# => "application/vnd.trailervote.configuration.product.v2+json,
|
60
|
+
# application/vnd.trailervote.configuration.product.v1+json; q=0.9,
|
61
|
+
# application/vnd.trailervote.errors.v1+json; q=0.1"
|
62
|
+
```
|
63
|
+
|
64
|
+
### Data validation
|
65
|
+
|
66
|
+
All the media types come equipped with validations, for most known / expected permutations of views and versions. Validations are based on [`Scheme`](https://www.rubydoc.info/gems/media_types/MediaTypes/Scheme) from the [`media_types`](https://github.com/SleeplessByte/media-types-ruby) gem.
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
media_type = TrailerVote::MediaTypes::ClientConfiguration.to_constructable.version(1)
|
70
|
+
# => application/vnd.trailervote.client_configuration.v1+json
|
71
|
+
|
72
|
+
media_type.valid?(
|
73
|
+
configuration: {
|
74
|
+
place: "https://fake.trailervote.com/api/places/435ec0b8-100d-4e92-8a17-04bc77e90880",
|
75
|
+
persona: "https://fake.trailervote.com/api/persona/e03a1c72-8bce-408c-a6e4-de215e73dd92"
|
76
|
+
}
|
77
|
+
)
|
78
|
+
# => true
|
79
|
+
|
80
|
+
media_type.validate!(
|
81
|
+
configuration: {
|
82
|
+
place: "https://fake.trailervote.com/api/places/435ec0b8-100d-4e92-8a17-04bc77e90880",
|
83
|
+
}
|
84
|
+
)
|
85
|
+
# => raises MediaTypes::Scheme::ExhaustedOutputError: Missing keys in output: [:persona] at [.->configuration]
|
86
|
+
```
|
87
|
+
|
88
|
+
### `Mime::Type` registration
|
89
|
+
|
90
|
+
In case you use `action_dispatch/http/mime_type`, you may register the TrailerVote Media Types into the `Mime::Type` registry like so:
|
91
|
+
```ruby
|
92
|
+
TrailerVote::MediaTypes::Persona.register
|
93
|
+
# => [...] # Array of registered types, each version, each suffix permutation, all aliases
|
94
|
+
```
|
95
|
+
|
96
|
+
You can now look them up in the registry:
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
media_type = TrailerVote::MediaTypes::Persona.to_constructable.version(1).to_s
|
100
|
+
# => "application/vnd.trailervote.persona.v1+json"
|
101
|
+
|
102
|
+
Mime::Type.lookup(media_type)
|
103
|
+
# => Mime::Type entry
|
104
|
+
```
|
105
|
+
|
106
|
+
## Development
|
107
|
+
|
108
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can
|
109
|
+
also run `bin/console` for an interactive prompt that will allow you to experiment.
|
110
|
+
|
111
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
|
112
|
+
version number in `version.rb`, and then run `bundle update trailer_vote-media_types` in any repository that depends on
|
113
|
+
this gem. If you have permissions, you may call `bundle exec rake release` to create a new git tag, push
|
114
|
+
git commits and tags, and push the `.gem` file to the rubygems gem server.
|
115
|
+
|
116
|
+
## Contributing
|
117
|
+
|
118
|
+
Bug reports and pull requests are welcome on GitHub at [TrailerVote/trailervote-media-types](https://github.com/TrailerVote/trailervote-media-types)
|