Class: Ezid::Client
- Inherits:
-
Object
- Object
- Ezid::Client
- 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.("../../../VERSION", __FILE__)).chomp.freeze
- API_VERSION =
EZID API version
"2".freeze
Instance Attribute Summary collapse
- #host ⇒ Object readonly
- #password ⇒ Object readonly
- #port ⇒ Object readonly
- #timeout ⇒ Object readonly
- #use_ssl ⇒ Object readonly
- #user ⇒ Object readonly
Class Method Summary collapse
-
.config ⇒ Object
Configuration reader.
-
.configure {|the| ... } ⇒ Object
Yields the configuration to a block.
-
.version ⇒ String
Verbose version string.
Instance Method Summary collapse
-
#batch_download(params = {}) ⇒ Object
Submit a batch download request.
-
#config ⇒ Ezid::Configuration
The client configuration.
-
#connection ⇒ Net::HTTP
The Net::HTTP object used to connect to EZID.
-
#create_identifier(identifier, metadata = nil) ⇒ Ezid::Response
Create an identifier (PUT an existing identifier).
-
#delete_identifier(identifier) ⇒ Ezid::Response
Delete an identifier (only reserved identifier can be deleted).
-
#get_identifier_metadata(identifier) ⇒ Ezid::Response
Get the metadata for an identifier.
-
#initialize(opts = {}) ⇒ Client
constructor
A new instance of Client.
- #inspect ⇒ Object
-
#logged_in? ⇒ true, false
Whether the client is logged in.
-
#logger ⇒ Logger
The client logger.
-
#login ⇒ Ezid::Client
Open a session.
-
#logout ⇒ Ezid::Client
Close the session.
-
#mint_identifier(shoulder = nil, metadata = nil) ⇒ Ezid::Response
Mint an identifier.
-
#modify_identifier(identifier, metadata) ⇒ Ezid::Response
Modify an identifier.
-
#server_status(*subsystems) ⇒ Ezid::StatusResponse
Get the EZID server status (and the status of one or more subsystems).
-
#session ⇒ Ezid::Session
The client session.
Constructor Details
#initialize(opts = {}) ⇒ Client
Returns a new instance of Client.
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ezid/client.rb', line 50 def initialize(opts = {}) @host = opts[:host] || config.host @port = (opts[:port] || config.port).to_i @use_ssl = opts[:use_ssl] || config.use_ssl @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 |
Instance Attribute Details
#host ⇒ Object (readonly)
48 49 50 |
# File 'lib/ezid/client.rb', line 48 def host @host end |
#password ⇒ Object (readonly)
48 49 50 |
# File 'lib/ezid/client.rb', line 48 def password @password end |
#port ⇒ Object (readonly)
48 49 50 |
# File 'lib/ezid/client.rb', line 48 def port @port end |
#timeout ⇒ Object (readonly)
48 49 50 |
# File 'lib/ezid/client.rb', line 48 def timeout @timeout end |
#use_ssl ⇒ Object (readonly)
48 49 50 |
# File 'lib/ezid/client.rb', line 48 def use_ssl @use_ssl end |
#user ⇒ Object (readonly)
48 49 50 |
# File 'lib/ezid/client.rb', line 48 def user @user end |
Class Method Details
.config ⇒ Object
Configuration reader
31 32 33 |
# File 'lib/ezid/client.rb', line 31 def config @config ||= Configuration.new end |
.configure {|the| ... } ⇒ Object
Yields the configuration to a block
37 38 39 |
# File 'lib/ezid/client.rb', line 37 def configure yield config end |
.version ⇒ String
Verbose version string
43 44 45 |
# File 'lib/ezid/client.rb', line 43 def version "ezid-client #{VERSION} (EZID API Version #{API_VERSION})" end |
Instance Method Details
#batch_download(params = {}) ⇒ Object
Submit a batch download request
180 181 182 |
# File 'lib/ezid/client.rb', line 180 def batch_download(params={}) execute BatchDownloadRequest, params end |
#config ⇒ Ezid::Configuration
The client configuration
71 72 73 |
# File 'lib/ezid/client.rb', line 71 def config self.class.config end |
#connection ⇒ Net::HTTP
The Net::HTTP object used to connect to EZID
186 187 188 |
# File 'lib/ezid/client.rb', line 186 def connection @connection ||= build_connection end |
#create_identifier(identifier, metadata = nil) ⇒ Ezid::Response
Create an identifier (PUT an existing identifier)
123 124 125 |
# File 'lib/ezid/client.rb', line 123 def create_identifier(identifier, =nil) execute CreateIdentifierRequest, identifier, end |
#delete_identifier(identifier) ⇒ Ezid::Response
Delete an identifier (only reserved identifier can be deleted)
163 164 165 |
# File 'lib/ezid/client.rb', line 163 def delete_identifier(identifier) execute DeleteIdentifierRequest, identifier end |
#get_identifier_metadata(identifier) ⇒ Ezid::Response
Get the metadata for an identifier
154 155 156 |
# File 'lib/ezid/client.rb', line 154 def (identifier) execute GetIdentifierMetadataRequest, identifier end |
#inspect ⇒ Object
64 65 66 67 |
# File 'lib/ezid/client.rb', line 64 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.
113 114 115 |
# File 'lib/ezid/client.rb', line 113 def logged_in? session.open? end |
#logger ⇒ Logger
The client logger
77 78 79 |
# File 'lib/ezid/client.rb', line 77 def logger @logger ||= config.logger end |
#login ⇒ Ezid::Client
Open a session
90 91 92 93 94 95 96 97 98 |
# File 'lib/ezid/client.rb', line 90 def login if logged_in? logger.info("Already logged in, skipping login request.") else response = execute LoginRequest session.open(response.) end self end |
#logout ⇒ Ezid::Client
Close the session
102 103 104 105 106 107 108 109 110 |
# File 'lib/ezid/client.rb', line 102 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
133 134 135 136 137 |
# File 'lib/ezid/client.rb', line 133 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
145 146 147 |
# File 'lib/ezid/client.rb', line 145 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)
172 173 174 |
# File 'lib/ezid/client.rb', line 172 def server_status(*subsystems) execute ServerStatusRequest, *subsystems end |
#session ⇒ Ezid::Session
The client session
83 84 85 |
# File 'lib/ezid/client.rb', line 83 def session @session ||= Session.new end |