Class: Preservation::Client

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/preservation/client.rb,
lib/preservation/client/catalog.rb,
lib/preservation/client/objects.rb,
lib/preservation/client/version.rb,
lib/preservation/client/versioned_api_service.rb,
lib/preservation/client/error_faraday_middleware.rb,
lib/preservation/client/response_error_formatter.rb

Overview

REST API client wrapper for PreservationCatalog with error handling

Defined Under Namespace

Classes: Catalog, ConflictError, ConnectionFailedError, Error, ErrorFaradayMiddleware, LockedError, NotFoundError, Objects, ResponseErrorFormatter, UnexpectedResponseError, VersionedApiService

Constant Summary collapse

DEFAULT_API_VERSION =
'v1'
DEFAULT_TIMEOUT =
300
TOKEN_HEADER =
'Authorization'
VERSION =
'7.0.1'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#connection=(value) ⇒ Object

Sets the attribute connection

Parameters:

  • value

    the value to set the attribute connection to.



71
72
73
# File 'lib/preservation/client.rb', line 71

def connection=(value)
  @connection = value
end

#read_timeout=(value) ⇒ Object

Sets the attribute read_timeout

Parameters:

  • value

    the value to set the attribute read_timeout to.



71
72
73
# File 'lib/preservation/client.rb', line 71

def read_timeout=(value)
  @read_timeout = value
end

#token=(value) ⇒ Object

Sets the attribute token

Parameters:

  • value

    the value to set the attribute token to.



71
72
73
# File 'lib/preservation/client.rb', line 71

def token=(value)
  @token = value
end

#url=(value) ⇒ Object

Sets the attribute url

Parameters:

  • value

    the value to set the attribute url to.



71
72
73
# File 'lib/preservation/client.rb', line 71

def url=(value)
  @url = value
end

Class Method Details

.configure(url:, token:, read_timeout: DEFAULT_TIMEOUT) ⇒ Object

Parameters:

  • url (String)

    the endpoint URL

  • token (String)

    a bearer token for HTTP authentication

  • read_timeout (Integer) (defaults to: DEFAULT_TIMEOUT)

    the value in seconds of the read timeout



57
58
59
60
61
62
63
64
65
66
# File 'lib/preservation/client.rb', line 57

def configure(url:, token:, read_timeout: DEFAULT_TIMEOUT)
  instance.url = url
  instance.token = token
  instance.read_timeout = read_timeout

  # Force connection to be re-established when `.configure` is called
  instance.connection = nil

  self
end

Instance Method Details

#catalogPreservation::Client::Catalog

Returns an instance of the ‘Client::Catalog` class.

Returns:



49
50
51
# File 'lib/preservation/client.rb', line 49

def catalog
  @catalog ||= Catalog.new(connection: connection, api_version: DEFAULT_API_VERSION)
end

#objectsPreservation::Client::Objects

Returns an instance of the ‘Client::Objects` class.

Returns:



44
45
46
# File 'lib/preservation/client.rb', line 44

def objects
  @objects ||= Objects.new(connection: connection, api_version: DEFAULT_API_VERSION)
end