lib/preservation/client.rb in preservation-client-2.0.0 vs lib/preservation/client.rb in preservation-client-2.1.0

- old
+ new

@@ -5,24 +5,12 @@ require 'active_support/core_ext/object/blank' require 'faraday' require 'singleton' require 'zeitwerk' -# Provides version exception to camels-case conversion -class PreservationClientInflector < Zeitwerk::Inflector - def camelize(basename, _abspath) - case basename - when 'version' - 'VERSION' - else - super - end - end -end - loader = Zeitwerk::Loader.new -loader.inflector = PreservationClientInflector.new +loader.inflector = Zeitwerk::GemInflector.new(__FILE__) loader.push_dir(File.absolute_path("#{__FILE__}/../..")) loader.setup module Preservation # REST API client wrapper for PreservationCatalog with error handling @@ -36,19 +24,24 @@ # e.g. 4xx or 5xx status class UnexpectedResponseError < Error; end class ConnectionFailedError < Error; end - DEFAULT_API_VERSION = '' # should be v1 once PreservationCatalog has versioned API + DEFAULT_API_VERSION = 'v1' include Singleton # @return [Preservation::Client::Objects] an instance of the `Client::Objects` class def objects @objects ||= Objects.new(connection: connection, api_version: DEFAULT_API_VERSION) end + # @return [Preservation::Client::Catalog] an instance of the `Client::Catalog` class + def catalog + @catalog ||= Catalog.new(connection: connection, api_version: DEFAULT_API_VERSION) + end + class << self # @param [String] url def configure(url:) instance.url = url @@ -56,14 +49,15 @@ instance.connection = nil self end - delegate :objects, to: :instance + delegate :objects, :update, to: :instance end attr_writer :url, :connection + delegate :update, to: :catalog private def url @url || raise(Error, 'url has not yet been configured') @@ -71,10 +65,10 @@ def connection @connection ||= Faraday.new(url) do |builder| builder.use ErrorFaradayMiddleware builder.use Faraday::Request::UrlEncoded - + builder.use Faraday::Response::RaiseError # raise exceptions on 40x, 50x responses builder.adapter Faraday.default_adapter builder.headers[:user_agent] = user_agent end end