trailer_vote-api 2.2.2 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 956fd41714b771778876b0866d669872edd2d8f37ece5d772744c4da75ef276f
4
- data.tar.gz: e5b2a15b46a430c7041744a03a9e03fabdce5814bfcea762c07ccdcaae58bbcc
3
+ metadata.gz: ffccb405ec69e5cb2f85fdc6bec5b629667d9ad4d4cb14030db0952fafc13a23
4
+ data.tar.gz: 5659979cd40ebb822a2b7eb01975490b05af87f4403e4cc69a90333a655f3ab0
5
5
  SHA512:
6
- metadata.gz: 6d63a64992eb931eebf15cc13d18c5e72f2b8a539585793af2a5927e02f1c6950396adaa216df9992b68d1126ef0f0714b7f9b4f74fd7b5a86fc8cf3c6f15a2c
7
- data.tar.gz: 92bbf3d85649fc5ae25310061d382b6d288136778f7082817dddcf203c6b59ab313d4212b0773ec7e1dd67e0cc4ce46494dcf6c3a71872634c2a6489ce04d9fe
6
+ metadata.gz: bc09c0745b73c5497dc6ca98521d359a95de307f2e38a1826930b1cc931eddfadbb43c750ff1d6aaf83d03ed1a794259caaa7a27cda34bf5cf5b361bb60ea412
7
+ data.tar.gz: cecc15619cbd422d7713036a8b743229970fe76481a777cf90df7c05ddbf5f8a10702548cf2920892b49adffc3d2dec6e34c1d6d1541d168ea859edf232fbec4
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- trailer_vote-api (2.2.2)
4
+ trailer_vote-api (3.1.0)
5
5
  http (>= 3.3.0, <= 4.1.1)
6
6
  oj (>= 3.6, < 4.x)
7
- trailer_vote-media_types (~> 2.4.1)
7
+ trailer_vote-media_types (~> 3.0)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
@@ -29,7 +29,7 @@ GEM
29
29
  domain_name (~> 0.5)
30
30
  http-form_data (2.3.0)
31
31
  http_parser.rb (0.6.0)
32
- media_types (0.6.2)
32
+ media_types (2.0.1)
33
33
  minitest (5.14.0)
34
34
  minitest-ci (3.4.0)
35
35
  minitest (>= 5.0.6)
@@ -38,7 +38,7 @@ GEM
38
38
  builder
39
39
  minitest (>= 5.0)
40
40
  ruby-progressbar
41
- oj (3.10.5)
41
+ oj (3.10.7)
42
42
  public_suffix (4.0.3)
43
43
  rake (13.0.1)
44
44
  ruby-progressbar (1.10.1)
@@ -47,8 +47,8 @@ GEM
47
47
  docile (~> 1.1)
48
48
  simplecov-html (~> 0.11)
49
49
  simplecov-html (0.12.2)
50
- trailer_vote-media_types (2.4.1)
51
- media_types (>= 0.6.0, < 1)
50
+ trailer_vote-media_types (3.0.4)
51
+ media_types (>= 2.0.0, < 3)
52
52
  unf (0.1.4)
53
53
  unf_ext
54
54
  unf_ext (0.0.7.7)
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'bundler/setup'
5
- require 'trailer_vote/api'
5
+ require 'trailer_vote/api/autoload'
6
6
 
7
7
  # You can add fixtures and/or initialization code here to make experimenting
8
8
  # with your gem easier. You can also use a different console, if you like.
@@ -3,6 +3,7 @@
3
3
  # require 'httpx'
4
4
  # HTTP_KLAZZ = HTTPX.plugin(:compression, :basic_authentication)
5
5
  require 'http'
6
+ require 'json'
6
7
  HTTP_KLAZZ = HTTP.use(:auto_inflate)
7
8
 
8
9
  require 'trailer_vote/api/version'
@@ -16,11 +17,18 @@ module TrailerVote
16
17
  module_function
17
18
 
18
19
  def decode(result)
19
- TypeRegistry[result.content_type.mime_type].decode(result.body.to_s)
20
+ begin
21
+ #Oj.load(result, mode: :strict, symbol_keys: true)
22
+ JSON.parse(result, {symbolize_names: true})
23
+ rescue Oj::Error => err
24
+ raise DecodeError.new(media_type: media_type, source: err)
25
+ rescue JSON::JSONError => err
26
+ raise DecodeError.new(media_type: media_type, source: err)
27
+ end
20
28
  end
21
29
 
22
30
  def encode(media_type, data)
23
- TypeRegistry[media_type.to_s].encode(data)
31
+ Oj.dump(data, mode: :compat)
24
32
  end
25
33
 
26
34
  def default_unauthenticated_client
@@ -42,5 +50,18 @@ module TrailerVote
42
50
  IF_MATCH = 'If-Match'
43
51
  USER_AGENT = 'User-Agent'
44
52
  end
53
+
54
+ TypeRegistry.register(MediaTypes::Configuration)
55
+ TypeRegistry.register(MediaTypes::Errors)
56
+ TypeRegistry.register(MediaTypes::Issue)
57
+ TypeRegistry.register(MediaTypes::Place)
58
+ TypeRegistry.register(MediaTypes::Product)
59
+ TypeRegistry.register(MediaTypes::ProductImage)
60
+ TypeRegistry.register(MediaTypes::ProductLookup)
61
+ TypeRegistry.register(MediaTypes::ProductPlaceLink)
62
+ TypeRegistry.register(MediaTypes::ProductVideo)
63
+ TypeRegistry.register(MediaTypes::PushRecipeAndroid)
64
+ TypeRegistry.register(MediaTypes::PushRecipeIos)
65
+ TypeRegistry.register(MediaTypes::VistaConfig)
45
66
  end
46
67
  end
@@ -10,6 +10,7 @@ require 'trailer_vote/api/place/children'
10
10
  require 'trailer_vote/api/place/children/urls'
11
11
  require 'trailer_vote/api/place/create'
12
12
  require 'trailer_vote/api/place/find'
13
+ require 'trailer_vote/api/place/lookup'
13
14
  require 'trailer_vote/api/product'
14
15
  require 'trailer_vote/api/product/create'
15
16
  require 'trailer_vote/api/product/find'
@@ -16,7 +16,7 @@ module TrailerVote
16
16
  class Configuration
17
17
  include Composable::Get
18
18
 
19
- SUCCESS = MediaTypes::Configuration.to_constructable.version(2)
19
+ SUCCESS = MediaTypes::Configuration.to_constructable.version(5)
20
20
  FAILURE = MediaTypes::Errors.to_constructable.version(1)
21
21
 
22
22
  ACCEPT = [SUCCESS.to_s, FAILURE.to_s(0.1)].join(', ').freeze
@@ -67,5 +67,3 @@ module TrailerVote
67
67
  end
68
68
  end
69
69
  end
70
-
71
- TrailerVote::MediaTypes::Configuration.register
@@ -111,5 +111,3 @@ module TrailerVote
111
111
 
112
112
  end
113
113
  end
114
-
115
- TrailerVote::MediaTypes::Errors.register
@@ -27,5 +27,3 @@ module TrailerVote
27
27
  end
28
28
  end
29
29
  end
30
-
31
- TrailerVote::MediaTypes::Issue.register
@@ -20,5 +20,3 @@ module TrailerVote
20
20
  end
21
21
  end
22
22
  end
23
-
24
- TrailerVote::MediaTypes::Place.register
@@ -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
@@ -29,5 +29,3 @@ module TrailerVote
29
29
  end
30
30
  end
31
31
  end
32
-
33
- TrailerVote::MediaTypes::Product.register
@@ -34,5 +34,3 @@ module TrailerVote
34
34
  end
35
35
  end
36
36
  end
37
-
38
- TrailerVote::MediaTypes::ProductImage.register
@@ -93,5 +93,3 @@ module TrailerVote
93
93
  end
94
94
  end
95
95
  end
96
-
97
- TrailerVote::MediaTypes::ProductLookup.register
@@ -36,5 +36,3 @@ module TrailerVote
36
36
  end
37
37
  end
38
38
  end
39
-
40
- TrailerVote::MediaTypes::ProductPlaceLink.register
@@ -34,5 +34,3 @@ module TrailerVote
34
34
  end
35
35
  end
36
36
  end
37
-
38
- TrailerVote::MediaTypes::ProductVideo.register
@@ -35,5 +35,3 @@ module TrailerVote
35
35
  end
36
36
  end
37
37
  end
38
-
39
- TrailerVote::MediaTypes::PushRecipeAndroid.register
@@ -35,5 +35,3 @@ module TrailerVote
35
35
  end
36
36
  end
37
37
  end
38
-
39
- TrailerVote::MediaTypes::PushRecipeIos.register
@@ -34,10 +34,10 @@ module TrailerVote
34
34
  def register(registerable)
35
35
  mime_type = registerable.to_s
36
36
 
37
- self[mime_type] = AdapterFor(registerable.media_type)
38
- shortcut(mime_type, registerable.to_sym)
37
+ self[mime_type] = AdapterFor(registerable)
38
+ shortcut(mime_type, registerable.to_s)
39
39
 
40
- registerable.aliases.each do |alias_mime_type|
40
+ registerable.available_validations.each do |alias_mime_type|
41
41
  shortcut(mime_type, alias_mime_type)
42
42
  end
43
43
  end
@@ -47,7 +47,7 @@ module TrailerVote
47
47
 
48
48
  # noinspection RubyClassMethodNamingConvention
49
49
  def AdapterFor(media_type) # rubocop:disable Naming/MethodName
50
- adapter_name = generate_adapter_name(media_type)
50
+ adapter_name = generate_adapter_name(media_type.identifier)
51
51
 
52
52
  if const_defined?(adapter_name)
53
53
  return const_get(adapter_name)
@@ -93,7 +93,3 @@ module TrailerVote
93
93
  end
94
94
  end
95
95
  end
96
-
97
- module MediaTypes
98
- integrate TrailerVote::Api::TypeRegistry
99
- end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module TrailerVote
4
4
  module Api
5
- VERSION = '2.2.2'
5
+ VERSION = '3.1.0'
6
6
  end
7
7
  end
@@ -9,7 +9,7 @@ module TrailerVote
9
9
 
10
10
  attr_accessor :client
11
11
 
12
- SUCCESS = MediaTypes::VistaConfig.to_constructable.version(1).view(:index)
12
+ SUCCESS = MediaTypes::VistaConfig.to_constructable.version(1).view(:collection)
13
13
  FAILURE = MediaTypes::Errors.to_constructable.version(1)
14
14
  ACCEPT = [SUCCESS.to_s, FAILURE.to_s(0.1)].join(', ').freeze
15
15
 
@@ -35,5 +35,3 @@ module TrailerVote
35
35
  end
36
36
  end
37
37
  end
38
-
39
- TrailerVote::MediaTypes::VistaConfig.register
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
32
32
  # spec.add_runtime_dependency 'httpx'
33
33
  spec.add_runtime_dependency 'http', '>= 3.3.0', '<= 4.1.1'
34
34
  spec.add_runtime_dependency 'oj', '>= 3.6', '< 4.x'
35
- spec.add_runtime_dependency 'trailer_vote-media_types', '~> 2.4.1'
35
+ spec.add_runtime_dependency 'trailer_vote-media_types', '~> 3.0'
36
36
 
37
37
  spec.add_development_dependency 'awesome_print', '~> 1.8'
38
38
  spec.add_development_dependency 'bundler', '~> 1.16'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trailer_vote-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derk-Jan Karrenbeld
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-29 00:00:00.000000000 Z
11
+ date: 2020-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -56,14 +56,14 @@ dependencies:
56
56
  requirements:
57
57
  - - "~>"
58
58
  - !ruby/object:Gem::Version
59
- version: 2.4.1
59
+ version: '3.0'
60
60
  type: :runtime
61
61
  prerelease: false
62
62
  version_requirements: !ruby/object:Gem::Requirement
63
63
  requirements:
64
64
  - - "~>"
65
65
  - !ruby/object:Gem::Version
66
- version: 2.4.1
66
+ version: '3.0'
67
67
  - !ruby/object:Gem::Dependency
68
68
  name: awesome_print
69
69
  requirement: !ruby/object:Gem::Requirement
@@ -208,6 +208,7 @@ files:
208
208
  - lib/trailer_vote/api/place/children/urls.rb
209
209
  - lib/trailer_vote/api/place/create.rb
210
210
  - lib/trailer_vote/api/place/find.rb
211
+ - lib/trailer_vote/api/place/lookup.rb
211
212
  - lib/trailer_vote/api/product.rb
212
213
  - lib/trailer_vote/api/product/create.rb
213
214
  - lib/trailer_vote/api/product/find.rb
@@ -253,7 +254,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
253
254
  - !ruby/object:Gem::Version
254
255
  version: '0'
255
256
  requirements: []
256
- rubygems_version: 3.0.3
257
+ rubygems_version: 3.1.2
257
258
  signing_key:
258
259
  specification_version: 4
259
260
  summary: Provides a client to interact with the TrailerVote API