trailer_vote-media_types 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +12 -12
  3. data/.rubocop.yml +29 -29
  4. data/.travis.yml +18 -18
  5. data/CHANGELOG.md +82 -82
  6. data/Gemfile +6 -6
  7. data/Gemfile.lock +5 -5
  8. data/README.md +118 -118
  9. data/Rakefile +12 -12
  10. data/bin/console +16 -16
  11. data/bin/setup +8 -8
  12. data/lib/trailer_vote/media_types/audio_fragment.rb +108 -108
  13. data/lib/trailer_vote/media_types/base_text.rb +22 -22
  14. data/lib/trailer_vote/media_types/carousel.rb +42 -42
  15. data/lib/trailer_vote/media_types/client_configuration.rb +35 -35
  16. data/lib/trailer_vote/media_types/configuration.rb +139 -139
  17. data/lib/trailer_vote/media_types/errors.rb +31 -31
  18. data/lib/trailer_vote/media_types/feedback.rb +50 -50
  19. data/lib/trailer_vote/media_types/feedback_listing.rb +49 -49
  20. data/lib/trailer_vote/media_types/fingerprint_binary.rb +67 -67
  21. data/lib/trailer_vote/media_types/interactive_player.rb +33 -33
  22. data/lib/trailer_vote/media_types/issue.rb +64 -64
  23. data/lib/trailer_vote/media_types/ordered_fragment.rb +35 -35
  24. data/lib/trailer_vote/media_types/partials/image_links.rb +30 -30
  25. data/lib/trailer_vote/media_types/persona.rb +47 -47
  26. data/lib/trailer_vote/media_types/place.rb +143 -143
  27. data/lib/trailer_vote/media_types/product.rb +191 -191
  28. data/lib/trailer_vote/media_types/product_image.rb +96 -96
  29. data/lib/trailer_vote/media_types/product_lookup.rb +37 -37
  30. data/lib/trailer_vote/media_types/product_place_link.rb +36 -36
  31. data/lib/trailer_vote/media_types/product_video.rb +100 -100
  32. data/lib/trailer_vote/media_types/products_listing.rb +43 -43
  33. data/lib/trailer_vote/media_types/push_consent.rb +44 -44
  34. data/lib/trailer_vote/media_types/push_manifest.rb +44 -44
  35. data/lib/trailer_vote/media_types/push_token_android.rb +41 -41
  36. data/lib/trailer_vote/media_types/push_token_index.rb +42 -42
  37. data/lib/trailer_vote/media_types/push_token_ios.rb +41 -41
  38. data/lib/trailer_vote/media_types/push_trivial_campaign.rb +23 -1
  39. data/lib/trailer_vote/media_types/release_push_campaign.rb +29 -2
  40. data/lib/trailer_vote/media_types/sentiment_feedback.rb +100 -100
  41. data/lib/trailer_vote/media_types/types/boolean.rb +15 -15
  42. data/lib/trailer_vote/media_types/types/formatted_url.rb +51 -51
  43. data/lib/trailer_vote/media_types/types/http_url.rb +23 -23
  44. data/lib/trailer_vote/media_types/types/influx_db_connection_url.rb +10 -10
  45. data/lib/trailer_vote/media_types/types/iso8601.rb +10 -10
  46. data/lib/trailer_vote/media_types/types/local_time.rb +11 -11
  47. data/lib/trailer_vote/media_types/types/product_data_type.rb +15 -15
  48. data/lib/trailer_vote/media_types/types/product_image_type.rb +25 -25
  49. data/lib/trailer_vote/media_types/types/product_movie_handler.rb +16 -16
  50. data/lib/trailer_vote/media_types/types/product_movie_type.rb +17 -17
  51. data/lib/trailer_vote/media_types/types/uuid_v4.rb +10 -10
  52. data/lib/trailer_vote/media_types/types/vote_value.rb +17 -17
  53. data/lib/trailer_vote/media_types/version.rb +1 -1
  54. data/trailer_vote-media_types.gemspec +2 -2
  55. metadata +7 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1288d7dad9c97ecc0a247b2ea0e97080350de1d05f8d99e1b90ec1c701e2d6a6
4
- data.tar.gz: af35a13402987a4377b6e1987203bc1e0cb4f3c90957e5e4a395ede1adef76ef
3
+ metadata.gz: 8d5fb985577a85efe9cea70dae0977968d35d11116b8305f7d0887f27e8cebe0
4
+ data.tar.gz: 606afe3ecef2b7b3892e37f3cd7350f2ba4ab2ce0b06223c54755d03f87ac90d
5
5
  SHA512:
6
- metadata.gz: 8547e41d4e776751d4bc2432141f0e3e4ca35571593b691bcf761711c76fc1b369aaac36b128189fb79ce20115bf096648e8128e81ca3ee42ad481e1019f0db1
7
- data.tar.gz: 83c2ca51ee349191ac9c5788481216a181c280c167e3a7cc4ccbddc6c1e58e1bd21a3129c02a737b183cb992bbe50915b92bc38407e1988d5ca9a15c358fa89f
6
+ metadata.gz: 0e64dafd643e022ac7e2fe9f2f1a47911ec31052031e7b0dcd2b3b2623ad33be21f57d5c0c9e5045c553c1c0d6045cdf3aedf6992dbd663e9f30731b8941fc86
7
+ data.tar.gz: 918b8c8a7d8214f1fb98c139164cbcacbf3991253efcfa84936275003e69bd5a36e2e49a1790f8678ea825927a88bbec72021b79a0d24fa6fd393198898142d9
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.5
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.5
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,18 +1,18 @@
1
- sudo: false
2
- language: ruby
3
- cache: bundler
4
- rvm:
5
- - 2.5
6
- - 2.6
7
- - rbx-3
8
- - ruby-head
9
- matrix:
10
- allow_failures:
11
- - rvm: ruby-head
12
- - rvm: rbx-3
13
- - rvm: 2.6
14
- before_install:
15
- - gem update --system
16
- - gem --version
17
- install:
18
- - 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.5
6
+ - 2.6
7
+ - rbx-3
8
+ - ruby-head
9
+ matrix:
10
+ allow_failures:
11
+ - rvm: ruby-head
12
+ - rvm: rbx-3
13
+ - rvm: 2.6
14
+ before_install:
15
+ - gem update --system
16
+ - gem --version
17
+ install:
18
+ - 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,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- trailer_vote-media_types (2.0.0)
4
+ trailer_vote-media_types (2.2.0)
5
5
  media_types (>= 0.6.0, < 1)
6
6
 
7
7
  GEM
@@ -29,7 +29,7 @@ GEM
29
29
  json (>= 1.8, < 3)
30
30
  simplecov-html (~> 0.10.0)
31
31
  simplecov-html (0.10.2)
32
- trailer_vote-fixtures (1.14.0)
32
+ trailer_vote-fixtures (1.15.0)
33
33
 
34
34
  PLATFORMS
35
35
  ruby
@@ -37,15 +37,15 @@ PLATFORMS
37
37
 
38
38
  DEPENDENCIES
39
39
  awesome_print (~> 1.8)
40
- bundler (~> 1.16)
40
+ bundler (~> 2.0)
41
41
  minitest (~> 5.0)
42
42
  minitest-ci (~> 3.4)
43
43
  minitest-reporters (~> 1.3)
44
44
  oj (~> 3.6)
45
45
  rake (~> 13.0)
46
46
  simplecov (~> 0.16)
47
- trailer_vote-fixtures (~> 1.14.0)
47
+ trailer_vote-fixtures (~> 1.15.0)
48
48
  trailer_vote-media_types!
49
49
 
50
50
  BUNDLED WITH
51
- 1.17.3
51
+ 2.1.0
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)
data/Rakefile CHANGED
@@ -1,12 +1,12 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler/gem_tasks'
4
- require 'rake/testtask'
5
-
6
- Rake::TestTask.new(:test) do |t|
7
- t.libs << 'test'
8
- t.libs << 'lib'
9
- t.test_files = FileList['test/**/*_test.rb']
10
- end
11
-
12
- task default: :test
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ end
11
+
12
+ task default: :test
data/bin/console CHANGED
@@ -1,16 +1,16 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require 'bundler/setup'
5
- require 'trailer_vote/media_types'
6
- require 'awesome_print'
7
-
8
- # You can add fixtures and/or initialization code here to make experimenting
9
- # with your gem easier. You can also use a different console, if you like.
10
-
11
- # (If you use this, don't forget to add pry to your Gemfile!)
12
- # require "pry"
13
- # Pry.start
14
-
15
- require 'irb'
16
- IRB.start(__FILE__)
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'trailer_vote/media_types'
6
+ require 'awesome_print'
7
+
8
+ # You can add fixtures and/or initialization code here to make experimenting
9
+ # with your gem easier. You can also use a different console, if you like.
10
+
11
+ # (If you use this, don't forget to add pry to your Gemfile!)
12
+ # require "pry"
13
+ # Pry.start
14
+
15
+ require 'irb'
16
+ IRB.start(__FILE__)
data/bin/setup CHANGED
@@ -1,8 +1,8 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here