Class: Libis::Services::Rosetta::PdsHandler

Inherits:
Object
  • Object
show all
Includes:
Libis::Services::RestClient
Defined in:
lib/libis/services/rosetta/pds_handler.rb

Instance Attribute Summary

Attributes included from Libis::Services::RestClient

#client

Instance Method Summary collapse

Methods included from Libis::Services::RestClient

#configure, #get, #post_data, #post_url, #put_data, #put_url

Constructor Details

#initialize(base_url = 'https://pds.libis.be') ⇒ PdsHandler

Returns a new instance of PdsHandler.

Parameters:

  • base_url (String) (defaults to: 'https://pds.libis.be')


13
14
15
# File 'lib/libis/services/rosetta/pds_handler.rb', line 13

def initialize(base_url = 'https://pds.libis.be')
  configure base_url
end

Instance Method Details

#login(user, password, institute) ⇒ String

Returns PDS handle, nil if could not login.

Parameters:

  • user (String)
  • password (String)
  • institute (String)

Returns:

  • (String)

    PDS handle, nil if could not login



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/libis/services/rosetta/pds_handler.rb', line 21

def (user, password, institute)
  params = {
      func: 'login-url',
      bor_id: user,
      bor_verification: password,
      institute: institute
  }
  response = get 'pds', params
  return nil unless response.code == 200 and response.body.match /pds_handle=(\d+)[^\d]/
  $1
end

#logout(pds_handle) ⇒ Boolean

Returns true if success.

Parameters:

  • pds_handle (String)

Returns:

  • (Boolean)

    true if success



35
36
37
38
39
40
41
42
# File 'lib/libis/services/rosetta/pds_handler.rb', line 35

def logout(pds_handle)
  params = {
      func: 'logout',
      pds_handle: pds_handle
  }
  response = get 'pds', params
  response.code == 200
end

#user_info(pds_handle) ⇒ Hash

Returns with user information. At least containing: ‘id’, ‘name’, ‘institute’ and ‘group’.

Parameters:

  • pds_handle (String)

Returns:

  • (Hash)

    with user information. At least containing: ‘id’, ‘name’, ‘institute’ and ‘group’



46
47
48
49
50
51
52
53
54
55
# File 'lib/libis/services/rosetta/pds_handler.rb', line 46

def (pds_handle)
  params = {
      func: 'get-attribute',
      attribute: 'BOR_INFO',
      pds_handle: pds_handle
  }
  response = get 'pds', params
  return nil unless response.code == 200
  Nori.new(convert_tags_to: lambda {|tag| tag.to_sym}).parse(response.body)
end