uc3-dmp-dynamo 0.0.12 → 0.0.14

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: 5f56e8305a7c18d00f32d82320410ee3541d192cb8316387520905b157ef2722
4
- data.tar.gz: 62a8052686169fd3a52d8109df505a4a5121d02cf46dad79c654cd1ab04ae001
3
+ metadata.gz: 5b3ca3eccd4443fafe0bf8e1de30d2a1fe545c1dafd4669341777954b616cf6a
4
+ data.tar.gz: 8a44cfa0bbd402b7f20a416178a2d7e8d32c52b1f5d4fac9e2af0b4d5b5ddc63
5
5
  SHA512:
6
- metadata.gz: 51379653dd5cefcc664257775443fea34108378596dd40d43ae4e1ef58b1195557fc5ea548159364e88794836ecaa68a03871c2508e14265f03a240295794689
7
- data.tar.gz: 80e910684933726b0009f498f525d7053255221031f74fe7fe7421dc3fe5e41989ff14da3f72095f20cb93979b75cfb609b9c224b96c847b8cdf6c2d8648fc61
6
+ metadata.gz: 3dbba27e4b3401a2537150bb59e317c212fe9cc24f95069d08710edb0a783277364fbb3b15409f5df94d992e15c2aeb48fb5dc2979c87d917c3dbaf450c89281
7
+ data.tar.gz: 832be3a84f034edfd88571cc84d176505b43f2e6dcc6c774d94b9448ec57187a73501d6269b6f8eaea388daccdd8c130fb360b1943daa90d5e6bf3ff9c2e40a8
@@ -30,7 +30,7 @@ module Uc3DmpDynamo
30
30
 
31
31
  # Fetch a single item
32
32
  # rubocop:disable Metrics/AbcSize
33
- def get_item(key:, debug: false)
33
+ def get_item(key:, logger: nil)
34
34
  raise ClientError, MSG_INVALID_KEY unless key.is_a?(Hash) && !key[:PK].nil?
35
35
 
36
36
  resp = @connection.get_item(
@@ -40,11 +40,7 @@ module Uc3DmpDynamo
40
40
  return_consumed_capacity: debug ? 'TOTAL' : 'NONE' }
41
41
  )
42
42
 
43
- # If debug is enabled then write the response to the LogWriter
44
- if debug
45
- puts "#{SOURCE} => get_item - #{key}"
46
- puts resp[:item].first.inspect
47
- end
43
+ logger.debug(message: "#{SOURCE} fetched DMP ID: #{key}") if logger.respond_to?(:debug)
48
44
  resp[:item].is_a?(Array) ? resp[:item].first : resp[:item]
49
45
  rescue Aws::Errors::ServiceError => e
50
46
  raise ClientError, format(MSG_DYNAMO_ERROR, msg: e.message, trace: e.backtrace)
@@ -58,14 +54,14 @@ module Uc3DmpDynamo
58
54
  #
59
55
  # See the DynamoDB docs for examples of key_conditions and projection_expressions
60
56
  # rubocop:disable Metrics/AbcSize
61
- def query(args:, debug: false)
57
+ def query(args:, logger: nil)
62
58
  raise ClientError, MSG_INVALID_KEY unless args.is_a?(Hash) && args.fetch(:key_conditions, {}).any?
63
59
 
64
60
  hash = {
65
61
  table_name: @table,
66
62
  key_conditions: args[:key_conditions],
67
63
  consistent_read: false,
68
- return_consumed_capacity: debug ? 'TOTAL' : 'NONE'
64
+ return_consumed_capacity: logger&.level == 'debug' ? 'TOTAL' : 'NONE'
69
65
  }
70
66
  # Look for and add any other filtering or projection args
71
67
  %i[filter_expression expression_attribute_values projection_expression scan_index_forward].each do |key|
@@ -75,11 +71,7 @@ module Uc3DmpDynamo
75
71
  end
76
72
 
77
73
  resp = @connection.query(hash)
78
- # If debug is enabled then write the response to the LogWriter
79
- if debug
80
- puts "#{SOURCE} => query - args: #{hash.inspect}"
81
- puts resp.items.inspect
82
- end
74
+ logger.debug(message: "#{SOURCE} queried for: #{args}") if logger.respond_to?(:debug)
83
75
  return [] unless resp.items.any?
84
76
  return resp.items if resp.items.first.is_a?(Hash)
85
77
 
@@ -90,31 +82,25 @@ module Uc3DmpDynamo
90
82
  # rubocop:enable Metrics/AbcSize
91
83
 
92
84
  # Create/Update an item
93
- def put_item(json:, debug: false)
85
+ def put_item(json:, logger: nil)
94
86
  raise ClientError, MSG_INVALID_KEY unless json.is_a?(Hash) && !json['PK'].nil? && !json['SK'].nil?
95
87
 
96
88
  resp = @connection.put_item(
97
89
  { table_name: @table,
98
90
  item: json,
99
- consistent_read: false,
100
- return_consumed_capacity: debug ? 'TOTAL' : 'NONE'
91
+ return_consumed_capacity: logger&.level == 'debug' ? 'TOTAL' : 'NONE'
101
92
  }
102
93
  )
103
94
 
104
- # If debug is enabled then write the response to the LogWriter
105
- if debug
106
- puts "#{SOURCE} => put_item -"
107
- puts json
108
- puts resp.inspect
109
- end
95
+ logger.debug(message: "#{SOURCE} put_item DMP ID: #{json['PK']}", details: json) if logger.respond_to?(:debug)
110
96
  resp
111
97
  rescue Aws::Errors::ServiceError => e
112
98
  raise ClientError, format(MSG_DYNAMO_ERROR, msg: e.message, trace: e.backtrace)
113
99
  end
114
100
 
115
101
  # Delete an item
116
- def delete_item(p_key:, s_key:, debug: false)
117
- raise ClientError, MSG_INVALID_KEY unless json.is_a?(Hash) && !json['PK'].nil? && !json['SK'].nil?
102
+ def delete_item(p_key:, s_key:, logger: nil)
103
+ raise ClientError, MSG_INVALID_KEY if p_key.nil? || s_key.nil?
118
104
 
119
105
  resp = @connection.delete_item(
120
106
  {
@@ -125,12 +111,7 @@ module Uc3DmpDynamo
125
111
  }
126
112
  }
127
113
  )
128
- # If debug is enabled then write the response to the LogWriter
129
- if debug
130
- puts "#{SOURCE} => delete_item -"
131
- puts json
132
- puts resp.inspect
133
- end
114
+ logger.debug(message: "#{SOURCE} deleted PK: #{p_key}, SK: #{s_key}") if logger.respond_to?(:debug)
134
115
  resp
135
116
  end
136
117
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uc3DmpDynamo
4
- VERSION = '0.0.12'
4
+ VERSION = '0.0.14'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uc3-dmp-dynamo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Riley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-08 00:00:00.000000000 Z
11
+ date: 2023-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json