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,63 +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
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
@@ -1,55 +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
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
@@ -1,38 +1,38 @@
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
37
-
38
- TrailerVote::MediaTypes::ProductImage.register
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
37
+
38
+ TrailerVote::MediaTypes::ProductImage.register
@@ -1,83 +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
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