Class: PurlFetcher::Client::Reader

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/purl_fetcher/client/reader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host: "https://purl-fetcher.stanford.edu", conn: nil) ⇒ Reader

Returns a new instance of Reader.



6
7
8
9
10
11
12
# File 'lib/purl_fetcher/client/reader.rb', line 6

def initialize(host: "https://purl-fetcher.stanford.edu", conn: nil)
  @host = host
  @conn = conn || Faraday.new(host) do |f|
            f.response :json
          end
  @range = {}
end

Instance Attribute Details

#connObject (readonly)

Returns the value of attribute conn.



4
5
6
# File 'lib/purl_fetcher/client/reader.rb', line 4

def conn
  @conn
end

#hostObject (readonly)

Returns the value of attribute host.



4
5
6
# File 'lib/purl_fetcher/client/reader.rb', line 4

def host
  @host
end

#rangeObject (readonly)

Returns the value of attribute range.



4
5
6
# File 'lib/purl_fetcher/client/reader.rb', line 4

def range
  @range
end

Instance Method Details

#collection_members(druid) ⇒ Object

Raises:



16
17
18
19
20
21
22
# File 'lib/purl_fetcher/client/reader.rb', line 16

def collection_members(druid)
  return to_enum(:collection_members, druid) unless block_given?

  paginated_get("/collections/druid:#{druid.delete_prefix('druid:')}/purls", "purls").each do |obj, _meta|
    yield obj["druid"].delete_prefix("druid:")
  end
end

#files_by_digest(druid) ⇒ Array<Hash<String,String>>

Returns a list of hashes where the key is a digest and the value is a filepath/filename.

Returns:

  • (Array<Hash<String,String>>)

    a list of hashes where the key is a digest and the value is a filepath/filename

Raises:



27
28
29
30
# File 'lib/purl_fetcher/client/reader.rb', line 27

def files_by_digest(druid)
  retrieve_json("/v1/purls/druid:#{druid.delete_prefix('druid:')}", {})
    .fetch("files_by_md5", [])
end