class ParentVUE::Service
Attributes
base_url[R]
mechanize[R]
students[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/parentvue/service.rb, line 10 def initialize(options = {}) @mechanize = Mechanize.new @login_url = options[:login_url] uri = URI.parse(@login_url) @base_url = "#{uri.scheme}://#{uri.host}" end
Public Instance Methods
main_login_page()
click to toggle source
# File lib/parentvue/service.rb, line 19 def main_login_page @mechanize.get(@login_url) end
parent_sign_in(username, password)
click to toggle source
# File lib/parentvue/service.rb, line 23 def parent_sign_in(username, password) parent_login_link = main_login_page.link_with(text: /ParentVUE/) login_page = parent_login_link.click post_login_page = login_with_credentials(login_page, username, password) return false if post_login_page.at '#ctl00_USER_ERROR' scrape_students(post_login_page) return post_login_page end
Private Instance Methods
login_with_credentials(parent_login_page, username, password)
click to toggle source
# File lib/parentvue/service.rb, line 38 def login_with_credentials(parent_login_page, username, password) login_form = parent_login_page.form('aspnetForm') login_form['ctl00$MainContent$username'] = username login_form['ctl00$MainContent$password'] = password @mechanize.submit(login_form, login_form.buttons.first) end
scrape_students(home_page)
click to toggle source
# File lib/parentvue/service.rb, line 45 def scrape_students(home_page) @students = [] home_page.search('div.student-info').each do |element| student_id = element.search('span.student-id').text student_id.slice! 'ID: ' @students << { name: element.search('span.student-name').text, id: student_id, school_name: element.search('div.school').text } end end