uc3-dmp-dynamo 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/uc3-dmp-dynamo/client.rb +19 -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: c011576d2723217aae4d7342bf91a859257e4216bd5206e044adf24bb29f7690
|
4
|
+
data.tar.gz: da6fa2f726afbfb00c0d55b331b014b29eb52369982ee6298b51c8b9d80ca979
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b267194e66c9970735c40bcd0146f0124d5692ea083954656826dd18a17d043a5b440c76d9d6c1444a6dcd473f7207b685603942bc32e0fa83042d14125080f1
|
7
|
+
data.tar.gz: 7ae5ef0d23a3d409075f885657898a3f720eaf0e4aef102af9b0fa881c40e48aa41b98adc971b1c40519884e4934028d3f3390f26d11f060b9d4b67ddbf3db52
|
@@ -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,13 @@ 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
|
-
resp.items
|
78
|
+
resp.items.any? ? resp.items.map(&:item) : []
|
80
79
|
rescue Aws::Errors::ServiceError => e
|
81
|
-
raise
|
80
|
+
raise ClientError, format(MSG_DYNAMO_ERROR, msg: e.message, trace: e.backtrace)
|
82
81
|
end
|
82
|
+
# rubocop:enable Metrics/AbcSize
|
83
83
|
end
|
84
84
|
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.5
|
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-05-
|
11
|
+
date: 2023-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|