class GeoCombine::GeoBlacklightHarvester::ModernBlacklightResponse
Class to return documents from the Blacklight API (v7 and above)
Attributes
base_url[R]
page[RW]
response[RW]
Public Class Methods
new(response:, base_url:)
click to toggle source
# File lib/geo_combine/geo_blacklight_harvester.rb, line 133 def initialize(response:, base_url:) @base_url = base_url @response = response @page = 1 end
Public Instance Methods
documents() { |documents_from_urls(document_urls)| ... }
click to toggle source
# File lib/geo_combine/geo_blacklight_harvester.rb, line 139 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 puts "Fetching page #{page} @ #{url}" if GeoCombine::GeoBlacklightHarvester.config[:debug] begin self.response = JSON.parse(Net::HTTP.get(URI(url))) rescue => e puts "Request for #{url} failed with #{e}" self.response = nil end end end
Private Instance Methods
documents_from_urls(urls)
click to toggle source
# File lib/geo_combine/geo_blacklight_harvester.rb, line 163 def documents_from_urls(urls) puts "Fetching #{urls.count} documents for page #{page}" if GeoCombine::GeoBlacklightHarvester.config[:debug] urls.map do |url| begin JSON.parse(Net::HTTP.get(URI("#{url}/raw"))) rescue => e puts "Fetching \"#{url}/raw\" failed with #{e}" nil end end.compact end