class IntraRequestsManager
Public Class Methods
new()
click to toggle source
# File lib/susies/IntraRequestsManager.rb, line 8 def initialize @http = Net::HTTP.new 'intra.epitech.eu', 443 @http.use_ssl = true @planningID = 0 end
Public Instance Methods
authenticate!(autologinPath)
click to toggle source
# File lib/susies/IntraRequestsManager.rb, line 15 def authenticate!(autologinPath) response = @http.get autologinPath response_cookies = response.get_fields 'set-cookie' cookies_array = response_cookies.collect { |cookie| cookie.split('; ').first } @cookies = cookies_array.join('; ') fetchPlanningID! end
fetchPlanningID!()
click to toggle source
# File lib/susies/IntraRequestsManager.rb, line 25 def fetchPlanningID! path = "/planning/all-schedules/?format=json" response = @http.get path, { 'Cookie' => @cookies } planningsJSON = JSON.parse response.body unless planningsJSON.nil? planningsJSON.each do |planning| if planning['type'] == 'susie' @planningID = planning['id'] break end end end end
getSusies(startDate, endDate)
click to toggle source
# File lib/susies/IntraRequestsManager.rb, line 42 def getSusies(startDate, endDate) path = "/planning/#{ @planningID }/events?start=#{ formatDate startDate }&end=#{ formatDate endDate }&format=json" response = @http.get path, { 'Cookie' => @cookies } susiesJSON = JSON.parse response.body unless susiesJSON.nil? susiesJSON.collect { |susieJSON| Susie.new susieJSON, "https://intra.epitech.eu/planning/#{ @planningID }/#{ susieJSON['id'] }" } else [] end end
registerSusie(susie)
click to toggle source
# File lib/susies/IntraRequestsManager.rb, line 56 def registerSusie(susie) path = "/planning/#{ @planningID }/#{ susie.id }/subscribe?format=json®istercalendar" response = @http.post path, '', { 'Cookie' => @cookies } susie.nb_registered += 1 susie end
Private Instance Methods
formatDate(date)
click to toggle source
# File lib/susies/IntraRequestsManager.rb, line 68 def formatDate(date) date.strftime '%Y-%m-%d' end