uwaterlooapi 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +5 -0
- data/README.md +65 -0
- data/Rakefile +7 -0
- data/lib/helpers/routes.rb +62 -0
- data/lib/helpers/uwaterlooapi_query.rb +107 -0
- data/lib/uwaterlooapi.rb +17 -0
- data/spec/responses/courses.json +1 -0
- data/spec/responses/timestamp.json +1 -0
- data/spec/spec_helper.rb +30 -0
- data/spec/uwaterlooapi_spec.rb +133 -0
- data/uwaterlooapi.gemspec +19 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6b964bbcdda67f37363b799315ce0c95b4aa7ac7
|
4
|
+
data.tar.gz: 44de178a290b03b0bc45634eb277764d5790b9fe
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5aba26699122d38b24d90007c22cc0fcbdee824884e8a7291a3dbf064f1716100c53a0e08e117c3b60f078f5b8e29755a5eace703a795fb1e7c5d7d07d090feb
|
7
|
+
data.tar.gz: c14a5ba395d33a1475bbf81a7c09be6ca487c9a0984a8a8fb52f28981b74852d25575cd5c82b2bb4c4e98211889b4ce75daa3fa2e77e18820387c056005b7353
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
uwaterlooapi
|
2
|
+
============
|
3
|
+
|
4
|
+
RubyGem wrapper for the University of Waterloo OpenData API
|
5
|
+
|
6
|
+
[![Build Status](https://travis-ci.org/amsardesai/uwaterlooapi.svg?branch=master)](https://travis-ci.org/amsardesai/uwaterlooapi)
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add the following to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'uwaterlooapi'
|
13
|
+
|
14
|
+
Or install it in your system:
|
15
|
+
|
16
|
+
$ gem install uwaterlooapi
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
To use the API, you must first get an API key from http://api.uwaterloo.ca/.
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
# Require the gem at the top of your ruby file
|
24
|
+
require 'uwaterlooapi'
|
25
|
+
|
26
|
+
# Initialize a new instance of the UWaterlooAPI
|
27
|
+
api = UWaterlooAPI.new '<your-api-key-goes-here>'
|
28
|
+
|
29
|
+
# Store an API query into a variable
|
30
|
+
current_weather = api.weather.current # '/weather/current'
|
31
|
+
uni_holidays = api.events.holidays # '/events/holidays'
|
32
|
+
info_sessions = api.terms.term(1149).infosessions # '/terms/1149/infosessions'
|
33
|
+
my_favorite_course = api.courses.subject('CS').catalog_number(247) # '/courses/CS/247'
|
34
|
+
my_favorite_course_schedule = my_favorite_course.schedule # '/courses/CS/247/schedule'
|
35
|
+
|
36
|
+
# Use the get method to manually retrieve the data and parse it
|
37
|
+
current_weather.get.temperature_24hr_max_c
|
38
|
+
|
39
|
+
# Or it will do it automatically for you
|
40
|
+
current_weather.temperature_24hr_max_c # does the same as above
|
41
|
+
uni_holidays.each do |holiday|
|
42
|
+
puts holiday.name
|
43
|
+
end # this will print out every holiday
|
44
|
+
uni_holidays[0].name # this will print out the first holiday
|
45
|
+
|
46
|
+
# Requests will only be performed once for each query
|
47
|
+
my_favorite_course.title # => 'Software Engineering Principles'
|
48
|
+
my_favorite_course.url # => 'http://www.ucalendar.uwaterloo.ca/1415/COURSE/course-CS.html#CS247'
|
49
|
+
|
50
|
+
# Check metadata of request
|
51
|
+
my_favorite_course_schedule.get # Retrieves data from server
|
52
|
+
if my_favorite_course_schedule.meta(:status) == 204
|
53
|
+
puts 'The schedule for this course cannot be found!'
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
For details regarding all API endpoints, go here: https://github.com/uWaterloo/api-documentation
|
58
|
+
|
59
|
+
## Contributing
|
60
|
+
|
61
|
+
If you find bugs or simply want to contribute to this project:
|
62
|
+
|
63
|
+
1. Fork this project
|
64
|
+
2. Make your changes and push it to your fork
|
65
|
+
3. Create a pull request in this repository
|
data/Rakefile
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
module Routes
|
2
|
+
|
3
|
+
# Route Methods
|
4
|
+
|
5
|
+
def self.route(route)
|
6
|
+
@@routes ||= []
|
7
|
+
@@routes.push route
|
8
|
+
end
|
9
|
+
|
10
|
+
# Routes
|
11
|
+
|
12
|
+
route '/foodservices/menu'
|
13
|
+
route '/foodservices/notes'
|
14
|
+
route '/foodservices/diets'
|
15
|
+
route '/foodservices/outlets'
|
16
|
+
route '/foodservices/locations'
|
17
|
+
route '/foodservices/watcard'
|
18
|
+
route '/foodservices/announcements'
|
19
|
+
route '/foodservices/products/{product_id}'
|
20
|
+
route '/foodservices/{year}/{week}/menu'
|
21
|
+
route '/foodservices/{year}/{week}/notes'
|
22
|
+
route '/foodservices/{year}/{week}/announcements'
|
23
|
+
route '/courses/{subject}'
|
24
|
+
route '/courses/{course_id}'
|
25
|
+
route '/courses/{class_number}/schedule'
|
26
|
+
route '/courses/{subject}/{catalog_number}'
|
27
|
+
route '/courses/{subject}/{catalog_number}/schedule'
|
28
|
+
route '/courses/{subject}/{catalog_number}/prerequisites'
|
29
|
+
route '/courses/{subject}/{catalog_number}/examschedule'
|
30
|
+
route '/events'
|
31
|
+
route '/events/{site}'
|
32
|
+
route '/events/{site}/{id}'
|
33
|
+
route '/events/holidays'
|
34
|
+
route '/news'
|
35
|
+
route '/news/{site}'
|
36
|
+
route '/news/{site}/{id}'
|
37
|
+
route '/weather/current'
|
38
|
+
route '/terms/list'
|
39
|
+
route '/terms/{term}/examschedule'
|
40
|
+
route '/terms/{term}/{subject}/schedule'
|
41
|
+
route '/terms/{term}/{subject}/{catalog_number}/schedule'
|
42
|
+
route '/terms/{term}/infosessions'
|
43
|
+
route '/resources/tutors'
|
44
|
+
route '/resources/printers'
|
45
|
+
route '/resources/infosessions'
|
46
|
+
route '/resources/goosewatch'
|
47
|
+
route '/codes/units'
|
48
|
+
route '/codes/terms'
|
49
|
+
route '/codes/groups'
|
50
|
+
route '/codes/subjects'
|
51
|
+
route '/codes/instructions'
|
52
|
+
route '/buildings/list'
|
53
|
+
route '/buildings/{building_code}'
|
54
|
+
route '/buildings/{building}/{room}/courses'
|
55
|
+
route '/api/usage'
|
56
|
+
route '/api/services'
|
57
|
+
route '/api/methods'
|
58
|
+
route '/api/versions'
|
59
|
+
route '/api/changelog'
|
60
|
+
route '/server/time'
|
61
|
+
route '/server/codes'
|
62
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'recursive-open-struct'
|
2
|
+
|
3
|
+
class UWaterlooAPIQuery
|
4
|
+
include Routes
|
5
|
+
|
6
|
+
def initialize(cur_route, cur_url, api_key)
|
7
|
+
@api_key = api_key
|
8
|
+
@cur_url = cur_url
|
9
|
+
@cur_route = cur_route
|
10
|
+
@retrieved_url = ''
|
11
|
+
@response = @meta = nil
|
12
|
+
|
13
|
+
# Select only routes that may come next
|
14
|
+
routes = @@routes.select { |s| s.start_with?(cur_route) }.
|
15
|
+
map { |s| s[@cur_route.length..-1] }.
|
16
|
+
join.split('/').uniq.delete_if(&:empty?)
|
17
|
+
|
18
|
+
# Define methods without parameters
|
19
|
+
routes.reject { |r| r =~ /^\{.*\}$/ }.
|
20
|
+
map(&:to_sym).each do |route|
|
21
|
+
|
22
|
+
self.class.send :define_method, route do
|
23
|
+
if is_in_routes?("#{@cur_route}/#{route}")
|
24
|
+
UWaterlooAPIQuery.new "#{@cur_route}/#{route}", "#{@cur_url}/#{route}", api_key
|
25
|
+
else
|
26
|
+
raise NoMethodError
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Define methods with parameters
|
32
|
+
routes.select { |r| r =~ /^\{.*\}$/ }.
|
33
|
+
map { |r| r.delete('{}') }.
|
34
|
+
map(&:to_sym).each do |route|
|
35
|
+
|
36
|
+
self.class.send :define_method, route do |value|
|
37
|
+
raise ArgumentError if ["", 0].include? value
|
38
|
+
if is_in_routes?("#{@cur_route}/{#{route}}")
|
39
|
+
UWaterlooAPIQuery.new "#{@cur_route}/{#{route}}", "#{@cur_url}/#{value}", api_key
|
40
|
+
else
|
41
|
+
raise NoMethodError
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Get meta variables
|
48
|
+
def meta(var)
|
49
|
+
raise NoMethodError unless is_full_route? @cur_route
|
50
|
+
if @meta
|
51
|
+
@meta[var.to_s]
|
52
|
+
else
|
53
|
+
raise "No request has been made yet, so meta data is not available."
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Get data from server
|
58
|
+
def get
|
59
|
+
raise NoMethodError unless is_full_route? @cur_route
|
60
|
+
@retrieved_url = @cur_url
|
61
|
+
response = HTTParty.get("https://api.uwaterloo.ca/v2#{@cur_url}.json", { query: { key: @api_key, format: 'json' } })
|
62
|
+
case response.code
|
63
|
+
when 400...600
|
64
|
+
raise "UWaterloo API Server returned a #{response.code} error"
|
65
|
+
end
|
66
|
+
@response = RecursiveOpenStruct.new response, recurse_over_arrays: true
|
67
|
+
@meta = response['meta']
|
68
|
+
@response.data
|
69
|
+
end
|
70
|
+
|
71
|
+
def method_missing(method, *args, &block)
|
72
|
+
# Get data from API server
|
73
|
+
get unless just_made_request
|
74
|
+
|
75
|
+
if @response.data.respond_to? method
|
76
|
+
@response.data.send method, *args, &block
|
77
|
+
else
|
78
|
+
super
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def respond_to?(method, include_private = false)
|
83
|
+
# Get data from API server
|
84
|
+
get unless just_made_request
|
85
|
+
|
86
|
+
if @response.data.respond_to? method
|
87
|
+
true
|
88
|
+
else
|
89
|
+
super
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
def just_made_request
|
96
|
+
@retrieved_url == @cur_url
|
97
|
+
end
|
98
|
+
|
99
|
+
def is_in_routes?(substring)
|
100
|
+
@@routes.any? { |s| s.start_with?(substring) }
|
101
|
+
end
|
102
|
+
|
103
|
+
def is_full_route?(substring)
|
104
|
+
@@routes.include? substring
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
data/lib/uwaterlooapi.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'helpers/routes'
|
3
|
+
require 'helpers/uwaterlooapi_query'
|
4
|
+
|
5
|
+
class UWaterlooAPI
|
6
|
+
VERSION = '0.0.1'
|
7
|
+
include Routes
|
8
|
+
|
9
|
+
def initialize(api_key)
|
10
|
+
@@routes.map { |r| r.split('/')[1] }.uniq.map(&:to_sym).each do |route|
|
11
|
+
self.class.send :define_method, route do
|
12
|
+
UWaterlooAPIQuery.new "/#{route}", "/#{route}", api_key
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{"meta":{"requests":104,"timestamp":1414371683,"status":200,"message":"Request successful","method_id":1193,"method":{"disclaimer":"Review the 'No Warranty' section of the University of Waterloo Open Data License before using this data. If building services upon this data, please inform your users of the inherent risks (as a best practice)","license":"https:\/\/uwaterloo.ca\/open-data\/university-waterloo-open-data-license-agreement-v1"}},"data":[{"subject":"CS","catalog_number":"115","units":0.5,"title":"Introduction to Computer Science 1","note":"LEC 001 & 002 and 004 to 007 choose LAB section for Related 1. LEC 003 is auto-enrolled.","class_number":5682,"section":"LEC 001","campus":"UW U","associated_class":1,"related_component_1":null,"related_component_2":"201","enrollment_capacity":250,"enrollment_total":248,"waiting_capacity":0,"waiting_total":0,"topic":null,"reserves":[{"reserve_group":"Year 1 students ","enrollment_capacity":239,"enrollment_total":241}],"classes":[{"date":{"start_time":"12:30","end_time":"13:50","weekdays":"MW","start_date":null,"end_date":null,"is_tba":false,"is_cancelled":false,"is_closed":false},"location":{"building":"OPT","room":"347"},"instructors":["Vasiga,Troy Michael John"]}],"held_with":[],"term":1139,"academic_level":"undergraduate","last_updated":"2013-12-23T20:01:31-05:00"},{"subject":"CS","catalog_number":"115","units":0.5,"title":"Introduction to Computer Science 1","note":"LEC 001 & 002 and 004 to 007 choose LAB section for Related 1. LEC 003 is auto-enrolled.","class_number":5683,"section":"LEC 002","campus":"UW U","associated_class":2,"related_component_1":null,"related_component_2":"201","enrollment_capacity":350,"enrollment_total":344,"waiting_capacity":0,"waiting_total":0,"topic":null,"reserves":[{"reserve_group":"Yr 1 Honours Geomatics ","enrollment_capacity":47,"enrollment_total":37},{"reserve_group":"Year 1 students ","enrollment_capacity":263,"enrollment_total":266}],"classes":[{"date":{"start_time":"14:30","end_time":"15:50","weekdays":"MW","start_date":null,"end_date":null,"is_tba":false,"is_cancelled":false,"is_closed":false},"location":{"building":"RCH","room":"101"},"instructors":["Vasiga,Troy Michael John"]}],"held_with":[],"term":1139,"academic_level":"undergraduate","last_updated":"2013-12-23T20:01:31-05:00"},{"subject":"CS","catalog_number":"115","units":0.5,"title":"Introduction to Computer Science 1","note":"LEC 001 & 002 and 004 to 007 choose LAB section for Related 1. LEC 003 is auto-enrolled.","class_number":5684,"section":"LEC 003","campus":"STJ J","associated_class":3,"related_component_1":"112","related_component_2":"202","enrollment_capacity":50,"enrollment_total":56,"waiting_capacity":0,"waiting_total":0,"topic":null,"reserves":[{"reserve_group":"Year 1 students ","enrollment_capacity":50,"enrollment_total":53}],"classes":[{"date":{"start_time":"13:00","end_time":"14:20","weekdays":"TTh","start_date":null,"end_date":null,"is_tba":false,"is_cancelled":false,"is_closed":false},"location":{"building":"STJ","room":"3014"},"instructors":["Case,Lori"]}],"held_with":[],"term":1139,"academic_level":"undergraduate","last_updated":"2013-12-23T20:01:31-05:00"},{"subject":"CS","catalog_number":"115","units":0.5,"title":"Introduction to Computer Science 1","note":"LEC 001 & 002 and 004 to 007 choose LAB section for Related 1. LEC 003 is auto-enrolled.","class_number":5685,"section":"LEC 004","campus":"UW U","associated_class":4,"related_component_1":null,"related_component_2":"201","enrollment_capacity":40,"enrollment_total":38,"waiting_capacity":0,"waiting_total":0,"topic":null,"reserves":[{"reserve_group":"2A GBDA students only ","enrollment_capacity":40,"enrollment_total":33}],"classes":[{"date":{"start_time":"09:00","end_time":"11:50","weekdays":"Th","start_date":null,"end_date":null,"is_tba":false,"is_cancelled":false,"is_closed":false},"location":{"building":"ECH","room":"1205"},"instructors":["Harrigan,Kevin"]}],"held_with":[],"term":1139,"academic_level":"undergraduate","last_updated":"2013-12-23T20:01:31-05:00"},{"subject":"CS","catalog_number":"115","units":0.5,"title":"Introduction to Computer Science 1","note":"LEC 001 & 002 and 004 to 007 choose LAB section for Related 1. LEC 003 is auto-enrolled.","class_number":5686,"section":"LEC 005","campus":"UW U","associated_class":5,"related_component_1":null,"related_component_2":"201","enrollment_capacity":350,"enrollment_total":336,"waiting_capacity":0,"waiting_total":0,"topic":null,"reserves":[{"reserve_group":"Year 1 students ","enrollment_capacity":246,"enrollment_total":253}],"classes":[{"date":{"start_time":"16:00","end_time":"17:20","weekdays":"TTh","start_date":null,"end_date":null,"is_tba":false,"is_cancelled":false,"is_closed":false},"location":{"building":"AL","room":"116"},"instructors":["Case,Lori"]}],"held_with":[],"term":1139,"academic_level":"undergraduate","last_updated":"2013-12-23T20:01:31-05:00"},{"subject":"CS","catalog_number":"115","units":0.5,"title":"Introduction to Computer Science 1","note":"LEC 001 & 002 and 004 to 007 choose LAB section for Related 1. LEC 003 is auto-enrolled.","class_number":5689,"section":"LAB 101","campus":"UW U","associated_class":99,"related_component_1":"99","related_component_2":null,"enrollment_capacity":85,"enrollment_total":69,"waiting_capacity":0,"waiting_total":0,"topic":null,"reserves":[],"classes":[{"date":{"start_time":"10:00","end_time":"11:20","weekdays":"W","start_date":null,"end_date":null,"is_tba":false,"is_cancelled":false,"is_closed":false},"location":{"building":"MC","room":"3003"},"instructors":[]}],"held_with":[],"term":1139,"academic_level":"undergraduate","last_updated":"2013-12-23T20:01:31-05:00"},{"subject":"CS","catalog_number":"115","units":0.5,"title":"Introduction to Computer Science 1","note":"LEC 001 & 002 and 004 to 007 choose LAB section for Related 1. LEC 003 is auto-enrolled.","class_number":5690,"section":"LAB 102","campus":"UW U","associated_class":99,"related_component_1":"99","related_component_2":null,"enrollment_capacity":85,"enrollment_total":84,"waiting_capacity":0,"waiting_total":0,"topic":null,"reserves":[],"classes":[{"date":{"start_time":"11:30","end_time":"12:50","weekdays":"W","start_date":null,"end_date":null,"is_tba":false,"is_cancelled":false,"is_closed":false},"location":{"building":"MC","room":"3003"},"instructors":[]}],"held_with":[],"term":1139,"academic_level":"undergraduate","last_updated":"2013-12-23T20:01:31-05:00"},{"subject":"CS","catalog_number":"115","units":0.5,"title":"Introduction to Computer Science 1","note":"LEC 001 & 002 and 004 to 007 choose LAB section for Related 1. LEC 003 is auto-enrolled.","class_number":5691,"section":"LAB 103","campus":"UW U","associated_class":99,"related_component_1":"99","related_component_2":null,"enrollment_capacity":85,"enrollment_total":84,"waiting_capacity":0,"waiting_total":0,"topic":null,"reserves":[],"classes":[{"date":{"start_time":"13:00","end_time":"14:20","weekdays":"W","start_date":null,"end_date":null,"is_tba":false,"is_cancelled":false,"is_closed":false},"location":{"building":"MC","room":"3003"},"instructors":[]}],"held_with":[],"term":1139,"academic_level":"undergraduate","last_updated":"2013-12-23T20:01:31-05:00"},{"subject":"CS","catalog_number":"115","units":0.5,"title":"Introduction to Computer Science 1","note":"LEC 001 & 002 and 004 to 007 choose LAB section for Related 1. LEC 003 is auto-enrolled.","class_number":5692,"section":"LAB 104","campus":"UW U","associated_class":99,"related_component_1":"99","related_component_2":null,"enrollment_capacity":85,"enrollment_total":84,"waiting_capacity":0,"waiting_total":0,"topic":null,"reserves":[],"classes":[{"date":{"start_time":"14:30","end_time":"15:50","weekdays":"W","start_date":null,"end_date":null,"is_tba":false,"is_cancelled":false,"is_closed":false},"location":{"building":"MC","room":"3003"},"instructors":[]}],"held_with":[],"term":1139,"academic_level":"undergraduate","last_updated":"2013-12-23T20:01:31-05:00"},{"subject":"CS","catalog_number":"115","units":0.5,"title":"Introduction to Computer Science 1","note":"LEC 001 & 002 and 004 to 007 choose LAB section for Related 1. LEC 003 is auto-enrolled.","class_number":5693,"section":"LAB 105","campus":"UW U","associated_class":99,"related_component_1":"99","related_component_2":null,"enrollment_capacity":85,"enrollment_total":89,"waiting_capacity":0,"waiting_total":0,"topic":null,"reserves":[],"classes":[{"date":{"start_time":"10:00","end_time":"11:20","weekdays":"Th","start_date":null,"end_date":null,"is_tba":false,"is_cancelled":false,"is_closed":false},"location":{"building":"MC","room":"3003"},"instructors":[]}],"held_with":[],"term":1139,"academic_level":"undergraduate","last_updated":"2013-12-23T20:01:31-05:00"},{"subject":"CS","catalog_number":"115","units":0.5,"title":"Introduction to Computer Science 1","note":"LEC 001 & 002 and 004 to 007 choose LAB section for Related 1. LEC 003 is auto-enrolled.","class_number":5694,"section":"LAB 106","campus":"UW U","associated_class":99,"related_component_1":"99","related_component_2":null,"enrollment_capacity":85,"enrollment_total":92,"waiting_capacity":0,"waiting_total":0,"topic":null,"reserves":[],"classes":[{"date":{"start_time":"11:30","end_time":"12:50","weekdays":"Th","start_date":null,"end_date":null,"is_tba":false,"is_cancelled":false,"is_closed":false},"location":{"building":"MC","room":"3003"},"instructors":[]}],"held_with":[],"term":1139,"academic_level":"undergraduate","last_updated":"2013-12-23T20:01:31-05:00"},{"subject":"CS","catalog_number":"115","units":0.5,"title":"Introduction to Computer Science 1","note":"LEC 001 & 002 and 004 to 007 choose LAB section for Related 1. LEC 003 is auto-enrolled.","class_number":5695,"section":"LAB 107","campus":"UW U","associated_class":99,"related_component_1":"99","related_component_2":null,"enrollment_capacity":80,"enrollment_total":87,"waiting_capacity":0,"waiting_total":0,"topic":null,"reserves":[],"classes":[{"date":{"start_time":"13:00","end_time":"14:20","weekdays":"Th","start_date":null,"end_date":null,"is_tba":false,"is_cancelled":false,"is_closed":false},"location":{"building":"MC","room":"3003"},"instructors":[]}],"held_with":[],"term":1139,"academic_level":"undergraduate","last_updated":"2013-12-23T20:01:31-05:00"},{"subject":"CS","catalog_number":"115","units":0.5,"title":"Introduction to Computer Science 1","note":"LEC 001 & 002 and 004 to 007 choose LAB section for Related 1. LEC 003 is auto-enrolled.","class_number":5696,"section":"LAB 108","campus":"UW U","associated_class":99,"related_component_1":"99","related_component_2":null,"enrollment_capacity":80,"enrollment_total":87,"waiting_capacity":0,"waiting_total":0,"topic":null,"reserves":[],"classes":[{"date":{"start_time":"14:30","end_time":"15:50","weekdays":"Th","start_date":null,"end_date":null,"is_tba":false,"is_cancelled":false,"is_closed":false},"location":{"building":"MC","room":"3003"},"instructors":[]}],"held_with":[],"term":1139,"academic_level":"undergraduate","last_updated":"2013-12-23T20:01:31-05:00"},{"subject":"CS","catalog_number":"115","units":0.5,"title":"Introduction to Computer Science 1","note":"LEC 001 & 002 and 004 to 007 choose LAB section for Related 1. LEC 003 is auto-enrolled.","class_number":5721,"section":"LAB 109","campus":"UW U","associated_class":99,"related_component_1":"99","related_component_2":null,"enrollment_capacity":80,"enrollment_total":57,"waiting_capacity":0,"waiting_total":0,"topic":null,"reserves":[],"classes":[{"date":{"start_time":"08:30","end_time":"09:50","weekdays":"F","start_date":null,"end_date":null,"is_tba":false,"is_cancelled":false,"is_closed":false},"location":{"building":"MC","room":"3003"},"instructors":[]}],"held_with":[],"term":1139,"academic_level":"undergraduate","last_updated":"2013-12-23T20:01:31-05:00"},{"subject":"CS","catalog_number":"115","units":0.5,"title":"Introduction to Computer Science 1","note":"LEC 001 & 002 and 004 to 007 choose LAB section for Related 1. LEC 003 is auto-enrolled.","class_number":5951,"section":"LAB 110","campus":"UW U","associated_class":99,"related_component_1":"99","related_component_2":null,"enrollment_capacity":80,"enrollment_total":61,"waiting_capacity":0,"waiting_total":0,"topic":null,"reserves":[],"classes":[{"date":{"start_time":"10:00","end_time":"11:20","weekdays":"F","start_date":null,"end_date":null,"is_tba":false,"is_cancelled":false,"is_closed":false},"location":{"building":"MC","room":"3003"},"instructors":[]}],"held_with":[],"term":1139,"academic_level":"undergraduate","last_updated":"2013-12-23T20:01:31-05:00"},{"subject":"CS","catalog_number":"115","units":0.5,"title":"Introduction to Computer Science 1","note":"LEC 001 & 002 and 004 to 007 choose LAB section for Related 1. LEC 003 is auto-enrolled.","class_number":5952,"section":"LAB 111","campus":"UW U","associated_class":99,"related_component_1":"99","related_component_2":null,"enrollment_capacity":80,"enrollment_total":84,"waiting_capacity":0,"waiting_total":0,"topic":null,"reserves":[],"classes":[{"date":{"start_time":"11:30","end_time":"12:50","weekdays":"F","start_date":null,"end_date":null,"is_tba":false,"is_cancelled":false,"is_closed":false},"location":{"building":"MC","room":"3003"},"instructors":[]}],"held_with":[],"term":1139,"academic_level":"undergraduate","last_updated":"2013-12-23T20:01:31-05:00"},{"subject":"CS","catalog_number":"115","units":0.5,"title":"Introduction to Computer Science 1","note":"LEC 001 & 002 and 004 to 007 choose LAB section for Related 1. LEC 003 is auto-enrolled.","class_number":5991,"section":"LAB 112","campus":"STJ U","associated_class":3,"related_component_1":null,"related_component_2":null,"enrollment_capacity":50,"enrollment_total":56,"waiting_capacity":0,"waiting_total":0,"topic":null,"reserves":[],"classes":[{"date":{"start_time":"13:00","end_time":"14:20","weekdays":"F","start_date":null,"end_date":null,"is_tba":false,"is_cancelled":false,"is_closed":false},"location":{"building":"MC","room":"3003"},"instructors":[]}],"held_with":[],"term":1139,"academic_level":"undergraduate","last_updated":"2013-12-23T20:01:31-05:00"},{"subject":"CS","catalog_number":"115","units":0.5,"title":"Introduction to Computer Science 1","note":"LEC 001 & 002 and 004 to 007 choose LAB section for Related 1. LEC 003 is auto-enrolled.","class_number":5992,"section":"LAB 113","campus":"UW U","associated_class":99,"related_component_1":"99","related_component_2":null,"enrollment_capacity":80,"enrollment_total":88,"waiting_capacity":0,"waiting_total":0,"topic":null,"reserves":[],"classes":[{"date":{"start_time":"14:30","end_time":"15:50","weekdays":"F","start_date":null,"end_date":null,"is_tba":false,"is_cancelled":false,"is_closed":false},"location":{"building":"MC","room":"3003"},"instructors":[]}],"held_with":[],"term":1139,"academic_level":"undergraduate","last_updated":"2013-12-23T20:01:31-05:00"},{"subject":"CS","catalog_number":"115","units":0.5,"title":"Introduction to Computer Science 1","note":"LEC 001 & 002 and 004 to 007 choose LAB section for Related 1. LEC 003 is auto-enrolled.","class_number":5717,"section":"TST 201","campus":"UW U","associated_class":99,"related_component_1":"99","related_component_2":null,"enrollment_capacity":990,"enrollment_total":966,"waiting_capacity":0,"waiting_total":0,"topic":null,"reserves":[],"classes":[{"date":{"start_time":"19:00","end_time":"20:50","weekdays":"M","start_date":"10\/28","end_date":"10\/28","is_tba":false,"is_cancelled":false,"is_closed":false},"location":{"building":null,"room":null},"instructors":[]}],"held_with":[],"term":1139,"academic_level":"undergraduate","last_updated":"2013-12-23T20:01:31-05:00"},{"subject":"CS","catalog_number":"115","units":0.5,"title":"Introduction to Computer Science 1","note":"LEC 001 & 002 and 004 to 007 choose LAB section for Related 1. LEC 003 is auto-enrolled.","class_number":5905,"section":"TST 202","campus":"STJ J","associated_class":3,"related_component_1":null,"related_component_2":null,"enrollment_capacity":50,"enrollment_total":56,"waiting_capacity":0,"waiting_total":0,"topic":null,"reserves":[],"classes":[{"date":{"start_time":"19:00","end_time":"20:50","weekdays":"M","start_date":"10\/28","end_date":"10\/28","is_tba":false,"is_cancelled":false,"is_closed":false},"location":{"building":null,"room":null},"instructors":[]}],"held_with":[],"term":1139,"academic_level":"undergraduate","last_updated":"2013-12-23T20:01:31-05:00"}]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"meta":{"requests":104,"timestamp":1414369440,"status":200,"message":"Request successful","method_id":1087,"method":{}},"data":{"timestamp":1414369440,"datetime":"2014-10-26T20:24:00-04:00","timezone":"EDT","key_reset_time":1416978000}}
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'webmock/rspec'
|
3
|
+
require 'uwaterlooapi'
|
4
|
+
|
5
|
+
WebMock.disable_net_connect! allow_localhost: true
|
6
|
+
Dir.chdir File.dirname __FILE__
|
7
|
+
|
8
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
9
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
10
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
11
|
+
# loaded once.
|
12
|
+
#
|
13
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
14
|
+
RSpec.configure do |config|
|
15
|
+
config.run_all_when_everything_filtered = true
|
16
|
+
config.filter_run :focus
|
17
|
+
|
18
|
+
config.before(:each) do
|
19
|
+
stub_request(:get, 'https://api.uwaterloo.ca/v2/server/time.json?format=json&key=testkey').
|
20
|
+
to_return(status: 200, body: File.new('responses/timestamp.json'), headers: { 'Content-Type' => 'application/json; charset=utf-8' })
|
21
|
+
stub_request(:get, 'https://api.uwaterloo.ca/v2/terms/1139/CS/115/schedule.json?format=json&key=testkey').
|
22
|
+
to_return(status: 200, body: File.new('responses/courses.json'), headers: { 'Content-Type' => 'application/json; charset=utf-8' })
|
23
|
+
end
|
24
|
+
|
25
|
+
# Run specs in random order to surface order dependencies. If you find an
|
26
|
+
# order dependency and want to debug it, you can fix the order by providing
|
27
|
+
# the seed, which is printed after each run.
|
28
|
+
# --seed 1234
|
29
|
+
#config.order = 'random'
|
30
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe UWaterlooAPI do
|
3
|
+
before :each do
|
4
|
+
@api = UWaterlooAPI.new 'testkey'
|
5
|
+
end
|
6
|
+
|
7
|
+
describe '#new' do
|
8
|
+
it 'returns a new UWaterlooAPI object' do
|
9
|
+
expect(@api).to be_an_instance_of(UWaterlooAPI)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'takes one parameter' do
|
13
|
+
expect{ UWaterlooAPI.new }.to raise_exception ArgumentError
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'returns a UWaterlooAPIQuery object for foodservices' do
|
17
|
+
expect(@api.foodservices).to be_an_instance_of UWaterlooAPIQuery
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'returns a UWaterlooAPIQuery object for courses' do
|
21
|
+
expect(@api.courses).to be_an_instance_of UWaterlooAPIQuery
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'returns a UWaterlooAPIQuery object for events' do
|
25
|
+
expect(@api.events).to be_an_instance_of UWaterlooAPIQuery
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'returns a UWaterlooAPIQuery object for news' do
|
29
|
+
expect(@api.news).to be_an_instance_of UWaterlooAPIQuery
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'returns a UWaterlooAPIQuery object for weather' do
|
33
|
+
expect(@api.weather).to be_an_instance_of UWaterlooAPIQuery
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'returns a UWaterlooAPIQuery object for terms' do
|
37
|
+
expect(@api.terms).to be_an_instance_of UWaterlooAPIQuery
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'returns a UWaterlooAPIQuery object for resources' do
|
41
|
+
expect(@api.resources).to be_an_instance_of UWaterlooAPIQuery
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'returns a UWaterlooAPIQuery object for codes' do
|
45
|
+
expect(@api.codes).to be_an_instance_of UWaterlooAPIQuery
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'returns a UWaterlooAPIQuery object for buildings' do
|
49
|
+
expect(@api.buildings).to be_an_instance_of UWaterlooAPIQuery
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'returns a UWaterlooAPIQuery object for api' do
|
53
|
+
expect(@api.api).to be_an_instance_of UWaterlooAPIQuery
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'returns a UWaterlooAPIQuery object for server' do
|
57
|
+
expect(@api.server).to be_an_instance_of UWaterlooAPIQuery
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'queries' do
|
61
|
+
before :each do
|
62
|
+
@time = @api.server.time
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'makes one request' do
|
66
|
+
expect(@time.timestamp).to eq 1414369440
|
67
|
+
expect(@time.datetime).to eq '2014-10-26T20:24:00-04:00'
|
68
|
+
expect(a_request(:get, 'https://api.uwaterloo.ca/v2/server/time.json?format=json&key=testkey')).to have_been_made.once
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'returns a RecursiveOpenStruct after response is parsed' do
|
72
|
+
expect(@time.key_reset_time).to eq 1416978000
|
73
|
+
expect(@time.get).to be_an_instance_of RecursiveOpenStruct
|
74
|
+
expect(@api.terms.term(1139).subject('CS').catalog_number(115).schedule[0]).to be_an_instance_of RecursiveOpenStruct
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'incrementally builds a query' do
|
78
|
+
expect(@api.terms.term(1139)).to be_an_instance_of UWaterlooAPIQuery
|
79
|
+
expect(@api.terms.term(1139).subject('CS')).to be_an_instance_of UWaterlooAPIQuery
|
80
|
+
expect(@api.terms.term(1139).subject('CS').catalog_number(115)).to be_an_instance_of UWaterlooAPIQuery
|
81
|
+
expect(@api.terms.term(1139).subject('CS').catalog_number(115).schedule).to be_an_instance_of UWaterlooAPIQuery
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'makes one request over an iteration' do
|
85
|
+
expect(@api.terms.term(1139).subject('CS').catalog_number(115).schedule.map { |s| s.topic }).to be_an_instance_of Array
|
86
|
+
expect(a_request(:get, 'https://api.uwaterloo.ca/v2/terms/1139/CS/115/schedule.json?format=json&key=testkey')).to have_been_made.once
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'can directly retrieve a deeply nested property' do
|
90
|
+
expect(@api.terms.term(1139).subject('CS').catalog_number(115).schedule[1].classes[0].instructors[0]).to eq 'Vasiga,Troy Michael John'
|
91
|
+
expect(@api.terms.term(1139).subject('CS').catalog_number(115).schedule[5].classes[0].date.end_time).to eq '11:20'
|
92
|
+
expect(@api.terms.term(1139).subject('CS').catalog_number(115).schedule[8].reserves.empty?).to eq true
|
93
|
+
expect(@api.terms.term(1139).subject('CS').catalog_number(115).schedule[14].class_number).to eq 5951
|
94
|
+
expect(@api.terms.term(1139).subject('CS').catalog_number(115).schedule[18].topic.nil?).to eq true
|
95
|
+
expect(@api.terms.term(1139).subject('CS').catalog_number(115).schedule[19].classes[0].date.is_closed).to eq false
|
96
|
+
expect(a_request(:get, 'https://api.uwaterloo.ca/v2/terms/1139/CS/115/schedule.json?format=json&key=testkey')).to have_been_made.times 6
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'makes one request per get call' do
|
100
|
+
expect(@time.get).to be_an_instance_of RecursiveOpenStruct
|
101
|
+
expect(@time.get).to be_an_instance_of RecursiveOpenStruct
|
102
|
+
expect(a_request(:get, 'https://api.uwaterloo.ca/v2/server/time.json?format=json&key=testkey')).to have_been_made.times 2
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'has a working respond_to? method' do
|
106
|
+
expect(@time.respond_to?(:get)).to eq true
|
107
|
+
expect(@time.respond_to?(:timestamp)).to eq true
|
108
|
+
expect(@time.respond_to?(:lolhi)).to eq false
|
109
|
+
expect(a_request(:get, 'https://api.uwaterloo.ca/v2/server/time.json?format=json&key=testkey')).to have_been_made.once
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'has a working method_missing method' do
|
113
|
+
expect{ @time.hellobrah }.to raise_exception NoMethodError
|
114
|
+
expect(@time.timezone).to eq 'EDT'
|
115
|
+
expect(a_request(:get, 'https://api.uwaterloo.ca/v2/server/time.json?format=json&key=testkey')).to have_been_made.once
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'allows retrieval of metadata' do
|
119
|
+
expect{ @time.meta(:status) }.to raise_exception RuntimeError
|
120
|
+
@time.get
|
121
|
+
expect(@time.meta(:status)).to eq 200
|
122
|
+
expect(@time.meta(:method_id)).to eq 1087
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'can detect invalid method chains' do
|
126
|
+
expect{ @api.terms.get }.to raise_exception NoMethodError
|
127
|
+
expect{ @api.terms.term(1139).meta :status }.to raise_exception NoMethodError
|
128
|
+
expect{ @api.courses.catalog_number(1) }.to raise_exception NoMethodError
|
129
|
+
expect{ @api.foodservices.year(2013).announcements }.to raise_exception NoMethodError
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
|
2
|
+
Gem::Specification.new do |spec|
|
3
|
+
spec.name = 'uwaterlooapi'
|
4
|
+
spec.version = '0.0.2'
|
5
|
+
spec.date = '2014-10-26'
|
6
|
+
spec.summary = "Ruby Gem wrapper for the University of Waterloo Open Data API"
|
7
|
+
spec.description = "Ruby Gem wrapper for the University of Waterloo Open Data API"
|
8
|
+
spec.authors = ["Ankit Sardesai"]
|
9
|
+
spec.email = 'me@ankitsardesai.ca'
|
10
|
+
spec.files = `git ls-files`.split("\n")
|
11
|
+
spec.test_files = `git ls-files spec`.split("\n")
|
12
|
+
spec.homepage = 'http://rubygems.org/gems/uwaterlooapi'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
spec.require_paths = ['lib']
|
15
|
+
spec.add_runtime_dependency 'httparty'
|
16
|
+
spec.add_runtime_dependency 'recursive-open-struct'
|
17
|
+
spec.add_development_dependency 'rspec'
|
18
|
+
spec.add_development_dependency 'webmock'
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: uwaterlooapi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ankit Sardesai
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: recursive-open-struct
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Ruby Gem wrapper for the University of Waterloo Open Data API
|
70
|
+
email: me@ankitsardesai.ca
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- ".gitignore"
|
76
|
+
- ".rspec"
|
77
|
+
- ".travis.yml"
|
78
|
+
- Gemfile
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- lib/helpers/routes.rb
|
82
|
+
- lib/helpers/uwaterlooapi_query.rb
|
83
|
+
- lib/uwaterlooapi.rb
|
84
|
+
- spec/responses/courses.json
|
85
|
+
- spec/responses/timestamp.json
|
86
|
+
- spec/spec_helper.rb
|
87
|
+
- spec/uwaterlooapi_spec.rb
|
88
|
+
- uwaterlooapi.gemspec
|
89
|
+
homepage: http://rubygems.org/gems/uwaterlooapi
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.2.2
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Ruby Gem wrapper for the University of Waterloo Open Data API
|
113
|
+
test_files:
|
114
|
+
- spec/responses/courses.json
|
115
|
+
- spec/responses/timestamp.json
|
116
|
+
- spec/spec_helper.rb
|
117
|
+
- spec/uwaterlooapi_spec.rb
|