uc3-dmp-dynamo 0.0.13 → 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: 0f311e0dd14cdcdf67fbd1742427a4c0fd93857e7587fe27938788fef0f5b125
4
- data.tar.gz: 41fb20ad5923eed5bc661e50bea069b88401d31ff4a60bbd2a2cb719cd0c6a27
3
+ metadata.gz: 5b3ca3eccd4443fafe0bf8e1de30d2a1fe545c1dafd4669341777954b616cf6a
4
+ data.tar.gz: 8a44cfa0bbd402b7f20a416178a2d7e8d32c52b1f5d4fac9e2af0b4d5b5ddc63
5
5
  SHA512:
6
- metadata.gz: 8098da3523121f55f043b031d3167e3adce5f09c64dd4baf58f471711bd8d22c28e29033716f09bd09dc432adfb836c621a04d3610cc120f57517c39a2522cdb
7
- data.tar.gz: 4dc5945515c0a6ff117e7e378bc32e98345d42f692504d146208fcd77cce92bb9910a348acbf4af4fba4f77062cc6d86d3dfec7312a971413f09b130300ec6ac
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,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.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.13
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