Class: GeoCombine::GeoBlacklightHarvester::ModernBlacklightResponse

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(response:, base_url:) ⇒ ModernBlacklightResponse

Returns a new instance of ModernBlacklightResponse.



133
134
135
136
137
# File 'lib/geo_combine/geo_blacklight_harvester.rb', line 133

def initialize(response:, base_url:)
  @base_url = base_url
  @response = response
  @page = 1
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



131
132
133
# File 'lib/geo_combine/geo_blacklight_harvester.rb', line 131

def base_url
  @base_url
end

#pageObject

Returns the value of attribute page.



132
133
134
# File 'lib/geo_combine/geo_blacklight_harvester.rb', line 132

def page
  @page
end

#responseObject

Returns the value of attribute response.



132
133
134
# File 'lib/geo_combine/geo_blacklight_harvester.rb', line 132

def response
  @response
end

Instance Method Details

#documentsObject



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# 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
    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