mitchellh-rubyuw 0.7.0 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.0
1
+ 0.7.2
@@ -0,0 +1,110 @@
1
+ class MyUW
2
+ # = Synopsis
3
+ # Gets information regarding enrollment within a specific
4
+ # subject.
5
+ class CurriculumEnrollment
6
+ attr_reader :term
7
+ attr_reader :curriculum
8
+ attr_accessor :myuw
9
+ attr_reader :data
10
+
11
+ def initialize(myuw)
12
+ @myuw = myuw
13
+ @term = nil
14
+ @data = nil
15
+ @curriculum = nil
16
+ end
17
+
18
+ # Custom setter for SLN to reset data
19
+ def curriculum=(value)
20
+ @curriculum = value
21
+ @data = nil
22
+ end
23
+
24
+ # Custom setter for term to reset data
25
+ def term=(value)
26
+ @term = value
27
+ @data = nil
28
+ end
29
+
30
+ # Fetches the information for the given SLN.
31
+ def fetch_data
32
+ raise ArgumentError.new("Curriculum not set.") if @curriculum.nil?
33
+ raise ArgumentError.new("Term not set.") if @term.nil?
34
+ raise NotLoggedInError.new("User must be logged in to fetch SLN data") unless @myuw.logged_in?
35
+
36
+ # Request the actual page
37
+ page = get_dept_page
38
+
39
+ # Get the actual course information
40
+ end
41
+
42
+ # Get data for a specific SLN
43
+ def data_by_sln(sln, reload = false)
44
+ fetch_data if @data.nil? || reload
45
+ @data[sln]
46
+ end
47
+
48
+ # Gets the SLN info page for the SLN and term, raising
49
+ # an exception if it is requested too soon
50
+ def get_dept_page
51
+ page = @myuw.browser.get("https://sdb.admin.washington.edu/timeschd/uwnetid/tsstat.asp?QTRYR=#{@term}&CURRIC=#{@curriculum}")
52
+ if page.body.to_s =~ /No sections found for #{@curriculum}./
53
+ raise InvalidCurriculumError.new("Curriculum does not exist.")
54
+ end
55
+
56
+ page
57
+ end
58
+
59
+ # Gets and stores all course data
60
+ def get_all_courses_data(page)
61
+ nodes = page.search('//table//tr[count(th)>1 and @bgcolor="#d0d0d0"]//following-sibling::tr')
62
+ raise InvalidPageError.new("Couldn't find any courses listed.") if nodes.empty?
63
+
64
+ @data = {}
65
+ nodes.each do |node|
66
+ node_data = get_course_data(node)
67
+ @data[node_data[:sln]] = node_data
68
+ end
69
+ end
70
+
71
+ # Gets a single course row's data
72
+ def get_course_data(row)
73
+ nodes = row.search('td')
74
+ raise InvalidPageError.new("Couldn't find course information for a single row.") if nodes.empty?
75
+
76
+ data_keys = [:sln, :course, :section, :type, :title, :current_enrollment, :limit_enrollment,
77
+ :room_capacity, :space_available, nil, :notes]
78
+
79
+ data = extract_info(data_keys, nodes)
80
+ raise InvalidPageError.new("Failed to extract data for single row.") if !data
81
+
82
+ data
83
+ end
84
+
85
+ # Extracts course information from each node and
86
+ # stores it as the proper key in the @data variable
87
+ def extract_info(keys, nodes)
88
+ return false if nodes.empty?
89
+
90
+ data = {}
91
+ nodes.each_with_index do |node, i|
92
+ # Make sure we have keys left still
93
+ if i < keys.length then
94
+ data_key = keys[i]
95
+
96
+ # If the key is nil, we skip this node
97
+ unless data_key.nil?
98
+ data[data_key] = node.inner_text.strip.gsub("\302\240", "")
99
+ end
100
+ end
101
+ end
102
+
103
+ data
104
+ end
105
+ end
106
+
107
+ #
108
+ # Exceptions
109
+ class InvalidCurriculumError < StandardError; end
110
+ end
data/lib/myuw/session.rb CHANGED
@@ -20,7 +20,7 @@ class MyUW
20
20
  def logged_in?
21
21
  home = get_bare_login_page
22
22
  relay_page = home.form_with(:name => 'f').submit()
23
- !relay_page.search("span.greetingw").empty?
23
+ !relay_page.search("//div[@class='main_search']").empty?
24
24
  end
25
25
 
26
26
  # Logs a user in using the given email and password
data/rubyuw.gemspec CHANGED
@@ -1,12 +1,15 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
1
4
  # -*- encoding: utf-8 -*-
2
5
 
3
6
  Gem::Specification.new do |s|
4
7
  s.name = %q{rubyuw}
5
- s.version = "0.7.0"
8
+ s.version = "0.7.2"
6
9
 
7
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
11
  s.authors = ["Mitchell Hashimoto"]
9
- s.date = %q{2009-07-11}
12
+ s.date = %q{2009-09-09}
10
13
  s.description = %q{TODO}
11
14
  s.email = %q{mitchell.hashimoto@gmail.com}
12
15
  s.extra_rdoc_files = [
@@ -18,6 +21,7 @@ Gem::Specification.new do |s|
18
21
  "Rakefile",
19
22
  "VERSION",
20
23
  "lib/myuw.rb",
24
+ "lib/myuw/curriculum_enrollment.rb",
21
25
  "lib/myuw/errors.rb",
22
26
  "lib/myuw/registration.rb",
23
27
  "lib/myuw/schedule.rb",
@@ -29,7 +33,11 @@ Gem::Specification.new do |s|
29
33
  "test/live/session_test.rb",
30
34
  "test/live/sln_test.rb",
31
35
  "test/live/test_helper.rb",
36
+ "test/mocked/curriculum_enrollment_test.rb",
32
37
  "test/mocked/fixture_pages/bad_request.html",
38
+ "test/mocked/fixture_pages/curric_courses.html",
39
+ "test/mocked/fixture_pages/curric_no_courses.html",
40
+ "test/mocked/fixture_pages/curric_no_curric_found.html",
33
41
  "test/mocked/fixture_pages/logged_in_relay.html",
34
42
  "test/mocked/fixture_pages/login.html",
35
43
  "test/mocked/fixture_pages/no_form_login.html",
@@ -59,11 +67,10 @@ Gem::Specification.new do |s|
59
67
  "test/mocked/test_helper.rb",
60
68
  "test/password.rb.sample"
61
69
  ]
62
- s.has_rdoc = true
63
70
  s.homepage = %q{http://github.com/mitchellh/rubyuw}
64
71
  s.rdoc_options = ["--charset=UTF-8"]
65
72
  s.require_paths = ["lib"]
66
- s.rubygems_version = %q{1.3.1}
73
+ s.rubygems_version = %q{1.3.4}
67
74
  s.summary = %q{Library which provides a ruby interface to the University of Washington student portal.}
68
75
  s.test_files = [
69
76
  "test/live/registration_test.rb",
@@ -82,7 +89,7 @@ Gem::Specification.new do |s|
82
89
 
83
90
  if s.respond_to? :specification_version then
84
91
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
85
- s.specification_version = 2
92
+ s.specification_version = 3
86
93
 
87
94
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
88
95
  s.add_runtime_dependency(%q<tenderlove-mechanize>, [">= 0.9.2.20090428085858"])