Module: TPEX::Client::Auth

Included in:
TPEX::Client
Defined in:
lib/tpex/client/auth.rb

Instance Method Summary collapse

Instance Method Details

#loginObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/tpex/client/auth.rb', line 6

def ()
  data = JSON.generate({"username" => username, "password" => password})
     #need raw response for set-cookie info
  response_raw = post('user/login', data, true)
     #puts "RAW RESPONSE: *********   #{response_raw.inspect}"
     response = Response.create( response_raw.body )
     #puts "OTHER RESPONSE: ******** #{response}"
     #puts "KEYS: ***** #{response.keys}"
     @cookie = "#{response["session_name"]}=#{response["sessid"]}"

     #production server cookies
     bnes = ""
     bni = ""
     junkout = response_raw["set-cookie"].split(";")
     junkout.each do |line|
       if line =~ /BNES_SESS/
         bnes = line.match(/(BNES_SESS.*)/)[0]
       end
     end
     junkout.each do |line|
       if line =~ /BNI/
         bni = line.match(/(BNI.*)/)[0]
       end
     end
     if bnes != ""
       @cookie = @cookie + ';' + bnes
     end
     if bni != ""
       @cookie = @cookie + ";" + bni
     end
     puts "COOKIES: #{@cookie}"
  response
end

#logoutObject



40
41
42
43
44
# File 'lib/tpex/client/auth.rb', line 40

def logout()
  response = post('user/logout')
  @cookie = nil
  response
end