uc3-dmp-dynamo 0.0.4 → 0.0.6
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 +4 -4
- data/lib/uc3-dmp-dynamo/client.rb +23 -19
- data/lib/uc3-dmp-dynamo/version.rb +1 -1
- data/lib/uc3-dmp-dynamo.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0b0c89e4e576fc8416abb7a2b1f8d131bc5b75107c387a81d7f60e416ef0887
|
4
|
+
data.tar.gz: 3a278bf8304c366ee9ec4768e174b5918d4958c008d8106e58166dfac9a30892
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84fc086e335afb9eed5c8acf57987658bd2580baf2dfa8bcb3edd44d0bdb0d38e0e8d68800e0ec3530706039894984af6bac882548389fa4c8139d915330081d
|
7
|
+
data.tar.gz: 1e1a9900aadbd51119408dfdfa0de0d66b0eb1cf588de109222587c7e63581f8bca87b9c6e5c1cb2b9c184c11d6316d7bb4ae6a661b550c03b81f2a790aeac18
|
@@ -1,12 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
3
|
# TODO: Be sure to update the API functions so that they call cleanse_dmp_json before
|
5
4
|
# calling Uc3DmpApiCore::Responder.respond !!!!!!!!!!
|
6
5
|
|
7
|
-
|
8
6
|
module Uc3DmpDynamo
|
9
|
-
class
|
7
|
+
class ClientError < StandardError; end
|
10
8
|
|
11
9
|
# Helper functions for working with Dynamo JSON
|
12
10
|
class Client
|
@@ -18,33 +16,35 @@ module Uc3DmpDynamo
|
|
18
16
|
|
19
17
|
attr_accessor :connection, :table
|
20
18
|
|
21
|
-
def initialize(**
|
22
|
-
@table = ENV
|
23
|
-
raise
|
19
|
+
def initialize(**_args)
|
20
|
+
@table = ENV.fetch('DYNAMO_TABLE', nil)
|
21
|
+
raise ClientError, MSG_MISSING_TABLE if @table.nil?
|
24
22
|
|
25
23
|
@connection = Aws::DynamoDB::Client.new(region: ENV.fetch('AWS_REGION', 'us-west-2'))
|
26
24
|
end
|
27
25
|
|
28
26
|
# Fetch a single item
|
27
|
+
# rubocop:disable Metrics/AbcSize
|
29
28
|
def get_item(key:, debug: false)
|
30
|
-
raise
|
29
|
+
raise ClientError, MSG_INVALID_KEY unless key.is_a?(Hash) && !key[:PK].nil?
|
31
30
|
|
32
31
|
resp = @connection.get_item(
|
33
32
|
{ table_name: @table,
|
34
33
|
key: key,
|
35
34
|
consistent_read: false,
|
36
|
-
return_consumed_capacity: debug ? 'TOTAL' : 'NONE'
|
37
|
-
}
|
35
|
+
return_consumed_capacity: debug ? 'TOTAL' : 'NONE' }
|
38
36
|
)
|
37
|
+
|
39
38
|
# If debug is enabled then write the response to the LogWriter
|
40
39
|
if debug
|
41
40
|
puts "#{SOURCE} => get_item - #{key}"
|
42
41
|
puts resp[:item].first.inspect
|
43
42
|
end
|
44
|
-
resp[:item].first
|
43
|
+
resp[:item].is_a?(Array) ? resp[:item].first : resp[:item]
|
45
44
|
rescue Aws::Errors::ServiceError => e
|
46
|
-
raise
|
45
|
+
raise ClientError, format(MSG_DYNAMO_ERROR, msg: e.message, trace: e.backtrace)
|
47
46
|
end
|
47
|
+
# rubocop:enable Metrics/AbcSize
|
48
48
|
|
49
49
|
# Perform a table scan if a filter was specified.
|
50
50
|
# For example:
|
@@ -52,9 +52,9 @@ module Uc3DmpDynamo
|
|
52
52
|
# projection_expression: 'title, dmp_id, modified'
|
53
53
|
#
|
54
54
|
# See the DynamoDB docs for examples of key_conditions and projection_expressions
|
55
|
-
|
56
|
-
|
57
|
-
|
55
|
+
# rubocop:disable Metrics/AbcSize
|
56
|
+
def query(args:, debug: false)
|
57
|
+
raise ClientError, MSG_INVALID_KEY unless args.is_a?(Hash) && args.fetch(:key_conditions, {}).any?
|
58
58
|
|
59
59
|
hash = {
|
60
60
|
table_name: @table,
|
@@ -63,7 +63,7 @@ module Uc3DmpDynamo
|
|
63
63
|
return_consumed_capacity: debug ? 'TOTAL' : 'NONE'
|
64
64
|
}
|
65
65
|
# Look for and add any other filtering or projection args
|
66
|
-
%i[filter_expression
|
66
|
+
%i[filter_expression expression_attribute_values projection_expression scan_index_forward].each do |key|
|
67
67
|
next if args[key.to_sym].nil?
|
68
68
|
|
69
69
|
hash[key.to_sym] = args[key.to_sym]
|
@@ -72,13 +72,17 @@ module Uc3DmpDynamo
|
|
72
72
|
resp = @connection.query(hash)
|
73
73
|
# If debug is enabled then write the response to the LogWriter
|
74
74
|
if debug
|
75
|
-
|
76
|
-
puts "#{SOURCE} => query - args: #{args.inspect}"
|
75
|
+
puts "#{SOURCE} => query - args: #{hash.inspect}"
|
77
76
|
puts resp.items.inspect
|
78
77
|
end
|
79
|
-
|
78
|
+
|
79
|
+
puts "QUERY RESULT:"
|
80
|
+
puts resp.items.first.inspect
|
81
|
+
|
82
|
+
resp.items.any? ? resp.items.map(&:item) : []
|
80
83
|
rescue Aws::Errors::ServiceError => e
|
81
|
-
raise
|
84
|
+
raise ClientError, format(MSG_DYNAMO_ERROR, msg: e.message, trace: e.backtrace)
|
82
85
|
end
|
86
|
+
# rubocop:enable Metrics/AbcSize
|
83
87
|
end
|
84
88
|
end
|
data/lib/uc3-dmp-dynamo.rb
CHANGED
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.
|
4
|
+
version: 0.0.6
|
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-
|
11
|
+
date: 2023-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|