mitchellh-rubyuw 0.99.0 → 0.99.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -46,6 +46,12 @@ The following is a quick and simple example:
46
46
  # Get SLN information
47
47
  sln_info = RubyUW::SLN.find(14153, "AUT+2009")
48
48
 
49
+ ## Documentation
50
+
51
+ You may view all documentation [at the following URL](http://mitchellh.github.com/RubyUW/):
52
+
53
+ http://mitchellh.github.com/RubyUW/
54
+
49
55
  ## Testing
50
56
 
51
57
  RubyUW includes a comprehensive test suite included both live and
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.99.0
1
+ 0.99.1
data/lib/rubyuw.rb CHANGED
@@ -5,4 +5,5 @@ require 'rubyuw/errors'
5
5
  require 'rubyuw/base'
6
6
  require 'rubyuw/connection'
7
7
  require 'rubyuw/sln'
8
- require 'rubyuw/curriculum_enrollment'
8
+ require 'rubyuw/curriculum_enrollment'
9
+ require 'rubyuw/schedule'
@@ -0,0 +1,52 @@
1
+ module RubyUW
2
+ # RubyUW::Schedule is used to grab the schedule of the
3
+ # authenticated user.
4
+ #
5
+ # <b>Requires authentication with RubyUW::Base prior to use!</b>
6
+ class Schedule
7
+ class << self
8
+ # Scrapes the authenticated user's schedule from MyUW.
9
+ # Authentication is required prior to use.
10
+ #
11
+ # Returns an array of {RubyUW::SLN} objects. The {RubyUW::SLN}
12
+ # object responds to the following data elements:
13
+ #
14
+ # * sln
15
+ # * course
16
+ # * type
17
+ # * credits
18
+ # * title
19
+ # * days
20
+ # * time
21
+ # * location
22
+ # * instructor
23
+ #
24
+ # To get any more details you have to use the {RubyUW::SLN.find}
25
+ # method.
26
+ def get
27
+ raise Errors::NotLoggedInError.new unless Base.authenticated?
28
+
29
+ page = Base.connection.get("https://sdb.admin.washington.edu/students/uwnetid/schedule.asp")
30
+ extract_courses(page)
31
+ end
32
+
33
+ protected
34
+
35
+ def extract_courses(page)
36
+ course_nodes = page.search("//table[@border=1 and @cellpadding=3]//tr[@bgcolor='#d0d0d0'][2]/following-sibling::*//td[@align='center']/parent::*")
37
+ courses = []
38
+ course_nodes.each do |node|
39
+ course = extract_course(node)
40
+ courses << RubyUW::SLN.new(course[:sln], nil, course)
41
+ end
42
+
43
+ courses
44
+ end
45
+
46
+ def extract_course(node)
47
+ keys = [:sln, :course, :type, :credits, :title, :days, :time, :location, :instructor]
48
+ Base.extract(node, 'td', keys)
49
+ end
50
+ end
51
+ end
52
+ end
data/rubyuw.gemspec ADDED
@@ -0,0 +1,96 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rubyuw}
8
+ s.version = "0.99.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Mitchell Hashimoto"]
12
+ s.date = %q{2009-09-14}
13
+ s.description = %q{Library which provides a ruby interface to the University of Washington student portal.}
14
+ s.email = %q{mitchell.hashimoto@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "README.md",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "lib/rubyuw.rb",
24
+ "lib/rubyuw/base.rb",
25
+ "lib/rubyuw/connection.rb",
26
+ "lib/rubyuw/curriculum_enrollment.rb",
27
+ "lib/rubyuw/errors.rb",
28
+ "lib/rubyuw/schedule.rb",
29
+ "lib/rubyuw/sln.rb",
30
+ "rubyuw.gemspec",
31
+ "test/live/curriculum_enrollment_test.rb",
32
+ "test/live/sln_test.rb",
33
+ "test/live/test_helper.rb",
34
+ "test/mocked/base_test.rb",
35
+ "test/mocked/connection_test.rb",
36
+ "test/mocked/curriculum_enrollment_test.rb",
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",
41
+ "test/mocked/fixture_pages/logged_in_relay.html",
42
+ "test/mocked/fixture_pages/login.html",
43
+ "test/mocked/fixture_pages/no_form_login.html",
44
+ "test/mocked/fixture_pages/no_login_button.html",
45
+ "test/mocked/fixture_pages/not_logged_in_relay.html",
46
+ "test/mocked/fixture_pages/registration.html",
47
+ "test/mocked/fixture_pages/registration_error.html",
48
+ "test/mocked/fixture_pages/registration_error_no_rows.html",
49
+ "test/mocked/fixture_pages/registration_no_form.html",
50
+ "test/mocked/fixture_pages/registration_success.html",
51
+ "test/mocked/fixture_pages/registration_unknown.html",
52
+ "test/mocked/fixture_pages/schedule.html",
53
+ "test/mocked/fixture_pages/schedule_diff_credit_row.html",
54
+ "test/mocked/fixture_pages/schedule_empty.html",
55
+ "test/mocked/fixture_pages/schedule_no_credit_row.html",
56
+ "test/mocked/fixture_pages/sln_does_not_exist.html",
57
+ "test/mocked/fixture_pages/sln_no_course_info.html",
58
+ "test/mocked/fixture_pages/sln_no_course_notes.html",
59
+ "test/mocked/fixture_pages/sln_no_enrollment_info.html",
60
+ "test/mocked/fixture_pages/sln_status.html",
61
+ "test/mocked/fixture_pages/welcome.html",
62
+ "test/mocked/schedule_test.rb",
63
+ "test/mocked/sln_test.rb",
64
+ "test/mocked/test_helper.rb",
65
+ "test/password.rb.sample"
66
+ ]
67
+ s.homepage = %q{http://github.com/mitchellh/rubyuw}
68
+ s.rdoc_options = ["--charset=UTF-8"]
69
+ s.require_paths = ["lib"]
70
+ s.rubygems_version = %q{1.3.4}
71
+ s.summary = %q{Library which provides a ruby interface to the University of Washington student portal.}
72
+ s.test_files = [
73
+ "test/live/curriculum_enrollment_test.rb",
74
+ "test/live/sln_test.rb",
75
+ "test/live/test_helper.rb",
76
+ "test/mocked/base_test.rb",
77
+ "test/mocked/connection_test.rb",
78
+ "test/mocked/curriculum_enrollment_test.rb",
79
+ "test/mocked/schedule_test.rb",
80
+ "test/mocked/sln_test.rb",
81
+ "test/mocked/test_helper.rb"
82
+ ]
83
+
84
+ if s.respond_to? :specification_version then
85
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
86
+ s.specification_version = 3
87
+
88
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
89
+ s.add_runtime_dependency(%q<tenderlove-mechanize>, [">= 0.9.3.20090623142847"])
90
+ else
91
+ s.add_dependency(%q<tenderlove-mechanize>, [">= 0.9.3.20090623142847"])
92
+ end
93
+ else
94
+ s.add_dependency(%q<tenderlove-mechanize>, [">= 0.9.3.20090623142847"])
95
+ end
96
+ end
@@ -0,0 +1,89 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class ScheduleTest < Test::Unit::TestCase
4
+ setup do
5
+ RubyUW::Schedule.publicize_singleton_methods
6
+ end
7
+
8
+ teardown do
9
+ RubyUW::Schedule.protect_singleton_methods
10
+ end
11
+
12
+ context "getting the schedule" do
13
+ context "with authentication" do
14
+ should "raise an error if not authenticated" do
15
+ RubyUW::Base.expects(:authenticated?).returns(false)
16
+ assert_raises(RubyUW::Errors::NotLoggedInError) { RubyUW::Schedule.get }
17
+ end
18
+
19
+ should "not raise an error if authenticated" do
20
+ RubyUW::Base.expects(:authenticated?).returns(true)
21
+ assert_nothing_raised { RubyUW::Schedule.get }
22
+ end
23
+ end
24
+
25
+ context "with the mocked pages" do
26
+ setup do
27
+ RubyUW::Base.stubs(:authenticated?).returns(true)
28
+
29
+ @courses = {
30
+ "14368" => {
31
+ :course => "HIST 111 A",
32
+ :type => "LC",
33
+ :credits => "5.0",
34
+ :title => "THE ANCIENT WORLD",
35
+ :days => "MTWTh",
36
+ :time => "130-220",
37
+ :location => "SMI 120",
38
+ :instructor => "WALKER,JOEL T"
39
+ },
40
+ "14372" => {},
41
+ "12271" => {}
42
+ }
43
+ end
44
+
45
+ should "pull the right data" do
46
+ expect_get("schedule")
47
+ schedule = RubyUW::Schedule.get
48
+
49
+ assert !schedule.nil?
50
+ assert_equal @courses.length, schedule.length
51
+ schedule.each do |course|
52
+ current_course = @courses[course.sln]
53
+ assert !current_course.nil?
54
+
55
+ current_course.each do |k,v|
56
+ assert_equal v, course.data(k)
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ context "extracting courses" do
64
+ setup do
65
+ @page = mock('page')
66
+ end
67
+
68
+ should "call extract_course on every result from the xpath" do
69
+ @results = [1,2,3]
70
+ @page.expects(:search).returns(@results)
71
+ RubyUW::Schedule.expects(:extract_course).times(@results.length).returns({:sln => "foo"})
72
+ RubyUW::Schedule.extract_courses(@page)
73
+ end
74
+
75
+ should "turn the results of extract_course into a RubyUW::SLN object" do
76
+ @results = [1]
77
+ @page.expects(:search).returns(@results)
78
+ RubyUW::Schedule.expects(:extract_course).once.returns({ :sln => "foo" })
79
+ RubyUW::SLN.expects(:new).once.with("foo", anything, anything)
80
+ RubyUW::Schedule.extract_courses(@page)
81
+ end
82
+
83
+ should "return an array of results" do
84
+ @page.expects(:search).returns([])
85
+ results = RubyUW::Schedule.extract_courses(@page)
86
+ assert results.empty?
87
+ end
88
+ end
89
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mitchellh-rubyuw
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.99.0
4
+ version: 0.99.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mitchell Hashimoto
@@ -40,7 +40,9 @@ files:
40
40
  - lib/rubyuw/connection.rb
41
41
  - lib/rubyuw/curriculum_enrollment.rb
42
42
  - lib/rubyuw/errors.rb
43
+ - lib/rubyuw/schedule.rb
43
44
  - lib/rubyuw/sln.rb
45
+ - rubyuw.gemspec
44
46
  - test/live/curriculum_enrollment_test.rb
45
47
  - test/live/sln_test.rb
46
48
  - test/live/test_helper.rb
@@ -72,12 +74,12 @@ files:
72
74
  - test/mocked/fixture_pages/sln_no_enrollment_info.html
73
75
  - test/mocked/fixture_pages/sln_status.html
74
76
  - test/mocked/fixture_pages/welcome.html
77
+ - test/mocked/schedule_test.rb
75
78
  - test/mocked/sln_test.rb
76
79
  - test/mocked/test_helper.rb
77
80
  - test/password.rb.sample
78
81
  has_rdoc: false
79
82
  homepage: http://github.com/mitchellh/rubyuw
80
- licenses:
81
83
  post_install_message:
82
84
  rdoc_options:
83
85
  - --charset=UTF-8
@@ -98,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
100
  requirements: []
99
101
 
100
102
  rubyforge_project:
101
- rubygems_version: 1.3.5
103
+ rubygems_version: 1.2.0
102
104
  signing_key:
103
105
  specification_version: 3
104
106
  summary: Library which provides a ruby interface to the University of Washington student portal.
@@ -109,5 +111,6 @@ test_files:
109
111
  - test/mocked/base_test.rb
110
112
  - test/mocked/connection_test.rb
111
113
  - test/mocked/curriculum_enrollment_test.rb
114
+ - test/mocked/schedule_test.rb
112
115
  - test/mocked/sln_test.rb
113
116
  - test/mocked/test_helper.rb