patriot_web_networker.rb 1.36 KB
Newer Older
1 2 3
require 'httparty'

module PatriotWeb
4
  # Contains utilities for making HTTP requests to PatriotWeb
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
  class Networker
    def fetch_page_containing_semester_data
      HTTParty.get('https://patriotweb.gmu.edu/pls/prod/bwckschd.p_disp_dyn_sched')
    end

    def fetch_subjects(semester_id)
      HTTParty.post('https://patriotweb.gmu.edu/pls/prod/bwckgens.p_proc_term_date',
                    body: "p_calling_proc=bwckschd.p_disp_dyn_sched&p_term=#{semester_id}&p_by_date=Y&p_from_date=&p_to_date=",
                    headers: {
                      'Content-Type' => 'application/x-www-form-urlencoded',
                      'charset' => 'utf-8'
                    })
    end

    def fetch_courses_in_subject(subject)
      HTTParty.post('https://patriotweb.gmu.edu/pls/prod/bwckschd.p_get_crse_unsec',
                    body: "term_in=201870&sel_subj=dummy&sel_day=dummy&sel_schd=dummy&sel_insm=dummy&sel_camp=dummy&sel_levl=dummy&sel_sess=dummy&sel_instr=dummy&sel_ptrm=dummy&sel_attr=dummy&sel_subj=#{subject}&sel_crse=&sel_title=&sel_schd=%25&sel_from_cred=&sel_to_cred=&sel_camp=%25&sel_levl=%25&sel_ptrm=%25&sel_instr=%25&begin_hh=0&begin_mi=0&begin_ap=x&end_hh=0&end_mi=0&end_ap=x",
                    headers: {
                      'Content-Type' => 'application/x-www-form-urlencoded',
                      'charset' => 'utf-8'
                    })
    end
  end
end