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) ⇒ Hash

Returns a hash including member item’s druid and release targets.

Returns:

  • (Hash)

    a hash including member item’s druid and release targets

Raises:



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

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

  paginated_get("/collections/druid:#{druid.delete_prefix('druid:')}/purls", "purls").each { |member| yield member }
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:



33
34
35
36
# File 'lib/purl_fetcher/client/reader.rb', line 33

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

#released_to(target) ⇒ Hash

Returns a hash including the item’s druid and its last updated time.

Returns:

  • (Hash)

    a hash including the item’s druid and its last updated time



24
25
26
27
28
# File 'lib/purl_fetcher/client/reader.rb', line 24

def released_to(target)
  return to_enum(:released_to, ERB::Util.url_encode(target)) unless block_given?

  retrieve_json("/released/#{target}").each { |item| yield item }
end