Class: Dor::ReleaseTags::PurlClient
- Inherits:
-
Object
- Object
- Dor::ReleaseTags::PurlClient
- Defined in:
- lib/dor/release_tags/purl_client.rb
Overview
Calls the purl service and returns the XML document
Instance Method Summary collapse
-
#fetch ⇒ Nokogiri::HTML::Document
Get XML from the purl service Fetches purl xml for a druid.
-
#initialize(host:, pid:) ⇒ PurlClient
constructor
A new instance of PurlClient.
Constructor Details
#initialize(host:, pid:) ⇒ PurlClient
Returns a new instance of PurlClient.
7 8 9 10 |
# File 'lib/dor/release_tags/purl_client.rb', line 7 def initialize(host:, pid:) @host = host @pid = pid end |
Instance Method Details
#fetch ⇒ Nokogiri::HTML::Document
Get XML from the purl service Fetches purl xml for a druid
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/dor/release_tags/purl_client.rb', line 16 def fetch handler = proc do |exception, attempt_number, total_delay| # We assume a 404 means the document has never been published before and thus has no purl Dor.logger.warn "[Attempt #{attempt_number}] GET #{url} -- #{exception.class}: #{exception.}; #{total_delay} seconds elapsed." raise exception unless exception.is_a? OpenURI::HTTPError return Nokogiri::HTML::Document.new if exception.io.status.first == '404' # ["404", "Not Found"] from OpenURI::Meta.status end with_retries(max_retries: 3, base_sleep_seconds: 3, max_sleep_seconds: 5, handler: handler) do |attempt| # If you change the method used for opening the webpage, you can change the :rescue param to handle the new method's errors Dor.logger.debug "[Attempt #{attempt}] GET #{url}" return Nokogiri::XML(OpenURI.open_uri(url)) end end |