Class: SGS::Authenticate

Inherits:
Object
  • Object
show all
Defined in:
lib/sgs/authenticate.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Authenticate

@args String @args String



7
8
9
# File 'lib/sgs/authenticate.rb', line 7

def initialize(args)
  @username, @password = args.fetch(:username), args.fetch(:password)
end

Instance Method Details

#cookiesObject

Returns Hash Cookies used by SGS.

Returns:

  • Hash Cookies used by SGS



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/sgs/authenticate.rb', line 14

def cookies
  @_cookies ||= lambda {
    url = %W{
      http://marknad.sgsstudentbostader.se/s3.aspx?
      page=pgRedirect&
      verifylogin=y&
      mg=1&
      id=/se/mina-sidor&
      client=#{@username}&
      pin=#{@password}&
      url=http://www.sgsstudentbostader.se/setlogin.aspx
    }.join("")

    RestClient.get(url) do |r1|
      if r1.headers[:location] =~ /blnInloggadFull=false/
        raise NotAuthorisedError.new("Invalid username of password")
      end
      RestClient.get(r1.headers[:location]) do |r2|
        return r2.cookies
      end
    end
  }.call
end