Class: PurlFetcher::Client::Reader
- Inherits:
-
Object
- Object
- PurlFetcher::Client::Reader
- Includes:
- Enumerable
- Defined in:
- lib/purl_fetcher/client/reader.rb
Instance Attribute Summary collapse
-
#conn ⇒ Object
readonly
Returns the value of attribute conn.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#range ⇒ Object
readonly
Returns the value of attribute range.
Instance Method Summary collapse
-
#collection_members(druid) ⇒ Hash
A hash including member item’s druid and release targets.
-
#files_by_digest(druid) ⇒ Array<Hash<String,String>>
A list of hashes where the key is a digest and the value is a filepath/filename.
-
#initialize(host: "https://purl-fetcher.stanford.edu", conn: nil) ⇒ Reader
constructor
A new instance of Reader.
-
#released_to(target) ⇒ Hash
A hash including the item’s druid and its last updated time.
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
#conn ⇒ Object (readonly)
Returns the value of attribute conn.
4 5 6 |
# File 'lib/purl_fetcher/client/reader.rb', line 4 def conn @conn end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
4 5 6 |
# File 'lib/purl_fetcher/client/reader.rb', line 4 def host @host end |
#range ⇒ Object (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.
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.
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.
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 |