trailer_vote-media_types 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.rubocop.yml +29 -0
  4. data/.travis.yml +20 -0
  5. data/CHANGELOG.md +3 -0
  6. data/Gemfile +6 -0
  7. data/Gemfile.lock +48 -0
  8. data/README.md +105 -0
  9. data/Rakefile +12 -0
  10. data/bin/console +16 -0
  11. data/bin/setup +8 -0
  12. data/lib/trailer_vote/media_types.rb +32 -0
  13. data/lib/trailer_vote/media_types/audio_fragment.rb +106 -0
  14. data/lib/trailer_vote/media_types/base_text.rb +22 -0
  15. data/lib/trailer_vote/media_types/carousel.rb +42 -0
  16. data/lib/trailer_vote/media_types/client_configuration.rb +34 -0
  17. data/lib/trailer_vote/media_types/configuration.rb +54 -0
  18. data/lib/trailer_vote/media_types/errors.rb +31 -0
  19. data/lib/trailer_vote/media_types/feedback.rb +49 -0
  20. data/lib/trailer_vote/media_types/feedback_listing.rb +48 -0
  21. data/lib/trailer_vote/media_types/fingerprint_binary.rb +67 -0
  22. data/lib/trailer_vote/media_types/interactive_player.rb +33 -0
  23. data/lib/trailer_vote/media_types/partials/image_links.rb +20 -0
  24. data/lib/trailer_vote/media_types/persona.rb +38 -0
  25. data/lib/trailer_vote/media_types/place.rb +105 -0
  26. data/lib/trailer_vote/media_types/product.rb +175 -0
  27. data/lib/trailer_vote/media_types/product_image.rb +113 -0
  28. data/lib/trailer_vote/media_types/product_lookup.rb +37 -0
  29. data/lib/trailer_vote/media_types/product_place_link.rb +37 -0
  30. data/lib/trailer_vote/media_types/product_video.rb +92 -0
  31. data/lib/trailer_vote/media_types/products_listing.rb +42 -0
  32. data/lib/trailer_vote/media_types/sentiment_feedback.rb +97 -0
  33. data/lib/trailer_vote/media_types/types/boolean.rb +15 -0
  34. data/lib/trailer_vote/media_types/types/product_data_type.rb +15 -0
  35. data/lib/trailer_vote/media_types/types/product_image_type.rb +25 -0
  36. data/lib/trailer_vote/media_types/types/product_movie_handler.rb +15 -0
  37. data/lib/trailer_vote/media_types/types/product_movie_type.rb +17 -0
  38. data/lib/trailer_vote/media_types/types/uuid_v4.rb +10 -0
  39. data/lib/trailer_vote/media_types/types/vote_value.rb +17 -0
  40. data/lib/trailer_vote/media_types/version.rb +7 -0
  41. data/trailer_vote-media_types.gemspec +32 -0
  42. metadata +209 -0
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './base_text'
4
+ require_relative './partials/image_links'
5
+
6
+ module TrailerVote
7
+ module MediaTypes
8
+
9
+ class Carousel < BaseText
10
+ media_type 'carousel'
11
+
12
+ defaults do
13
+ suffix :json
14
+ version 1
15
+ end
16
+
17
+ validations do
18
+ version 1 do
19
+ attribute :carousel do
20
+ collection :items do
21
+ attribute :title, AllowNil(String)
22
+ attribute :image, expected_type: AllowNil(::Hash), allow_empty: true, optional: true do
23
+ attribute :_embedded, expected_type: AllowNil(::Hash), allow_empty: true do
24
+ merge Partials::IMAGE_LINKS
25
+ end
26
+ end
27
+
28
+ link :product
29
+ link :video
30
+ link :direct
31
+ link :interactive_player
32
+ end
33
+
34
+ link :self
35
+ end
36
+ end
37
+ end
38
+
39
+ registrations(:carousel) {}
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './base_text'
4
+
5
+ module TrailerVote
6
+ module MediaTypes
7
+
8
+ ##
9
+ # Media Types for Client Configuration
10
+ #
11
+ # The client configuration media type is used when a client, such as the SDK clients, want to configure the
12
+ # TrailerVote services. When accepted, the TrailerVote services may use the passed configurations to return specific
13
+ # responses based on that configuration. For example, the {Configuration} from the root endpoint changed based on
14
+ # the values.
15
+ #
16
+ class ClientConfiguration < BaseText
17
+ media_type 'client_configuration', defaults: { suffix: :json, version: 1 }
18
+
19
+ validations do
20
+ version 1 do
21
+ attribute :configuration do
22
+ attribute :place, String
23
+ attribute :persona, String
24
+ end
25
+ end
26
+ end
27
+
28
+ registrations :client_configuration do
29
+ versions 1
30
+ type_alias 'client-configuration'
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './base_text'
4
+
5
+ module TrailerVote
6
+ module MediaTypes
7
+
8
+ ##
9
+ # Media Types for Configuration
10
+ #
11
+ class Configuration < BaseText
12
+ media_type 'configuration', defaults: { suffix: :json, version: 2 }
13
+
14
+ validations do
15
+ version 2 do
16
+ attribute :configuration do
17
+ link :self
18
+ link :place
19
+ link :products
20
+ link :product_lookup
21
+ link :persona do
22
+ attribute :templated, TrueClass
23
+ end
24
+ link :analytics do
25
+ attribute :href, AllowNil(String)
26
+ end
27
+ link :telemetrics do
28
+ attribute :href, AllowNil(String)
29
+ end
30
+ end
31
+ end
32
+
33
+ version 1 do
34
+ attribute :configuration do
35
+ link :place
36
+ link :feedback do
37
+ attribute :templated, TrueClass
38
+ end
39
+ link :persona do
40
+ attribute :templated, TrueClass
41
+ end
42
+ link :analytics do
43
+ attribute :href, AllowNil(String)
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ registrations :configuration do
50
+ versions 1, 2
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'trailer_vote/media_types/base_text'
4
+
5
+ module TrailerVote
6
+ module MediaTypes
7
+ ##
8
+ # Media Types for errors
9
+ #
10
+ # All errors given back to any TrailerVote service have this media type. In order to ensure correct error
11
+ # content-type negotiation, clients SHOULD include the media type with a reduced quality param q in the Accept
12
+ # header of each request. The RECOMMENDED value for q is 0.1.
13
+ #
14
+ class Errors < BaseText
15
+ media_type 'errors', defaults: { suffix: :json, version: 1 }
16
+
17
+ validations do
18
+ version 1 do
19
+ collection :errors do
20
+ attribute :message, String
21
+ attribute :code, AllowNil(String)
22
+ end
23
+ end
24
+ end
25
+
26
+ registrations :errors do
27
+ versions 1
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './base_text'
4
+ require_relative './types/uuid_v4'
5
+ require_relative './types/vote_value'
6
+
7
+ module TrailerVote
8
+ module MediaTypes
9
+ class Feedback < BaseText
10
+ media_type 'feedback', defaults: { suffix: :json, version: 1 }
11
+
12
+ validations do
13
+ version 1 do
14
+ version_1_base = ::MediaTypes::Scheme.new do
15
+ attribute :value, Types::VoteValue
16
+ attribute :updated_at, String
17
+
18
+ link :audio_fragment
19
+ link :product
20
+ link :persona
21
+ end
22
+
23
+ attribute :feedback do
24
+ merge version_1_base
25
+ end
26
+
27
+ view 'collection' do
28
+ attribute :feedback do
29
+ collection :_embedded, version_1_base, allow_empty: true
30
+ not_strict
31
+ end
32
+ end
33
+
34
+ view 'create' do
35
+ attribute :feedback do
36
+ attribute :persona, Types::UuidV4
37
+ attribute :value, Types::VoteValue
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ registrations :feedback do
44
+ view 'create', :create_feedback
45
+ view 'collection', :feedback_collection
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './base_text'
4
+ require_relative './types/vote_value'
5
+ require_relative './partials/image_links'
6
+
7
+ module TrailerVote
8
+ module MediaTypes
9
+ class FeedbackListing < BaseText
10
+ media_type 'feedback_listing'
11
+
12
+ defaults do
13
+ suffix :json
14
+ version 1
15
+ end
16
+
17
+ validations do
18
+ version 1 do
19
+ attribute :feedback_listing do
20
+ collection :items, allow_empty: true do
21
+ attribute :title, AllowNil(String)
22
+ attribute :value, Types::VoteValue
23
+ attribute :updated_at, String
24
+
25
+ link :audio_fragment
26
+ link :product
27
+ link :persona
28
+ link :feedback
29
+ link :interactive_player
30
+
31
+ attribute :image, expected_type: AllowNil(::Hash), allow_empty: true, optional: true do
32
+ attribute :_embedded, expected_type: AllowNil(::Hash), allow_empty: true do
33
+ merge Partials::IMAGE_LINKS
34
+ end
35
+ end
36
+ end
37
+
38
+ link :self
39
+ end
40
+ end
41
+ end
42
+
43
+ registrations :feedback_listing do
44
+ type_alias 'feedback-listing'
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'media_types'
4
+
5
+ module TrailerVote
6
+ module MediaTypes
7
+
8
+ ##
9
+ # Media Types for Fingerprints
10
+ #
11
+ # Clients **MUST** match the version of their audio fingerprinter and this media type version. This is a binary
12
+ # media type and returns a file or {Errors}.
13
+ #
14
+ class FingerprintBinary
15
+ include ::MediaTypes::Dsl
16
+
17
+ def self.base_format
18
+ 'application/vnd.trailervote.fingerprint.v%<version>s'
19
+ end
20
+
21
+ media_type 'fingerprint', defaults: { version: '~' }
22
+
23
+ class Current < FingerprintBinary
24
+ media_type 'fingerprint', defaults: { version: 'C' }
25
+
26
+ class << self
27
+ def register(version:, **___)
28
+ mime_type = FingerprintBinary.to_constructable.version(version).to_s
29
+
30
+ Array(
31
+ ::MediaTypes::Registerable.new(
32
+ mime_type,
33
+ symbol: :fingerprint_bin,
34
+ aliases: []
35
+ ).tap { |registerable| ::MediaTypes.register(registerable) }
36
+ )
37
+ end
38
+ end
39
+ end
40
+
41
+ class Deprecated < FingerprintBinary
42
+ def self.base_format
43
+ 'application/vnd.trailervote.fingerprint.deprecated'
44
+ end
45
+
46
+ media_type 'fingerprint.deprecated', defaults: { version: nil }
47
+
48
+ class << self
49
+
50
+ def register(versions:, **___)
51
+ aliases = versions.map do |version|
52
+ FingerprintBinary.to_constructable.version(version).to_s
53
+ end
54
+
55
+ Array(
56
+ ::MediaTypes::Registerable.new(
57
+ base_format,
58
+ symbol: :fingerprint_deprecated_bin,
59
+ aliases: aliases
60
+ ).tap { |registerable| ::MediaTypes.register(registerable) }
61
+ )
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './base_text'
4
+
5
+ module TrailerVote
6
+ module MediaTypes
7
+ class InteractivePlayer < BaseText
8
+ media_type 'interactive_player'
9
+
10
+ defaults do
11
+ suffix :json
12
+ version 1
13
+ end
14
+
15
+ validations do
16
+ version 1 do
17
+ attribute :interactive_player do
18
+ attribute :title, AllowNil(String)
19
+
20
+ link :self
21
+ link :advert
22
+ link :direct
23
+ link :product
24
+ end
25
+ end
26
+ end
27
+
28
+ registrations :interactive_player do
29
+ type_alias 'interactive-player'
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'media_types'
4
+
5
+ module TrailerVote
6
+ module MediaTypes
7
+ module Partials
8
+ IMAGE_LINKS = ::MediaTypes::Scheme.new do
9
+ link :self
10
+ link :original
11
+ link :thumbnail, optional: true
12
+ link :xlarge, optional: true
13
+ link :large, optional: true
14
+ link :medium, optional: true
15
+ link :small, optional: true
16
+ link :xsmall, optional: true
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './base_text'
4
+ require_relative './types/uuid_v4'
5
+
6
+ module TrailerVote
7
+ module MediaTypes
8
+
9
+ ##
10
+ # Media Types for Persona
11
+ #
12
+ # A Persona is a uniquely identified person / a unique device. When someone uses the SDK, the client MUST generate a
13
+ # UUID v4 and use that as Persona. This allows the API to link Feedback on Audio Fragments to a Persona, and MAY act
14
+ # as likes/dislikes (interests/disinterests).
15
+ #
16
+ class Persona < BaseText
17
+ media_type 'persona', defaults: { suffix: :json, version: 1 }
18
+
19
+ validations do
20
+ version 1 do
21
+ attribute :persona do
22
+ attribute :id, Types::UuidV4
23
+ link :self
24
+ link :feedback
25
+ end
26
+
27
+ view('create') {}
28
+ end
29
+ end
30
+
31
+ registrations :persona do
32
+ view 'create', :create_persona
33
+
34
+ versions 1
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,105 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './base_text'
4
+ require_relative './types/uuid_v4'
5
+
6
+ module TrailerVote
7
+ module MediaTypes
8
+
9
+ ##
10
+ # Media Types for places
11
+ #
12
+ # Each set of credentials has a Place associated to it. A place might be the HQ of an enterprise, or a physical
13
+ # location on the map. You can always access all the data of your place and all the children, as the places in our
14
+ # system are configured to be a tree.
15
+ #
16
+ class Place < BaseText
17
+ media_type 'place', defaults: { suffix: :json, version: 2 }
18
+
19
+ validations do
20
+ index_scheme = ::MediaTypes::Scheme.new do
21
+ attribute :places do
22
+ collection :_index, allow_empty: true do
23
+ attribute :href, String
24
+ not_strict
25
+ end
26
+
27
+ not_strict
28
+ end
29
+ end
30
+
31
+ version 2 do
32
+ version_2_base = ::MediaTypes::Scheme.new do
33
+ attribute :name, String
34
+ attribute :parent_place, AllowNil(Types::UuidV4)
35
+ attribute :deleted_at, AllowNil(String)
36
+ attribute :updated_at, String
37
+
38
+ link :self
39
+ link :products_archive
40
+ link :parent, allow_nil: true
41
+ end
42
+
43
+ attribute :place do
44
+ merge version_2_base
45
+ end
46
+
47
+ view 'create' do
48
+ attribute :place do
49
+ attribute :name, String
50
+ attribute :parent_place, String
51
+ attribute :deleted_at, AllowNil(String)
52
+ end
53
+ end
54
+
55
+ view 'collection' do
56
+ attribute :places do
57
+ collection :_embedded, version_2_base
58
+ not_strict
59
+ end
60
+ end
61
+
62
+ view 'index' do
63
+ merge index_scheme
64
+ end
65
+ end
66
+
67
+ version 1 do
68
+ version_1_base = ::MediaTypes::Scheme.new do
69
+ attribute :name, String
70
+ attribute :parent_place, AllowNil(String)
71
+ attribute :deleted_at, AllowNil(String)
72
+ attribute :updated_at, String
73
+
74
+ link :self
75
+ link :products
76
+ link :parent, allow_nil: true
77
+ end
78
+
79
+ attribute :place do
80
+ merge version_1_base
81
+ end
82
+
83
+ view 'collection' do
84
+ attribute :places do
85
+ collection :_embedded, version_1_base
86
+ not_strict
87
+ end
88
+ end
89
+
90
+ view 'index' do
91
+ merge index_scheme
92
+ end
93
+ end
94
+ end
95
+
96
+ registrations :place do
97
+ view 'create', :create_place
98
+ view 'index', :place_urls
99
+ view 'collection', :places
100
+
101
+ versions 1, 2
102
+ end
103
+ end
104
+ end
105
+ end