Class: HandleSystem::Client

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

Overview

Handle System client

Author:

  • David Walker

Instance Method Summary collapse

Constructor Details

#initialize(server, hs_admin, priv_key_path, pass_phrase = nil) ⇒ Client

New Handle System client

Parameters:

  • server (String)

    ip_address:port, e.g., 123.456.78.9:8000

  • hs_admin (String)

    handle administrator

  • priv_key_path (String)

    file path to private key

  • pass_phrase (String) (defaults to: nil)
    optional

    pass phrase for private key



18
19
20
21
# File 'lib/handle_system/client.rb', line 18

def initialize(server, hs_admin, priv_key_path, pass_phrase = nil)
  @http_client = HttpClient.new(server, hs_admin, priv_key_path, pass_phrase)
  @handle_base = 'http://hdl.handle.net/'
end

Instance Method Details

#create(handle, url, email = nil, hs_admin = nil) ⇒ string

Create a new handle

Parameters:

  • handle (String)

    e.g., 20.500.12345/876

  • url (String)

    the url we want to register

  • email (String) (defaults to: nil)
    optional

    email address

  • hs_admin (String) (defaults to: nil)
    optional

    handle administrator

Returns:

  • (string)

    the new handle url at hdl.handle.net



33
34
35
# File 'lib/handle_system/client.rb', line 33

def create(handle, url, email = nil, hs_admin = nil)
  set_record(handle, url, email, hs_admin, false)
end

#delete(handle) ⇒ Boolean

Delete a handle

Parameters:

  • handle (String)

    handle identifier

Returns:

  • (Boolean)

    true if we deleted the record



72
73
74
75
# File 'lib/handle_system/client.rb', line 72

def delete(handle)
  json = @http_client.delete('/handles/' + handle)
  return true if json['responseCode'] == 1
end

#get(handle) ⇒ HandleSystem::Record

Return the full record for a handle

Parameters:

  • handle (String)

    handle identifier

Returns:



60
61
62
63
# File 'lib/handle_system/client.rb', line 60

def get(handle)
  json = @http_client.get('/handles/' + handle)
  Record.new.from_json(json)
end

#update(handle, url, email = nil, hs_admin = nil) ⇒ string

Update an existing handle

Will create a new handle if no record already exists

Parameters:

  • handle (String)

    e.g., 20.500.12345/876

  • url (String)

    the url we want to register

  • email (String) (defaults to: nil)
    optional

    email address

  • hs_admin (String) (defaults to: nil)
    optional

    handle administrator

Returns:

  • (string)

    the new handle url at hdl.handle.net



49
50
51
# File 'lib/handle_system/client.rb', line 49

def update(handle, url, email = nil, hs_admin = nil)
  set_record(handle, url, email, hs_admin, true)
end