Class: GeoCombine::GeoBlacklightHarvester::LegacyBlacklightResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/geo_combine/geo_blacklight_harvester.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response:, base_url:) ⇒ LegacyBlacklightResponse

Returns a new instance of LegacyBlacklightResponse.



88
89
90
91
92
# File 'lib/geo_combine/geo_blacklight_harvester.rb', line 88

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.



86
87
88
# File 'lib/geo_combine/geo_blacklight_harvester.rb', line 86

def base_url
  @base_url
end

#pageObject

Returns the value of attribute page.



87
88
89
# File 'lib/geo_combine/geo_blacklight_harvester.rb', line 87

def page
  @page
end

#responseObject

Returns the value of attribute response.



87
88
89
# File 'lib/geo_combine/geo_blacklight_harvester.rb', line 87

def response
  @response
end

Instance Method Details

#documentsObject



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/geo_combine/geo_blacklight_harvester.rb', line 94

def documents
  return enum_for(:documents) unless block_given?

  while current_page && total_pages && (current_page <= total_pages) do
    yield response.dig('response', 'docs')

    break if current_page == total_pages
    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