Class: GeoCombine::GeoBlacklightHarvester::ModernBlacklightResponse
- Inherits:
-
Object
- Object
- GeoCombine::GeoBlacklightHarvester::ModernBlacklightResponse
- Defined in:
- lib/geo_combine/geo_blacklight_harvester.rb
Overview
Class to return documents from the Blacklight API (v7 and above)
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#page ⇒ Object
Returns the value of attribute page.
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
- #documents ⇒ Object
-
#initialize(response:, base_url:, logger: GeoCombine::Logger.logger) ⇒ ModernBlacklightResponse
constructor
A new instance of ModernBlacklightResponse.
Constructor Details
#initialize(response:, base_url:, logger: GeoCombine::Logger.logger) ⇒ ModernBlacklightResponse
Returns a new instance of ModernBlacklightResponse.
145 146 147 148 149 150 |
# File 'lib/geo_combine/geo_blacklight_harvester.rb', line 145 def initialize(response:, base_url:, logger: GeoCombine::Logger.logger) @base_url = base_url @response = response @page = 1 @logger = logger end |
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
142 143 144 |
# File 'lib/geo_combine/geo_blacklight_harvester.rb', line 142 def base_url @base_url end |
#page ⇒ Object
Returns the value of attribute page.
143 144 145 |
# File 'lib/geo_combine/geo_blacklight_harvester.rb', line 143 def page @page end |
#response ⇒ Object
Returns the value of attribute response.
143 144 145 |
# File 'lib/geo_combine/geo_blacklight_harvester.rb', line 143 def response @response end |
Instance Method Details
#documents ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/geo_combine/geo_blacklight_harvester.rb', line 152 def documents return enum_for(:documents) unless block_given? while response && response['data'].any? document_urls = response['data'].collect { |data| data.dig('links', 'self') }.compact yield documents_from_urls(document_urls) url = response.dig('links', 'next') break unless url url = "#{url}&format=json" self.page += 1 @logger.debug "fetching page #{page} @ #{url}" begin self.response = JSON.parse(Net::HTTP.get(URI(url))) rescue StandardError => e @logger.error "Request for #{url} failed with #{e}" self.response = nil end end end |