eco-helpers 2.1.2 → 2.1.4

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: 65d5ec6baab743f216afd4ca77a4d36f9a43a52e841f0c2ca9ef73f63e3423b1
4
- data.tar.gz: 5906de7dd2f2765c6222ac707b42b6b270914b40c964e7ba579966652a418e72
3
+ metadata.gz: ca676558c0e1a885b1f9e15d68e3c4f3688b90713c88182854b426a8ce1bf447
4
+ data.tar.gz: 41e8693e90664d7789040dd2dab66521e330693a9ae62f7bb5c5bc2dbd940911
5
5
  SHA512:
6
- metadata.gz: e0494e227d268046a78fb6bf2df120506056bf96bf09464816ebc3a2fb2e6907e89729ed9c9ab848d93bfb9b53bdcf7f3c220c60847ffb403e54f663eca4c3c6
7
- data.tar.gz: 26b09ee8c9eb63b9cd91772d55f1c52bdc941bff59e83da809d80272978eb8f62d687caf4417404a32d494e2853644b2e3532a151b81f001bc6b9b87f3263067
6
+ metadata.gz: 65b5157cc78ff3016f932283e2f0504e46681e15dc2acd902bb0e6188af98f5fe5271ad0db49a48fe969c642df3146daffeffcb0008dda3012433450dbbc1e87
7
+ data.tar.gz: 3a23f58986631f819b18bd8395ec92c321e9cb21bfde172a3e565df309cdad3b759d1d60f8c4bf52cff29332b49607f30afad19c90a80c5f9fb974637c3b218e
data/CHANGELOG.md CHANGED
@@ -1,12 +1,31 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [2.1.3] - 2022-09-xx
4
+ ## [2.1.5] - 2022-10-xx
5
5
 
6
6
  ### Added
7
7
  ### Changed
8
8
  ### Fixed
9
9
 
10
+ ## [2.1.4] - 2022-10-20
11
+
12
+ ### Added
13
+ - `Eco::API::Common::Session::Mailer#mail` added parameters `cc` and `bcc`
14
+
15
+ ## [2.1.3] - 2022-10-11
16
+
17
+ ### Added
18
+ - `Eco::API::UseCases::OozeSamples::OozeBaseCase`
19
+ - `with_fields`, `with_sections` and `add_field` accept an `entry` parameter
20
+ - also did some internal refactor
21
+
22
+ ### Changed
23
+ - Upgraded `ecoportal-api-v2` **gem**
24
+
25
+ ### Fixed
26
+ - `Eco::API::UseCases::OozeSamples::RegisterUpdateCase`
27
+ - account for stages with updates within same entry
28
+
10
29
  ## [2.1.2] - 2022-09-29
11
30
 
12
31
  ### Added
data/eco-helpers.gemspec CHANGED
@@ -31,7 +31,7 @@ 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.2', '< 0.10'
34
+ spec.add_dependency 'ecoportal-api-v2', '>= 0.9.3', '< 0.10'
35
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'
@@ -16,11 +16,9 @@ module Eco
16
16
  # @param to [String] destination email address
17
17
  # @param subject [String] subject of the email
18
18
  # @param body [String] `html` or plain text message
19
- def mail(to: nil, subject:, body:)
19
+ def mail(to: nil, subject:, body:, cc: nil, bcc: nil)
20
20
  ses.send_email(
21
- destination: {
22
- to_addresses: [fetch_to(to)].flatten,
23
- },
21
+ destination: fetch_destination(to: to, cc: cc, bcc: bcc),
24
22
  source: fetch_from,
25
23
  message: {
26
24
  subject: {
@@ -64,6 +62,15 @@ module Eco
64
62
  @enviro.config || {}
65
63
  end
66
64
 
65
+ def fetch_destination(to: nil, cc: nil, bcc: nil)
66
+ cc_to = [cc].flatten.compact.uniq
67
+ bcc_to = [bcc].flatten.compact.uniq
68
+ { to_addresses: [fetch_to(to)].flatten }.tap do |dest|
69
+ dest.merge!(cc_addresses: cc_to) unless cc_to.empty?
70
+ dest.merge!(bcc_addresses: bcc_to) unless bcc_to.empty?
71
+ end
72
+ end
73
+
67
74
  def fetch_to(value = nil)
68
75
  value || config.mailer.to
69
76
  end
@@ -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.2"
2
+ VERSION = "2.1.4"
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.2
4
+ version: 2.1.4
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.2
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.2
149
+ version: 0.9.3
150
150
  - - "<"
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0.10'