Class: Harvestdor::Indexer::PurlFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/harvestdor/indexer/purl_fetcher.rb

Overview

Client for working with the PURL Fetcher API

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ PurlFetcher

Returns a new instance of PurlFetcher.



7
8
9
# File 'lib/harvestdor/indexer/purl_fetcher.rb', line 7

def initialize(config = {})
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/harvestdor/indexer/purl_fetcher.rb', line 5

def config
  @config
end

Instance Method Details

#druids_from_collection(collection) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/harvestdor/indexer/purl_fetcher.rb', line 11

def druids_from_collection(collection)
  return to_enum(:druids_from_collection, collection) unless block_given?

  page = 1

  loop do
    response = client.get("/collections/#{collection}/purls", page: page, per_page: 100)
    data = JSON.parse(response.body)

    break if data['purls'].blank?

    data['purls'].each { |d| yield d['druid'] }

    page += 1

    break if data['pages']['next_page'].nil?
  end
end