insights-api-common 4.0.3 → 4.1.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
  SHA256:
3
- metadata.gz: 972f294824d5a600f98ee785b45a310d83b2b056d1bc9e8fee4af2afd1d43f9c
4
- data.tar.gz: 93f294e0f183debaa844c4ff4272c4fa921a8aef51269d0caffbe8a630a84de7
3
+ metadata.gz: e43686bd25c46149f1fd5886e5c60452fd04a06c183042ea4f678f227a6b1ca6
4
+ data.tar.gz: 882ea648b87f2ee1d7c6c8fa171e85f828c1c46ad818799f3e0d638b4e7b9384
5
5
  SHA512:
6
- metadata.gz: 7f12eb12ddd1bd97b486d88e09463c5ac29f95350ad5431c1ff292df6eb222700628d9a8e0cc055ec7942a0e5a8814aad7249edfd4603f691d6426d85faceef1
7
- data.tar.gz: df4bbc507ad58eb38b94e8bddebd3dd3060a3f4eff33d807b85a88cfd5d9fa33ade8239db2dbae7197b56548fec1fbf456a953fa57226be2b9da1b709f04c0ca
6
+ metadata.gz: cc9dd41c400b94bf67648ac2ddf0f6b5d30ec44ed17cc5f3294155e518908911e261cd5b304518ed9f730840695c06a2b5ecbbc05a6149f38571d95c1d4d8748
7
+ data.tar.gz: 92e36a165e0b440a279951f6d5a0e8ddd516eb439b9b31768be0ef880350eacf52b8ec2286552f112553eec01cf72e2ba3d2bb635d6791cdab3ea6e134c267d6
@@ -45,7 +45,7 @@ module Insights
45
45
  end
46
46
 
47
47
  def api_client_errors(exc, error_document)
48
- body = JSON.parse(exc.response_body)
48
+ body = json_parsed_body(exc)
49
49
  if body.is_a?(Hash) && body.key?('errors') && body['errors'].is_a?(Array)
50
50
  body['errors'].each do |error|
51
51
  next unless error.key?('status') && error.key?('detail')
@@ -56,6 +56,12 @@ module Insights
56
56
  error_document.add(exc.code.to_s, exc.message )
57
57
  end
58
58
  end
59
+
60
+ def json_parsed_body(exc)
61
+ JSON.parse(exc.response_body)
62
+ rescue StandardError
63
+ nil
64
+ end
59
65
  end
60
66
  end
61
67
  end
@@ -1,2 +1,3 @@
1
1
  require "insights/api/common/open_api/docs"
2
+ require "insights/api/common/open_api/version_from_prefix"
2
3
  require "insights/api/common/open_api/serializer"
@@ -3,27 +3,40 @@ module Insights
3
3
  module Common
4
4
  module OpenApi
5
5
  module Serializer
6
+ include VersionFromPrefix
7
+
6
8
  def as_json(arg = {})
7
- previous = super
9
+ previous = super(:except => _excluded_attributes(arg))
10
+
8
11
  encrypted_columns_set = (self.class.try(:encrypted_columns) || []).to_set
9
12
  encryption_filtered = previous.except(*encrypted_columns_set)
10
13
  return encryption_filtered unless arg.key?(:prefixes)
11
- version = api_version_from_prefix(arg[:prefixes].first)
12
- presentation_name = self.class.try(:presentation_name) || self.class.name
13
- schema = ::Insights::API::Common::OpenApi::Docs.instance[version].definitions[presentation_name]
14
- attrs = encryption_filtered.slice(*schema["properties"].keys)
15
- schema["properties"].keys.each do |name|
14
+
15
+ attrs = encryption_filtered.slice(*_schema_properties(arg).keys)
16
+ _schema_properties(arg).keys.each do |name|
16
17
  next if attrs[name].nil?
17
18
  attrs[name] = attrs[name].iso8601 if attrs[name].kind_of?(Time)
18
19
  attrs[name] = attrs[name].to_s if name.ends_with?("_id") || name == "id"
19
- attrs[name] = self.public_send(name) if !attrs.key?(name) && !encrypted_columns_set.include?(name)
20
20
  end
21
21
  attrs.compact
22
22
  end
23
23
 
24
- def api_version_from_prefix(prefix)
25
- /\/?\w+\/v(?<major>\d+)[x\.]?(?<minor>\d+)?\// =~ prefix
26
- [major, minor].compact.join(".")
24
+ private
25
+
26
+ def _excluded_attributes(arg)
27
+ return [] unless arg.key?(:prefixes)
28
+
29
+ self.attributes.keys - _schema_properties(arg).keys
30
+ end
31
+
32
+ def _schema_properties(arg)
33
+ @schema_properties ||= _schema(arg)["properties"]
34
+ end
35
+
36
+ def _schema(arg)
37
+ version = api_version_from_prefix(arg[:prefixes].first)
38
+ presentation_name = self.class.try(:presentation_name) || self.class.name
39
+ ::Insights::API::Common::OpenApi::Docs.instance[version].definitions[presentation_name]
27
40
  end
28
41
  end
29
42
  end
@@ -0,0 +1,14 @@
1
+ module Insights
2
+ module API
3
+ module Common
4
+ module OpenApi
5
+ module VersionFromPrefix
6
+ def api_version_from_prefix(prefix)
7
+ /\/?\w+\/v(?<major>\d+)[x\.]?(?<minor>\d+)?\// =~ prefix
8
+ [major, minor].compact.join(".")
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,7 +1,7 @@
1
1
  module Insights
2
2
  module API
3
3
  module Common
4
- VERSION = "4.0.3".freeze
4
+ VERSION = "4.1.0".freeze
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: insights-api-common
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.3
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Insights Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-13 00:00:00.000000000 Z
11
+ date: 2020-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: acts_as_tenant
@@ -292,16 +292,16 @@ dependencies:
292
292
  name: simplecov
293
293
  requirement: !ruby/object:Gem::Requirement
294
294
  requirements:
295
- - - ">="
295
+ - - "~>"
296
296
  - !ruby/object:Gem::Version
297
- version: '0'
297
+ version: 0.17.1
298
298
  type: :development
299
299
  prerelease: false
300
300
  version_requirements: !ruby/object:Gem::Requirement
301
301
  requirements:
302
- - - ">="
302
+ - - "~>"
303
303
  - !ruby/object:Gem::Version
304
- version: '0'
304
+ version: 0.17.1
305
305
  - !ruby/object:Gem::Dependency
306
306
  name: webmock
307
307
  requirement: !ruby/object:Gem::Requirement
@@ -371,6 +371,7 @@ files:
371
371
  - lib/insights/api/common/open_api/docs/object_definition.rb
372
372
  - lib/insights/api/common/open_api/generator.rb
373
373
  - lib/insights/api/common/open_api/serializer.rb
374
+ - lib/insights/api/common/open_api/version_from_prefix.rb
374
375
  - lib/insights/api/common/option_redirect_enhancements.rb
375
376
  - lib/insights/api/common/paginated_response.rb
376
377
  - lib/insights/api/common/paginated_response_v2.rb