trailer_vote-api 3.1.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 (49) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.rubocop.yml +29 -0
  4. data/CHANGELOG.md +56 -0
  5. data/Gemfile +6 -0
  6. data/Gemfile.lock +77 -0
  7. data/README.md +188 -0
  8. data/Rakefile +12 -0
  9. data/bin/console +15 -0
  10. data/bin/setup +8 -0
  11. data/lib/trailer_vote/api.rb +67 -0
  12. data/lib/trailer_vote/api/autoload.rb +28 -0
  13. data/lib/trailer_vote/api/composable/common.rb +91 -0
  14. data/lib/trailer_vote/api/composable/get.rb +66 -0
  15. data/lib/trailer_vote/api/configuration.rb +69 -0
  16. data/lib/trailer_vote/api/errors.rb +113 -0
  17. data/lib/trailer_vote/api/fallback_content_types.rb +50 -0
  18. data/lib/trailer_vote/api/issue.rb +29 -0
  19. data/lib/trailer_vote/api/issue/create.rb +72 -0
  20. data/lib/trailer_vote/api/issue/find.rb +42 -0
  21. data/lib/trailer_vote/api/links.rb +54 -0
  22. data/lib/trailer_vote/api/place.rb +22 -0
  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 -0
  26. data/lib/trailer_vote/api/place/find.rb +60 -0
  27. data/lib/trailer_vote/api/place/lookup.rb +72 -0
  28. data/lib/trailer_vote/api/product.rb +31 -0
  29. data/lib/trailer_vote/api/product/create.rb +63 -0
  30. data/lib/trailer_vote/api/product/find.rb +55 -0
  31. data/lib/trailer_vote/api/product/image.rb +36 -0
  32. data/lib/trailer_vote/api/product/image/create.rb +83 -0
  33. data/lib/trailer_vote/api/product/image/find.rb +54 -0
  34. data/lib/trailer_vote/api/product/image/urls.rb +66 -0
  35. data/lib/trailer_vote/api/product/lookup.rb +95 -0
  36. data/lib/trailer_vote/api/product/place.rb +38 -0
  37. data/lib/trailer_vote/api/product/place/link.rb +75 -0
  38. data/lib/trailer_vote/api/product/update.rb +80 -0
  39. data/lib/trailer_vote/api/product/video.rb +36 -0
  40. data/lib/trailer_vote/api/product/video/create.rb +80 -0
  41. data/lib/trailer_vote/api/product/video/find.rb +56 -0
  42. data/lib/trailer_vote/api/product/video/urls.rb +66 -0
  43. data/lib/trailer_vote/api/push_recipe_android.rb +37 -0
  44. data/lib/trailer_vote/api/push_recipe_ios.rb +37 -0
  45. data/lib/trailer_vote/api/type_registry.rb +95 -0
  46. data/lib/trailer_vote/api/version.rb +7 -0
  47. data/lib/trailer_vote/api/vista_config.rb +37 -0
  48. data/trailer_vote-api.gemspec +45 -0
  49. metadata +261 -0
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'trailer_vote/media_types'
4
+ require 'trailer_vote/api/configuration'
5
+
6
+ module TrailerVote
7
+ module Api
8
+ class Configuration
9
+ # @return [TrailerVote::Api::Product] api to deal with products
10
+ def product
11
+ Product.new(configuration: self)
12
+ end
13
+
14
+ alias products product
15
+ end
16
+
17
+ class Product
18
+ def initialize(configuration:)
19
+ self.configuration = configuration
20
+ end
21
+
22
+ def back
23
+ configuration
24
+ end
25
+
26
+ private
27
+
28
+ attr_accessor :configuration
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'trailer_vote/api/composable/common'
4
+
5
+ require 'trailer_vote/api/product'
6
+ require 'trailer_vote/api/product/find'
7
+
8
+ module TrailerVote
9
+ module Api
10
+ class Product
11
+ # @return [TrailerVote::Api::Product::Create] api to create a new product
12
+ def create
13
+ Create.new(configuration: configuration)
14
+ end
15
+
16
+ class Create
17
+ include Composable::Common
18
+
19
+ CONTENT = MediaTypes::Product.to_constructable.version(2).view('create')
20
+ SUCCESS = MediaTypes::Product.to_constructable.version(2)
21
+ FAILURE = MediaTypes::Errors.to_constructable.version(1)
22
+
23
+ ACCEPT = [SUCCESS.to_s, FAILURE.to_s(0.1)].join(', ').freeze
24
+
25
+ def initialize(configuration:)
26
+ self.configuration = configuration
27
+ end
28
+
29
+ # @return [TrailerVote::Api::Product] api to deal with products
30
+ def back
31
+ configuration.product
32
+ end
33
+
34
+ def call(data:, url: resolve_url)
35
+ body = encode(data)
36
+ guard_network_errors do
37
+ branch(
38
+ resolve_client.headers(
39
+ Headers::ACCEPT => ACCEPT,
40
+ Headers::CONTENT_TYPE => "#{CONTENT}; charset=#{body.encoding.name}"
41
+ ).post(url, body: body),
42
+ data: data
43
+ )
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ def resolve_url
50
+ configuration.links.products
51
+ end
52
+
53
+ def encode(data)
54
+ TrailerVote::Api.encode(CONTENT, product: data)
55
+ end
56
+
57
+ def redirect_klazz
58
+ Find
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'trailer_vote/api/composable/get'
4
+ require 'trailer_vote/api/product'
5
+
6
+ module TrailerVote
7
+ module Api
8
+ class Product
9
+ # @param [TrailerVote::Api::Product::Find,
10
+ # TrailerVote::Api::Product::Create,
11
+ # TrailerVote::Api::Product::Update,
12
+ # TrailerVote::Api::Product::Lookup,
13
+ # NilClass] result the found product
14
+ # @return [TrailerVote::Api::Product::Find] api to deal with a found product
15
+ def find(result: nil)
16
+ Find.new(configuration: configuration, result: result)
17
+ end
18
+
19
+ class Find
20
+ include Composable::Get
21
+
22
+ SUCCESS = MediaTypes::Product.to_constructable.version(2)
23
+ FAILURE = MediaTypes::Errors.to_constructable.version(1)
24
+ ACCEPT = [SUCCESS.to_s, FAILURE.to_s(0.1)].join(', ').freeze
25
+
26
+ def initialize(configuration:, result: nil)
27
+ self.configuration = configuration
28
+ self.result = result
29
+ end
30
+
31
+ # @return [TrailerVote::Api::Product::Find,
32
+ # TrailerVote::Api::Product::Create,
33
+ # TrailerVote::Api::Product::Update,
34
+ # TrailerVote::Api::Product::Lookup,
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, data: nil)
43
+ return self if ok? || !url
44
+ guard_network_errors do
45
+ branch(resolve_client.headers(Headers::ACCEPT => ACCEPT).get(url), data: data)
46
+ end
47
+ end
48
+
49
+ def data
50
+ to_h[:product]
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'trailer_vote/api/product'
4
+ require 'trailer_vote/api/product/find'
5
+
6
+ module TrailerVote
7
+ module Api
8
+ class Product
9
+ class Find
10
+ # @return [TrailerVote::Api::Product::Image] api to deal with a product's images
11
+ def image
12
+ Image.new(configuration: configuration, product: self)
13
+ end
14
+
15
+ alias product_image image
16
+ alias images image
17
+ end
18
+
19
+ class Image
20
+ def initialize(configuration:, product: nil)
21
+ self.configuration = configuration
22
+ self.product = product
23
+ end
24
+
25
+ # @return [TrailerVote::Api::Product::Find] api to deal with a found product
26
+ def back
27
+ product
28
+ end
29
+
30
+ private
31
+
32
+ attr_accessor :configuration, :product
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'trailer_vote/api/composable/common'
4
+
5
+ require 'trailer_vote/api/product/image'
6
+ require 'trailer_vote/api/product/image/find'
7
+
8
+ module TrailerVote
9
+ module Api
10
+ class Product
11
+ class Image
12
+
13
+ # @return [TrailerVote::Api::Product::Image::Create] the api to create an image for the current +product+
14
+ def create
15
+ Create.new(configuration: configuration, product: product)
16
+ end
17
+
18
+ class Create
19
+ include Composable::Common
20
+
21
+ CONTENT = MediaTypes::ProductImage.to_constructable.version(1).view('create')
22
+ SUCCESS = MediaTypes::ProductImage.to_constructable.version(1)
23
+ FAILURE = MediaTypes::Errors.to_constructable.version(1)
24
+
25
+ ACCEPT = [SUCCESS.to_s, FAILURE.to_s(0.1)].join(', ').freeze
26
+
27
+ def initialize(configuration:, product:)
28
+ self.configuration = configuration
29
+ self.product = product
30
+ end
31
+
32
+ # @return [TrailerVote::Api::Product::Image] the api to deal with the current +product+ images
33
+ def back
34
+ product.image
35
+ end
36
+
37
+ # Create the image
38
+ #
39
+ # @see https://www.rubydoc.info/gems/trailer_vote-media_types/TrailerVote/MediaTypes/ProductImage TrailerVote::MediaTypes::ProductImage
40
+ #
41
+ # @param [String] url (#resolve_url result) the url to post to
42
+ # @param [Hash] data the image data
43
+ #
44
+ # @return [TrailerVote::Api::Product::Image::Find]
45
+ def call(data:, url: resolve_url)
46
+ body = encode(data)
47
+ guard_network_errors do
48
+ branch(
49
+ resolve_client.headers(
50
+ Headers::ACCEPT => ACCEPT,
51
+ Headers::CONTENT_TYPE => "#{CONTENT}; charset=#{body.encoding.name}"
52
+ ).post(url, body: body),
53
+ data: data
54
+ )
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ attr_accessor :product
61
+
62
+ def resolve_url
63
+ product.links.images
64
+ end
65
+
66
+ def encode(data)
67
+ TrailerVote::Api.encode(CONTENT, product_image: data)
68
+ end
69
+
70
+ def forward(result, data:)
71
+ return unless [307, 308].include?(result.status)
72
+ forward_klazz.new(configuration: configuration, product: product)
73
+ .call(data: data, url: redirected_url(result))
74
+ end
75
+
76
+ def redirect_klazz
77
+ Find
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'trailer_vote/api/composable/get'
4
+ require 'trailer_vote/api/product/image'
5
+
6
+ module TrailerVote
7
+ module Api
8
+ class Product
9
+ class Image
10
+
11
+ # @param [TrailerVote::Api::Product::Image::Find,
12
+ # TrailerVote::Api::Product::Image::Create,
13
+ # TrailerVote::Api::Product::Image::Urls::Traverse,
14
+ # NilClass] result the found image, or nil
15
+ # @return [TrailerVote::Api::Product::Image::Find] the api to deal with the found image
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::ProductImage.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::Image::Create,
34
+ # TrailerVote::Api::Product::Image::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
+ branch(resolve_client.headers(Headers::ACCEPT => ACCEPT).get(url))
45
+ end
46
+
47
+ def data
48
+ to_h[:product_image]
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'trailer_vote/api/composable/get'
4
+ require 'trailer_vote/api/product/image'
5
+
6
+ module TrailerVote
7
+ module Api
8
+ class Product
9
+ class Image
10
+
11
+ # @return [TrailerVote::Api::Product::Image::Urls] the api to get the image 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::ProductImage.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::Image] the api to deal with a product's images
31
+ def back
32
+ product.image
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_images]
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.images
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
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'trailer_vote/api/composable/common'
4
+
5
+ require 'trailer_vote/api/product'
6
+ require 'trailer_vote/api/product/find'
7
+
8
+ module TrailerVote
9
+ module Api
10
+
11
+ class Configuration
12
+ # @return [TrailerVote::Api::Product::Lookup] api to deal with looking up a product
13
+ def product_lookup
14
+ product.lookup
15
+ end
16
+ end
17
+
18
+ class Product
19
+
20
+ # @return [TrailerVote::Api::Product::Lookup] api to deal with looking up a product
21
+ def lookup
22
+ Lookup.new(configuration: configuration)
23
+ end
24
+
25
+ ##
26
+ # Looks up a product by a set of authority and identifiers in +lookups+
27
+ #
28
+ # @example lookup a product by imdb or tmdb authority
29
+ #
30
+ # lookups = [
31
+ # { authority: 'imdb', identifier: 'tt1825683'},
32
+ # { authority: 'tmdb', identifier: '284054' }
33
+ # ]
34
+ # result = TrailerVote::Api.configure(...).product.lookup.call(data: lookups)
35
+ # result.product
36
+ # # => { "title": "" }
37
+ #
38
+ # @example try to lookup multiple products at the same time
39
+ #
40
+ # lookups = [
41
+ # { authority: 'imdb', identifier: 'tt1825683'},
42
+ # { authority: 'isbn', identifier: '978-1-59448-194-9' }
43
+ # ]
44
+ # result = TrailerVote::Api.configure(...).product.lookup.call(data: lookups)
45
+ # result.errors
46
+ # # => [{ "message": "Found multiple products for the given identifiers, only one result ..." }]
47
+ #
48
+ class Lookup
49
+ include Composable::Common
50
+
51
+ CONTENT = MediaTypes::ProductLookup.to_constructable.version(1)
52
+ SUCCESS = MediaTypes::Product.to_constructable.version(2)
53
+ FAILURE = MediaTypes::Errors.to_constructable.version(1)
54
+
55
+ ACCEPT = [SUCCESS.to_s, FAILURE.to_s(0.1)].join(', ').freeze
56
+
57
+ def initialize(configuration:)
58
+ self.configuration = configuration
59
+ end
60
+
61
+ # @return [TrailerVote::Api::Product] api to deal with products
62
+ def back
63
+ configuration.product
64
+ end
65
+
66
+ def call(data:, url: resolve_url)
67
+ body = encode(data)
68
+ guard_network_errors do
69
+ branch(
70
+ resolve_client.headers(
71
+ Headers::ACCEPT => ACCEPT,
72
+ Headers::CONTENT_TYPE => "#{CONTENT}; charset=#{body.encoding.name}"
73
+ ).post(url, body: body),
74
+ data: data
75
+ )
76
+ end
77
+ end
78
+
79
+ private
80
+
81
+ def resolve_url
82
+ configuration.links.product_lookup
83
+ end
84
+
85
+ def encode(data)
86
+ TrailerVote::Api.encode(CONTENT, product_identifiers: data)
87
+ end
88
+
89
+ def redirect_klazz
90
+ Find
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end