aws-dev-utils 1.4.9 → 1.5.0

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: 4687e761d49ec6e0b5c4c49e8a0eb2bbca0505940b309c5b62eb2b82413645d6
4
- data.tar.gz: 6916a3900eba9cef3409f86a0ec7eb0984eb0b631c18a1b18f617ad49070c6f9
3
+ metadata.gz: 0fa3a5f5b41c92caa60a64b79f2c1710d6600f0306e48ef33f9c338489b23a11
4
+ data.tar.gz: 5673be8d53221e6997e7eb0c68245481fefe7587352f40b329820a7aa88a2cd0
5
5
  SHA512:
6
- metadata.gz: 472cbb329917024f484fc736d7226b5e4e6207ec3d9223e4df1d9c5a619a882f7dfcbc612a26e87a689ad3b781a75bfb36bc47410bf88a84b4381be9317a0a7d
7
- data.tar.gz: d2403e51af30fb2c4205305fbe8c258b03bbcb1cd080ffa726f20ffa6006ac9b0ff731af0f3a991f0cf8c5da93f3d95c5e9c402db25051d4a7e075f240edc4d5
6
+ metadata.gz: c4c426208915958d31aa394852de7c4bb6998c6e93a3e8562db7c8a84a38f65b3f481fbc16bbd45f658450f3a960873b0a16be76de21cf7949f92f49cd452a8a
7
+ data.tar.gz: '08febba1667d5f9865980fc6161bdd70b620586d9acbb2409c6f7b6b0c6481c7301267fd87a7c4ebb76c58c97427e67b8d4747a7a41fa35952e9ee9699365a88'
data/README.md CHANGED
@@ -9,7 +9,7 @@ AWS Dev Utilities is available from RubyGems.
9
9
  ### Option 1: Via Bundler
10
10
  Add the following to your application's Gemfile:
11
11
  ```ruby
12
- gem 'aws-dev-utils', '~> 1.4'
12
+ gem 'aws-dev-utils', '~> 1.5'
13
13
  ```
14
14
  And then execute:
15
15
  ```
@@ -18,7 +18,7 @@ $ bundle install
18
18
  ### Option 2: Via `gem install`
19
19
  Execute the following inside your application directory:
20
20
  ```
21
- $ gem install aws-dev-utils -v '~> 1.4'
21
+ $ gem install aws-dev-utils -v '~> 1.5'
22
22
  ```
23
23
  ## Usage
24
24
  Add the following at the top of each Ruby script, or in each module/class you want to use the `with_next_token`, `with_cache` or `with_retry` functions:
@@ -32,7 +32,7 @@ Many AWS operations limit the number of results returned with each response. To
32
32
  This functionality is rarely needed and causes a lot of boilerplate code.
33
33
  Using the `client.with_next_token` the paged results will be collected for you.
34
34
  The AWS client function and its results will be concatenated until either no more results are available or the max number of requests is reached.
35
- _`with_next_token` works with APIs that use `next_token`, `next_marker` or `next_continuation_token`._
35
+ _`with_next_token` works with APIs that use `next_token`, `next_marker`, `next_continuation_token` or `next_record_name`._
36
36
 
37
37
  ```ruby
38
38
  require 'aws-dev-utils'
@@ -14,7 +14,7 @@ module AwsDevUtils
14
14
  end
15
15
 
16
16
  # @return ClientWrapper with next_token option
17
- def with_next_token max=100
17
+ def with_next_token max=NextTokenWrapper::DEFAULT_MAX
18
18
  self.class.new(@client, @options.merge(next_token: max))
19
19
  end
20
20
 
@@ -1,42 +1,53 @@
1
1
  module AwsDevUtils
2
2
  class NextTokenWrapper
3
3
 
4
+ DEFAULT_MAX=100
5
+
4
6
  # Initialize a new NextTokenWrapper, internal use only
5
7
  # @params client [Aws client / NextTokenWrapper / RetryWrapper]
6
8
  # @param max [Integer] - max number of requests
7
- def initialize client, max=100
9
+ def initialize client, max=DEFAULT_MAX
8
10
  @client = client
9
11
  @max = max
10
12
  end
11
13
 
12
- def method_missing m, *args, &block
13
- do_call(m,*args,&block)
14
+ def method_missing method, *args, &block
15
+ do_call(method, *args, &block)
14
16
  end
15
17
 
16
18
  private
19
+ def do_call method, *args, &block
20
+ response = @client.send(method, *args, &block).to_h
21
+ i = 1
22
+ req_keys, next_req_keys = extract_keys response
23
+
24
+ return response if req_keys.nil?
25
+
26
+ props = args.first || {}
27
+ while req_keys.all?{ |req_keys| response[req_keys] } && i < @max do
28
+ i += 1
29
+ pagination_token_props = Hash[next_req_keys.zip(req_keys.map { |req_keys| response[req_keys] } ) ]
30
+ new_response = @client.send(method, props.merge(pagination_token_props)).to_h
17
31
 
18
- def do_call m, *args, &block
19
- @client.send(m , *args, &block).to_h.tap do |r|
20
- i = 1
21
- key, key2 = extract_keys r
22
- while(key && r[key] && i < @max) do
23
- i += 1
24
- res = @client.send(m, (args[0]||{}).merge(key2 => r[key])).to_h
25
- res.each { |k,v| r[k] = v.is_a?(Array) ? r[k].concat(v) : v }
26
- r.delete_if {|k,v| !res.keys.include?(k) }
27
- end
28
- r.delete key
32
+ new_response.each { |k,v| new_response[k] = v.is_a?(Array) ? response[k]+new_response[k] : v }
33
+
34
+ response = new_response
29
35
  end
36
+
37
+ req_keys.each { |req_keys| response.delete req_keys}
38
+ response
30
39
  end
31
40
 
32
- def extract_keys x
41
+ def extract_keys response
33
42
  case
34
- when x[:next_token]
35
- [:next_token, :next_token]
36
- when x[:next_marker]
37
- [:next_marker, :marker]
38
- when x[:next_continuation_token]
39
- [:next_continuation_token, :continuation_token]
43
+ when response[:next_token]
44
+ [[:next_token], [:next_token]]
45
+ when response[:next_marker]
46
+ [[:next_marker], [:marker]]
47
+ when response[:next_continuation_token]
48
+ [[:next_continuation_token], [:continuation_token]]
49
+ when response[:next_record_name]
50
+ [[:next_record_type, :next_record_name], [:start_record_type, :start_record_name]]
40
51
  else nil
41
52
  end
42
53
  end
@@ -5,7 +5,8 @@ module AwsDevUtils
5
5
 
6
6
  refine Seahorse::Client::Base do
7
7
  def with_next_token *args
8
- AwsDevUtils::ClientWrapper.new(self).yield_self { |c| c.send(__callee__, *args) }
8
+ c = AwsDevUtils::ClientWrapper.new(self)
9
+ c.send(__callee__, *args)
9
10
  end
10
11
  alias_method :with_retry, :with_next_token
11
12
  alias_method :with_cache, :with_next_token
@@ -1,3 +1,3 @@
1
1
  module AwsDevUtils
2
- VERSION = '1.4.9'
2
+ VERSION = '1.5.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-dev-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.9
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amobee BI Infrastructure
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-22 00:00:00.000000000 Z
11
+ date: 2021-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-core
@@ -70,14 +70,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
70
  requirements:
71
71
  - - ">="
72
72
  - !ruby/object:Gem::Version
73
- version: 2.5.0
73
+ version: 2.3.0
74
74
  required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  requirements:
76
76
  - - ">="
77
77
  - !ruby/object:Gem::Version
78
78
  version: '0'
79
79
  requirements: []
80
- rubygems_version: 3.0.8
80
+ rubygems_version: 3.0.9
81
81
  signing_key:
82
82
  specification_version: 4
83
83
  summary: Ruby library gem that provides common AWS utilities