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
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'trailer_vote/api/place'
4
+ require 'trailer_vote/api/place/find'
5
+
6
+ module TrailerVote
7
+ module Api
8
+ class Product
9
+ class Find
10
+ # @return [TrailerVote::Api::Product::Children] api to deal with a place's children
11
+ def children
12
+ Children.new(configuration: configuration, place: self)
13
+ end
14
+ end
15
+
16
+ class Children
17
+ def initialize(configuration:, place: nil)
18
+ self.configuration = configuration
19
+ self.place = place
20
+ end
21
+
22
+ # @return [TrailerVote::Api::Product::Find] api to deal with a found place
23
+ def back
24
+ place
25
+ end
26
+
27
+ private
28
+
29
+ attr_accessor :configuration, :place
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'trailer_vote/api/composable/get'
4
+ require 'trailer_vote/api/place'
5
+
6
+ module TrailerVote
7
+ module Api
8
+ class Place
9
+ class Children
10
+
11
+ # @return [TrailerVote::Api::Place::Children::Urls] the api to get the children urls for the current place
12
+ def urls
13
+ Urls.new(configuration: configuration, place: place)
14
+ end
15
+
16
+ class Urls
17
+ include Composable::Get
18
+
19
+ SUCCESS = MediaTypes::Place.to_constructable.version(3).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:, place:, result: nil)
25
+ self.configuration = configuration
26
+ self.place = place
27
+ self.result = result
28
+ end
29
+
30
+ # @return [TrailerVote::Api::Place::Children] the api to deal with a place's children
31
+ def back
32
+ place.children
33
+ end
34
+
35
+ def call(url: resolve_url)
36
+ return self if ok? || !url
37
+
38
+ guard_network_errors do
39
+ branch(resolve_client.headers(Headers::ACCEPT => ACCEPT).get(url))
40
+ end
41
+ end
42
+
43
+ def data
44
+ to_h[:places]
45
+ end
46
+
47
+ private
48
+
49
+ attr_accessor :place
50
+
51
+ def ok?
52
+ result&.status&.ok?
53
+ end
54
+
55
+ def resolve_url
56
+ place.links.children
57
+ end
58
+
59
+ def redirect(result)
60
+ redirect_klazz.new(configuration: configuration, place: place, result: result)
61
+ .call(url: redirected_url(result))
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -1,83 +1,83 @@
1
- # frozen_string_literal: true
2
-
3
- require 'trailer_vote/api/composable/common'
4
- require 'trailer_vote/api/place'
5
- require 'trailer_vote/api/place/find'
6
-
7
- module TrailerVote
8
- module Api
9
- class Place
10
- class Find
11
-
12
- # @return [TrailerVote::Api::Place::Create] the api to create a child place
13
- def create
14
- Create.new(configuration: configuration, place: self)
15
- end
16
- end
17
-
18
- class Create
19
- include Composable::Common
20
-
21
- CONTENT = MediaTypes::Place.to_constructable.version(2).view('create')
22
- SUCCESS = MediaTypes::Place.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
- # @private
28
- def initialize(configuration:, place:)
29
- self.configuration = configuration
30
- self.place = place
31
- end
32
-
33
- # @return [TrailerVote::Api::Place::Find] the found place
34
- def back
35
- place
36
- end
37
-
38
- # Create a place
39
- #
40
- # @see https://www.rubydoc.info/gems/trailer_vote-media_types/TrailerVote/MediaTypes/Place TrailerVote::MediaTypes::Place
41
- #
42
- # @param [String, Hash] data the data conform to the Place media type
43
- # @param [String] url (#resolve_url result) the url to post to
44
- #
45
- # @return [TrailerVote::Api::Place::Find]
46
- def call(data:, url: resolve_url)
47
- guard_network_errors do
48
- body = encode(data)
49
- branch(
50
- resolve_client.headers(
51
- Headers::ACCEPT => ACCEPT,
52
- Headers::CONTENT_TYPE => "#{CONTENT}; charset=#{body.encoding.name}"
53
- ).post(url, body: body),
54
- data: data
55
- )
56
- end
57
- end
58
-
59
- private
60
-
61
- attr_accessor :place
62
-
63
- def resolve_url
64
- place.links.self
65
- end
66
-
67
- def encode(data)
68
- TrailerVote::Api.encode(CONTENT, place: data)
69
- end
70
-
71
- def forward(result, data:)
72
- return unless [307, 308].include?(result.status)
73
- forward_klazz.new(configuration: configuration, place: place)
74
- .call(data: data, url: redirected_url(result))
75
- end
76
-
77
- def redirect_klazz
78
- Find
79
- end
80
- end
81
- end
82
- end
83
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'trailer_vote/api/composable/common'
4
+ require 'trailer_vote/api/place'
5
+ require 'trailer_vote/api/place/find'
6
+
7
+ module TrailerVote
8
+ module Api
9
+ class Place
10
+ class Find
11
+
12
+ # @return [TrailerVote::Api::Place::Create] the api to create a child place
13
+ def create
14
+ Create.new(configuration: configuration, place: self)
15
+ end
16
+ end
17
+
18
+ class Create
19
+ include Composable::Common
20
+
21
+ CONTENT = MediaTypes::Place.to_constructable.version(2).view('create')
22
+ SUCCESS = MediaTypes::Place.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
+ # @private
28
+ def initialize(configuration:, place:)
29
+ self.configuration = configuration
30
+ self.place = place
31
+ end
32
+
33
+ # @return [TrailerVote::Api::Place::Find] the found place
34
+ def back
35
+ place
36
+ end
37
+
38
+ # Create a place
39
+ #
40
+ # @see https://www.rubydoc.info/gems/trailer_vote-media_types/TrailerVote/MediaTypes/Place TrailerVote::MediaTypes::Place
41
+ #
42
+ # @param [String, Hash] data the data conform to the Place media type
43
+ # @param [String] url (#resolve_url result) the url to post to
44
+ #
45
+ # @return [TrailerVote::Api::Place::Find]
46
+ def call(data:, url: resolve_url)
47
+ guard_network_errors do
48
+ body = encode(data)
49
+ branch(
50
+ resolve_client.headers(
51
+ Headers::ACCEPT => ACCEPT,
52
+ Headers::CONTENT_TYPE => "#{CONTENT}; charset=#{body.encoding.name}"
53
+ ).post(url, body: body),
54
+ data: data
55
+ )
56
+ end
57
+ end
58
+
59
+ private
60
+
61
+ attr_accessor :place
62
+
63
+ def resolve_url
64
+ place.links.self
65
+ end
66
+
67
+ def encode(data)
68
+ TrailerVote::Api.encode(CONTENT, place: data)
69
+ end
70
+
71
+ def forward(result, data:)
72
+ return unless [307, 308].include?(result.status)
73
+ forward_klazz.new(configuration: configuration, place: place)
74
+ .call(data: data, url: redirected_url(result))
75
+ end
76
+
77
+ def redirect_klazz
78
+ Find
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -1,59 +1,60 @@
1
- # frozen_string_literal: true
2
-
3
- require 'trailer_vote/api/composable/get'
4
- require 'trailer_vote/api/place'
5
-
6
- module TrailerVote
7
- module Api
8
- class Configuration
9
-
10
- # @return [TrailerVote::Api::Place::Find] the root place attached to the credentials
11
- def place
12
- Place::Find.new(configuration: self)
13
- end
14
- end
15
-
16
- class Place
17
- class Find
18
- include Composable::Get
19
-
20
- SUCCESS = MediaTypes::Place.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:, result: nil)
26
- self.configuration = configuration
27
- self.result = result
28
- end
29
-
30
- # @return [TrailerVote::Api::Configuration, TrailerVote::Api::Place::Create]
31
- def back
32
- backtrack = result
33
- backtrack = result.back while backtrack&.is_a?(self.class)
34
- backtrack || configuration
35
- end
36
-
37
- def call(url: resolve_url)
38
- return self if ok? || !url
39
- guard_network_errors do
40
- branch(resolve_client.headers(Headers::ACCEPT => ACCEPT).get(url))
41
- end
42
- end
43
-
44
- def resolve_url
45
- configuration.links.place
46
- end
47
-
48
- def data
49
- to_h[:place]
50
- end
51
-
52
- def parent
53
- Find.new(configuration: configuration)
54
- .call(url: links.parent)
55
- end
56
- end
57
- end
58
- end
59
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'trailer_vote/api/composable/get'
4
+ require 'trailer_vote/api/place'
5
+
6
+ module TrailerVote
7
+ module Api
8
+ class Configuration
9
+
10
+ # @return [TrailerVote::Api::Place::Find] the root place attached to the credentials
11
+ def place
12
+ Place::Find.new(configuration: self)
13
+ end
14
+ end
15
+
16
+ class Place
17
+ class Find
18
+ include Composable::Get
19
+
20
+ SUCCESS = MediaTypes::Place.to_constructable.version(3)
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:, result: nil)
26
+ self.configuration = configuration
27
+ self.result = result
28
+ end
29
+
30
+ # @return [TrailerVote::Api::Configuration, TrailerVote::Api::Place::Create]
31
+ def back
32
+ backtrack = result
33
+ backtrack = result.back while backtrack&.is_a?(self.class)
34
+ backtrack || configuration
35
+ end
36
+
37
+ def call(url: resolve_url)
38
+ return self if ok? || !url
39
+
40
+ guard_network_errors do
41
+ branch(resolve_client.headers(Headers::ACCEPT => ACCEPT).get(url))
42
+ end
43
+ end
44
+
45
+ def resolve_url
46
+ configuration.links.place
47
+ end
48
+
49
+ def data
50
+ to_h[:place]
51
+ end
52
+
53
+ def parent
54
+ Find.new(configuration: configuration)
55
+ .call(url: links.parent)
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -1,33 +1,33 @@
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
32
-
33
- TrailerVote::MediaTypes::Product.register
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
32
+
33
+ TrailerVote::MediaTypes::Product.register