Class: Dor::Services::Client

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/dor/services/client.rb,
lib/dor/services/client/events.rb,
lib/dor/services/client/mutate.rb,
lib/dor/services/client/object.rb,
lib/dor/services/client/members.rb,
lib/dor/services/client/objects.rb,
lib/dor/services/client/version.rb,
lib/dor/services/client/transfer.rb,
lib/dor/services/client/accession.rb,
lib/dor/services/client/workspace.rb,
lib/dor/services/client/collections.rb,
lib/dor/services/client/async_result.rb,
lib/dor/services/client/object_version.rb,
lib/dor/services/client/virtual_objects.rb,
lib/dor/services/client/versioned_service.rb,
lib/dor/services/client/administrative_tags.rb,
lib/dor/services/client/background_job_results.rb,
lib/dor/services/client/error_faraday_middleware.rb,
lib/dor/services/client/response_error_formatter.rb,
lib/dor/services/client/administrative_tag_search.rb

Defined Under Namespace

Classes: Accession, AdministrativeTagSearch, AdministrativeTags, AsyncResult, BackgroundJobResults, BadRequestError, Collections, ConflictResponse, ConnectionFailed, Error, ErrorFaradayMiddleware, Events, MalformedResponse, Members, Mutate, NotFoundResponse, Object, ObjectVersion, Objects, PreconditionFailedResponse, ResponseErrorFormatter, Transfer, UnauthorizedResponse, UnexpectedResponse, VersionedService, VirtualObjects, Workspace

Constant Summary collapse

DEFAULT_VERSION =
'v1'
TOKEN_HEADER =
'Authorization'
VERSION =
'14.2.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.



135
136
137
# File 'lib/dor/services/client.rb', line 135

def connection=(value)
  @connection = value
end

#enable_get_retries=(value) ⇒ Object

Sets the attribute enable_get_retries

Parameters:

  • value

    the value to set the attribute enable_get_retries to.



135
136
137
# File 'lib/dor/services/client.rb', line 135

def enable_get_retries=(value)
  @enable_get_retries = value
end

#logger=(value) ⇒ Object

Sets the attribute logger

Parameters:

  • value

    the value to set the attribute logger to.



135
136
137
# File 'lib/dor/services/client.rb', line 135

def logger=(value)
  @logger = value
end

#token=(value) ⇒ Object

Sets the attribute token

Parameters:

  • value

    the value to set the attribute token to.



135
136
137
# File 'lib/dor/services/client.rb', line 135

def token=(value)
  @token = value
end

#url=(value) ⇒ Object

Sets the attribute url

Parameters:

  • value

    the value to set the attribute url to.



135
136
137
# File 'lib/dor/services/client.rb', line 135

def url=(value)
  @url = value
end

Class Method Details

.configure(url:, token:, enable_get_retries: true, logger: nil) ⇒ Object

Parameters:

  • url (String)

    the base url of the endpoint the client should connect to (required)

  • token (String)

    a bearer token for HTTP authentication (required)

  • enable_get_retries (Boolean) (defaults to: true)

    retries get requests on errors

  • logger (Logger, nil) (defaults to: nil)

    for logging retry attempts



120
121
122
123
124
125
126
127
128
129
130
# File 'lib/dor/services/client.rb', line 120

def configure(url:, token:, enable_get_retries: true, logger: nil)
  instance.url = url
  instance.token = token
  instance.enable_get_retries = enable_get_retries
  instance.logger = logger

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

  self
end

Instance Method Details

#administrative_tagsDor::Services::Client::AdministrativeTagSearch

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

Returns:



96
97
98
# File 'lib/dor/services/client.rb', line 96

def administrative_tags
  @administrative_tags ||= AdministrativeTagSearch.new(connection: connection, version: DEFAULT_VERSION)
end

#background_job_resultsDor::Services::Client::BackgroundJobResults

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

Returns:



111
112
113
# File 'lib/dor/services/client.rb', line 111

def background_job_results
  @background_job_results ||= BackgroundJobResults.new(connection: connection, version: DEFAULT_VERSION)
end

#object(object_identifier) ⇒ Dor::Services::Client::Object

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

Parameters:

  • object_identifier (String)

    the pid for the object

Returns:

Raises:

  • (ArgumentError)

    when ‘object_identifier` is `nil`



84
85
86
87
88
89
90
91
92
93
# File 'lib/dor/services/client.rb', line 84

def object(object_identifier)
  raise ArgumentError, '`object_identifier` argument cannot be `nil` in call to `#object(object_identifier)' if object_identifier.nil?

  # Return memoized object instance if object identifier value is the same
  # This allows us to test the client more easily in downstream codebases,
  # opening up stubbing without requiring `any_instance_of`
  return @object if @object&.object_identifier == object_identifier

  @object = Object.new(connection: connection, version: DEFAULT_VERSION, object_identifier: object_identifier)
end

#objectsDor::Services::Client::Objects

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

Returns:



101
102
103
# File 'lib/dor/services/client.rb', line 101

def objects
  @objects ||= Objects.new(connection: connection, version: DEFAULT_VERSION)
end

#virtual_objectsDor::Services::Client::VirtualObjects

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

Returns:



106
107
108
# File 'lib/dor/services/client.rb', line 106

def virtual_objects
  @virtual_objects ||= VirtualObjects.new(connection: connection, version: DEFAULT_VERSION)
end