Class: SGS::Wash

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

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Wash

@args Fixnum Optional @args String @args Password



8
9
10
11
12
13
14
15
16
17
# File 'lib/sgs/wash.rb', line 8

def initialize(args)
  @week = args[:week] || Date.today.cweek

  @cookies = SGS::Authenticate.new({
    username: args.fetch(:username),
    password: args.fetch(:password)
  }).cookies

  @booking = Struct.new(:group, :start_time, :end_time, :where)
end

Instance Method Details

#bookingsObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/sgs/wash.rb', line 22

def bookings
  @_bookings ||= lambda {
    url = %W{
      http://tvatta.sgsstudentbostader.se/wwwashbookings.aspx?
      panelId=616&
      weekoffset=0&
      date=#{URI.escape week_dates(@week).strftime("%Y-%m-%d %H:%M:%S")}
    }.join("")

    RestClient.get("http://www.sgsstudentbostader.se/ext_gw.aspx?module=wwwash&lang=se", cookies: @cookies) do |r|
      RestClient.get(r.headers[:location], cookies: @cookies) do |r|
        return prepare_data(RestClient.get(url, {
          cookies: r.cookies.merge(@cookies)
        }))
      end
    end
  }.call
end