trailer_vote-api 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rubocop.yml +29 -0
- data/CHANGELOG.md +56 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +77 -0
- data/README.md +188 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/trailer_vote/api.rb +67 -0
- data/lib/trailer_vote/api/autoload.rb +28 -0
- data/lib/trailer_vote/api/composable/common.rb +91 -0
- data/lib/trailer_vote/api/composable/get.rb +66 -0
- data/lib/trailer_vote/api/configuration.rb +69 -0
- data/lib/trailer_vote/api/errors.rb +113 -0
- data/lib/trailer_vote/api/fallback_content_types.rb +50 -0
- data/lib/trailer_vote/api/issue.rb +29 -0
- data/lib/trailer_vote/api/issue/create.rb +72 -0
- data/lib/trailer_vote/api/issue/find.rb +42 -0
- data/lib/trailer_vote/api/links.rb +54 -0
- data/lib/trailer_vote/api/place.rb +22 -0
- data/lib/trailer_vote/api/place/children.rb +33 -0
- data/lib/trailer_vote/api/place/children/urls.rb +67 -0
- data/lib/trailer_vote/api/place/create.rb +83 -0
- data/lib/trailer_vote/api/place/find.rb +60 -0
- data/lib/trailer_vote/api/place/lookup.rb +72 -0
- data/lib/trailer_vote/api/product.rb +31 -0
- data/lib/trailer_vote/api/product/create.rb +63 -0
- data/lib/trailer_vote/api/product/find.rb +55 -0
- data/lib/trailer_vote/api/product/image.rb +36 -0
- data/lib/trailer_vote/api/product/image/create.rb +83 -0
- data/lib/trailer_vote/api/product/image/find.rb +54 -0
- data/lib/trailer_vote/api/product/image/urls.rb +66 -0
- data/lib/trailer_vote/api/product/lookup.rb +95 -0
- data/lib/trailer_vote/api/product/place.rb +38 -0
- data/lib/trailer_vote/api/product/place/link.rb +75 -0
- data/lib/trailer_vote/api/product/update.rb +80 -0
- data/lib/trailer_vote/api/product/video.rb +36 -0
- data/lib/trailer_vote/api/product/video/create.rb +80 -0
- data/lib/trailer_vote/api/product/video/find.rb +56 -0
- data/lib/trailer_vote/api/product/video/urls.rb +66 -0
- data/lib/trailer_vote/api/push_recipe_android.rb +37 -0
- data/lib/trailer_vote/api/push_recipe_ios.rb +37 -0
- data/lib/trailer_vote/api/type_registry.rb +95 -0
- data/lib/trailer_vote/api/version.rb +7 -0
- data/lib/trailer_vote/api/vista_config.rb +37 -0
- data/trailer_vote-api.gemspec +45 -0
- metadata +261 -0
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'trailer_vote/api/composable/common'
|
4
|
+
require 'trailer_vote/api/issue'
|
5
|
+
require 'trailer_vote/api/issue/find'
|
6
|
+
|
7
|
+
module TrailerVote
|
8
|
+
module Api
|
9
|
+
class Issue
|
10
|
+
|
11
|
+
def create
|
12
|
+
Create.new(configuration: configuration)
|
13
|
+
end
|
14
|
+
|
15
|
+
class Create
|
16
|
+
include Composable::Common
|
17
|
+
|
18
|
+
CONTENT = MediaTypes::Issue.to_constructable.version(1).view('create')
|
19
|
+
SUCCESS = MediaTypes::Issue.to_constructable.version(1)
|
20
|
+
FAILURE = MediaTypes::Errors.to_constructable.version(1)
|
21
|
+
|
22
|
+
ACCEPT = [SUCCESS.to_s, FAILURE.to_s(0.1)].join(', ').freeze
|
23
|
+
|
24
|
+
# @private
|
25
|
+
def initialize(configuration:)
|
26
|
+
self.configuration = configuration
|
27
|
+
end
|
28
|
+
|
29
|
+
def back
|
30
|
+
configuration.issue
|
31
|
+
end
|
32
|
+
|
33
|
+
# Create an issue
|
34
|
+
#
|
35
|
+
# @see https://www.rubydoc.info/gems/trailer_vote-media_types/TrailerVote/MediaTypes/Issue TrailerVote::MediaTypes::Issue
|
36
|
+
#
|
37
|
+
# @param [String, Hash] data the data conform to the Issue media type
|
38
|
+
# @param [String] url (#resolve_url result) the url to post to
|
39
|
+
#
|
40
|
+
# @return [TrailerVote::Api::Issue]
|
41
|
+
def call(data:, url: resolve_url)
|
42
|
+
guard_network_errors do
|
43
|
+
body = encode(data)
|
44
|
+
branch(
|
45
|
+
resolve_client.headers(
|
46
|
+
Headers::ACCEPT => ACCEPT,
|
47
|
+
Headers::CONTENT_TYPE => "#{CONTENT}; charset=#{body.encoding.name}"
|
48
|
+
).post(url, body: body),
|
49
|
+
data: data
|
50
|
+
)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
attr_accessor :configuration
|
57
|
+
|
58
|
+
def resolve_url
|
59
|
+
configuration.links.issues
|
60
|
+
end
|
61
|
+
|
62
|
+
def encode(data)
|
63
|
+
TrailerVote::Api.encode(CONTENT, issue: data)
|
64
|
+
end
|
65
|
+
|
66
|
+
def redirect_klazz
|
67
|
+
Find
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'trailer_vote/api/composable/get'
|
4
|
+
require 'trailer_vote/api/issue'
|
5
|
+
|
6
|
+
module TrailerVote
|
7
|
+
module Api
|
8
|
+
class Issue
|
9
|
+
class Find
|
10
|
+
include Composable::Get
|
11
|
+
|
12
|
+
SUCCESS = MediaTypes::Issue.to_constructable.version(1)
|
13
|
+
FAILURE = MediaTypes::Errors.to_constructable.version(1)
|
14
|
+
|
15
|
+
ACCEPT = [SUCCESS.to_s, FAILURE.to_s(0.1)].join(', ').freeze
|
16
|
+
|
17
|
+
def initialize(configuration:, result: nil)
|
18
|
+
self.configuration = configuration
|
19
|
+
self.result = result
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [TrailerVote::Api::Configuration, TrailerVote::Api::Issue::Create]
|
23
|
+
def back
|
24
|
+
backtrack = result
|
25
|
+
backtrack = result.back while backtrack&.is_a?(self.class)
|
26
|
+
backtrack || configuration
|
27
|
+
end
|
28
|
+
|
29
|
+
def call(url: nil)
|
30
|
+
return self if ok? || !url
|
31
|
+
guard_network_errors do
|
32
|
+
branch(resolve_client.headers(Headers::ACCEPT => ACCEPT).get(url))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def data
|
37
|
+
to_h[:issue]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TrailerVote
|
4
|
+
module Api
|
5
|
+
class Links
|
6
|
+
def initialize(links)
|
7
|
+
self.links = links
|
8
|
+
end
|
9
|
+
|
10
|
+
def respond_to_missing?(method_name, include_private = false)
|
11
|
+
links.key?(method_name) || super
|
12
|
+
end
|
13
|
+
|
14
|
+
def method_missing(method_name, *arguments)
|
15
|
+
link_name = method_name
|
16
|
+
if links.key?(link_name)
|
17
|
+
return call(link_name, *arguments)
|
18
|
+
end
|
19
|
+
|
20
|
+
if /[a-z_]+/.match? method_name
|
21
|
+
raise ArgumentError, format(
|
22
|
+
'Unknown link %<link>s. Available: %<links>s',
|
23
|
+
link: method_name,
|
24
|
+
links: links.keys
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
super
|
29
|
+
end
|
30
|
+
|
31
|
+
def [](key)
|
32
|
+
links.fetch(key)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
attr_accessor :links
|
38
|
+
|
39
|
+
def call(link, **arguments)
|
40
|
+
if arguments.length.zero?
|
41
|
+
return self[link][:href]
|
42
|
+
end
|
43
|
+
|
44
|
+
fill_template(self[link][:href], **arguments)
|
45
|
+
end
|
46
|
+
|
47
|
+
def fill_template(templated, **arguments)
|
48
|
+
arguments.each_with_object(templated) do |(variable, value), result|
|
49
|
+
result.gsub!("{#{variable}}", value)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,22 @@
|
|
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 Place
|
9
|
+
def initialize(configuration:)
|
10
|
+
self.configuration = configuration
|
11
|
+
end
|
12
|
+
|
13
|
+
def back
|
14
|
+
configuration
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
attr_accessor :configuration
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -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 Place
|
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
|
@@ -0,0 +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
|
+
configuration.links.place
|
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
|
@@ -0,0 +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(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
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'trailer_vote/api/composable/common'
|
4
|
+
|
5
|
+
require 'trailer_vote/api/place'
|
6
|
+
require 'trailer_vote/api/place/find'
|
7
|
+
|
8
|
+
module TrailerVote
|
9
|
+
module Api
|
10
|
+
|
11
|
+
class Configuration
|
12
|
+
# @return [TrailerVote::Api::Place::Lookup] api to deal with looking up a place
|
13
|
+
def place_lookup
|
14
|
+
Place::Lookup.new(configuration: self)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class Place
|
19
|
+
|
20
|
+
# @return [TrailerVote::Api::Place::Lookup] api to deal with looking up a place
|
21
|
+
def lookup
|
22
|
+
Lookup.new(configuration: configuration)
|
23
|
+
end
|
24
|
+
|
25
|
+
##
|
26
|
+
# Looks up a place by a concatenated authority and identifier string
|
27
|
+
#
|
28
|
+
# @example lookup a place by vista authority
|
29
|
+
#
|
30
|
+
# result = TrailerVote::Api.configure(...).place.lookup.call(url: '')
|
31
|
+
# result.place
|
32
|
+
# # => { "title": "" }
|
33
|
+
#
|
34
|
+
class Lookup
|
35
|
+
include Composable::Common
|
36
|
+
|
37
|
+
SUCCESS = MediaTypes::Place.to_constructable.version(2)
|
38
|
+
FAILURE = MediaTypes::Errors.to_constructable.version(1)
|
39
|
+
|
40
|
+
ACCEPT = [SUCCESS.to_s, FAILURE.to_s(0.1)].join(', ').freeze
|
41
|
+
|
42
|
+
def initialize(configuration:)
|
43
|
+
self.configuration = configuration
|
44
|
+
end
|
45
|
+
|
46
|
+
# @return [TrailerVote::Api::Place] api to deal with places
|
47
|
+
def back
|
48
|
+
configuration.place
|
49
|
+
end
|
50
|
+
|
51
|
+
def call(authority:, identifier:)
|
52
|
+
url = resolve_url(authority: authority, identifier: identifier)
|
53
|
+
guard_network_errors do
|
54
|
+
branch(
|
55
|
+
resolve_client.headers(Headers::ACCEPT => ACCEPT).get(url, body: nil)
|
56
|
+
)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def resolve_url(authority:, identifier:)
|
63
|
+
configuration.links.lookup(authority: authority, identifier: identifier)
|
64
|
+
end
|
65
|
+
|
66
|
+
def redirect_klazz
|
67
|
+
Find
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|