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) ⇒ Object
-
#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.
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) ⇒ Object
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, | 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.
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 |