trailer_vote-api 0.8.4 → 0.9.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 (45) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +13 -13
  3. data/.rubocop.yml +29 -29
  4. data/CHANGELOG.md +56 -56
  5. data/Gemfile +6 -6
  6. data/Gemfile.lock +10 -11
  7. data/README.md +188 -188
  8. data/Rakefile +12 -12
  9. data/bin/console +15 -15
  10. data/bin/setup +8 -8
  11. data/lib/trailer_vote/api.rb +43 -43
  12. data/lib/trailer_vote/api/autoload.rb +24 -22
  13. data/lib/trailer_vote/api/composable/common.rb +91 -91
  14. data/lib/trailer_vote/api/composable/get.rb +66 -66
  15. data/lib/trailer_vote/api/configuration.rb +71 -71
  16. data/lib/trailer_vote/api/errors.rb +115 -115
  17. data/lib/trailer_vote/api/fallback_content_types.rb +50 -50
  18. data/lib/trailer_vote/api/issue.rb +31 -31
  19. data/lib/trailer_vote/api/issue/create.rb +72 -72
  20. data/lib/trailer_vote/api/issue/find.rb +42 -42
  21. data/lib/trailer_vote/api/links.rb +54 -54
  22. data/lib/trailer_vote/api/place.rb +24 -24
  23. data/lib/trailer_vote/api/place/children.rb +33 -0
  24. data/lib/trailer_vote/api/place/children/urls.rb +67 -0
  25. data/lib/trailer_vote/api/place/create.rb +83 -83
  26. data/lib/trailer_vote/api/place/find.rb +60 -59
  27. data/lib/trailer_vote/api/product.rb +33 -33
  28. data/lib/trailer_vote/api/product/create.rb +63 -63
  29. data/lib/trailer_vote/api/product/find.rb +55 -55
  30. data/lib/trailer_vote/api/product/image.rb +38 -38
  31. data/lib/trailer_vote/api/product/image/create.rb +83 -83
  32. data/lib/trailer_vote/api/product/image/find.rb +54 -54
  33. data/lib/trailer_vote/api/product/image/urls.rb +66 -66
  34. data/lib/trailer_vote/api/product/lookup.rb +97 -97
  35. data/lib/trailer_vote/api/product/place.rb +40 -40
  36. data/lib/trailer_vote/api/product/place/link.rb +75 -75
  37. data/lib/trailer_vote/api/product/update.rb +80 -80
  38. data/lib/trailer_vote/api/product/video.rb +38 -38
  39. data/lib/trailer_vote/api/product/video/create.rb +80 -80
  40. data/lib/trailer_vote/api/product/video/find.rb +56 -56
  41. data/lib/trailer_vote/api/product/video/urls.rb +66 -66
  42. data/lib/trailer_vote/api/type_registry.rb +99 -99
  43. data/lib/trailer_vote/api/version.rb +7 -7
  44. data/trailer_vote-api.gemspec +45 -45
  45. metadata +7 -6
@@ -1,56 +1,56 @@
1
- # frozen_string_literal: true
2
-
3
- require 'trailer_vote/api/composable/get'
4
- require 'trailer_vote/api/product/video'
5
-
6
- module TrailerVote
7
- module Api
8
- class Product
9
- class Video
10
-
11
- # @param [TrailerVote::Api::Product::Video::Find,
12
- # TrailerVote::Api::Product::Video::Create,
13
- # TrailerVote::Api::Product::Video::Urls::Traverse,
14
- # NilClass] result the found video, or nil
15
- # @return [TrailerVote::Api::Product::Video::Find] the api to deal with the found video
16
- def find(result: nil)
17
- Find.new(configuration: configuration, result: result)
18
- end
19
-
20
- class Find
21
- include Composable::Get
22
-
23
- SUCCESS = MediaTypes::ProductVideo.to_constructable.version(1)
24
- FAILURE = MediaTypes::Errors.to_constructable.version(1)
25
-
26
- ACCEPT = [SUCCESS.to_s, FAILURE.to_s(0.1)].join(', ').freeze
27
-
28
- def initialize(configuration:, result: nil)
29
- self.configuration = configuration
30
- self.result = result
31
- end
32
-
33
- # @return [TrailerVote::Api::Product::Video::Create,
34
- # TrailerVote::Api::Product::Video::Urls::Traverse,
35
- # NilClass] return the api that yielded this
36
- def back
37
- backtrack = result
38
- backtrack = result.back while backtrack&.is_a?(self.class)
39
- backtrack
40
- end
41
-
42
- def call(url: nil)
43
- return self if ok? || !url
44
- guard_network_errors do
45
- branch(resolve_client.headers(Headers::ACCEPT => ACCEPT).get(url))
46
- end
47
- end
48
-
49
- def data
50
- to_h[:product_video]
51
- end
52
- end
53
- end
54
- end
55
- end
56
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'trailer_vote/api/composable/get'
4
+ require 'trailer_vote/api/product/video'
5
+
6
+ module TrailerVote
7
+ module Api
8
+ class Product
9
+ class Video
10
+
11
+ # @param [TrailerVote::Api::Product::Video::Find,
12
+ # TrailerVote::Api::Product::Video::Create,
13
+ # TrailerVote::Api::Product::Video::Urls::Traverse,
14
+ # NilClass] result the found video, or nil
15
+ # @return [TrailerVote::Api::Product::Video::Find] the api to deal with the found video
16
+ def find(result: nil)
17
+ Find.new(configuration: configuration, result: result)
18
+ end
19
+
20
+ class Find
21
+ include Composable::Get
22
+
23
+ SUCCESS = MediaTypes::ProductVideo.to_constructable.version(1)
24
+ FAILURE = MediaTypes::Errors.to_constructable.version(1)
25
+
26
+ ACCEPT = [SUCCESS.to_s, FAILURE.to_s(0.1)].join(', ').freeze
27
+
28
+ def initialize(configuration:, result: nil)
29
+ self.configuration = configuration
30
+ self.result = result
31
+ end
32
+
33
+ # @return [TrailerVote::Api::Product::Video::Create,
34
+ # TrailerVote::Api::Product::Video::Urls::Traverse,
35
+ # NilClass] return the api that yielded this
36
+ def back
37
+ backtrack = result
38
+ backtrack = result.back while backtrack&.is_a?(self.class)
39
+ backtrack
40
+ end
41
+
42
+ def call(url: nil)
43
+ return self if ok? || !url
44
+ guard_network_errors do
45
+ branch(resolve_client.headers(Headers::ACCEPT => ACCEPT).get(url))
46
+ end
47
+ end
48
+
49
+ def data
50
+ to_h[:product_video]
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -1,66 +1,66 @@
1
- # frozen_string_literal: true
2
-
3
- require 'trailer_vote/api/composable/get'
4
- require 'trailer_vote/api/product/video'
5
-
6
- module TrailerVote
7
- module Api
8
- class Product
9
- class Video
10
-
11
- # @return [TrailerVote::Api::Product::Video::Urls] the api to get the video urls for the current product
12
- def urls
13
- Urls.new(configuration: configuration, product: product)
14
- end
15
-
16
- class Urls
17
- include Composable::Get
18
-
19
- SUCCESS = MediaTypes::ProductVideo.to_constructable.version(1).view('index')
20
- FAILURE = MediaTypes::Errors.to_constructable.version(1)
21
-
22
- ACCEPT = [SUCCESS.to_s, FAILURE.to_s(0.1)].join(', ').freeze
23
-
24
- def initialize(configuration:, product:, result: nil)
25
- self.configuration = configuration
26
- self.product = product
27
- self.result = result
28
- end
29
-
30
- # @return [TrailerVote::Api::Product::Video] the api to deal with a product's videos
31
- def back
32
- product.video
33
- end
34
-
35
- def call(url: resolve_url)
36
- return self if ok? || !url
37
- guard_network_errors do
38
- branch(resolve_client.headers(Headers::ACCEPT => ACCEPT).get(url))
39
- end
40
- end
41
-
42
- def data
43
- to_h[:product_videos]
44
- end
45
-
46
- private
47
-
48
- attr_accessor :product
49
-
50
- def ok?
51
- result&.status&.ok?
52
- end
53
-
54
- def resolve_url
55
- product.links.videos
56
- end
57
-
58
- def redirect(result)
59
- redirect_klazz.new(configuration: configuration, product: product, result: result)
60
- .call(url: redirected_url(result))
61
- end
62
- end
63
- end
64
- end
65
- end
66
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'trailer_vote/api/composable/get'
4
+ require 'trailer_vote/api/product/video'
5
+
6
+ module TrailerVote
7
+ module Api
8
+ class Product
9
+ class Video
10
+
11
+ # @return [TrailerVote::Api::Product::Video::Urls] the api to get the video urls for the current product
12
+ def urls
13
+ Urls.new(configuration: configuration, product: product)
14
+ end
15
+
16
+ class Urls
17
+ include Composable::Get
18
+
19
+ SUCCESS = MediaTypes::ProductVideo.to_constructable.version(1).view('index')
20
+ FAILURE = MediaTypes::Errors.to_constructable.version(1)
21
+
22
+ ACCEPT = [SUCCESS.to_s, FAILURE.to_s(0.1)].join(', ').freeze
23
+
24
+ def initialize(configuration:, product:, result: nil)
25
+ self.configuration = configuration
26
+ self.product = product
27
+ self.result = result
28
+ end
29
+
30
+ # @return [TrailerVote::Api::Product::Video] the api to deal with a product's videos
31
+ def back
32
+ product.video
33
+ end
34
+
35
+ def call(url: resolve_url)
36
+ return self if ok? || !url
37
+ guard_network_errors do
38
+ branch(resolve_client.headers(Headers::ACCEPT => ACCEPT).get(url))
39
+ end
40
+ end
41
+
42
+ def data
43
+ to_h[:product_videos]
44
+ end
45
+
46
+ private
47
+
48
+ attr_accessor :product
49
+
50
+ def ok?
51
+ result&.status&.ok?
52
+ end
53
+
54
+ def resolve_url
55
+ product.links.videos
56
+ end
57
+
58
+ def redirect(result)
59
+ redirect_klazz.new(configuration: configuration, product: product, result: result)
60
+ .call(url: redirected_url(result))
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -1,99 +1,99 @@
1
- # frozen_string_literal: true
2
-
3
- require 'oj'
4
- require 'media_types'
5
- require 'trailer_vote/media_types'
6
-
7
- module TrailerVote
8
- module Api
9
-
10
- module TypeRegistry
11
- class << self
12
- attr_accessor :registry, :registry_shortcuts
13
- end
14
-
15
- self.registry = {}
16
- self.registry_shortcuts = {}
17
-
18
- module_function
19
-
20
- def [](key)
21
- registry.fetch(key) { registry.fetch(registry_shortcuts.fetch(key)) }
22
- rescue KeyError
23
- raise UnknownMediaType, format('Unknown media type %<type>s', type: key)
24
- end
25
-
26
- def []=(key, value)
27
- registry[key] = value
28
- end
29
-
30
- def shortcut(key, alias_name)
31
- registry_shortcuts[alias_name] = key
32
- end
33
-
34
- def register(registerable)
35
- mime_type = registerable.to_s
36
-
37
- self[mime_type] = AdapterFor(registerable.media_type)
38
- shortcut(mime_type, registerable.to_sym)
39
-
40
- registerable.aliases.each do |alias_mime_type|
41
- shortcut(mime_type, alias_mime_type)
42
- end
43
- end
44
-
45
- class << self
46
- private
47
-
48
- # noinspection RubyClassMethodNamingConvention
49
- def AdapterFor(media_type) # rubocop:disable Naming/MethodName
50
- adapter_name = generate_adapter_name(media_type)
51
-
52
- if const_defined?(adapter_name)
53
- return const_get(adapter_name)
54
- end
55
-
56
- const_set(adapter_name, Module.new).tap do |adapter|
57
- define_encode(adapter, media_type)
58
- define_decode(adapter, media_type)
59
- end
60
- end
61
-
62
- def generate_adapter_name(media_type)
63
- media_type.split(%r{[./_+-]}).map(&:capitalize).join('').tr('^A-z0-9', '_')
64
- end
65
-
66
- def define_encode(adapter, media_type)
67
- adapter.define_singleton_method(:encode) do |obj|
68
- begin
69
- media_type.validate!(obj)
70
- Oj.dump(obj, mode: :compat)
71
- rescue Oj::Error, ::MediaTypes::Scheme::ValidationError => err
72
- raise EncodeError.new(media_type: media_type, source: err)
73
- end
74
- end
75
- end
76
-
77
- def define_decode(adapter, media_type)
78
- adapter.define_singleton_method('decode') do |str|
79
- begin
80
- Oj.load(str, mode: :strict, symbol_keys: true).tap do |result|
81
- begin
82
- media_type.validate!(result)
83
- rescue ::MediaTypes::Scheme::ValidationError => err
84
- warn format('Decode error! API might now be in an invalid or incomplete state. %<err>s', err: err)
85
- end
86
- end
87
- rescue Oj::Error => err
88
- raise DecodeError.new(media_type: media_type, source: err)
89
- end
90
- end
91
- end
92
- end
93
- end
94
- end
95
- end
96
-
97
- module MediaTypes
98
- integrate TrailerVote::Api::TypeRegistry
99
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'oj'
4
+ require 'media_types'
5
+ require 'trailer_vote/media_types'
6
+
7
+ module TrailerVote
8
+ module Api
9
+
10
+ module TypeRegistry
11
+ class << self
12
+ attr_accessor :registry, :registry_shortcuts
13
+ end
14
+
15
+ self.registry = {}
16
+ self.registry_shortcuts = {}
17
+
18
+ module_function
19
+
20
+ def [](key)
21
+ registry.fetch(key) { registry.fetch(registry_shortcuts.fetch(key)) }
22
+ rescue KeyError
23
+ raise UnknownMediaType, format('Unknown media type %<type>s', type: key)
24
+ end
25
+
26
+ def []=(key, value)
27
+ registry[key] = value
28
+ end
29
+
30
+ def shortcut(key, alias_name)
31
+ registry_shortcuts[alias_name] = key
32
+ end
33
+
34
+ def register(registerable)
35
+ mime_type = registerable.to_s
36
+
37
+ self[mime_type] = AdapterFor(registerable.media_type)
38
+ shortcut(mime_type, registerable.to_sym)
39
+
40
+ registerable.aliases.each do |alias_mime_type|
41
+ shortcut(mime_type, alias_mime_type)
42
+ end
43
+ end
44
+
45
+ class << self
46
+ private
47
+
48
+ # noinspection RubyClassMethodNamingConvention
49
+ def AdapterFor(media_type) # rubocop:disable Naming/MethodName
50
+ adapter_name = generate_adapter_name(media_type)
51
+
52
+ if const_defined?(adapter_name)
53
+ return const_get(adapter_name)
54
+ end
55
+
56
+ const_set(adapter_name, Module.new).tap do |adapter|
57
+ define_encode(adapter, media_type)
58
+ define_decode(adapter, media_type)
59
+ end
60
+ end
61
+
62
+ def generate_adapter_name(media_type)
63
+ media_type.split(%r{[./_+-]}).map(&:capitalize).join('').tr('^A-z0-9', '_')
64
+ end
65
+
66
+ def define_encode(adapter, media_type)
67
+ adapter.define_singleton_method(:encode) do |obj|
68
+ begin
69
+ media_type.validate!(obj)
70
+ Oj.dump(obj, mode: :compat)
71
+ rescue Oj::Error, ::MediaTypes::Scheme::ValidationError => err
72
+ raise EncodeError.new(media_type: media_type, source: err)
73
+ end
74
+ end
75
+ end
76
+
77
+ def define_decode(adapter, media_type)
78
+ adapter.define_singleton_method('decode') do |str|
79
+ begin
80
+ Oj.load(str, mode: :strict, symbol_keys: true).tap do |result|
81
+ begin
82
+ media_type.validate!(result)
83
+ rescue ::MediaTypes::Scheme::ValidationError => err
84
+ warn format('Decode error! API might now be in an invalid or incomplete state. %<err>s', err: err)
85
+ end
86
+ end
87
+ rescue Oj::Error => err
88
+ raise DecodeError.new(media_type: media_type, source: err)
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
96
+
97
+ module MediaTypes
98
+ integrate TrailerVote::Api::TypeRegistry
99
+ end
@@ -1,7 +1,7 @@
1
- # frozen_string_literal: true
2
-
3
- module TrailerVote
4
- module Api
5
- VERSION = '0.8.4'
6
- end
7
- end
1
+ # frozen_string_literal: true
2
+
3
+ module TrailerVote
4
+ module Api
5
+ VERSION = '0.9.0'
6
+ end
7
+ end