trailer_vote-api 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b341c5f1af4fab01aaa581d934e82ca906802831
4
- data.tar.gz: 84d7734f7f69b71c192436a6c990926f0849ec5d
3
+ metadata.gz: 035d07df472d9ab44ddba2e14502be9afda848d7
4
+ data.tar.gz: dc7b3e5583f5983bf5c91eed6ef50a85699c67ce
5
5
  SHA512:
6
- metadata.gz: 46a655c726b94de729886ce610e6d0271ec75622a712656a680b5dd410a0519a07ae354cffb40f2b0df62e07561e17a65bf3b14dbeb8ac197897445257776904
7
- data.tar.gz: 359f30bbb77df6eaf57617c5cd3007bc6b67156f35099281857f97eab8e5a92f0633e259105511d6dd6a88bb9d50e67dbfc8bba9c028b9710d08e89d96afb91a
6
+ metadata.gz: 483ea0ce019b10b29b9c8f598d3e5f2822dd0e38efca8e6e16428d4cd2a116442c0f948483c3fbf3ac2762f95715f27112eb5f8df63819b72d30b6dfd043d89d
7
+ data.tar.gz: 97e6fba14eabe8c3ee27c65cc9bcdcfb6f89e42f97bfd476ecf1cd76461df64664b715cd8e3c5d39aca6610193343f6efc5076c120bc4b6f0748f029867d1b77
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 0.8.0
2
+
3
+ - Symbolize all keys to ensure interopt. with TrailerVote ingestion, and Ruby hash defaults
4
+ - Add warning to STDERR when decoding yields a validation error (server response does not match media type)
5
+
1
6
  # 0.7.0
2
7
 
3
8
  - Guards network errors during all API calls
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- trailer_vote-api (0.7.0)
4
+ trailer_vote-api (0.8.0)
5
5
  http (>= 3.3.0, < 4.x)
6
6
  oj (>= 3.6, < 4.x)
7
7
  trailer_vote-media_types (>= 0.6.1, < 1)
data/README.md CHANGED
@@ -1,4 +1,7 @@
1
1
  # TrailerVote::Api
2
+ [![Build Status](https://travis-ci.com/TrailerVote/trailervote-api-clients.svg?branch=master)](https://travis-ci.com/TrailerVote/trailervote-api-clients)
3
+ [![Gem Version](https://badge.fury.io/rb/trailer_vote-api.svg)](https://badge.fury.io/rb/trailer_vote-api)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/da722ca43c5811db5926/maintainability)](https://codeclimate.com/github/TrailerVote/trailervote-api-clients/maintainability)
2
5
 
3
6
  The TrailerVote Api gem is the official interface to communicate with the TrailerVote product service. It allows you to
4
7
  keep your code simple and not deal with the HTTP suite.
@@ -18,7 +18,7 @@ module TrailerVote
18
18
  # @return [Links] the links
19
19
  def links
20
20
  # TODO: or headers
21
- @links ||= Links.new(data['_links'])
21
+ @links ||= Links.new(data[:_links])
22
22
  end
23
23
 
24
24
  # Decode the result via {TypeRegistry}. This also takes care of MediaTypes validation.
@@ -30,7 +30,7 @@ module TrailerVote
30
30
  end
31
31
 
32
32
  def data
33
- to_h['configuration']
33
+ to_h[:configuration]
34
34
  end
35
35
 
36
36
  def call(url: resolve_url)
@@ -15,7 +15,7 @@ module TrailerVote
15
15
  end
16
16
 
17
17
  def decode(obj)
18
- Oj.load(obj, mode: :strict)
18
+ Oj.load(obj, mode: :strict, symbol_keys: true)
19
19
  rescue Oj::Error => err
20
20
  raise DecodeError.new(media_type: 'application/json', source: err)
21
21
  end
@@ -8,12 +8,13 @@ module TrailerVote
8
8
  end
9
9
 
10
10
  def respond_to_missing?(method_name, include_private = false)
11
- links.key?(String(method_name)) || super
11
+ links.key?(method_name) || super
12
12
  end
13
13
 
14
14
  def method_missing(method_name, *arguments)
15
- if links.key?(String(method_name))
16
- return call(String(method_name), *arguments)
15
+ link_name = method_name
16
+ if links.key?(link_name)
17
+ return call(link_name, *arguments)
17
18
  end
18
19
 
19
20
  if /[a-z_]+/.match? method_name
@@ -37,10 +38,10 @@ module TrailerVote
37
38
 
38
39
  def call(link, **arguments)
39
40
  if arguments.length.zero?
40
- return self[link]['href']
41
+ return self[link][:href]
41
42
  end
42
43
 
43
- fill_template(self[link]['href'], **arguments)
44
+ fill_template(self[link][:href], **arguments)
44
45
  end
45
46
 
46
47
  def fill_template(templated, **arguments)
@@ -46,7 +46,7 @@ module TrailerVote
46
46
  end
47
47
 
48
48
  def data
49
- to_h['place']
49
+ to_h[:place]
50
50
  end
51
51
 
52
52
  def parent
@@ -47,7 +47,7 @@ module TrailerVote
47
47
  end
48
48
 
49
49
  def data
50
- to_h['product']
50
+ to_h[:product]
51
51
  end
52
52
  end
53
53
  end
@@ -45,7 +45,7 @@ module TrailerVote
45
45
  end
46
46
 
47
47
  def data
48
- to_h['product_image']
48
+ to_h[:product_image]
49
49
  end
50
50
  end
51
51
  end
@@ -40,7 +40,7 @@ module TrailerVote
40
40
  end
41
41
 
42
42
  def data
43
- to_h['product_images']
43
+ to_h[:product_images]
44
44
  end
45
45
 
46
46
  private
@@ -47,7 +47,7 @@ module TrailerVote
47
47
  end
48
48
 
49
49
  def data
50
- to_h['product_video']
50
+ to_h[:product_video]
51
51
  end
52
52
  end
53
53
  end
@@ -40,7 +40,7 @@ module TrailerVote
40
40
  end
41
41
 
42
42
  def data
43
- to_h['product_videos']
43
+ to_h[:product_videos]
44
44
  end
45
45
 
46
46
  private
@@ -77,10 +77,14 @@ module TrailerVote
77
77
  def define_decode(adapter, media_type)
78
78
  adapter.define_singleton_method('decode') do |str|
79
79
  begin
80
- Oj.load(str, mode: :strict).tap do |result|
81
- media_type.valid?(result)
80
+ Oj.load(str, mode: :strict, symbol_keys: true).tap do |result|
81
+ begin
82
+ media_type.validate!(result)
83
+ rescue ::MediaTypes::Scheme::ValidationError => err
84
+ warn format('Decode error! API might now be in an invalid or incomplete state. %<err>s', err: err)
85
+ end
82
86
  end
83
- rescue Oj::Error, ::MediaTypes::Scheme::ValidationError => err
87
+ rescue Oj::Error => err
84
88
  raise DecodeError.new(media_type: media_type, source: err)
85
89
  end
86
90
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module TrailerVote
4
4
  module Api
5
- VERSION = '0.7.0'
5
+ VERSION = '0.8.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trailer_vote-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derk-Jan Karrenbeld