Class: Ecoportal::API::V2::Registers
- Inherits:
-
Object
- Object
- Ecoportal::API::V2::Registers
- Extended by:
- Common::BaseClass
- Includes:
- Common::Content::DocHelpers, Enumerable
- Defined in:
- lib/ecoportal/api/v2/registers.rb,
lib/ecoportal/api/v2/registers/register.rb,
lib/ecoportal/api/v2/registers/template.rb,
lib/ecoportal/api/v2/registers/page_result.rb,
lib/ecoportal/api/v2/registers/stage_result.rb,
lib/ecoportal/api/v2/registers/stages_result.rb,
lib/ecoportal/api/v2/registers/search_results.rb,
lib/ecoportal/api/v2/registers/page_result/membrane_droplet.rb
Defined Under Namespace
Classes: PageResult, Register, SearchResults, StageResult, StagesResult, Template
Instance Attribute Summary collapse
-
#client ⇒ Ecoportal::API::Common::Client
readonly
a
Ecoportal::API::Common::Client
object that holds the configuration of the api connection.
Instance Method Summary collapse
- #each(params: {}, &block) ⇒ Object
-
#get ⇒ Enumerable<Register>
Gets all the registers via api request.
-
#initialize(client) ⇒ Registers
constructor
An instance object ready to make registers api requests.
-
#search(register_id, options = {}) {|result| ... } ⇒ Ecoportal::API::V2::Registers, Ecoportal::API::V2::Registers::SearchResults
Gets all the oozes/pages of
register_id
matching theoptions
.
Methods included from Common::Content::DocHelpers
#array_id_index, #array_id_item, #array_ids, #get_body, #get_id
Constructor Details
#initialize(client) ⇒ Registers
Returns an instance object ready to make registers api requests.
21 22 23 |
# File 'lib/ecoportal/api/v2/registers.rb', line 21 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ Ecoportal::API::Common::Client (readonly)
a Ecoportal::API::Common::Client
object that
holds the configuration of the api connection.
7 8 9 |
# File 'lib/ecoportal/api/v2/registers.rb', line 7 def client @client end |
Instance Method Details
#each(params: {}, &block) ⇒ Object
25 26 27 28 29 |
# File 'lib/ecoportal/api/v2/registers.rb', line 25 def each(params: {}, &block) return to_enum(:each, params: params) unless block get.each(&block) end |
#get ⇒ Enumerable<Register>
Gets all the registers via api request.
33 34 35 36 37 38 39 40 |
# File 'lib/ecoportal/api/v2/registers.rb', line 33 def get response = client.get("/templates") Ecoportal::API::Common::Content::WrappedResponse.new( response, register_class, key: "registers" ) end |
#search(register_id, options = {}) {|result| ... } ⇒ Ecoportal::API::V2::Registers, Ecoportal::API::V2::Registers::SearchResults
Gets all the oozes/pages of register_id
matching the options
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/ecoportal/api/v2/registers.rb', line 51 def search(register_id, = {}) # rubocop:disable Metrics/AbcSize only_first = .delete(:only_first) = () if only_first response = client.get("/registers/#{register_id}/search", params: ) raise "Request failed - Status #{response.status}: #{response.body}" unless response.success? return register_search_results.new(response.body["data"]) end cursor_id = nil results = 0 total = nil loop do .update(cursor_id: cursor_id) if cursor_id response = client.get("/registers/#{register_id}/search", params: ) raise "Request failed - Status #{response.status}: #{response.body}" unless response.success? data = response.body["data"] total ||= data["total"] if total != data["total"] msg = "Change of total in search results. " msg << "Probably due to changes that affect the filter" msg << "(register: #{register_id}):" print_search_status(msg, total, results, cursor_id, data, ) #total = data["total"] end unless total&.zero? results += data["results"].length print_progress(results, total) end data["results"].each do |result| object = register_search_result_class.new(result) yield object end break if total <= results unless data["cursor_id"] msg = "Possible error... finishing search for lack of cursor_id in response:" print_search_status(msg, total, results, cursor_id, data, ) end break unless (cursor_id = data["cursor_id"]) end self end |