trailer_vote-media_types 2.3.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) 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 +8 -8
  7. data/Gemfile.lock +49 -51
  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.rb +1 -0
  13. data/lib/trailer_vote/media_types/audio_fragment.rb +108 -108
  14. data/lib/trailer_vote/media_types/base_text.rb +22 -22
  15. data/lib/trailer_vote/media_types/carousel.rb +42 -42
  16. data/lib/trailer_vote/media_types/client_configuration.rb +35 -35
  17. data/lib/trailer_vote/media_types/configuration.rb +139 -139
  18. data/lib/trailer_vote/media_types/errors.rb +31 -31
  19. data/lib/trailer_vote/media_types/feedback.rb +50 -50
  20. data/lib/trailer_vote/media_types/feedback_listing.rb +49 -49
  21. data/lib/trailer_vote/media_types/fingerprint_binary.rb +67 -67
  22. data/lib/trailer_vote/media_types/interactive_player.rb +33 -33
  23. data/lib/trailer_vote/media_types/issue.rb +64 -64
  24. data/lib/trailer_vote/media_types/ordered_fragment.rb +35 -35
  25. data/lib/trailer_vote/media_types/partials/image_links.rb +30 -30
  26. data/lib/trailer_vote/media_types/persona.rb +47 -47
  27. data/lib/trailer_vote/media_types/place.rb +143 -143
  28. data/lib/trailer_vote/media_types/product.rb +191 -191
  29. data/lib/trailer_vote/media_types/product_image.rb +96 -96
  30. data/lib/trailer_vote/media_types/product_lookup.rb +37 -37
  31. data/lib/trailer_vote/media_types/product_place_link.rb +36 -36
  32. data/lib/trailer_vote/media_types/product_video.rb +100 -100
  33. data/lib/trailer_vote/media_types/products_listing.rb +43 -43
  34. data/lib/trailer_vote/media_types/push_consent.rb +44 -44
  35. data/lib/trailer_vote/media_types/push_manifest.rb +44 -44
  36. data/lib/trailer_vote/media_types/push_token_android.rb +41 -41
  37. data/lib/trailer_vote/media_types/push_token_index.rb +42 -42
  38. data/lib/trailer_vote/media_types/push_token_ios.rb +41 -41
  39. data/lib/trailer_vote/media_types/push_trivial_campaign.rb +219 -219
  40. data/lib/trailer_vote/media_types/release_push_campaign.rb +77 -77
  41. data/lib/trailer_vote/media_types/sentiment_feedback.rb +100 -100
  42. data/lib/trailer_vote/media_types/types/boolean.rb +15 -15
  43. data/lib/trailer_vote/media_types/types/formatted_url.rb +51 -51
  44. data/lib/trailer_vote/media_types/types/http_url.rb +23 -23
  45. data/lib/trailer_vote/media_types/types/influx_db_connection_url.rb +10 -10
  46. data/lib/trailer_vote/media_types/types/iso8601.rb +10 -10
  47. data/lib/trailer_vote/media_types/types/local_time.rb +11 -11
  48. data/lib/trailer_vote/media_types/types/product_data_type.rb +15 -15
  49. data/lib/trailer_vote/media_types/types/product_image_type.rb +25 -25
  50. data/lib/trailer_vote/media_types/types/product_movie_handler.rb +16 -16
  51. data/lib/trailer_vote/media_types/types/product_movie_type.rb +17 -17
  52. data/lib/trailer_vote/media_types/types/uuid_v4.rb +10 -10
  53. data/lib/trailer_vote/media_types/types/vote_value.rb +17 -17
  54. data/lib/trailer_vote/media_types/version.rb +7 -7
  55. data/lib/trailer_vote/media_types/vista_config.rb +37 -0
  56. data/trailer_vote-media_types.gemspec +43 -43
  57. metadata +6 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7ca31bc160325f98ea1813dbe49cb992977819eba3501f7b153eaa5ec1de23be
4
- data.tar.gz: 3a9c7ebc6d63078cd97d777e24bbf216adfae82d5fd4a9ea7a9d2be00e030711
3
+ metadata.gz: 9e6c6d669fd9696a3bff78ca4d8d41930f1e7351dd43ac8223f58965ec7e2fe8
4
+ data.tar.gz: 93de80ebc356441a7284366369ce27ef5bf4bbfbda3b6448d6eadfdd484f58ba
5
5
  SHA512:
6
- metadata.gz: cfbeb7c6c7731ce18fc714ea6f96c77d159558bbc7767c273bbd65fd25edd176e9069d045a207514759b301efa3e40aa52a6d0d5cfb80c4c71ac28aaba99d96f
7
- data.tar.gz: 2fb24373eaaf8c12dd44892c7de38b1b5ff6ef0009fea309e5ae36bac827cb4bb5d5cc2d6190f589c2f8c0d5c32f28eff3257697688b8b9fae5dfef1fbb187ad
6
+ metadata.gz: '068aa9e0ae0b526a5b56fe93517a22adc8594346317fd6ff75cf6da9391f5790f9965fce5d700e4647265aae7bd24e2cf268d4e4f9edc2dd4bf672a3f6a0e668'
7
+ data.tar.gz: a38670fa2a25719e28ed16f3182aaa270002d37459d66a3d0fdc190a8ba15cf17b593832b8c5a4252e12401ed4411716e6c0723f4b1a10b1b974132f0d9a8275
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,8 +1,8 @@
1
- source 'https://rubygems.org'
2
-
3
- git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
-
5
- # gem "trailer_vote-fixtures", path: "../../trailervote-fixtures"
6
- # Specify your gem's dependencies in trailer_vote-api.gemspec
7
- gemspec
8
-
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # gem "trailer_vote-fixtures", path: "../../trailervote-fixtures"
6
+ # Specify your gem's dependencies in trailer_vote-api.gemspec
7
+ gemspec
8
+
data/Gemfile.lock CHANGED
@@ -1,51 +1,49 @@
1
- PATH
2
- remote: .
3
- specs:
4
- trailer_vote-media_types (2.3.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.4)
13
- docile (1.3.2)
14
- json (2.3.0)
15
- media_types (0.6.2)
16
- minitest (5.14.0)
17
- minitest-ci (3.4.0)
18
- minitest (>= 5.0.6)
19
- minitest-reporters (1.4.2)
20
- ansi
21
- builder
22
- minitest (>= 5.0)
23
- ruby-progressbar
24
- oj (3.10.0)
25
- rake (13.0.1)
26
- ruby-progressbar (1.10.1)
27
- simplecov (0.17.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.16.0)
33
-
34
- PLATFORMS
35
- ruby
36
- x64-mingw32
37
-
38
- DEPENDENCIES
39
- awesome_print (~> 1.8)
40
- bundler (~> 2.0)
41
- minitest (~> 5.0)
42
- minitest-ci (~> 3.4)
43
- minitest-reporters (~> 1.3)
44
- oj (~> 3.6)
45
- rake (~> 13.0)
46
- simplecov (~> 0.16)
47
- trailer_vote-fixtures (~> 1.16.0)
48
- trailer_vote-media_types!
49
-
50
- BUNDLED WITH
51
- 2.1.0
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ trailer_vote-media_types (2.4.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.4)
13
+ docile (1.3.2)
14
+ media_types (0.6.2)
15
+ minitest (5.14.0)
16
+ minitest-ci (3.4.0)
17
+ minitest (>= 5.0.6)
18
+ minitest-reporters (1.4.2)
19
+ ansi
20
+ builder
21
+ minitest (>= 5.0)
22
+ ruby-progressbar
23
+ oj (3.10.5)
24
+ rake (13.0.1)
25
+ ruby-progressbar (1.10.1)
26
+ simplecov (0.18.5)
27
+ docile (~> 1.1)
28
+ simplecov-html (~> 0.11)
29
+ simplecov-html (0.12.2)
30
+ trailer_vote-fixtures (1.17.0)
31
+
32
+ PLATFORMS
33
+ ruby
34
+ x64-mingw32
35
+
36
+ DEPENDENCIES
37
+ awesome_print (~> 1.8)
38
+ bundler (~> 2.0)
39
+ minitest (~> 5.0)
40
+ minitest-ci (~> 3.4)
41
+ minitest-reporters (~> 1.3)
42
+ oj (~> 3.6)
43
+ rake (~> 13.0)
44
+ simplecov (~> 0.16)
45
+ trailer_vote-fixtures (~> 1.17.0)
46
+ trailer_vote-media_types!
47
+
48
+ BUNDLED WITH
49
+ 2.1.4
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)