Sha256: dee22b00e0c462c370ca4ca13bbcffbd1f803c028bc23884bcaf5316ee2560fd

Contents?: true

Size: 1.19 KB

Versions: 10

Compression:

Stored size: 1.19 KB

Contents

module Geoblacklight
  class Metadata

    ##
    # Instantiates a Geoblacklight::Metadata object used for retrieving and
    # formatting metadata
    # @param reference [Geoblacklight::Reference] the reference object
    def initialize(reference)
      @reference = reference
    end

    ##
    # Handles metadata and returns the retrieved metadata or an error message if
    # something went wrong
    # @return [String] returned metadata string
    def metadata
      response = retrieve_metadata
      if response.nil? || response.status == 404
        Geoblacklight.logger.error "Could not reach #{@reference.endpoint}"
        return "Could not reach #{@reference.endpoint}"
      else
        return response.body
      end
    end

    ##
    # Retrieves metadata from a url source
    # @return [Faraday::Response, nil] Faraday::Response or nil if there is a
    # connection error
    def retrieve_metadata
      conn = Faraday.new(url: @reference.endpoint)
      conn.get
    rescue Faraday::Error::ConnectionFailed => error
      Geoblacklight.logger.error error.inspect
      nil
    rescue Faraday::Error::TimeoutError => error
      Geoblacklight.logger.error error.inspect
      nil
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
geoblacklight-0.11.1 lib/geoblacklight/metadata.rb
geoblacklight-0.11.0 lib/geoblacklight/metadata.rb
geoblacklight-0.10.2 lib/geoblacklight/metadata.rb
geoblacklight-0.10.1 lib/geoblacklight/metadata.rb
geoblacklight-0.10.0 lib/geoblacklight/metadata.rb
geoblacklight-0.9.2 lib/geoblacklight/metadata.rb
geoblacklight-0.9.1 lib/geoblacklight/metadata.rb
geoblacklight-0.9.0 lib/geoblacklight/metadata.rb
geoblacklight-0.8.0 lib/geoblacklight/metadata.rb
geoblacklight-0.7.1 lib/geoblacklight/metadata.rb