Sha256: 79ba5a283ab303ce6a523817482d54576d06dcaf929bf63ca5ce7b8029da5b4a

Contents?: true

Size: 1.64 KB

Versions: 31

Compression:

Stored size: 1.64 KB

Contents

# encoding: utf-8

require 'libis/services/rest_client'

module Libis
  module Services
    module Rosetta

      class PdsHandler
        include Libis::Services::RestClient

        # @param [String] base_url
        def initialize(base_url = 'https://pds.libis.be')
          configure base_url
        end

        # @param [String] user
        # @param [String] password
        # @param [String] institute
        # @return [String] PDS handle, nil if could not login
        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

        # @param [String] pds_handle
        # @return [Boolean] true if success
        def logout(pds_handle)
          params = {
              func: 'logout',
              pds_handle: pds_handle
          }
          response = get 'pds', params
          response.code == 200
        end

        # @param [String] pds_handle
        # @return [Hash] with user information. At least containing: 'id', 'name', 'institute' and 'group'
        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
      end

    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
libis-services-1.1.0 lib/libis/services/rosetta/pds_handler.rb
libis-services-1.0.13 lib/libis/services/rosetta/pds_handler.rb
libis-services-1.0.12 lib/libis/services/rosetta/pds_handler.rb
libis-services-1.0.11 lib/libis/services/rosetta/pds_handler.rb
libis-services-1.0.10 lib/libis/services/rosetta/pds_handler.rb
libis-services-1.0.7 lib/libis/services/rosetta/pds_handler.rb
libis-services-1.0.6 lib/libis/services/rosetta/pds_handler.rb
libis-services-1.0.5 lib/libis/services/rosetta/pds_handler.rb
libis-services-1.0.2 lib/libis/services/rosetta/pds_handler.rb
libis-services-1.0.1 lib/libis/services/rosetta/pds_handler.rb
libis-services-1.0.0 lib/libis/services/rosetta/pds_handler.rb
libis-services-0.2.1 lib/libis/services/rosetta/pds_handler.rb
libis-services-0.2.0 lib/libis/services/rosetta/pds_handler.rb
libis-services-0.1.18 lib/libis/services/rosetta/pds_handler.rb
libis-services-0.1.17 lib/libis/services/rosetta/pds_handler.rb
libis-services-0.1.16 lib/libis/services/rosetta/pds_handler.rb
libis-services-0.1.15 lib/libis/services/rosetta/pds_handler.rb
libis-services-0.1.14 lib/libis/services/rosetta/pds_handler.rb
libis-services-0.1.13 lib/libis/services/rosetta/pds_handler.rb
libis-services-0.1.12 lib/libis/services/rosetta/pds_handler.rb