trailer_vote-api 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
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,38 @@
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
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'trailer_vote/api/composable/common'
4
+
5
+ require 'trailer_vote/api/product/place'
6
+ require 'trailer_vote/api/place/find'
7
+
8
+ module TrailerVote
9
+ module Api
10
+ class Product
11
+ class Place
12
+
13
+ # @return [TrailerVote::Api::Product::Place::Link] api to link a place to the current +product+
14
+ def link
15
+ Link.new(configuration: configuration, product: product)
16
+ end
17
+
18
+ class Link
19
+ include Composable::Common
20
+
21
+ CONTENT = MediaTypes::ProductPlaceLink.to_constructable.version(1).view('create')
22
+ SUCCESS = MediaTypes::ProductPlaceLink.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::Place] the api to deal with the product places
33
+ def back
34
+ product.place
35
+ end
36
+
37
+ def call(data:, url: resolve_url)
38
+ body = encode(data)
39
+ guard_network_errors do
40
+ branch(
41
+ resolve_client.headers(
42
+ Headers::ACCEPT => ACCEPT,
43
+ Headers::CONTENT_TYPE => "#{CONTENT}; charset=#{body.encoding.name}"
44
+ ).post(url, body: body),
45
+ data: data
46
+ )
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ attr_accessor :product
53
+
54
+ def resolve_url
55
+ product.links.places
56
+ end
57
+
58
+ def encode(data)
59
+ TrailerVote::Api.encode(CONTENT, data.is_a?(::Hash) ? data : { place: data })
60
+ end
61
+
62
+ def forward(result, data:)
63
+ return unless [307, 308].include?(result.status)
64
+ forward_klazz.new(configuration: configuration, product: product)
65
+ .call(data: data, url: redirected_url(result))
66
+ end
67
+
68
+ def redirect_klazz
69
+ TrailerVote::Api::Place::Find
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,80 @@
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
+ class Find
12
+ # @return [TrailerVote::Api::Product::Update] api to deal with a updating a found product
13
+ def update
14
+ Update.new(configuration: configuration, product: self)
15
+ end
16
+ end
17
+
18
+ class Update
19
+ include Composable::Common
20
+
21
+ CONTENT = MediaTypes::Product.to_constructable.version(2)
22
+ SUCCESS = MediaTypes::Product.to_constructable.version(2)
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::Find] api to deal with a found product
33
+ def back
34
+ product
35
+ end
36
+
37
+ def call(data:, url: resolve_url, etag: resolve_etag)
38
+ body = encode(data)
39
+ guard_network_errors do
40
+ branch(
41
+ resolve_client.headers(
42
+ Headers::ACCEPT => ACCEPT,
43
+ Headers::CONTENT_TYPE => "#{CONTENT}; charset=#{body.encoding.name}",
44
+ Headers::IF_MATCH => etag
45
+ ).put(url, body: body),
46
+ data: data
47
+ )
48
+ end
49
+ end
50
+
51
+ private
52
+
53
+ attr_accessor :product
54
+
55
+ def resolve_url
56
+ product.links.self
57
+ end
58
+
59
+ def resolve_etag
60
+ product.etag
61
+ end
62
+
63
+ def encode(data)
64
+ TrailerVote::Api.encode(CONTENT, product: data)
65
+ end
66
+
67
+ def redirect_klazz
68
+ Find
69
+ end
70
+
71
+ def forward(result, data:)
72
+ return unless [307, 308].include?(result.status)
73
+ url = result['Location'] || result['Content-Location']
74
+ forward_klazz.new(configuration: configuration, product: product)
75
+ .call(data: data, url: url, etag: resolve_etag)
76
+ end
77
+ end
78
+ end
79
+ end
80
+ 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::Video] api to deal with a product's videos
11
+ def video
12
+ Video.new(configuration: configuration, product: self)
13
+ end
14
+
15
+ alias product_video video
16
+ alias videos video
17
+ end
18
+
19
+ class Video
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,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'trailer_vote/api/composable/common'
4
+
5
+ require 'trailer_vote/api/product/video'
6
+ require 'trailer_vote/api/product/video/find'
7
+
8
+ module TrailerVote
9
+ module Api
10
+ class Product
11
+ class Video
12
+ def create
13
+ Create.new(configuration: configuration, product: product)
14
+ end
15
+
16
+ class Create
17
+ include Composable::Common
18
+
19
+ CONTENT = MediaTypes::ProductVideo.to_constructable.version(1).view('create')
20
+ SUCCESS = MediaTypes::ProductVideo.to_constructable.version(1)
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:, product:)
26
+ self.configuration = configuration
27
+ self.product = product
28
+ end
29
+
30
+ def back
31
+ product.video
32
+ end
33
+
34
+ # Create the image
35
+ #
36
+ # @see https://www.rubydoc.info/gems/trailer_vote-media_types/TrailerVote/MediaTypes/ProductImage TrailerVote::MediaTypes::ProductImage
37
+ #
38
+ # @param [String] url (#resolve_url result) the url to post to
39
+ # @param [Hash] data the image data
40
+ #
41
+ # @return [TrailerVote::Api::Product::Video::Find]
42
+ def call(data:, url: resolve_url)
43
+ body = encode(data)
44
+ guard_network_errors do
45
+ branch(
46
+ resolve_client.headers(
47
+ Headers::ACCEPT => ACCEPT,
48
+ Headers::CONTENT_TYPE => "#{CONTENT}; charset=#{body.encoding.name}"
49
+ ).post(url, body: body),
50
+ data: data
51
+ )
52
+ end
53
+ end
54
+
55
+ private
56
+
57
+ attr_accessor :product
58
+
59
+ def resolve_url
60
+ product.links.videos
61
+ end
62
+
63
+ def encode(data)
64
+ TrailerVote::Api.encode(CONTENT, product_video: data)
65
+ end
66
+
67
+ def forward(result, data:)
68
+ return unless [307, 308].include?(result.status)
69
+ forward_klazz.new(configuration: configuration, product: product)
70
+ .call(data: data, url: redirected_url(result))
71
+ end
72
+
73
+ def redirect_klazz
74
+ Find
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +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
@@ -0,0 +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
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'trailer_vote/media_types'
4
+
5
+ module TrailerVote
6
+ module Api
7
+ class PushRecipeAndroid
8
+ include Composable::Get
9
+
10
+ attr_accessor :client
11
+
12
+ SUCCESS = MediaTypes::PushRecipeAndroid.to_constructable.version(1)
13
+ FAILURE = MediaTypes::Errors.to_constructable.version(1)
14
+ ACCEPT = [SUCCESS.to_s, FAILURE.to_s(0.1)].join(', ').freeze
15
+
16
+ def initialize(configuration: nil, result: nil)
17
+ self.configuration = configuration
18
+ self.result = result
19
+ end
20
+
21
+ def call(url: nil)
22
+ return self if ok? || !url
23
+
24
+ local_client = client
25
+ unless client
26
+ uri = URI(url)
27
+ local_client = TrailerVote::Api.default_unauthenticated_client
28
+ local_client = local_client.basic_auth(user: uri.user, pass: uri.password)
29
+ end
30
+
31
+ guard_network_errors do
32
+ branch(local_client.headers(Headers::ACCEPT => ACCEPT).get(url))
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end