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/object.rb,
lib/dor/services/client/embargo.rb,
lib/dor/services/client/marcxml.rb,
lib/dor/services/client/members.rb,
lib/dor/services/client/objects.rb,
lib/dor/services/client/version.rb,
lib/dor/services/client/metadata.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/release_tags.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/connection_wrapper.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, Collections, ConflictResponse, ConnectionFailed, ConnectionWrapper, Embargo, Error, ErrorFaradayMiddleware, Events, MalformedResponse, Marcxml, Members, Metadata, NotFoundResponse, Object, ObjectVersion, Objects, ReleaseTags, ResponseErrorFormatter, UnauthorizedResponse, UnexpectedResponse, VersionedService, VirtualObjects, Workspace

Constant Summary collapse

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



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

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.



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

def enable_get_retries=(value)
  @enable_get_retries = value
end

#token=(value) ⇒ Object

Sets the attribute token

Parameters:

  • value

    the value to set the attribute token to.



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

def token=(value)
  @token = value
end

#url=(value) ⇒ Object

Sets the attribute url

Parameters:

  • value

    the value to set the attribute url to.



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

def url=(value)
  @url = value
end

Class Method Details

.configure(url:, token:, enable_get_retries: false) ⇒ 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: false)

    retries get requests on errors



91
92
93
94
95
96
97
98
99
100
# File 'lib/dor/services/client.rb', line 91

def configure(url:, token:, enable_get_retries: false)
  instance.url = url
  instance.token = token
  instance.enable_get_retries = enable_get_retries

  # 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:



63
64
65
# File 'lib/dor/services/client.rb', line 63

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:



78
79
80
# File 'lib/dor/services/client.rb', line 78

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

#marcxmlDor::Services::Client::Marcxml

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

Returns:



83
84
85
# File 'lib/dor/services/client.rb', line 83

def marcxml
  @marcxml ||= Marcxml.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`



51
52
53
54
55
56
57
58
59
60
# File 'lib/dor/services/client.rb', line 51

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:



68
69
70
# File 'lib/dor/services/client.rb', line 68

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:



73
74
75
# File 'lib/dor/services/client.rb', line 73

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