Class: Ezid::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/ezid/client.rb

Overview

EZID client

Constant Summary collapse

VERSION =

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

File.read(File.expand_path("../../../VERSION", __FILE__)).chomp.freeze
API_VERSION =

EZID API version

"2".freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Client

Returns a new instance of Client.



49
50
51
52
53
54
55
56
57
58
59
60
# 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?
    
    yield self
    logout
  end
end

Instance Attribute Details

#hostObject (readonly)



47
48
49
# File 'lib/ezid/client.rb', line 47

def host
  @host
end

#passwordObject (readonly)



47
48
49
# File 'lib/ezid/client.rb', line 47

def password
  @password
end

#portObject (readonly)



47
48
49
# File 'lib/ezid/client.rb', line 47

def port
  @port
end

#timeoutObject (readonly)



47
48
49
# File 'lib/ezid/client.rb', line 47

def timeout
  @timeout
end

#userObject (readonly)



47
48
49
# File 'lib/ezid/client.rb', line 47

def user
  @user
end

Class Method Details

.configObject

Configuration reader



30
31
32
# File 'lib/ezid/client.rb', line 30

def config
  @config ||= Configuration.new
end

.configure {|the| ... } ⇒ Object

Yields the configuration to a block

Yield Parameters:



36
37
38
# File 'lib/ezid/client.rb', line 36

def configure
  yield config
end

.versionString

Verbose version string

Returns:

  • (String)

    the version



42
43
44
# File 'lib/ezid/client.rb', line 42

def version
  "ezid-client #{VERSION} (EZID API Version #{API_VERSION})"
end

Instance Method Details

#batch_download(params = {}) ⇒ Object

Submit a batch download request

Parameters:

  • format (String)

    format of results - one of “anvl”, “csv”, “xml”

  • params (Hash) (defaults to: {})

    optional request parameters

See Also:



184
185
186
# File 'lib/ezid/client.rb', line 184

def batch_download(params={})
  execute BatchDownloadRequest, params
end

#configEzid::Configuration

The client configuration

Returns:



75
76
77
# File 'lib/ezid/client.rb', line 75

def config
  self.class.config
end

#connectionNet::HTTP

The Net::HTTP object used to connect to EZID

Returns:

  • (Net::HTTP)

    the connection



190
191
192
# File 'lib/ezid/client.rb', line 190

def connection
  @connection ||= build_connection
end

#create_identifier(identifier, metadata = nil) ⇒ Ezid::Response

Create an identifier (PUT an existing identifier)

Parameters:

  • identifier (String)

    the identifier string to create

  • metadata (String, Hash, Ezid::Metadata) (defaults to: nil)

    optional metadata to set

Returns:

Raises:

See Also:



127
128
129
# File 'lib/ezid/client.rb', line 127

def create_identifier(identifier, =nil)
  execute CreateIdentifierRequest, identifier, 
end

#delete_identifier(identifier) ⇒ Ezid::Response

Delete an identifier (only reserved identifier can be deleted)

Parameters:

  • identifier (String)

    the identifier to delete

Returns:

Raises:

See Also:



167
168
169
# File 'lib/ezid/client.rb', line 167

def delete_identifier(identifier)
  execute DeleteIdentifierRequest, identifier
end

#get_identifier_metadata(identifier) ⇒ Ezid::Response

Get the metadata for an identifier

Parameters:

  • identifier (String)

    the identifier to retrieve

Returns:

Raises:

See Also:



158
159
160
# File 'lib/ezid/client.rb', line 158

def (identifier)
  execute GetIdentifierMetadataRequest, identifier
end

#inspectObject



68
69
70
71
# 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?true, false

Returns whether the client is logged in.

Returns:

  • (true, false)

    whether the client is logged in



117
118
119
# File 'lib/ezid/client.rb', line 117

def logged_in?
  session.open?
end

#loggerLogger

The client logger

Returns:

  • (Logger)

    the logger



81
82
83
# File 'lib/ezid/client.rb', line 81

def logger
  @logger ||= config.logger
end

#loginEzid::Client

Open a session

Returns:

Raises:



94
95
96
97
98
99
100
101
102
# File 'lib/ezid/client.rb', line 94

def 
  if logged_in?
    logger.info("Already logged in, skipping login request.")
  else
    response = execute LoginRequest
    session.open(response.cookie)
  end
  self
end

#logoutEzid::Client

Close the session

Returns:



106
107
108
109
110
111
112
113
114
# 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) ⇒ Ezid::Response

Mint an identifier

Parameters:

  • shoulder (String) (defaults to: nil)

    the shoulder on which to mint a new identifier

  • metadata (String, Hash, Ezid::Metadata) (defaults to: nil)

    metadata to set

Returns:

Raises:

See Also:



137
138
139
140
141
# File 'lib/ezid/client.rb', line 137

def mint_identifier(shoulder=nil, =nil)
  shoulder ||= config.default_shoulder
  raise Error, "Shoulder missing -- cannot mint identifier." unless shoulder
  execute MintIdentifierRequest, shoulder, 
end

#modify_identifier(identifier, metadata) ⇒ Ezid::Response

Modify an identifier

Parameters:

  • identifier (String)

    the identifier to modify

  • metadata (String, Hash, Ezid::Metadata)

    metadata to set

Returns:

Raises:

See Also:



149
150
151
# File 'lib/ezid/client.rb', line 149

def modify_identifier(identifier, )
  execute ModifyIdentifierRequest, identifier, 
end

#server_status(*subsystems) ⇒ Ezid::StatusResponse

Get the EZID server status (and the status of one or more subsystems)

Parameters:

  • subsystems (Array)

Returns:

  • (Ezid::StatusResponse)

    the status response

Raises:

See Also:



176
177
178
# File 'lib/ezid/client.rb', line 176

def server_status(*subsystems)
  execute ServerStatusRequest, *subsystems
end

#sessionEzid::Session

The client session

Returns:



87
88
89
# File 'lib/ezid/client.rb', line 87

def session
  @session ||= Session.new
end

#use_sslObject



62
63
64
65
66
# 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