trailer_vote-api 0.8.4 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
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,54 +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
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
@@ -1,66 +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
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
@@ -1,97 +1,97 @@
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
96
-
97
- TrailerVote::MediaTypes::ProductLookup.register
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
96
+
97
+ TrailerVote::MediaTypes::ProductLookup.register
@@ -1,40 +1,40 @@
1
- # frozen_string_literal: true
2
-
3
- require 'trailer_vote/media_types'
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
- class Find
12
- # @return [TrailerVote::Api::Place] api to deal with a product's places
13
- def place
14
- Place.new(configuration: configuration, product: self)
15
- end
16
-
17
- alias product_place place
18
- alias places place
19
- end
20
-
21
- class Place
22
- def initialize(configuration:, product: nil)
23
- self.configuration = configuration
24
- self.product = product
25
- end
26
-
27
- # @return [TrailerVote::Api::Place::Find] api to deal with a found product
28
- def back
29
- product
30
- end
31
-
32
- private
33
-
34
- attr_accessor :configuration, :product
35
- end
36
- end
37
- end
38
- end
39
-
40
- TrailerVote::MediaTypes::ProductPlaceLink.register
1
+ # frozen_string_literal: true
2
+
3
+ require 'trailer_vote/media_types'
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
+ class Find
12
+ # @return [TrailerVote::Api::Place] api to deal with a product's places
13
+ def place
14
+ Place.new(configuration: configuration, product: self)
15
+ end
16
+
17
+ alias product_place place
18
+ alias places place
19
+ end
20
+
21
+ class Place
22
+ def initialize(configuration:, product: nil)
23
+ self.configuration = configuration
24
+ self.product = product
25
+ end
26
+
27
+ # @return [TrailerVote::Api::Place::Find] api to deal with a found product
28
+ def back
29
+ product
30
+ end
31
+
32
+ private
33
+
34
+ attr_accessor :configuration, :product
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ TrailerVote::MediaTypes::ProductPlaceLink.register