Class: Libis::Services::Rosetta::PdsHandler
- Inherits:
-
Object
- Object
- Libis::Services::Rosetta::PdsHandler
- Includes:
- Libis::Services::RestClient
- Defined in:
- lib/libis/services/rosetta/pds_handler.rb
Instance Attribute Summary
Attributes included from Libis::Services::RestClient
Instance Method Summary collapse
-
#initialize(base_url = 'https://pds.libis.be') ⇒ PdsHandler
constructor
A new instance of PdsHandler.
-
#login(user, password, institute) ⇒ String
PDS handle, nil if could not login.
-
#logout(pds_handle) ⇒ Boolean
True if success.
-
#user_info(pds_handle) ⇒ Hash
With user information.
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.
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.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/libis/services/rosetta/pds_handler.rb', line 21 def login(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.
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’.
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/libis/services/rosetta/pds_handler.rb', line 46 def user_info(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 |