class Ecoportal::API::V2::Registers
@attr_reader client [Common::Client] a `Common::Client` object that holds the configuration of the api connection.
Attributes
Public Class Methods
@param client [Common::Client] a `Common::Client` object that holds the configuration of the api connection. @return [Registers] an instance object ready to make registers api requests.
# File lib/ecoportal/api/v2/registers.rb, line 17 def initialize(client) @client = client end
Public Instance Methods
# File lib/ecoportal/api/v2/registers.rb, line 21 def each(params: {}, &block) return to_enum(:each) unless block get.each(&block) end
Gets all the registers via api request. @return [Enumerable<Register>] an `Enumerable` with all schemas already wrapped as `Register` objects.
# File lib/ecoportal/api/v2/registers.rb, line 28 def get response = client.get("/templates") Common::Content::WrappedResponse.new(response, register_class, key: "registers") end
Gets all the oozes/pages of `register_id` matching the `options` @param register_id [String] the `id` of the target register to search on. @param options [Hash] the search options @option options [Hash<Symbol, String>] :query plain search (like the search box in register). @option options [Hash<Symbol, Array<Object>>] :filters the set of filters.
# File lib/ecoportal/api/v2/registers.rb, line 38 def search(register_id, options = {}) # supply a query string # or a filter array (copy/paste from dev tools in the browser) options = {query: nil, filters: []}.update(options) options = {}.tap do |ret| options.each do |key, value| if key == :filters && value.any? ret[key] = {filters: value}.to_json else ret[key] = value if key end end end cursor_id = nil results = 0 loop do options.update(cursor_id: cursor_id) if cursor_id response = client.get("/registers/#{register_id}/search", params: options) raise "Request failed - Status #{response.status}: #{response.body}" unless response.success? data = response.body["data"] unless (total = data["total"]) == 0 results += data["results"].length percent = results * 100 / total msg = "Registers SEARCH" print "#{msg}: #{percent.round}% (of #{total})\r" $stdout.flush end data["results"].each do |result| object = register_search_result_class.new(result) yield object end # break unless (cursor_id = data["cursor_id"]) break if total == results end self end