uc3-dmp-dynamo 0.0.9 → 0.0.11

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: 6b054d85d718d47e62a50c5f227d5442a4467d235da417491d05e2100c4750eb
4
- data.tar.gz: 90e7d99d66f4bf219089c508b42cb7813d13f2d16cc8fd0fdb7662519234701f
3
+ metadata.gz: cafdf1d130211a041170de96bbb3fb658030f948391db697843433680f4d6971
4
+ data.tar.gz: f7e0e5317a22cb9efec2127332989e8b6465b599deee9a227cd31c3b2e705a2b
5
5
  SHA512:
6
- metadata.gz: 7f1aaa39b77ec58b14b7c0b395bf19a11719afb08a12e42d7cf1358143206aad955cf78694033511d6ea810e0b738179415e1cd3f6c5b52dd59e0f964904c5aa
7
- data.tar.gz: f16bba459f0226371303fb86132836c9576ad9af0b6224ecd18c19148b20cc301c9313f5a805d4674abc44f9de74e6f8dd1f8bb4f9dfd7340d4bb04304697cbe
6
+ metadata.gz: 3671178ca35799ab235a8f11065457b6fea2897fd32039f3c3d92ded435bedf236af2767790a4f80ef2c7c5bbf55ee00ac8671851bf15b612180ca89a7101084
7
+ data.tar.gz: a14e9969869432a435242e5d600eb3537e930f6cd548e9dbe5bca64bd9f706de7b359e3c5fe93d75a82835a4b8b96bc2a8b50b874f9d5e4b30bd443b63a37b5f
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # TODO: Be sure to update the API functions so that they call cleanse_dmp_json before
4
- # calling Uc3DmpApiCore::Responder.respond !!!!!!!!!!
5
-
6
3
  module Uc3DmpDynamo
7
4
  class ClientError < StandardError; end
8
5
 
@@ -23,6 +20,14 @@ module Uc3DmpDynamo
23
20
  @connection = Aws::DynamoDB::Client.new(region: ENV.fetch('AWS_REGION', 'us-west-2'))
24
21
  end
25
22
 
23
+ # Quick get_item that only returns the PK to validate that the item exists
24
+ def pk_exists?(key:)
25
+ return nil unless key.is_a?(Hash) && !key['PK'].nil?
26
+
27
+ resp = client.get_item(table_name: @table, key: key, projection_expression: 'PK')
28
+ resp.item.is_a?(Hash) && resp.item['PK'] == key['PK']
29
+ end
30
+
26
31
  # Fetch a single item
27
32
  # rubocop:disable Metrics/AbcSize
28
33
  def get_item(key:, debug: false)
@@ -83,5 +88,52 @@ module Uc3DmpDynamo
83
88
  raise ClientError, format(MSG_DYNAMO_ERROR, msg: e.message, trace: e.backtrace)
84
89
  end
85
90
  # rubocop:enable Metrics/AbcSize
91
+
92
+ # Create/Update an item
93
+ def put_item(json:, debug: false)
94
+ json = Helper.parse_json(json: json)
95
+ raise ClientError, MSG_INVALID_KEY unless json.is_a?(Hash) && !json['PK'].nil? && !json['SK'].nil?
96
+
97
+ resp = @connection.put_item(
98
+ { table_name: @table,
99
+ item: json,
100
+ consistent_read: false,
101
+ return_consumed_capacity: debug ? 'TOTAL' : 'NONE'
102
+ }
103
+ )
104
+
105
+ # If debug is enabled then write the response to the LogWriter
106
+ if debug
107
+ puts "#{SOURCE} => put_item -"
108
+ puts json
109
+ puts resp.inspect
110
+ end
111
+ resp
112
+ rescue Aws::Errors::ServiceError => e
113
+ raise ClientError, format(MSG_DYNAMO_ERROR, msg: e.message, trace: e.backtrace)
114
+ end
115
+
116
+ # Delete an item
117
+ def delete_item(p_key:, s_key:, debug: false)
118
+ json = Helper.parse_json(json: json)
119
+ raise ClientError, MSG_INVALID_KEY unless json.is_a?(Hash) && !json['PK'].nil? && !json['SK'].nil?
120
+
121
+ resp = @connection.delete_item(
122
+ {
123
+ table_name: @table,
124
+ key: {
125
+ PK: p_key,
126
+ SK: s_key
127
+ }
128
+ }
129
+ )
130
+ # If debug is enabled then write the response to the LogWriter
131
+ if debug
132
+ puts "#{SOURCE} => delete_item -"
133
+ puts json
134
+ puts resp.inspect
135
+ end
136
+ resp
137
+ end
86
138
  end
87
139
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uc3DmpDynamo
4
- VERSION = '0.0.9'
4
+ VERSION = '0.0.11'
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.9
4
+ version: 0.0.11
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-06 00:00:00.000000000 Z
11
+ date: 2023-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json