uwaterlooapi 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -0
- data/Gemfile +4 -1
- data/README.md +4 -2
- data/lib/helpers/uwaterlooapi_query.rb +28 -29
- data/lib/uwaterlooapi.rb +6 -1
- data/spec/spec_helper.rb +4 -1
- data/uwaterlooapi.gemspec +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c80d6d3357a1f8ff107de957c4658dd0f638969
|
4
|
+
data.tar.gz: d10287d3b38a0149093b855bfaf57aad194615de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dda02ad184753bd3aec01a2e03e0816af7dd647dd127477fa3eab4c3a9a7731df4854ceaefc6c9702486aab463ab5eeabd75db4251ff46a313a9032e9e1393be
|
7
|
+
data.tar.gz: c342610a4c54a140fa5321cbc503d37e3b7f28c770fe301c4c29c6a68a0819d070aba8f6ccea2896b5783a4d96c22e1acb584626eb5861a78996178be5d0f61c
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -3,7 +3,9 @@ uwaterlooapi
|
|
3
3
|
|
4
4
|
RubyGem wrapper for the University of Waterloo OpenData API
|
5
5
|
|
6
|
-
[![Build Status](https://travis-ci.org/amsardesai/uwaterlooapi.svg
|
6
|
+
[![Build Status](https://travis-ci.org/amsardesai/uwaterlooapi.svg)](https://travis-ci.org/amsardesai/uwaterlooapi)
|
7
|
+
[![Code Climate](https://codeclimate.com/github/amsardesai/uwaterlooapi/badges/gpa.svg)](https://codeclimate.com/github/amsardesai/uwaterlooapi)
|
8
|
+
[![Test Coverage](https://codeclimate.com/github/amsardesai/uwaterlooapi/badges/coverage.svg)](https://codeclimate.com/github/amsardesai/uwaterlooapi)
|
7
9
|
|
8
10
|
## Installation
|
9
11
|
|
@@ -17,7 +19,7 @@ Or install it in your system:
|
|
17
19
|
|
18
20
|
## Usage
|
19
21
|
|
20
|
-
To use
|
22
|
+
To use this gem, you must first get an API key from http://api.uwaterloo.ca/.
|
21
23
|
|
22
24
|
```ruby
|
23
25
|
# Require the gem at the top of your ruby file
|
@@ -2,7 +2,7 @@ require 'recursive-open-struct'
|
|
2
2
|
|
3
3
|
class UWaterlooAPIQuery
|
4
4
|
include Routes
|
5
|
-
|
5
|
+
|
6
6
|
def initialize(cur_route, cur_url, api_key)
|
7
7
|
@api_key = api_key
|
8
8
|
@cur_url = cur_url
|
@@ -10,36 +10,20 @@ class UWaterlooAPIQuery
|
|
10
10
|
@retrieved_url = ''
|
11
11
|
@response = @meta = nil
|
12
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
13
|
# Define methods without parameters
|
19
|
-
|
20
|
-
map(&:to_sym).each do |route|
|
21
|
-
|
14
|
+
get_next_routes_without_params.each do |route|
|
22
15
|
self.class.send :define_method, route do
|
23
|
-
|
24
|
-
|
25
|
-
else
|
26
|
-
raise NoMethodError
|
27
|
-
end
|
16
|
+
raise NoMethodError unless is_in_routes?("#{@cur_route}/#{route}")
|
17
|
+
UWaterlooAPIQuery.new "#{@cur_route}/#{route}", "#{@cur_url}/#{route}", @api_key
|
28
18
|
end
|
29
19
|
end
|
30
20
|
|
31
21
|
# Define methods with parameters
|
32
|
-
|
33
|
-
map { |r| r.delete('{}') }.
|
34
|
-
map(&:to_sym).each do |route|
|
35
|
-
|
22
|
+
get_next_routes_with_params.each do |route|
|
36
23
|
self.class.send :define_method, route do |value|
|
37
24
|
raise ArgumentError if ["", 0].include? value
|
38
|
-
|
39
|
-
|
40
|
-
else
|
41
|
-
raise NoMethodError
|
42
|
-
end
|
25
|
+
raise NoMethodError unless is_in_routes?("#{@cur_route}/{#{route}}")
|
26
|
+
UWaterlooAPIQuery.new "#{@cur_route}/{#{route}}", "#{@cur_url}/#{value}", @api_key
|
43
27
|
end
|
44
28
|
end
|
45
29
|
end
|
@@ -47,11 +31,8 @@ class UWaterlooAPIQuery
|
|
47
31
|
# Get meta variables
|
48
32
|
def meta(var)
|
49
33
|
raise NoMethodError unless is_full_route? @cur_route
|
50
|
-
|
51
|
-
|
52
|
-
else
|
53
|
-
raise "No request has been made yet, so meta data is not available."
|
54
|
-
end
|
34
|
+
raise "No request has been made yet, so meta data is not available." unless @meta
|
35
|
+
@meta[var.to_s]
|
55
36
|
end
|
56
37
|
|
57
38
|
# Get data from server
|
@@ -90,12 +71,30 @@ class UWaterlooAPIQuery
|
|
90
71
|
end
|
91
72
|
end
|
92
73
|
|
93
|
-
|
74
|
+
private
|
94
75
|
|
95
76
|
def just_made_request
|
96
77
|
@retrieved_url == @cur_url
|
97
78
|
end
|
98
79
|
|
80
|
+
def get_next_routes
|
81
|
+
@next_routes ||= @@routes.
|
82
|
+
select { |s| s.start_with?(@cur_route) }.
|
83
|
+
map { |s| s[@cur_route.length..-1] }.
|
84
|
+
join.split('/').uniq.delete_if(&:empty?)
|
85
|
+
end
|
86
|
+
|
87
|
+
def get_next_routes_without_params
|
88
|
+
@next_routes_without_params ||= get_next_routes.
|
89
|
+
reject { |r| r =~ /^\{.*\}$/ }.map(&:to_sym)
|
90
|
+
end
|
91
|
+
|
92
|
+
def get_next_routes_with_params
|
93
|
+
@next_routes_with_params ||= get_next_routes.
|
94
|
+
select { |r| r =~ /^\{.*\}$/ }.
|
95
|
+
map { |r| r.delete('{}') }.map(&:to_sym)
|
96
|
+
end
|
97
|
+
|
99
98
|
def is_in_routes?(substring)
|
100
99
|
@@routes.any? { |s| s.start_with?(substring) }
|
101
100
|
end
|
data/lib/uwaterlooapi.rb
CHANGED
@@ -7,11 +7,16 @@ class UWaterlooAPI
|
|
7
7
|
include Routes
|
8
8
|
|
9
9
|
def initialize(api_key)
|
10
|
-
|
10
|
+
get_base_routes.each do |route|
|
11
11
|
self.class.send :define_method, route do
|
12
12
|
UWaterlooAPIQuery.new "/#{route}", "/#{route}", api_key
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
private
|
18
|
+
|
19
|
+
def get_base_routes
|
20
|
+
@base_routes ||= @@routes.map { |r| r.split('/')[1] }.uniq.map(&:to_sym)
|
21
|
+
end
|
17
22
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
require 'codeclimate-test-reporter'
|
2
|
+
CodeClimate::TestReporter.start
|
3
|
+
|
1
4
|
require 'rspec'
|
2
5
|
require 'webmock/rspec'
|
3
6
|
require 'uwaterlooapi'
|
4
7
|
|
5
|
-
WebMock.disable_net_connect! allow_localhost: true
|
8
|
+
WebMock.disable_net_connect! allow_localhost: true, allow: 'codeclimate.com'
|
6
9
|
Dir.chdir File.dirname __FILE__
|
7
10
|
|
8
11
|
# This file was generated by the `rspec --init` command. Conventionally, all
|
data/uwaterlooapi.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
Gem::Specification.new do |spec|
|
3
3
|
spec.name = 'uwaterlooapi'
|
4
|
-
spec.version = '0.0.
|
4
|
+
spec.version = '0.0.3'
|
5
5
|
spec.date = '2014-10-26'
|
6
6
|
spec.summary = "Ruby Gem wrapper for the University of Waterloo Open Data API"
|
7
7
|
spec.description = "Ruby Gem wrapper for the University of Waterloo Open Data API"
|
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.email = 'me@ankitsardesai.ca'
|
10
10
|
spec.files = `git ls-files`.split("\n")
|
11
11
|
spec.test_files = `git ls-files spec`.split("\n")
|
12
|
-
spec.homepage = '
|
12
|
+
spec.homepage = 'https://rubygems.org/gems/uwaterlooapi'
|
13
13
|
spec.license = 'MIT'
|
14
14
|
spec.require_paths = ['lib']
|
15
15
|
spec.add_runtime_dependency 'httparty'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uwaterlooapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ankit Sardesai
|
@@ -86,7 +86,7 @@ files:
|
|
86
86
|
- spec/spec_helper.rb
|
87
87
|
- spec/uwaterlooapi_spec.rb
|
88
88
|
- uwaterlooapi.gemspec
|
89
|
-
homepage:
|
89
|
+
homepage: https://rubygems.org/gems/uwaterlooapi
|
90
90
|
licenses:
|
91
91
|
- MIT
|
92
92
|
metadata: {}
|
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
106
|
version: '0'
|
107
107
|
requirements: []
|
108
108
|
rubyforge_project:
|
109
|
-
rubygems_version: 2.
|
109
|
+
rubygems_version: 2.4.4
|
110
110
|
signing_key:
|
111
111
|
specification_version: 4
|
112
112
|
summary: Ruby Gem wrapper for the University of Waterloo Open Data API
|