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, IntegrityError, LockedError, NotFoundError, Object, Objects, ResponseErrorFormatter, UnexpectedResponseError, VersionedApiService

Constant Summary collapse

DEFAULT_API_VERSION =
'v1'
DEFAULT_TIMEOUT =
300
DEFAULT_RETRY_MAX =
3
DEFAULT_RETRY_INTERVAL =
0.5
RETRY_BACKOFF_FACTOR =
2
TOKEN_HEADER =
'Authorization'
VERSION =
'8.0.0'

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.



100
101
102
# File 'lib/preservation/client.rb', line 100

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.



100
101
102
# File 'lib/preservation/client.rb', line 100

def read_timeout=(value)
  @read_timeout = value
end

#retry_interval=(value) ⇒ Object

Sets the attribute retry_interval

Parameters:

  • value

    the value to set the attribute retry_interval to.



100
101
102
# File 'lib/preservation/client.rb', line 100

def retry_interval=(value)
  @retry_interval = value
end

#retry_max=(value) ⇒ Object

Sets the attribute retry_max

Parameters:

  • value

    the value to set the attribute retry_max to.



100
101
102
# File 'lib/preservation/client.rb', line 100

def retry_max=(value)
  @retry_max = value
end

#streaming_connection=(value) ⇒ Object

Sets the attribute streaming_connection

Parameters:

  • value

    the value to set the attribute streaming_connection to.



100
101
102
# File 'lib/preservation/client.rb', line 100

def streaming_connection=(value)
  @streaming_connection = value
end

#token=(value) ⇒ Object

Sets the attribute token

Parameters:

  • value

    the value to set the attribute token to.



100
101
102
# File 'lib/preservation/client.rb', line 100

def token=(value)
  @token = value
end

#url=(value) ⇒ Object

Sets the attribute url

Parameters:

  • value

    the value to set the attribute url to.



100
101
102
# File 'lib/preservation/client.rb', line 100

def url=(value)
  @url = value
end

Class Method Details

.configure(url:, token:, read_timeout: DEFAULT_TIMEOUT, retry_max: DEFAULT_RETRY_MAX, retry_interval: DEFAULT_RETRY_INTERVAL) ⇒ 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

  • retry_max (Integer) (defaults to: DEFAULT_RETRY_MAX)

    number of retry attempts for GET requests

  • retry_interval (Float) (defaults to: DEFAULT_RETRY_INTERVAL)

    base delay in seconds between retries (exponential backoff)



82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/preservation/client.rb', line 82

def configure(url:, token:, read_timeout: DEFAULT_TIMEOUT,
              retry_max: DEFAULT_RETRY_MAX, retry_interval: DEFAULT_RETRY_INTERVAL)
  instance.url = url
  instance.token = token
  instance.read_timeout = read_timeout
  instance.retry_max = retry_max
  instance.retry_interval = retry_interval

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

  self
end

Instance Method Details

#catalogPreservation::Client::Catalog

Returns an instance of the Client::Catalog class.

Returns:



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

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:



65
66
67
68
69
# File 'lib/preservation/client.rb', line 65

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