ecoportal-api 0.10.6 → 0.10.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae05088d3d0542b2200a614b0043d8580cd713cbfcf4fb473b17be4f1930aafe
4
- data.tar.gz: 90259cfa1c993c457b2bcfcd57d343538c7bf4f3746b21c921eb1be3e92dc370
3
+ metadata.gz: e7809f3ff8865db913a9f1c26d2884057d4f9a585d4919d17a61326e264ebe12
4
+ data.tar.gz: 8816f23d52faf898a04f80c8ba283cf428684d5b3ad67cddbb7178c1280e81e2
5
5
  SHA512:
6
- metadata.gz: '058bd304110936dc08ee37c77c081b65fc08b68a29f60ff74ead0798e0894100a26f6a85b60ce4d38c447d74707f78eec55a69755002ec10c6b36b98f4db8b67'
7
- data.tar.gz: 7340fe5e7875a9a2b3aefda197927fbfe733299c0dc0494b3b09b59db24ae7bac80b135ea0fb9fd1d7b5abc1ed246a715e3f3b14ee5d26e45a8bef2f14017815
6
+ metadata.gz: d6eb969d3965fc9d86eacd1fa941178ca678b81ab528aa5c0b703bdec2a27866f191172d5f077fcc77638f6a39faeb03ab9394a8a901ca8dee5f65b5ae1c9003
7
+ data.tar.gz: 22ed539fbf7cae6d9336efc1b0816d3142c4fe6f6155a8e0d57a986c199b668bf67e3b3481c91889ff8aa99b70168316be195d2fa0f3d371e9a310d015305135
data/CHANGELOG.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
- ## [0.10.7] - 2024-10-xx
5
+ ## [0.10.9] - 2024-12-xx
6
6
 
7
7
  ### Added
8
8
 
@@ -10,6 +10,30 @@ All notable changes to this project will be documented in this file.
10
10
 
11
11
  ### Fixed
12
12
 
13
+ ## [0.10.8] - 2024-12-xx
14
+
15
+ ### Changed
16
+
17
+ - `Ecoportal::API::Common::BaseModel` tidy up code
18
+
19
+ ### Fixed
20
+
21
+ - `Ecoportal::API::V1::Job::Awaiter::Timer#time_left`
22
+ - To include `time_left_to_start` when not started.
23
+ - Remove call to `byebug`
24
+
25
+ ## [0.10.7] - 2024-11-21
26
+
27
+ ### Changed
28
+
29
+ - Remove unused code
30
+ - `Ecoportal::API::Common::Client.new` the `version` argument doesn't default to `v1` but to `nil`.
31
+
32
+ ### Fixed
33
+
34
+ - A couple of errors
35
+ - Remove missing api key error log when no client `version` is specified.
36
+
13
37
  ## [0.10.6] - 2024-10-28
14
38
 
15
39
  ### Added
@@ -17,9 +17,11 @@ module Ecoportal
17
17
  def passthrough(*methods, to: :doc)
18
18
  methods.each do |method|
19
19
  method = method.to_s
20
+
20
21
  define_method method do
21
22
  send(to)[method]
22
23
  end
24
+
23
25
  define_method "#{method}=" do |value|
24
26
  send(to)[method] = value
25
27
  end
@@ -36,6 +38,7 @@ module Ecoportal
36
38
  value = instance_variable_get(var)
37
39
  return value unless nullable
38
40
  return value if (value && doc[key]) || (!value && !doc[key])
41
+
39
42
  remove_instance_variable(var)
40
43
  end
41
44
 
@@ -44,8 +47,12 @@ module Ecoportal
44
47
  return instance_variable_set(var, nil) unless doc[key]
45
48
 
46
49
  self.class.resolve_class(klass).new(
47
- doc[key], parent: self, key: key
48
- ).tap {|obj| instance_variable_set(var, obj)}
50
+ doc[key],
51
+ parent: self,
52
+ key: key
53
+ ).tap do |obj|
54
+ instance_variable_set(var, obj)
55
+ end
49
56
  end
50
57
  end
51
58
  end
@@ -119,12 +126,16 @@ module Ecoportal
119
126
  end
120
127
 
121
128
  def dirty?
122
- as_update != {}
129
+ return false unless (json = as_update)
130
+ return false unless json.is_a?(Hash)
131
+
132
+ !json.empty?
123
133
  end
124
134
 
125
135
  # It consolidates all the changes carried by `doc` by setting it as `original_doc`.
126
136
  def consolidate!
127
- raise UnlinkedModel.new(from: "#{self.class}#consolidate!", key: _key) unless linked?
137
+ err = UnlinkedModel.new(from: "#{self.class}##{__method__}", key: _key)
138
+ raise err unless linked?
128
139
 
129
140
  new_doc = JSON.parse(doc.to_json)
130
141
  if is_root?
@@ -143,7 +154,9 @@ module Ecoportal
143
154
  def reset!(key = nil) # rubocop:disable Metrics/AbcSize>
144
155
  msg = "'key' should be a String. Given #{key}"
145
156
  raise ArgumentError, msg unless !key || key.is_a?(String)
146
- raise UnlinkedModel.new(from: "#{self.class}#reset!", key: _key) unless linked?
157
+
158
+ err = UnlinkedModel.new(from: "#{self.class}##{__method__}", key: _key)
159
+ raise err unless linked?
147
160
 
148
161
  if key
149
162
  if respond_to?(key) && (child = send(key)) && child.is_a?(Ecoportal::API::Common::BaseModel)
@@ -156,6 +169,7 @@ module Ecoportal
156
169
  end
157
170
  else
158
171
  new_doc = JSON.parse(original_doc.to_json)
172
+
159
173
  if is_root?
160
174
  @doc = new_doc
161
175
  else
@@ -61,10 +61,10 @@ module Ecoportal
61
61
  }.tap do |options|
62
62
  # next unless false
63
63
 
64
- options.merge!({
65
- log_level: Logger::DEBUG,
66
- log_path: File.join(__dir__, "elastic_apm.log")
67
- })
64
+ # options.merge!({
65
+ # log_level: ::Logger::DEBUG,
66
+ # log_path: File.join('log', "elastic_apm.log")
67
+ # })
68
68
  end
69
69
  end
70
70
 
@@ -28,7 +28,7 @@ module Ecoportal
28
28
  msg = "Received non json body in response "
29
29
  msg << "(#{response.src_body.class}):\n "
30
30
  msg << response.src_body
31
- puts
31
+ puts msg
32
32
  end
33
33
  end
34
34
  end
@@ -47,7 +47,7 @@ module Ecoportal
47
47
  log_unexpected_server_error(response)
48
48
 
49
49
  msg = "Got server error (#{response.status}): #{response.body}\n"
50
- msg << "Going to retry (##{i} of #{attempts})"
50
+ msg << "Going to retry (##{i + 1} of #{attempts})"
51
51
  log(:debug) { msg }
52
52
 
53
53
  sleep(delay) if i < attempts
@@ -39,7 +39,7 @@ module Ecoportal
39
39
  # @param logger [Logger] an object with `Logger` interface to generate logs.
40
40
  # @param deep_logging [Boolean] whether or not batch responses should be logged
41
41
  # @return [Client] an object that holds the configuration of the api connection.
42
- def initialize(api_key:, version: "v1", host: DEFAULT_HOST, logger: nil, deep_logging: false)
42
+ def initialize(api_key:, version: nil, host: DEFAULT_HOST, logger: nil, deep_logging: false)
43
43
  @version = version
44
44
  @api_key = api_key
45
45
  @logger = logger
@@ -59,6 +59,7 @@ module Ecoportal
59
59
  end
60
60
 
61
61
  return unless @api_key.nil? || @api_key.match(/\A\W*\z/)
62
+ return unless version
62
63
 
63
64
  log(:error) { "Api-key missing!" }
64
65
  end
@@ -2,7 +2,6 @@ module Ecoportal
2
2
  module API
3
3
  module Common
4
4
  module DocHelpers
5
-
6
5
  def get_body(doc)
7
6
  if doc.respond_to?(:as_update)
8
7
  doc.as_update
@@ -21,11 +21,7 @@ module Ecoportal
21
21
  end
22
22
 
23
23
  alias_method :original_start, :start
24
- # `start` time only counts from the moment that
25
- # it already started to progress
26
24
  def start
27
- return timestamp unless lstatus&.started?
28
-
29
25
  original_start || timestamp
30
26
  end
31
27
 
@@ -76,6 +72,10 @@ module Ecoportal
76
72
  end
77
73
 
78
74
  def time_left
75
+ (timeout_in - waited).round(2)
76
+ end
77
+
78
+ def time_left_total
79
79
  (timeout - waited).round(2)
80
80
  end
81
81
 
@@ -86,7 +86,7 @@ module Ecoportal
86
86
  end
87
87
 
88
88
  def timeout_in
89
- return time_left if started?
89
+ return time_left_total if started?
90
90
 
91
91
  time_left_to_start
92
92
  end
@@ -94,7 +94,7 @@ module Ecoportal
94
94
  # timeout library is evil. So we make poor-man timeout.
95
95
  # https://jvns.ca/blog/2015/11/27/why-rubys-timeout-is-dangerous-and-thread-dot-raise-is-terrifying/
96
96
  def timeout?
97
- !time_left.positive?
97
+ !time_left_total.positive?
98
98
  end
99
99
 
100
100
  def start_timeout?
@@ -140,7 +140,8 @@ module Ecoportal
140
140
  %i[total timeout start].each_with_object({}) do |key, kargs|
141
141
  kargs[key] = send(key)
142
142
  end.tap do |kargs|
143
- kargs[:start] = timestamp
143
+ kargs[:start] = start
144
+ kargs[:last] = timestamp
144
145
  kargs[:lstatus] = status
145
146
  end
146
147
  end
@@ -1,5 +1,5 @@
1
1
  module Ecoportal
2
2
  module API
3
- VERSION = '0.10.6'.freeze
3
+ VERSION = '0.10.8'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecoportal-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.6
4
+ version: 0.10.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tapio Saarinen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-10-28 00:00:00.000000000 Z
11
+ date: 2024-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -289,7 +289,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
289
289
  - !ruby/object:Gem::Version
290
290
  version: '0'
291
291
  requirements: []
292
- rubygems_version: 3.5.18
292
+ rubygems_version: 3.5.23
293
293
  signing_key:
294
294
  specification_version: 4
295
295
  summary: A collection of helpers for interacting with the ecoPortal MS's various APIs