class Ezid::Client

EZID client

@api public

Constants

API_VERSION

EZID API version

VERSION

ezid-client gem version (e.g., “0.8.0”)

Attributes

host[R]
password[R]
port[R]
timeout[R]
user[R]

Public Class Methods

config() click to toggle source

Configuration reader

# File lib/ezid/client.rb, line 30
def config
  @config ||= Configuration.new
end
configure() { |config| ... } click to toggle source

Yields the configuration to a block @yieldparam [Ezid::Configuration] the configuration

# File lib/ezid/client.rb, line 36
def configure
  yield config
end
new(opts = {}) { |self| ... } click to toggle source
# File lib/ezid/client.rb, line 49
def initialize(opts = {})
  @host = opts[:host] || config.host
  @port = (opts[:port] || config.port).to_i
  @timeout = (opts[:timeout] || config.timeout).to_i
  @user = opts[:user] || config.user
  @password = opts[:password] || config.password
  if block_given?
    login
    yield self
    logout
  end
end
version() click to toggle source

Verbose version string @return [String] the version

# File lib/ezid/client.rb, line 42
def version
  "ezid-client #{VERSION} (EZID API Version #{API_VERSION})"
end

Public Instance Methods

batch_download(params={}) click to toggle source

Submit a batch download request @see ezid.cdlib.org/doc/apidoc.html#batch-download @param format [String] format of results - one of “anvl”, “csv”, “xml” @param params [Hash] optional request parameters

# File lib/ezid/client.rb, line 184
def batch_download(params={})
  execute BatchDownloadRequest, params
end
config() click to toggle source

The client configuration @return [Ezid::Configuration] the configuration object

# File lib/ezid/client.rb, line 75
def config
  self.class.config
end
connection() click to toggle source

The Net::HTTP object used to connect to EZID @return [Net::HTTP] the connection

# File lib/ezid/client.rb, line 190
def connection
  @connection ||= build_connection
end
create_identifier(identifier, metadata=nil) click to toggle source

Create an identifier (PUT an existing identifier) @see ezid.cdlib.org/doc/apidoc.html#operation-create-identifier @param identifier [String] the identifier string to create @param metadata [String, Hash, Ezid::Metadata] optional metadata to set @raise [Ezid::Error] @return [Ezid::Response] the response

# File lib/ezid/client.rb, line 127
def create_identifier(identifier, metadata=nil)
  execute CreateIdentifierRequest, identifier, metadata
end
delete_identifier(identifier) click to toggle source

Delete an identifier (only reserved identifier can be deleted) @see ezid.cdlib.org/doc/apidoc.html#operation-delete-identifier @param identifier [String] the identifier to delete @raise [Ezid::Error] @return [Ezid::Response] the response

# File lib/ezid/client.rb, line 167
def delete_identifier(identifier)
  execute DeleteIdentifierRequest, identifier
end
get_identifier_metadata(identifier) click to toggle source

Get the metadata for an identifier @see ezid.cdlib.org/doc/apidoc.html#operation-get-identifier-metadata @param identifier [String] the identifier to retrieve @raise [Ezid::Error] @return [Ezid::Response] the response

# File lib/ezid/client.rb, line 158
def get_identifier_metadata(identifier)
  execute GetIdentifierMetadataRequest, identifier
end
inspect() click to toggle source
# File lib/ezid/client.rb, line 68
def inspect
  "#<#{self.class.name} connection=#{connection.inspect}, " \
    "user=#{user.inspect}, session=#{logged_in? ? 'OPEN' : 'CLOSED'}>"
end
logged_in?() click to toggle source

@return [true, false] whether the client is logged in

# File lib/ezid/client.rb, line 117
def logged_in?
  session.open?
end
logger() click to toggle source

The client logger @return [Logger] the logger

# File lib/ezid/client.rb, line 81
def logger
  @logger ||= config.logger
end
login() click to toggle source

Open a session @raise [Ezid::Error] @return [Ezid::Client] the client

# File lib/ezid/client.rb, line 94
def login
  if logged_in?
    logger.info("Already logged in, skipping login request.")
  else
    response = execute LoginRequest
    session.open(response.cookie)
  end
  self
end
logout() click to toggle source

Close the session @return [Ezid::Client] the client

# File lib/ezid/client.rb, line 106
def logout
  if logged_in?
    execute LogoutRequest
    session.close
  else
    logger.info("Not logged in, skipping logout request.")
  end
  self
end
mint_identifier(shoulder=nil, metadata=nil) click to toggle source

Mint an identifier @see ezid.cdlib.org/doc/apidoc.html#operation-mint-identifier @param shoulder [String] the shoulder on which to mint a new identifier @param metadata [String, Hash, Ezid::Metadata] metadata to set @raise [Ezid::Error] @return [Ezid::Response] the response

# File lib/ezid/client.rb, line 137
def mint_identifier(shoulder=nil, metadata=nil)
  shoulder ||= config.default_shoulder
  raise Error, "Shoulder missing -- cannot mint identifier." unless shoulder
  execute MintIdentifierRequest, shoulder, metadata
end
modify_identifier(identifier, metadata) click to toggle source

Modify an identifier @see ezid.cdlib.org/doc/apidoc.html#operation-modify-identifier @param identifier [String] the identifier to modify @param metadata [String, Hash, Ezid::Metadata] metadata to set @raise [Ezid::Error] @return [Ezid::Response] the response

# File lib/ezid/client.rb, line 149
def modify_identifier(identifier, metadata)
  execute ModifyIdentifierRequest, identifier, metadata
end
server_status(*subsystems) click to toggle source

Get the EZID server status (and the status of one or more subsystems) @see ezid.cdlib.org/doc/apidoc.html#server-status @param subsystems [Array] @raise [Ezid::Error] @return [Ezid::StatusResponse] the status response

# File lib/ezid/client.rb, line 176
def server_status(*subsystems)
  execute ServerStatusRequest, *subsystems
end
session() click to toggle source

The client session @return [Ezid::Session] the session

# File lib/ezid/client.rb, line 87
def session
  @session ||= Session.new
end
use_ssl() click to toggle source
# File lib/ezid/client.rb, line 62
def use_ssl
  warn "[DEPRECATION] `use_ssl` is deprecated and will be removed in ezid-client v2.0." \
       " EZID requires SSL as of April 30, 2017."
  true
end

Private Instance Methods

build_connection() click to toggle source
# File lib/ezid/client.rb, line 196
def build_connection
  Net::HTTP.new(host, port).tap do |conn|
    conn.use_ssl = true
    conn.read_timeout = timeout
  end
end
execute(request_class, *args) click to toggle source
# File lib/ezid/client.rb, line 211
def execute(request_class, *args)
  response = request_class.execute(self, *args)
  handle_response(response, request_class.short_name)
end
handle_response(response, request_name) click to toggle source
# File lib/ezid/client.rb, line 203
def handle_response(response, request_name)
  log_level = response.error? ? Logger::ERROR : Logger::INFO
  message = "EZID #{request_name} -- #{response.status_line}"
  logger.log(log_level, message)
  raise response.exception if response.exception
  response
end