uc3-dmp-dynamo 0.0.13 → 0.0.15

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: 0f311e0dd14cdcdf67fbd1742427a4c0fd93857e7587fe27938788fef0f5b125
4
- data.tar.gz: 41fb20ad5923eed5bc661e50bea069b88401d31ff4a60bbd2a2cb719cd0c6a27
3
+ metadata.gz: 0e232855e0dddf52bce679e4128755c52ad6b168c76ee8e95024cf552756796d
4
+ data.tar.gz: 6bb543acf5b330f2cd69e929fea73f9c855586e88a46d3f5a62451f78ab0e782
5
5
  SHA512:
6
- metadata.gz: 8098da3523121f55f043b031d3167e3adce5f09c64dd4baf58f471711bd8d22c28e29033716f09bd09dc432adfb836c621a04d3610cc120f57517c39a2522cdb
7
- data.tar.gz: 4dc5945515c0a6ff117e7e378bc32e98345d42f692504d146208fcd77cce92bb9910a348acbf4af4fba4f77062cc6d86d3dfec7312a971413f09b130300ec6ac
6
+ metadata.gz: 4d72c2ebab13c2abe974e6849a8209e5b836c05cb091885be47b800e0183e335ece6df20d263e5437262f077f396c205fab68ff272868c99d67d99140efd57e8
7
+ data.tar.gz: ce129bdb743e76939d465dff87c3e8e45b0b8954d5ada0218e304c4a8719bf9bbd6f9165a2ea6b7d553b85df21e9deaa3da7dbee3b553e4208999b64f3530f78
@@ -30,21 +30,17 @@ 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(
37
37
  { table_name: @table,
38
38
  key: key,
39
39
  consistent_read: false,
40
- return_consumed_capacity: debug ? 'TOTAL' : 'NONE' }
40
+ return_consumed_capacity: logger&.level == '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,30 +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
- return_consumed_capacity: debug ? 'TOTAL' : 'NONE'
91
+ return_consumed_capacity: logger&.level == 'debug' ? 'TOTAL' : 'NONE'
100
92
  }
101
93
  )
102
94
 
103
- # If debug is enabled then write the response to the LogWriter
104
- if debug
105
- puts "#{SOURCE} => put_item -"
106
- puts json
107
- puts resp.inspect
108
- end
95
+ logger.debug(message: "#{SOURCE} put_item DMP ID: #{json['PK']}", details: json) if logger.respond_to?(:debug)
109
96
  resp
110
97
  rescue Aws::Errors::ServiceError => e
111
98
  raise ClientError, format(MSG_DYNAMO_ERROR, msg: e.message, trace: e.backtrace)
112
99
  end
113
100
 
114
101
  # Delete an item
115
- def delete_item(p_key:, s_key:, debug: false)
116
- 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?
117
104
 
118
105
  resp = @connection.delete_item(
119
106
  {
@@ -124,12 +111,7 @@ module Uc3DmpDynamo
124
111
  }
125
112
  }
126
113
  )
127
- # If debug is enabled then write the response to the LogWriter
128
- if debug
129
- puts "#{SOURCE} => delete_item -"
130
- puts json
131
- puts resp.inspect
132
- end
114
+ logger.debug(message: "#{SOURCE} deleted PK: #{p_key}, SK: #{s_key}") if logger.respond_to?(:debug)
133
115
  resp
134
116
  end
135
117
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uc3DmpDynamo
4
- VERSION = '0.0.13'
4
+ VERSION = '0.0.15'
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.13
4
+ version: 0.0.15
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-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json