ecoportal-api 0.6.0 → 0.7.4
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 +4 -4
- data/CHANGELOG.md +68 -1
- data/ecoportal-api.gemspec +1 -1
- data/lib/ecoportal/api.rb +1 -0
- data/lib/ecoportal/api/common/base_model.rb +4 -4
- data/lib/ecoportal/api/common/client.rb +9 -2
- data/lib/ecoportal/api/internal/account.rb +49 -0
- data/lib/ecoportal/api/internal/permissions.rb +3 -2
- data/lib/ecoportal/api/v1/people.rb +20 -7
- data/lib/ecoportal/api/v1/person.rb +18 -2
- data/lib/ecoportal/api/v2.rb +47 -0
- data/lib/ecoportal/api/v2/field.rb +9 -0
- data/lib/ecoportal/api/v2/page.rb +30 -0
- data/lib/ecoportal/api/v2/pages.rb +46 -0
- data/lib/ecoportal/api/v2/register_search_result.rb +20 -0
- data/lib/ecoportal/api/v2/registers.rb +65 -0
- data/lib/ecoportal/api/v2/stage.rb +9 -0
- data/lib/ecoportal/api/version.rb +1 -1
- metadata +11 -6
- data/lib/ecoportal/api/internal/.git-keep +0 -0
- data/lib/ecoportal/api/v1/.git-keep +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 275ffcb5e9bfe17f44295a7c4438b9e169dc87f22afe19591752425ef008cdba
|
4
|
+
data.tar.gz: aeb53e930f75dc7299fc400a8a00624428dfe496b77a5fdf1af1075b144a6944
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e2e4c03089ccf675057b335a9c9e46a5a40a92d3720b256fb9a679eec6431885889171960bf106e3586efbc77d9b2384262c9e4aa52cdf34b6c291be78b76dd
|
7
|
+
data.tar.gz: c1df25f369172d215ba64bf932b63d78514871579540edabc991719a737999a5700828352bceca140d5715861b47cb6b2e4e56fab4b7b916fe5ef42627ec7e4f
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,74 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
-
## [0.
|
4
|
+
## [0.7.4] - 2021-01-2
|
5
|
+
|
6
|
+
### Added
|
7
|
+
|
8
|
+
### Fixed
|
9
|
+
- changed `compact` to `compact!`:
|
10
|
+
- `Ecoportal::API::V1::Person#filter_tags=`
|
11
|
+
- `Ecoportal::API::Internal::Account#policy_group_ids=`
|
12
|
+
- `Ecoportal::API::Internal::Account#login_provider_ids=`
|
13
|
+
- `Ecoportal::API::Internal::Account#starred_ids=`
|
14
|
+
|
15
|
+
### Changed
|
16
|
+
|
17
|
+
## [0.7.3] - 2020-11-30
|
18
|
+
|
19
|
+
### Added
|
20
|
+
|
21
|
+
### Fixed
|
22
|
+
- `Ecoportal::API::V1::Person#email=`: was not showing the incorrect value in the error message
|
23
|
+
- added `compact` to remove `null` values on:
|
24
|
+
- `Ecoportal::API::V1::Person#filter_tags=`
|
25
|
+
- `Ecoportal::API::Internal::Account#policy_group_ids=`
|
26
|
+
- `Ecoportal::API::Internal::Account#login_provider_ids=`
|
27
|
+
- `Ecoportal::API::Internal::Account#starred_ids=`
|
28
|
+
|
29
|
+
### Changed
|
30
|
+
|
31
|
+
|
32
|
+
## [0.7.2] - 2020-10-19
|
33
|
+
|
34
|
+
### Added
|
35
|
+
- `Ecoportal::API::V1::Person#email=`:
|
36
|
+
- do a minimum validation (no blanks in the email)
|
37
|
+
- set in lower case (as this is how it's in the server)
|
38
|
+
### Fixed
|
39
|
+
- `Ecoportal::API::V1::People#each`: when `silent` it shouldn't print a blank line
|
40
|
+
- fixed so they return empty array `[]` when `nil`:
|
41
|
+
- `Ecoportal::API::V1::Person#filter_tags`
|
42
|
+
- `Ecoportal::API::Internal::Account#policy_group_ids`
|
43
|
+
- `Ecoportal::API::Internal::Account#login_provider_ids`
|
44
|
+
- `Ecoportal::API::Internal::Account#starred_ids`
|
45
|
+
### Changed
|
46
|
+
- made it so some methods the `Array` with `uniq` values:
|
47
|
+
- `Ecoportal::API::V1::Person#filter_tags=`
|
48
|
+
- `Ecoportal::API::Internal::Account#policy_group_ids=`
|
49
|
+
- made it so it only updates the keys defined in the `Hash` passed to the setter:
|
50
|
+
- `Ecoportal::API::Internal::Account#permissions_custom=`
|
51
|
+
- `Ecoportal::API::Internal::Account#preferences=`
|
52
|
+
|
53
|
+
|
54
|
+
## [0.7.1] - 2020-09-30
|
55
|
+
|
56
|
+
### Added
|
57
|
+
- `Ecoportal::API::Internal::Permissions`: **update for new ability `tasks` of ecoPortal release `1.5.3`**
|
58
|
+
- `Ecoportal::API::V1::People#each`: added keyword argument `silent:` to display download progress
|
59
|
+
### Fixed
|
60
|
+
- `Ecoportal::API::V1::People#each`: when no block provided, it was creating an `Enumarator` without preserving the parameters (i.e. `:q` or `per_page` were lost)
|
61
|
+
|
62
|
+
## [0.7.0] - 2020-09-11
|
63
|
+
|
64
|
+
### Added
|
65
|
+
### Changed
|
66
|
+
- `Ecoportal::API::Internal::Permissions`: **update for new abilities of ecoPortal release `1.5.2`**
|
67
|
+
- decoupled abilities: `person_core` into `person_core_create`, `person_core_edit`
|
68
|
+
### Fixed
|
69
|
+
|
70
|
+
|
71
|
+
## [0.6.0] - 2020-07-14
|
5
72
|
|
6
73
|
### Added
|
7
74
|
- `Ecoportal::API::Common::BaseModel#initial_doc`: `#consolidate!` modifies `original_doc`
|
data/ecoportal-api.gemspec
CHANGED
@@ -27,6 +27,6 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_development_dependency "redcarpet", "~> 3.5", ">= 3.5.0"
|
28
28
|
spec.add_development_dependency "pry" , "~> 0.13"
|
29
29
|
|
30
|
-
spec.add_dependency 'http', '~>
|
30
|
+
spec.add_dependency 'http', '~> 4'
|
31
31
|
spec.add_dependency 'hash-polyfill', '~> 0'
|
32
32
|
end
|
data/lib/ecoportal/api.rb
CHANGED
@@ -119,11 +119,18 @@ module Ecoportal
|
|
119
119
|
Ecoportal::API::Common::Response.new(response)
|
120
120
|
end
|
121
121
|
|
122
|
-
# Creates a HTTP object adding the `X-ApiKey` param to the header.
|
122
|
+
# Creates a HTTP object adding the `X-ApiKey` or `X-ECOPORTAL-API-KEY` param to the header, depending on the API version.
|
123
123
|
# @note It configures HTTP so it only allows body data in json format.
|
124
124
|
# @return [HTTP] HTTP object.
|
125
125
|
def base_request
|
126
|
-
@base_request ||=
|
126
|
+
@base_request ||= begin
|
127
|
+
case @version
|
128
|
+
when "v2"
|
129
|
+
HTTP.headers("X-ECOPORTAL-API-KEY" => @api_key).accept(:json)
|
130
|
+
else
|
131
|
+
HTTP.headers("X-ApiKey" => @api_key).accept(:json)
|
132
|
+
end
|
133
|
+
end
|
127
134
|
end
|
128
135
|
|
129
136
|
# Full URl builder of the request
|
@@ -13,14 +13,49 @@ module Ecoportal
|
|
13
13
|
embeds_one :preferences, klass: :preferences_class
|
14
14
|
|
15
15
|
# Sets the `policy_group_ids`
|
16
|
+
# @note it preserves the original order
|
17
|
+
# @param value [Array<String>] the policy group ids to be set.
|
16
18
|
def policy_group_ids=(value)
|
17
19
|
unless value.is_a?(Array)
|
18
20
|
raise "policy_group_ids= needs to be passed an Array, got #{value.class}"
|
19
21
|
end
|
20
22
|
|
23
|
+
value.uniq!
|
21
24
|
ini_ids = (original_doc && original_doc["policy_group_ids"]) || []
|
22
25
|
# preserve original order to avoid false updates
|
23
26
|
doc["policy_group_ids"] = (ini_ids & value) + (value - ini_ids)
|
27
|
+
doc["policy_group_ids"].compact
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [Array<String>] the policy group ids of this user.
|
31
|
+
def policy_group_ids
|
32
|
+
doc["policy_group_ids"] ||= []
|
33
|
+
end
|
34
|
+
|
35
|
+
# Sets the `login_provider_ids`
|
36
|
+
def login_provider_ids=(value)
|
37
|
+
unless value.is_a?(Array)
|
38
|
+
raise "login_provider_ids= needs to be passed an Array, got #{value.class}"
|
39
|
+
end
|
40
|
+
doc["login_provider_ids"] = value.compact
|
41
|
+
end
|
42
|
+
|
43
|
+
# @return [Array<String>] the login provider ids of this user.
|
44
|
+
def login_provider_ids
|
45
|
+
doc["login_provider_ids"] ||= []
|
46
|
+
end
|
47
|
+
|
48
|
+
# Sets the `starred_ids`
|
49
|
+
def starred_ids=(value)
|
50
|
+
unless value.is_a?(Array)
|
51
|
+
raise "starred_ids= needs to be passed an Array, got #{value.class}"
|
52
|
+
end
|
53
|
+
doc["starred_ids"] = value.compact
|
54
|
+
end
|
55
|
+
|
56
|
+
# @return [Array<String>] the starred page ids of this user.
|
57
|
+
def starred_ids
|
58
|
+
doc["starred_ids"] ||= []
|
24
59
|
end
|
25
60
|
|
26
61
|
# Sets the `permissions_preset`.
|
@@ -37,6 +72,20 @@ module Ecoportal
|
|
37
72
|
self.permissions_preset.nil? ? "custom" : self.permissions_preset
|
38
73
|
end
|
39
74
|
|
75
|
+
# It preserves the values of keys that are not defined in `value`.
|
76
|
+
# @param value [Hash] the abilities that you want to update.
|
77
|
+
def permissions_custom=(value)
|
78
|
+
doc["permissions_custom"] ||= {}
|
79
|
+
doc["permissions_custom"].merge!(value)
|
80
|
+
end
|
81
|
+
|
82
|
+
# It preserves the values of keys that are not defined in `value`.
|
83
|
+
# @param value [Hash] the preferences that you want to update.
|
84
|
+
def preferences=(value)
|
85
|
+
doc["preferences"] ||= {}
|
86
|
+
doc["preferences"].merge!(value)
|
87
|
+
end
|
88
|
+
|
40
89
|
def as_json
|
41
90
|
super.tap do |hash|
|
42
91
|
if preset == "custom"
|
@@ -3,8 +3,9 @@ module Ecoportal
|
|
3
3
|
class Internal
|
4
4
|
class Permissions < Common::BaseModel
|
5
5
|
passthrough :files, :data, :reports
|
6
|
-
passthrough :organization, :person_core, :
|
7
|
-
passthrough :
|
6
|
+
passthrough :organization, :person_core, :person_core_create, :person_core_edit
|
7
|
+
passthrough :person_account, :person_details
|
8
|
+
passthrough :pages, :page_editor, :registers, :tasks
|
8
9
|
end
|
9
10
|
end
|
10
11
|
end
|
@@ -27,15 +27,27 @@ module Ecoportal
|
|
27
27
|
# @param params [Hash]
|
28
28
|
# @option params [String] :per_page the number of people you get per request.
|
29
29
|
# @option params [String] :q some text to search. Omit this parameter to target all the people.
|
30
|
+
# @param silent [Boolean] `false` to show percentage of progress.
|
30
31
|
# @yield [person] does some stuff with the person.
|
31
32
|
# @yieldparam person [Person]
|
32
|
-
def each(params: {}, &block)
|
33
|
-
return to_enum(:each) unless block
|
34
|
-
cursor_id = nil
|
33
|
+
def each(params: {}, silent: false, &block)
|
34
|
+
return to_enum(:each, params: params, silent: silent) unless block
|
35
|
+
cursor_id = nil; results = 0
|
36
|
+
puts "\n" unless silent
|
35
37
|
loop do
|
36
38
|
params.update(cursor_id: cursor_id) if cursor_id
|
37
39
|
response = client.get("/people", params: params)
|
38
|
-
raise "Request failed." unless response.success?
|
40
|
+
raise "Request failed - Status #{response.status}: #{response.body}" unless response.success?
|
41
|
+
|
42
|
+
unless silent || (total = response.body["total_results"]) == 0
|
43
|
+
results += response.body["results"].length
|
44
|
+
percent = results * 100 / total
|
45
|
+
msg = "People GET"
|
46
|
+
msg += " (search=#{params[:q]})" if params.key?(:q)
|
47
|
+
print "#{msg}: #{percent.round}% (of #{total})\r"
|
48
|
+
$stdout.flush
|
49
|
+
end
|
50
|
+
|
39
51
|
response.body["results"].each do |person|
|
40
52
|
yield person_class.new(person)
|
41
53
|
end
|
@@ -45,13 +57,14 @@ module Ecoportal
|
|
45
57
|
end
|
46
58
|
|
47
59
|
# Gets all the people via api requests.
|
48
|
-
# @note it ignores the key `:
|
60
|
+
# @note it ignores the key `:cursor_id` in `params:`.
|
49
61
|
# @param params [Hash]
|
50
62
|
# @option params [Integer] :per_page the number of people you get per request.
|
51
63
|
# @option params [String] :q some text to search.
|
64
|
+
# @param silent [Boolean] `false` to show percentage of progress.
|
52
65
|
# @return [Array<Person>] the array of people got via api.
|
53
|
-
def get_all(params: {})
|
54
|
-
each(params: params).to_a
|
66
|
+
def get_all(params: {}, silent: false)
|
67
|
+
each(params: params, silent: silent).to_a
|
55
68
|
end
|
56
69
|
|
57
70
|
# Gets a person via api.
|
@@ -15,6 +15,7 @@ module Ecoportal
|
|
15
15
|
embeds_one :details, nullable: true, klass: :person_details_class
|
16
16
|
|
17
17
|
VALID_TAG_REGEX = /^[A-Za-z0-9 &_'\/-]+$/
|
18
|
+
VALID_EMAIL_REGEX = /^[^@\s]+@[^@\s]+\.[^@\s]+$/
|
18
19
|
|
19
20
|
# Gets the supervisor (`Person`) of this person, with given his `supervisor_id`.
|
20
21
|
#
|
@@ -41,8 +42,17 @@ module Ecoportal
|
|
41
42
|
self.supervisor_id = person&.id || person&.external_id
|
42
43
|
end
|
43
44
|
|
45
|
+
# Sets the email of a person.
|
46
|
+
# @param value [String, nil] the email of this person.
|
47
|
+
def email=(value)
|
48
|
+
unless !value || value.match(VALID_EMAIL_REGEX)
|
49
|
+
raise "Invalid email #{value.inspect}"
|
50
|
+
end
|
51
|
+
doc["email"] = value&.downcase
|
52
|
+
end
|
53
|
+
|
44
54
|
# Validates the string tags of the array, and sets the `filter_tags` property of the account.
|
45
|
-
# @note all is set in upper case.
|
55
|
+
# @note all is set in upper case and preserves the original order.
|
46
56
|
# @raise [Exception] if there was any invalid string tag.
|
47
57
|
# @param value [Array<String>] array of tags.
|
48
58
|
def filter_tags=(value)
|
@@ -54,11 +64,17 @@ module Ecoportal
|
|
54
64
|
raise "Invalid filter tag #{tag.inspect}"
|
55
65
|
end
|
56
66
|
tag.upcase
|
57
|
-
end
|
67
|
+
end.uniq
|
58
68
|
|
59
69
|
ini_tags = (original_doc && original_doc["filter_tags"]) || []
|
60
70
|
# preserve original order to avoid false updates
|
61
71
|
doc["filter_tags"] = (ini_tags & end_tags) + (end_tags - ini_tags)
|
72
|
+
doc["filter_tags"].compact
|
73
|
+
end
|
74
|
+
|
75
|
+
# @return [Array<String>] the filter tags of this person.
|
76
|
+
def filter_tags
|
77
|
+
doc["filter_tags"] ||= []
|
62
78
|
end
|
63
79
|
|
64
80
|
def as_json
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Ecoportal
|
2
|
+
module API
|
3
|
+
# @attr_reader client [Common::Client] a `Common::Client` object that holds the configuration of the api connection.
|
4
|
+
# @attr_reader logger [Logger] the logger.
|
5
|
+
class V2
|
6
|
+
extend Common::BaseClass
|
7
|
+
include Common::Logging
|
8
|
+
|
9
|
+
VERSION = "v2"
|
10
|
+
class_resolver :registers_class, "Ecoportal::API::V2::Registers"
|
11
|
+
class_resolver :pages_class, "Ecoportal::API::V2::Pages"
|
12
|
+
|
13
|
+
attr_reader :client, :logger
|
14
|
+
|
15
|
+
# Creates an `V2` object to scope version specific api requests.
|
16
|
+
# @note
|
17
|
+
# - The const `VERSION` determineds the api version that client will query against.
|
18
|
+
# - This means that each subclass of `V2` should define their own `VERSION` constant.
|
19
|
+
# @param api_key [String] the key version to stablish the api connection.
|
20
|
+
# @param host [String] api server domain.
|
21
|
+
# @param logger [Logger] an object with `Logger` interface to generate logs.
|
22
|
+
# @return [V2] an object with the api version suit.
|
23
|
+
def initialize(api_key, version: VERSION, host: "live.ecoportal.com", logger: default_logger)
|
24
|
+
@logger = logger
|
25
|
+
@client = Common::Client.new(
|
26
|
+
api_key: api_key,
|
27
|
+
host: host,
|
28
|
+
version: self.class::VERSION,
|
29
|
+
logger: @logger
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Obtain specific object for register api requests.
|
34
|
+
# @return [Register] an instance object ready to make register api requests.
|
35
|
+
def registers
|
36
|
+
registers_class.new(client)
|
37
|
+
end
|
38
|
+
|
39
|
+
def pages
|
40
|
+
pages_class.new(client)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
require 'ecoportal/api/v2/registers'
|
47
|
+
require 'ecoportal/api/v2/pages'
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Ecoportal
|
2
|
+
module API
|
3
|
+
class V2
|
4
|
+
class Page < Common::BaseModel
|
5
|
+
passthrough :id, :name, :state
|
6
|
+
|
7
|
+
class_resolver :stage_class, "Ecoportal::API::V2::Stage"
|
8
|
+
class_resolver :field_class, "Ecoportal::API::V2::Field"
|
9
|
+
|
10
|
+
def stages
|
11
|
+
return nil unless doc["evolution"]
|
12
|
+
return @stages if defined?(@stages)
|
13
|
+
@stages = (doc["evolution"]["stages"] || []).each_with_index.map do |stage, i|
|
14
|
+
stage_class.new(stage, parent: self, key: ["stages", i])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def fields
|
19
|
+
return @fields if defined?(@fields)
|
20
|
+
@fields = (doc["components"] || []).each_with_index.map do |component, i|
|
21
|
+
field_class.new(component, parent: self, key: ["components", i])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
require 'ecoportal/api/v2/stage'
|
30
|
+
require 'ecoportal/api/v2/field'
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Ecoportal
|
2
|
+
module API
|
3
|
+
class V2
|
4
|
+
# @attr_reader client [Common::Client] a `Common::Client` object that holds the configuration of the api connection.
|
5
|
+
class Pages
|
6
|
+
extend Common::BaseClass
|
7
|
+
include Enumerable
|
8
|
+
include Common::DocHelpers
|
9
|
+
|
10
|
+
attr_reader :client
|
11
|
+
|
12
|
+
class_resolver :page_class, "Ecoportal::API::V2::Page"
|
13
|
+
|
14
|
+
# @param client [Common::Client] a `Common::Client` object that holds the configuration of the api connection.
|
15
|
+
# @return [People] an instance object ready to make people api requests.
|
16
|
+
def initialize(client)
|
17
|
+
@client = client
|
18
|
+
end
|
19
|
+
|
20
|
+
def get(id, stage_id: nil)
|
21
|
+
if stage_id
|
22
|
+
response = get_with_stage_id(id, stage_id)
|
23
|
+
return page_class.new(response.body["data"])
|
24
|
+
end
|
25
|
+
|
26
|
+
response = client.get("/pages/#{id}")
|
27
|
+
# we get a 302 back when there's stages for the page
|
28
|
+
# let's follow it
|
29
|
+
if response.status == 302
|
30
|
+
stage_id = response.body["data"].match(/stages\/(.*)/)[1]
|
31
|
+
response = get_with_stage_id(id, stage_id)
|
32
|
+
end
|
33
|
+
page_class.new(response.body["data"])
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def get_with_stage_id(id, stage_id)
|
39
|
+
client.get("/pages/#{id}/stages/#{stage_id}")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
require 'ecoportal/api/v2/page'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Ecoportal
|
2
|
+
module API
|
3
|
+
class V2
|
4
|
+
class RegisterSearchResult < Common::BaseModel
|
5
|
+
passthrough :id, :name, :state
|
6
|
+
|
7
|
+
class_resolver :stage_class, "Ecoportal::API::V2::Stage"
|
8
|
+
|
9
|
+
def stages
|
10
|
+
return @stages if defined?(@stages)
|
11
|
+
@stages = (doc["stages"] || []).each_with_index.map do |stage, i|
|
12
|
+
stage_class.new(stage, parent: self, key: ["stages", i])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'ecoportal/api/v2/stage'
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Ecoportal
|
2
|
+
module API
|
3
|
+
class V2
|
4
|
+
# @attr_reader client [Common::Client] a `Common::Client` object that holds the configuration of the api connection.
|
5
|
+
class Registers
|
6
|
+
extend Common::BaseClass
|
7
|
+
include Enumerable
|
8
|
+
include Common::DocHelpers
|
9
|
+
|
10
|
+
class_resolver :register_search_result_class, "Ecoportal::API::V2::RegisterSearchResult"
|
11
|
+
|
12
|
+
attr_reader :client
|
13
|
+
|
14
|
+
# @param client [Common::Client] a `Common::Client` object that holds the configuration of the api connection.
|
15
|
+
# @return [People] an instance object ready to make people api requests.
|
16
|
+
def initialize(client)
|
17
|
+
@client = client
|
18
|
+
end
|
19
|
+
|
20
|
+
def search(register_id, options = {})
|
21
|
+
# supply a query string
|
22
|
+
# or a filter array (copy/paste from dev tools in the browser)
|
23
|
+
options = {query: nil, filters: []}.update(options)
|
24
|
+
options = {}.tap do |ret|
|
25
|
+
options.each do |key, value|
|
26
|
+
if key == :filters && value.any?
|
27
|
+
ret[key] = {filters: value}.to_json
|
28
|
+
else
|
29
|
+
ret[key] = value if key
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
cursor_id = nil
|
35
|
+
results = 0
|
36
|
+
loop do
|
37
|
+
options.update(cursor_id: cursor_id) if cursor_id
|
38
|
+
response = client.get("/registers/#{register_id}/search", params: options)
|
39
|
+
raise "Request failed - Status #{response.status}: #{response.body}" unless response.success?
|
40
|
+
|
41
|
+
data = response.body["data"]
|
42
|
+
unless (total = data["total"]) == 0
|
43
|
+
results += data["results"].length
|
44
|
+
percent = results * 100 / total
|
45
|
+
msg = "Registers SEARCH"
|
46
|
+
print "#{msg}: #{percent.round}% (of #{total})\r"
|
47
|
+
$stdout.flush
|
48
|
+
end
|
49
|
+
|
50
|
+
data["results"].each do |result|
|
51
|
+
object = register_search_result_class.new(result)
|
52
|
+
yield object
|
53
|
+
end
|
54
|
+
|
55
|
+
# break unless (cursor_id = data["cursor_id"])
|
56
|
+
break if total == results
|
57
|
+
end
|
58
|
+
self
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
require 'ecoportal/api/v2/register_search_result'
|
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.
|
4
|
+
version: 0.7.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tapio Saarinen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -124,14 +124,14 @@ dependencies:
|
|
124
124
|
requirements:
|
125
125
|
- - "~>"
|
126
126
|
- !ruby/object:Gem::Version
|
127
|
-
version: '
|
127
|
+
version: '4'
|
128
128
|
type: :runtime
|
129
129
|
prerelease: false
|
130
130
|
version_requirements: !ruby/object:Gem::Requirement
|
131
131
|
requirements:
|
132
132
|
- - "~>"
|
133
133
|
- !ruby/object:Gem::Version
|
134
|
-
version: '
|
134
|
+
version: '4'
|
135
135
|
- !ruby/object:Gem::Dependency
|
136
136
|
name: hash-polyfill
|
137
137
|
requirement: !ruby/object:Gem::Requirement
|
@@ -182,7 +182,6 @@ files:
|
|
182
182
|
- lib/ecoportal/api/common/response.rb
|
183
183
|
- lib/ecoportal/api/common/wrapped_response.rb
|
184
184
|
- lib/ecoportal/api/internal.rb
|
185
|
-
- lib/ecoportal/api/internal/.git-keep
|
186
185
|
- lib/ecoportal/api/internal/account.rb
|
187
186
|
- lib/ecoportal/api/internal/login_provider.rb
|
188
187
|
- lib/ecoportal/api/internal/login_providers.rb
|
@@ -199,7 +198,6 @@ files:
|
|
199
198
|
- lib/ecoportal/api/internal/schema_field_value.rb
|
200
199
|
- lib/ecoportal/api/logger.rb
|
201
200
|
- lib/ecoportal/api/v1.rb
|
202
|
-
- lib/ecoportal/api/v1/.git-keep
|
203
201
|
- lib/ecoportal/api/v1/people.rb
|
204
202
|
- lib/ecoportal/api/v1/person.rb
|
205
203
|
- lib/ecoportal/api/v1/person_details.rb
|
@@ -207,6 +205,13 @@ files:
|
|
207
205
|
- lib/ecoportal/api/v1/person_schemas.rb
|
208
206
|
- lib/ecoportal/api/v1/schema_field.rb
|
209
207
|
- lib/ecoportal/api/v1/schema_field_value.rb
|
208
|
+
- lib/ecoportal/api/v2.rb
|
209
|
+
- lib/ecoportal/api/v2/field.rb
|
210
|
+
- lib/ecoportal/api/v2/page.rb
|
211
|
+
- lib/ecoportal/api/v2/pages.rb
|
212
|
+
- lib/ecoportal/api/v2/register_search_result.rb
|
213
|
+
- lib/ecoportal/api/v2/registers.rb
|
214
|
+
- lib/ecoportal/api/v2/stage.rb
|
210
215
|
- lib/ecoportal/api/version.rb
|
211
216
|
homepage: https://www.ecoportal.com
|
212
217
|
licenses:
|
File without changes
|
File without changes
|