ecoportal-api-v2 0.8.22 → 0.8.23

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: d6699a6cd1b82c54b0bf097dde24c034b4b114faa6cf23a7765429c384d45b3d
4
- data.tar.gz: eef7fb625d8073d7de972f028fe9628886eb04e3b1eee6e9a8bf760170e64a1c
3
+ metadata.gz: 95c3cc7227186059ebac670bc0b3ba3637addab3f51dfe22d9303a27088cb2fd
4
+ data.tar.gz: 05c0ee0a0a548081136d328ef1b33a27d6ee4f029752a8a1f3c28308fd05ea82
5
5
  SHA512:
6
- metadata.gz: b6eb538df89c4d99b7715d23c75c3eea53a4ffbb3063c612a797a7aebe58f4e427393c410a10e7b67b3744f4986d550c24659ad4d17b9dd870d742f924c0d7c7
7
- data.tar.gz: 3da71eae2f509fa6a7afaf7b6744e18210741efddffa5f7d06858de091922f1dccbc64017be8dbc9b13bc8f6aaaaea4abb0b94b433f8a7bb178f07407268dd57
6
+ metadata.gz: 2ad708f7fcec88a0380997bbf493d2186b5853e1eb4884e62c1107a4116337c53939852f99ab3d7cedbf2dddceed5fca63531f985a32a3a67139e150c9b94e7d
7
+ data.tar.gz: aec3d7c8faa9cae78da045b34865da17a5ceb5b548fb9a66a1be51dc2448da92c150f528d9a9b62d1fdb93d1bfbeadbb7ff812ea02a9c7c0d6eb07aadb985f0d
data/CHANGELOG.md CHANGED
@@ -1,10 +1,16 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [0.8.22] - 2021-12-23
4
+ ## [0.8.23] - 2021-12-24
5
5
 
6
6
  ### Added
7
+ - `Ecoportal::API::V2::Registers#search` added more feedback on what is going on
8
+
7
9
  ### Changed
10
+ ### Fixed
11
+
12
+ ## [0.8.22] - 2021-12-23
13
+
8
14
  ### Fixed
9
15
  - `Ecoportal::API::V2::Page::Section#add_component` was not using correctly `before` and `after`
10
16
  - It was not correctly translating them into the existing component
@@ -49,7 +49,7 @@ module Ecoportal
49
49
  # Requests to update an existing page via api.
50
50
  # @note It won't launch the update unless there are changes
51
51
  # @param doc [Hash, Page] data that at least contains an `id` (internal or external) of the target page.
52
- # @return [Response] an object with the api response.
52
+ # @return [Ecoportal::API::Common::Response] an object with the api response.
53
53
  def update(doc)
54
54
  body = get_body(doc) # , level: "page"
55
55
  # Launch only if there are changes
@@ -1,3 +1,4 @@
1
+ require 'base64'
1
2
  module Ecoportal
2
3
  module API
3
4
  class V2
@@ -42,18 +43,7 @@ module Ecoportal
42
43
  # @return [Ecoportal::API::V2::Registers, Ecoportal::API::V2::Registers::SearchResults]
43
44
  def search(register_id, options = {})
44
45
  only_first = options.delete(:only_first)
45
- # supply a query string
46
- # or a filter array (copy/paste from dev tools in the browser)
47
- options = {query: nil, filters: []}.update(options)
48
- options = {}.tap do |ret|
49
- options.each do |key, value|
50
- if key == :filters && value.any?
51
- ret[key] = {filters: value}.to_json
52
- else
53
- ret[key] = value if key
54
- end
55
- end
56
- end
46
+ options = build_options(options)
57
47
 
58
48
  if only_first
59
49
  response = client.get("/registers/#{register_id}/search", params: options)
@@ -62,19 +52,23 @@ module Ecoportal
62
52
  end
63
53
 
64
54
  cursor_id = nil
65
- results = 0
55
+ results = 0; total = nil
66
56
  loop do
67
57
  options.update(cursor_id: cursor_id) if cursor_id
68
58
  response = client.get("/registers/#{register_id}/search", params: options)
69
59
  raise "Request failed - Status #{response.status}: #{response.body}" unless response.success?
70
60
 
71
- data = response.body["data"]
72
- unless (total = data["total"]) == 0
61
+ data = response.body["data"]
62
+ total ||= data["total"]
63
+ if total != data["total"]
64
+ msg = "Change of total in search results. Probably due to changes that affect the filter (register: #{register_id}):"
65
+ print_search_status(msg, total, results, cursor_id, data)
66
+ #total = data["total"]
67
+ end
68
+
69
+ unless total == 0
73
70
  results += data["results"].length
74
- percent = results * 100 / total
75
- msg = "Registers SEARCH"
76
- print "#{msg}: #{percent.round}% (of #{total})\r"
77
- $stdout.flush
71
+ print_progress(results, total)
78
72
  end
79
73
 
80
74
  data["results"].each do |result|
@@ -83,12 +77,50 @@ module Ecoportal
83
77
  end
84
78
 
85
79
  break if total <= results
80
+ unless data["cursor_id"]
81
+ msg = "Possible error... finishing search for lack of cursor_id in response:"
82
+ print_search_status(msg, total, results, cursor_id, data)
83
+ end
86
84
  break unless (cursor_id = data["cursor_id"])
87
85
  end
88
86
  self
89
87
  end
90
88
 
89
+ private
90
+
91
+ def build_options(options)
92
+ # supply a query string
93
+ # or a filter array (copy/paste from dev tools in the browser)
94
+ options = {query: nil, filters: []}.update(options)
95
+ {}.tap do |ret|
96
+ options.each do |key, value|
97
+ if key == :filters && value.any?
98
+ ret[key] = {filters: value}.to_json
99
+ else
100
+ ret[key] = value if key
101
+ end
102
+ end
103
+ end
104
+ end
105
+
106
+ def print_search_status(msg, total, results, cursor_id, data)
107
+ msg += "\n"
108
+ msg += " • Original total: #{total}\n"
109
+ msg += " • Total results retrieved: #{results}\n"
110
+ msg += " • Cursor id: #{cursor_id} (#{Base64.decode64(cursor_id)})\n"
111
+ msg += " • Current cursor results: #{data["results"]&.length}\n"
112
+ msg += " • Next id: #{data["cursor_id"]} (#{Base64.decode64(data["cursor_id"])})\n" if data["cursor_id"]
113
+ msg += " • Options:"
114
+ puts msg
115
+ pp options
116
+ end
91
117
 
118
+ def print_progress(results, total)
119
+ percent = results * 100 / total
120
+ msg = "Registers SEARCH"
121
+ print "#{msg}: #{percent.round}% (of #{total})\r"
122
+ $stdout.flush
123
+ end
92
124
  end
93
125
  end
94
126
  end
@@ -1,5 +1,5 @@
1
1
  module Ecoportal
2
2
  module API
3
- GEM2_VERSION = "0.8.22"
3
+ GEM2_VERSION = "0.8.23"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecoportal-api-v2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.22
4
+ version: 0.8.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-23 00:00:00.000000000 Z
11
+ date: 2021-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler