uwapi 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5bd35dfe9fbd704be9fab9dc0565b28813a82219
4
+ data.tar.gz: fed1379bab2ca9e8a954fa6d30322a14b09b70e2
5
+ SHA512:
6
+ metadata.gz: e3a3f12154c4f16cca043bca84f4d19a77555c8e42cbfa18c6b0245a91844f164a2020d10af9dbd0e158a684efa6128aa5b7661ce08aa116817e8bf24089135f
7
+ data.tar.gz: 532150f994548346829ed78b8fe3a14884f66293546884ee83549d8c5bf9e639e3179b79ae67da848294a111b4d09a756999f1e98d68a9e3ff4db1b6fdd034a9
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ test.rb
19
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in uwapi.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Bill Li
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # UWAPI
2
+
3
+ This gem is a wrapper for University of Waterloo's Open Data API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'uwapi'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install uwapi
18
+
19
+ ## Usage
20
+
21
+ 1. Go to http://api.uwaterloo.ca/ and register for an API key.
22
+ 2. Use the gem.
23
+ 3. ???
24
+ 4. Profit.
25
+
26
+ ```ruby
27
+ api = UWAPI.new(:api_key => 'foo')
28
+ weather = api.Weather
29
+ buildings = api.Buildings
30
+ ```
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/lib/uwapi.rb ADDED
@@ -0,0 +1,79 @@
1
+ require 'rubygems'
2
+ require 'httparty'
3
+ require 'json'
4
+
5
+ require 'uwapi/version'
6
+ require 'uwapi/service/course'
7
+ require 'uwapi/service/event'
8
+ require 'uwapi/service/exam_info'
9
+ require 'uwapi/service/experimental'
10
+ require 'uwapi/service/faculty_info'
11
+ require 'uwapi/service/food_services'
12
+ require 'uwapi/service/geolocation'
13
+ require 'uwapi/service/other'
14
+ require 'uwapi/service/professor'
15
+ require 'uwapi/service/schedule'
16
+ require 'uwapi/service/weather'
17
+ require 'uwapi/service/wireless_data'
18
+
19
+ module UWAPI
20
+ class Result
21
+ def initialize(args)
22
+ if args.is_a?(Hash) && args.has_key?('response')
23
+ @result = args
24
+ else
25
+ raise ArgumentError, 'args is not a UWAPI returned result'
26
+ end
27
+ end
28
+
29
+ def result
30
+ @result ||= {}
31
+ @result
32
+ end
33
+
34
+ def meta
35
+ @result['response']['meta']
36
+ end
37
+
38
+ def success?
39
+ Integer.new(@result['response']['meta']['Status']) == 200
40
+ end
41
+
42
+ def failure?
43
+ !success?
44
+ end
45
+ end
46
+
47
+ class API
48
+ include Course, Event, ExamInfo, Experimental, FacultyInfo, FoodServices, Geolocation
49
+ include Other, Professor, Schedule, Weather, WirelessData
50
+
51
+ def initialize(args)
52
+ if args.include?(:api_key)
53
+ @api_key = args[:api_key]
54
+ else
55
+ raise ArgumentError, ':api_key is required. See http://api.uwaterloo.ca/'
56
+ end
57
+ @api_format = args[:api_format] if args.include?(:api_format)
58
+ raise ArgumentError, ':api_format must be one of [json, xml]' unless ['json', 'xml'].include?(api_format)
59
+ end
60
+
61
+ def api_format
62
+ @api_format ||= 'json'
63
+ end
64
+
65
+ def api_url
66
+ 'http://api.uwaterloo.ca/public/v1/'
67
+ end
68
+
69
+ def api_key
70
+ @api_key
71
+ end
72
+
73
+ private
74
+ def get(opt)
75
+ request = HTTParty.get(api_url, :query => {:key => api_key, :output => api_format}.merge(opt))
76
+ UWAPI::Result.new(request)
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,35 @@
1
+ module Abstraction
2
+ module ClassMethods
3
+ def call_with_q(methods)
4
+ return unless methods.is_a?(Array)
5
+ methods.each do |m|
6
+ define_method(m) do |args|
7
+ opt = {:service => __method__}
8
+ if args.include?(:q)
9
+ opt[:q] = args[:q]
10
+ else
11
+ raise ArgumentError, ':q is required'
12
+ end
13
+
14
+ opt[:term] = args[:term] if args.include?(:term)
15
+ get(opt)
16
+ end
17
+ end
18
+ end
19
+
20
+ def call_without_q(methods)
21
+ return unless methods.is_a?(Array)
22
+ methods.each do |m|
23
+ define_method(m) do
24
+ opt = {:service => __method__}
25
+ get(opt)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ extend ClassMethods
31
+
32
+ def self.included(other)
33
+ other.extend(ClassMethods)
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ require_relative 'abstraction'
2
+ module AcademicPrograms
3
+ include Abstraction
4
+ call_without_q(['ProgramsList'])
5
+ end
@@ -0,0 +1,5 @@
1
+ require_relative 'abstraction'
2
+ module Course
3
+ include Abstraction
4
+ call_with_q(['CourseSearch', 'CourseInfo', 'Prerequisites', 'CourseFromRoom'])
5
+ end
@@ -0,0 +1,5 @@
1
+ require_relative 'abstraction'
2
+ module Event
3
+ include Abstraction
4
+ call_without_q(['Events', 'CalendarEvents', 'Holidays'])
5
+ end
@@ -0,0 +1,5 @@
1
+ require_relative 'abstraction'
2
+ module ExamInfo
3
+ include Abstraction
4
+ call_without_q(['ExamSchedule'])
5
+ end
@@ -0,0 +1,5 @@
1
+ require_relative 'abstraction'
2
+ module Experimental
3
+ include Abstraction
4
+ call_with_q(['DirectorySearch'])
5
+ end
@@ -0,0 +1,5 @@
1
+ require_relative 'abstraction'
2
+ module FacultyInfo
3
+ include Abstraction
4
+ call_without_q(['FacultiesList', 'DepartmentsList', 'TermsList'])
5
+ end
@@ -0,0 +1,5 @@
1
+ require_relative 'abstraction'
2
+ module FoodServices
3
+ include Abstraction
4
+ call_without_q(['FoodServices', 'FoodMenu', 'VendingMachines', 'WatcardVendors'])
5
+ end
@@ -0,0 +1,5 @@
1
+ require_relative 'abstraction'
2
+ module Geolocation
3
+ include Abstraction
4
+ call_without_q(['Buildings', 'ParkingList', 'BuildingCoordinates', 'WatPark'])
5
+ end
@@ -0,0 +1,4 @@
1
+ require_relative 'abstraction'
2
+ module Other
3
+ include Abstraction
4
+ end
@@ -0,0 +1,5 @@
1
+ require_relative 'abstraction'
2
+ module Professor
3
+ include Abstraction
4
+ call_with_q(['ProfessorSearch'])
5
+ end
@@ -0,0 +1,6 @@
1
+ require_relative 'abstraction'
2
+ module Publications
3
+ include Abstraction
4
+ call_without_q(['RecentDissertations'])
5
+ call_with_q(['DissertationDetails'])
6
+ end
@@ -0,0 +1,5 @@
1
+ require_relative 'abstraction'
2
+ module Schedule
3
+ include Abstraction
4
+ call_with_q(['Schedule'])
5
+ end
@@ -0,0 +1,5 @@
1
+ require_relative 'abstraction'
2
+ module Weather
3
+ include Abstraction
4
+ call_without_q(['Weather'])
5
+ end
@@ -0,0 +1,6 @@
1
+ require_relative 'abstraction'
2
+ module WirelessData
3
+ include Abstraction
4
+ call_without_q(['APLocations'])
5
+ call_with_q(['APInfo'])
6
+ end
@@ -0,0 +1,3 @@
1
+ module Uwapi
2
+ VERSION = "0.0.1"
3
+ end
data/uwapi.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'uwapi/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'uwapi'
8
+ spec.version = Uwapi::VERSION
9
+ spec.authors = ['Bill Li']
10
+ spec.email = ['me@billxinli.com']
11
+ spec.description = %q{University of Waterloo OpenData API Ruby Implementation}
12
+ spec.summary = %q{University of Waterloo OpenData API Ruby Implementation}
13
+ spec.homepage = 'https://github.com/billxinli/uwapi'
14
+ spec.license = 'MIT'
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+ spec.add_dependency('httparty')
20
+ spec.add_dependency('json')
21
+ spec.add_development_dependency('bundler', '~> 1.3')
22
+ spec.add_development_dependency('rake')
23
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uwapi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Bill Li
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-18 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: json
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: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
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: University of Waterloo OpenData API Ruby Implementation
70
+ email:
71
+ - me@billxinli.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/uwapi.rb
82
+ - lib/uwapi/service/abstraction.rb
83
+ - lib/uwapi/service/academic_programs.rb
84
+ - lib/uwapi/service/course.rb
85
+ - lib/uwapi/service/event.rb
86
+ - lib/uwapi/service/exam_info.rb
87
+ - lib/uwapi/service/experimental.rb
88
+ - lib/uwapi/service/faculty_info.rb
89
+ - lib/uwapi/service/food_services.rb
90
+ - lib/uwapi/service/geolocation.rb
91
+ - lib/uwapi/service/other.rb
92
+ - lib/uwapi/service/professor.rb
93
+ - lib/uwapi/service/publications.rb
94
+ - lib/uwapi/service/schedule.rb
95
+ - lib/uwapi/service/weather.rb
96
+ - lib/uwapi/service/wireless_data.rb
97
+ - lib/uwapi/version.rb
98
+ - uwapi.gemspec
99
+ homepage: https://github.com/billxinli/uwapi
100
+ licenses:
101
+ - MIT
102
+ metadata: {}
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 2.0.2
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: University of Waterloo OpenData API Ruby Implementation
123
+ test_files: []