Class: Ezid::Client
- Inherits:
-
Object
- Object
- Ezid::Client
- Defined in:
- lib/ezid/client.rb
Overview
EZID client
Instance Attribute Summary collapse
-
#password ⇒ Object
readonly
, :host.
-
#session ⇒ Object
readonly
, :host.
-
#user ⇒ Object
readonly
, :host.
Class Method Summary collapse
-
.config ⇒ Object
Configuration reader.
-
.configure {|the| ... } ⇒ Object
Yields the configuration to a block.
Instance Method Summary collapse
-
#config ⇒ Ezid::Configuration
The client configuration.
-
#create_identifier(identifier, metadata = nil) ⇒ Ezid::Response
The response.
-
#delete_identifier(identifier) ⇒ Ezid::Response
The response.
-
#get_identifier_metadata(identifier) ⇒ Ezid::Response
The response.
-
#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
The response.
-
#modify_identifier(identifier, metadata) ⇒ Ezid::Response
The response.
-
#server_status(*subsystems) ⇒ Ezid::Status
The status response.
Constructor Details
#initialize(opts = {}) ⇒ Client
Returns a new instance of Client.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ezid/client.rb', line 33 def initialize(opts = {}) @session = Session.new @user = opts[:user] || config.user @password = opts[:password] || config.password if block_given? login yield self logout end end |
Instance Attribute Details
#password ⇒ Object (readonly)
, :host
31 32 33 |
# File 'lib/ezid/client.rb', line 31 def password @password end |
#session ⇒ Object (readonly)
, :host
31 32 33 |
# File 'lib/ezid/client.rb', line 31 def session @session end |
#user ⇒ Object (readonly)
, :host
31 32 33 |
# File 'lib/ezid/client.rb', line 31 def user @user end |
Class Method Details
.config ⇒ Object
Configuration reader
20 21 22 |
# File 'lib/ezid/client.rb', line 20 def config @config ||= Configuration.new end |
.configure {|the| ... } ⇒ Object
Yields the configuration to a block
26 27 28 |
# File 'lib/ezid/client.rb', line 26 def configure yield config end |
Instance Method Details
#config ⇒ Ezid::Configuration
The client configuration
50 51 52 |
# File 'lib/ezid/client.rb', line 50 def config self.class.config end |
#create_identifier(identifier, metadata = nil) ⇒ Ezid::Response
Returns the response.
98 99 100 101 102 103 104 |
# File 'lib/ezid/client.rb', line 98 def create_identifier(identifier, =nil) response = Request.execute(:Put, "/id/#{identifier}") do |request| add_authentication(request) (request, ) end handle_response(response, "CREATE #{identifier}") end |
#delete_identifier(identifier) ⇒ Ezid::Response
Returns the response.
145 146 147 148 149 150 |
# File 'lib/ezid/client.rb', line 145 def delete_identifier(identifier) response = Request.execute(:Delete, "/id/#{identifier}") do |request| add_authentication(request) end handle_response(response, "DELETE #{identifier}") end |
#get_identifier_metadata(identifier) ⇒ Ezid::Response
Returns the response.
135 136 137 138 139 140 |
# File 'lib/ezid/client.rb', line 135 def (identifier) response = Request.execute(:Get, "/id/#{identifier}") do |request| add_authentication(request) end handle_response(response, "GET #{identifier}") end |
#inspect ⇒ Object
44 45 46 |
# File 'lib/ezid/client.rb', line 44 def inspect "#<#{self.class.name} user=\"#{user}\" session=#{logged_in? ? 'OPEN' : 'CLOSED'}>" end |
#logged_in? ⇒ true, false
Returns whether the client is logged in.
90 91 92 |
# File 'lib/ezid/client.rb', line 90 def logged_in? session.open? end |
#logger ⇒ Logger
The client logger
56 57 58 |
# File 'lib/ezid/client.rb', line 56 def logger @logger ||= config.logger end |
#login ⇒ Ezid::Client
Open a session
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/ezid/client.rb', line 63 def login if logged_in? logger.info("Already logged in, skipping login request.") else response = Request.execute(:Get, "/login") do |request| add_authentication(request) end handle_response(response, "LOGIN") session.open(response.) end self end |
#logout ⇒ Ezid::Client
Close the session
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/ezid/client.rb', line 78 def logout if logged_in? response = Request.execute(:Get, "/logout") handle_response(response, "LOGOUT") session.close else logger.info("Not logged in, skipping logout request.") end self end |
#mint_identifier(shoulder = nil, metadata = nil) ⇒ Ezid::Response
Returns the response.
110 111 112 113 114 115 116 117 118 |
# File 'lib/ezid/client.rb', line 110 def mint_identifier(shoulder=nil, =nil) shoulder ||= config.default_shoulder raise Error, "Shoulder missing -- cannot mint identifier." unless shoulder response = Request.execute(:Post, "/shoulder/#{shoulder}") do |request| add_authentication(request) (request, ) end handle_response(response, "MINT #{shoulder}") end |
#modify_identifier(identifier, metadata) ⇒ Ezid::Response
Returns the response.
124 125 126 127 128 129 130 |
# File 'lib/ezid/client.rb', line 124 def modify_identifier(identifier, ) response = Request.execute(:Post, "/id/#{identifier}") do |request| add_authentication(request) (request, ) end handle_response(response, "MODIFY #{identifier}") end |
#server_status(*subsystems) ⇒ Ezid::Status
Returns the status response.
155 156 157 158 |
# File 'lib/ezid/client.rb', line 155 def server_status(*subsystems) response = Request.execute(:Get, "/status?subsystems=#{subsystems.join(',')}") handle_response(Status.new(response), "STATUS") end |