Class: Ezid::Client

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

Overview

EZID client

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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?
    
    yield self
    logout
  end
end

Instance Attribute Details

#passwordObject (readonly)

, :host



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

def password
  @password
end

#sessionObject (readonly)

, :host



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

def session
  @session
end

#userObject (readonly)

, :host



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

def user
  @user
end

Class Method Details

.configObject

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

Yield Parameters:



26
27
28
# File 'lib/ezid/client.rb', line 26

def configure
  yield config
end

Instance Method Details

#configEzid::Configuration

The client configuration

Returns:



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.

Parameters:

  • identifier (String)

    the identifier string to create

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

    optional metadata to set

Returns:

Raises:



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.

Parameters:

  • identifier (String)

    the identifier to delete

Returns:

Raises:



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.

Parameters:

  • identifier (String)

    the identifier to retrieve

Returns:

Raises:



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

#inspectObject



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.

Returns:

  • (true, false)

    whether the client is logged in



90
91
92
# File 'lib/ezid/client.rb', line 90

def logged_in?
  session.open?
end

#loggerLogger

The client logger

Returns:

  • (Logger)

    the logger



56
57
58
# File 'lib/ezid/client.rb', line 56

def logger
  @logger ||= config.logger
end

#loginEzid::Client

Open a session

Returns:

Raises:



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ezid/client.rb', line 63

def 
  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.cookie)
  end
  self
end

#logoutEzid::Client

Close the session

Returns:



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.

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:



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.

Parameters:

  • identifier (String)

    the identifier to modify

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

    metadata to set

Returns:

Raises:



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.

Parameters:

  • subsystems (Array)

Returns:

Raises:



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