eco-helpers 2.1.1 → 2.1.3

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: 7b298bca88b1ee202218bf3e0ab5727db52d8893a4ea969deda1179198b02ddf
4
- data.tar.gz: dd183eb58a6481851fde1fe257217541a175b4524f61ed1c61c9dff131d484b5
3
+ metadata.gz: bd18bdf6133a2fa0ccc023a3bdf11140b9af98364bfa6327f171e93373ee51f0
4
+ data.tar.gz: 4918192e55fe12081ba8db062b2bdcaf8afd1058732a93d23cd1180015af623a
5
5
  SHA512:
6
- metadata.gz: 4d73a73a2dba773d09b83d0713e71f333f44e83acb51c5e6fbde83fbff60350c468ae5a79d60eaf4a9fd446b7416e5bd38ed181769e221df893b20b1a84afc50
7
- data.tar.gz: 7a157045ebf97b9d0b10dadc5f1951a4eed311cd03335ac9f9b85288ef4fe3aa71bb7939e2266f124a9ee6687076bc5fc0afbaecff213ed2af45f11988b6543f
6
+ metadata.gz: 8bdd14bfa761ce494c920bd4242d49b9bfb37eb91b2021a7f1d4799b10e09a3d0af66491aca287c8d15874d436a77e9e94e4b1237e3925795b48b2df7876ec92
7
+ data.tar.gz: 06cc22d088ef35c755ed554578c58357782443a48ba0542fe21c13dc332b87123fb244bd8f98f805e9801b011cec309e33166c57876c7456cb101bf1bbd37867
data/CHANGELOG.md CHANGED
@@ -1,13 +1,42 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [2.1.2] - 2022-09-xx
4
+ ## [2.1.4] - 2022-10-xx
5
5
 
6
6
  ### Added
7
7
  ### Changed
8
8
  ### Fixed
9
9
 
10
- ## [2.1.1] - 2022-09-xx
10
+ ## [2.1.3] - 2022-10-11
11
+
12
+ ### Added
13
+ - `Eco::API::UseCases::OozeSamples::OozeBaseCase`
14
+ - `with_fields`, `with_sections` and `add_field` accept an `entry` parameter
15
+ - also did some internal refactor
16
+
17
+ ### Changed
18
+ - Upgraded `ecoportal-api-v2` **gem**
19
+
20
+ ### Fixed
21
+ - `Eco::API::UseCases::OozeSamples::RegisterUpdateCase`
22
+ - account for stages with updates within same entry
23
+
24
+ ## [2.1.2] - 2022-09-29
25
+
26
+ ### Added
27
+ - `Ecoportal::API::Session::Config#live_tree` to retrieve the tagtree of the back-end
28
+ - Requires `graphql` connection parameters
29
+ - `Ecoportal::API::Session#live_tree` see above
30
+
31
+ ### Changed
32
+ - `Ecoportal::API::Session::Config#tagtree` to use `#live_tree` if there isn't a `tagtree.json` file
33
+ - upgraded **dependency** to `ecoportal-api-graphql` **gem**
34
+ - upgraded **dependency** to `ecoportal-api-v2` **gem**
35
+
36
+ ### Fixed
37
+ - `Ecoportal::API::Session::Config::API#version_available?` **typo**
38
+
39
+ ## [2.1.1] - 2022-09-26
11
40
 
12
41
  ### Added
13
42
  - `Eco::API::Session::Config::Api#version_available?` to know if a version is available for use
data/eco-helpers.gemspec CHANGED
@@ -31,8 +31,8 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency "redcarpet", ">= 3.5.1", "< 3.6"
32
32
 
33
33
  spec.add_dependency 'ecoportal-api', '>= 0.8.5', '< 0.9'
34
- spec.add_dependency 'ecoportal-api-v2', '>= 0.9.1', '< 0.10'
35
- spec.add_dependency 'ecoportal-api-graphql', '>= 0.1.9', '< 0.2'
34
+ spec.add_dependency 'ecoportal-api-v2', '>= 0.9.3', '< 0.10'
35
+ spec.add_dependency 'ecoportal-api-graphql', '>= 0.1.10', '< 0.2'
36
36
  spec.add_dependency 'aws-sdk-s3', '>= 1.83.0', '< 2'
37
37
  spec.add_dependency 'aws-sdk-ses', '>= 1.36.0', '< 2'
38
38
  spec.add_dependency 'dotenv', '>= 2.7.6', '< 2.8'
@@ -145,7 +145,7 @@ module Eco
145
145
 
146
146
  # @return [Boolean] whether or not `version` is available
147
147
  def version_available?(version)
148
- api_paramms?(version)
148
+ api_params?(version)
149
149
  end
150
150
 
151
151
  def version(value = nil)
@@ -228,6 +228,7 @@ module Eco
228
228
  org["tagtree"] = file
229
229
  end
230
230
 
231
+ # It uses the `tagtree.json` file and in its absence, if `graphql` enabled, the `life_tagtree`
231
232
  # @return [Eco::API::Organization::TagTree]
232
233
  def tagtree(enviro: nil)
233
234
  return @tagtree if instance_variable_defined?(:@tagtree) && @tagtree.enviro == enviro
@@ -235,6 +236,23 @@ module Eco
235
236
  tree = []
236
237
  tree = file_manager.load_json(tree_file) unless !tree_file
237
238
  @tagtree = Eco::API::Organization::TagTree.new(tree, enviro: enviro)
239
+ else
240
+ @tagtree = live_tree(enviro: enviro)
241
+ end
242
+ end
243
+
244
+ # It obtains the first of the live tagtree in the org
245
+ # @note it requires graphql connection configuration parameters
246
+ # @return [Eco::API::Organization::TagTree]
247
+ def live_tree(enviro: nil)
248
+ return @live_tree if instance_variable_defined?(:@live_tree) && @live_tree.enviro == enviro
249
+ if apis.active_api.version_available?(:graphql)
250
+ graphql = apis.api(version: :graphql)
251
+ if tree = graphql.currentOrganization.tagTrees.to_a.first.treeify
252
+ @live_tree = Eco::API::Organization::TagTree.new(tree, enviro: enviro)
253
+ else
254
+ @live_tree = nil
255
+ end
238
256
  end
239
257
  end
240
258
 
@@ -44,6 +44,11 @@ module Eco
44
44
  config.tagtree(enviro: enviro)
45
45
  end
46
46
 
47
+ # @see Eco::API::Session::Config#live_tree
48
+ def live_tree
49
+ config.live_tree
50
+ end
51
+
47
52
  # @see Eco::API::Session::Config#schemas
48
53
  def schemas
49
54
  config.schemas
@@ -46,30 +46,30 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
46
46
  ooze(ooze_id, stage_id: stage_id)
47
47
  end
48
48
 
49
- def add_field_by_doc(doc, section, after: nil, before: nil, side: :left)
49
+ def add_field_by_doc(doc, section, entry: target, after: nil, before: nil, side: :left)
50
50
  unless section.is_a?(Ecoportal::API::V2::Page::Section)
51
51
  raise "You need to specify a section for a new field. Given: #{section.class}"
52
52
  end
53
- target.components.add(doc: doc) do |field|
53
+ entry.components.add(doc: doc) do |field|
54
54
  section.add_component(field, after: after, before: before, side: side)
55
55
  end.tap do |field|
56
56
  yield(field) if block_given?
57
57
  end
58
58
  end
59
59
 
60
- def add_field(name, type, section, after: nil, before: nil, side: :left)
60
+ def add_field(name, type, section, entry: target, after: nil, before: nil, side: :left)
61
61
  unless section.is_a?(Ecoportal::API::V2::Page::Section)
62
62
  raise "You need to specify a section for a new field. Given: #{section.class}"
63
63
  end
64
- target.components.add(label: name, type: type) do |field|
64
+ entry.components.add(label: name, type: type) do |field|
65
65
  section.add_component(field, after: after, before: before, side: side)
66
66
  end.tap do |field|
67
67
  yield(field) if block_given?
68
68
  end
69
69
  end
70
70
 
71
- def with_fields(type: nil, label: nil)
72
- flds = target.components
71
+ def with_fields(entry = target, type: nil, label: nil)
72
+ flds = entry.components
73
73
  flds = flds.get_by_type(type) if type
74
74
  flds = flds.select do |fld|
75
75
  value = (label == :unnamed) ? nil : label
@@ -79,8 +79,8 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
79
79
  end
80
80
  end
81
81
 
82
- def with_sections(type: nil, heading: nil)
83
- secs = target.sections
82
+ def with_sections(entry = target, type: nil, heading: nil)
83
+ secs = entry.sections
84
84
  secs = secs.get_by_type(type) if type
85
85
  secs = secs.select do |sec|
86
86
  value = (heading == :unnamed) ? nil : heading
@@ -141,7 +141,10 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
141
141
  # It fill update the ooze only if it's dirty (it carries changes)
142
142
  # @return [Boolean, Response] `false` if there was not request against the server, `Response` otherwise
143
143
  def update_ooze(ooze = target)
144
- if !options[:simulate]
144
+ if options[:simulate]
145
+ dry_run_feedback(ooze)
146
+ false
147
+ else
145
148
  return false unless dirty?(ooze)
146
149
 
147
150
  ooze.validate.tap do |validation|
@@ -156,19 +159,6 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
156
159
  logger.error("Could not update #{object_reference(ooze)} (created_at: #{ooze.created_at}: #{response.body}")
157
160
  end
158
161
  end
159
- else
160
- ooze.validate.tap do |validation|
161
- logger.error(validation) if validation.is_a?(String)
162
- end
163
- unless options.dig(:feedback, :only_stats)
164
- if patch = (patch_doc(ooze) || {})["page"]
165
- pp patch
166
- end
167
- end
168
-
169
- backup_patch!(ooze)
170
- exit(0) if dirty?(ooze) && dry_count > DRY_COUNT
171
- false
172
162
  end
173
163
  end
174
164
 
@@ -204,6 +194,14 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
204
194
  puts "Saved patch at: #{File.expand_path(SAVE_PATCH)}"
205
195
  end
206
196
 
197
+ def display_patch(entry = target)
198
+ unless options.dig(:feedback, :only_stats)
199
+ if patch = (patch_doc(entry) || {})["page"]
200
+ pp patch
201
+ end
202
+ end
203
+ end
204
+
207
205
  def patch_doc(ooze = target)
208
206
  apiv2.pages.get_body(ooze)
209
207
  end
@@ -213,6 +211,19 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
213
211
  @dry_count += 1
214
212
  end
215
213
 
214
+ def dry_run_feedback(entry = target)
215
+ entry.validate.tap do |validation|
216
+ logger.error(validation) if validation.is_a?(String)
217
+ end
218
+ display_patch(entry)
219
+ backup_patch!(entry)
220
+ if dirty?(entry) && dry_count > self.class::DRY_COUNT
221
+ logger.info("Reached #{self.class::DRY_COUNT} dry-run samples.")
222
+ exit(0)
223
+ end
224
+ false
225
+ end
226
+
216
227
  def apiv2
217
228
  @apiv2 ||= session.api(version: :oozes)
218
229
  end
@@ -52,7 +52,15 @@ class Eco::API::UseCases::OozeSamples::RegisterUpdateCase < Eco::API::UseCases::
52
52
 
53
53
  def before_loading_new_target(ooze_id)
54
54
  if pending = queue_shift(ooze_id)
55
- update_ooze(pending)
55
+ update_ooze(pending).tap do |result|
56
+ if result.is_a?(Ecoportal::API::Common::Response)
57
+ if result.success?
58
+ @updated_oozes += 1
59
+ else
60
+ @failed_update_oozes +=1
61
+ end
62
+ end
63
+ end
56
64
  end
57
65
  end
58
66
 
data/lib/eco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "2.1.1"
2
+ VERSION = "2.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eco-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura
@@ -136,7 +136,7 @@ dependencies:
136
136
  requirements:
137
137
  - - ">="
138
138
  - !ruby/object:Gem::Version
139
- version: 0.9.1
139
+ version: 0.9.3
140
140
  - - "<"
141
141
  - !ruby/object:Gem::Version
142
142
  version: '0.10'
@@ -146,7 +146,7 @@ dependencies:
146
146
  requirements:
147
147
  - - ">="
148
148
  - !ruby/object:Gem::Version
149
- version: 0.9.1
149
+ version: 0.9.3
150
150
  - - "<"
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0.10'
@@ -156,7 +156,7 @@ dependencies:
156
156
  requirements:
157
157
  - - ">="
158
158
  - !ruby/object:Gem::Version
159
- version: 0.1.9
159
+ version: 0.1.10
160
160
  - - "<"
161
161
  - !ruby/object:Gem::Version
162
162
  version: '0.2'
@@ -166,7 +166,7 @@ dependencies:
166
166
  requirements:
167
167
  - - ">="
168
168
  - !ruby/object:Gem::Version
169
- version: 0.1.9
169
+ version: 0.1.10
170
170
  - - "<"
171
171
  - !ruby/object:Gem::Version
172
172
  version: '0.2'