collegiate_directories 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.rubocop.yml +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +19 -0
- data/README.md +43 -0
- data/Rakefile +13 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/collegiate_directories.gemspec +32 -0
- data/lib/collegiate_directories.rb +78 -0
- data/lib/collegiate_directories/version.rb +3 -0
- metadata +155 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 69e65c52fd53b190297060d4351612f2d046e010
|
4
|
+
data.tar.gz: 5226a6ddec70cb2b370408d5ba664cc3281ef26f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3599f2ed51a5f4fadbf8b8aff27796db06e4607484228a1ba44faa6a5dab35f61e0d8f99ed665fac1af25c2abb9ee197b7fec92aee55ce5f99152a9f407a5803
|
7
|
+
data.tar.gz: 811d46fbf2259e63b63390211c1d3d4e5a6498d7b57548998e5113aab713217dd4f3c0adc398a39074a8673dd33b5136ccebf117afab535b49712b9a21c9002b
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2016 Locker Room Talk
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
7
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
8
|
+
so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# CollegiateDirectories
|
2
|
+
|
3
|
+
Interact with the https://www.collegiatedirectories.com API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'collegiate_directories'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install collegiate_directories
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require "collegiate_directories"
|
25
|
+
|
26
|
+
directory = CollegiateDirectories.new("my-api-token")
|
27
|
+
directory.sports
|
28
|
+
#=> {"Sports"=>[{"Name"=>"Archery", "IsTraditional"=>false, "Id"=>1}, ... }
|
29
|
+
directory.coaches_for(:archery)
|
30
|
+
#=> {"Coaches"=>[{"School"=>{"Name"=>"Univ. of the Cumberlands", "AlphaName"=>"CUMBERLANDS, UNIVERSITY OF THE", ... }
|
31
|
+
directory.coaches_for(:rollerball)
|
32
|
+
#=> CollegiateDirectories::SportNotFound: rollerball is an invalid sport
|
33
|
+
```
|
34
|
+
|
35
|
+
## Development
|
36
|
+
|
37
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
38
|
+
|
39
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/lockerroomtalk/collegiate_directories.
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
begin
|
4
|
+
require "rspec/core/rake_task"
|
5
|
+
require "rubocop/rake_task"
|
6
|
+
rescue LoadError
|
7
|
+
abort "Run `bundle install` before using Rake!"
|
8
|
+
end
|
9
|
+
|
10
|
+
RSpec::Core::RakeTask.new(:spec)
|
11
|
+
RuboCop::RakeTask.new
|
12
|
+
|
13
|
+
task default: %i(spec rubocop)
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "collegiate_directories"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "collegiate_directories/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "collegiate_directories"
|
8
|
+
spec.version = CollegiateDirectories::VERSION
|
9
|
+
spec.authors = ["Paul Stengel"]
|
10
|
+
spec.email = ["paul.stengel@lockerroomtalk.com"]
|
11
|
+
spec.license = "MIT"
|
12
|
+
|
13
|
+
# rubocop:disable Metrics/LineLength
|
14
|
+
spec.summary = "Gem for interacting with the https://www.collegiatedirectories.com API"
|
15
|
+
spec.homepage = "https://github.com/lockerroomtalk/collegiate_directories"
|
16
|
+
# rubocop:enable Metrics/LineLength
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0")
|
19
|
+
spec.files.reject! { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_runtime_dependency "httparty", "~> 0.14"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
27
|
+
spec.add_development_dependency "dotenv", "~> 2.1"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.5"
|
30
|
+
spec.add_development_dependency "rubocop", "~> 0.43"
|
31
|
+
spec.add_development_dependency "rubocop-rspec", "~> 1.4"
|
32
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require "collegiate_directories/version"
|
2
|
+
|
3
|
+
require "json"
|
4
|
+
require "httparty"
|
5
|
+
|
6
|
+
# Public: Interact with the Collegiate Directories API.
|
7
|
+
class CollegiateDirectories
|
8
|
+
include HTTParty
|
9
|
+
|
10
|
+
class ApiError < StandardError; end
|
11
|
+
class SportNotFound < StandardError; end
|
12
|
+
|
13
|
+
base_uri "https://www.collegiatedirectories.com/data/api"
|
14
|
+
format :json
|
15
|
+
headers "Content-Type" => "application/json"
|
16
|
+
|
17
|
+
# Public: Check a response for validity.
|
18
|
+
#
|
19
|
+
# response - Object representing the response.
|
20
|
+
#
|
21
|
+
# Raises ApiError on error.
|
22
|
+
CHECK_RESPONSE = lambda do |response|
|
23
|
+
begin
|
24
|
+
response.fetch("ResultCode").nonzero? &&
|
25
|
+
raise(ApiError, response["Message"])
|
26
|
+
rescue KeyError, NoMethodError
|
27
|
+
raise ApiError, "Incomplete response"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Public: Initialize the API client.
|
32
|
+
#
|
33
|
+
# token - A String containing the API token (default:
|
34
|
+
# COLLEGIATE_DIRECTORIES_TOKEN environment variable).
|
35
|
+
def initialize(token: ENV["COLLEGIATE_DIRECTORIES_TOKEN"])
|
36
|
+
@default_opts = { body: token.to_json }
|
37
|
+
end
|
38
|
+
|
39
|
+
# Public: Return the coaches for a specific sport.
|
40
|
+
#
|
41
|
+
# sport - The Integer ID of the sport or the String name of the sport.
|
42
|
+
#
|
43
|
+
# Returns Hash.
|
44
|
+
# Raises CollegiateDirectories::ApiError on error.
|
45
|
+
def coaches_for(sport)
|
46
|
+
sport = sport_to_api(sport)
|
47
|
+
|
48
|
+
response = self.class.post("/Coaches?sportId=#{sport}", @default_opts)
|
49
|
+
response.parsed_response.tap(&CHECK_RESPONSE)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Public: Return the sports the directory supports.
|
53
|
+
#
|
54
|
+
# Returns Hash.
|
55
|
+
# Raises CollegiateDirectories::ApiError on error.
|
56
|
+
def sports
|
57
|
+
response = self.class.post("/Sports", @default_opts)
|
58
|
+
response.parsed_response.tap(&CHECK_RESPONSE)
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
# Private: Convert a String representation of a sport to the correct Integer
|
64
|
+
# ID.
|
65
|
+
#
|
66
|
+
# sport - The Integer ID of the sport or the String name of the sport.
|
67
|
+
#
|
68
|
+
# Returns Integer.
|
69
|
+
# Raises CollegiateDirectories::SportNotFound on error.
|
70
|
+
def sport_to_api(sport)
|
71
|
+
return sport if sport.is_a?(Integer)
|
72
|
+
|
73
|
+
found = sports["Sports"].find { |o| o["Name"].casecmp(sport.to_s).zero? }
|
74
|
+
raise SportNotFound, "#{sport} is an invalid sport" if found.nil?
|
75
|
+
|
76
|
+
found["Id"]
|
77
|
+
end
|
78
|
+
end
|
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: collegiate_directories
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paul Stengel
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-03 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.14'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.12'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.12'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: dotenv
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.5'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.5'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.43'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.43'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop-rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.4'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.4'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- paul.stengel@lockerroomtalk.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".rubocop.yml"
|
121
|
+
- Gemfile
|
122
|
+
- LICENSE.txt
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- bin/console
|
126
|
+
- bin/setup
|
127
|
+
- collegiate_directories.gemspec
|
128
|
+
- lib/collegiate_directories.rb
|
129
|
+
- lib/collegiate_directories/version.rb
|
130
|
+
homepage: https://github.com/lockerroomtalk/collegiate_directories
|
131
|
+
licenses:
|
132
|
+
- MIT
|
133
|
+
metadata: {}
|
134
|
+
post_install_message:
|
135
|
+
rdoc_options: []
|
136
|
+
require_paths:
|
137
|
+
- lib
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
requirements: []
|
149
|
+
rubyforge_project:
|
150
|
+
rubygems_version: 2.5.1
|
151
|
+
signing_key:
|
152
|
+
specification_version: 4
|
153
|
+
summary: Gem for interacting with the https://www.collegiatedirectories.com API
|
154
|
+
test_files: []
|
155
|
+
has_rdoc:
|