Class: TuwienLogon::UserInfoRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/tuwien_logon/user_info_request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url = TuwienLogon.config.user_info_url) ⇒ UserInfoRequest

Returns a new instance of UserInfoRequest.



9
10
11
# File 'lib/tuwien_logon/user_info_request.rb', line 9

def initialize(url = TuwienLogon.config.)
  @url = URI.parse(url)
end

Instance Attribute Details

#urlObject

Returns the value of attribute url.



7
8
9
# File 'lib/tuwien_logon/user_info_request.rb', line 7

def url
  @url
end

Instance Method Details

#create_user_info(infos = [], params = TuwienLogon.config.user_info_params) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/tuwien_logon/user_info_request.rb', line 21

def (infos = [], params = TuwienLogon.config.)
  infos = split_response(infos.to_s) unless infos.is_a? Array
    
  userdata = TuwienLogon::UserInfo.new(params)
  params.each_with_index do |param, index|
    userdata.send("#{param}=".to_sym, infos[index]) unless infos[index].nil? || infos[index].empty?
  end
  userdata
end

#get(params = {}) ⇒ Object



31
32
33
34
# File 'lib/tuwien_logon/user_info_request.rb', line 31

def get(params = {})
  url.query = query_string(params)
  Net::HTTP.get_response(url).body
end

#get_user_info(params = {}) ⇒ Object



17
18
19
# File 'lib/tuwien_logon/user_info_request.rb', line 17

def (params = {})
  (get(params))
end

#query_string(params = {}) ⇒ Object



36
37
38
# File 'lib/tuwien_logon/user_info_request.rb', line 36

def query_string(params = {})
  params.map { |key, value| "#{key}=#{value}" }.join('&')
end

#split_response(response) ⇒ Object



13
14
15
# File 'lib/tuwien_logon/user_info_request.rb', line 13

def split_response(response)
  response.strip.split("\t")
end