class CollegiateDirectories
Public: Interact with the Collegiate Directories API.
Constants
- CHECK_RESPONSE
Public: Check a response for validity.
response - Object representing the response.
Raises
ApiError
on error.- VERSION
Public Class Methods
Public: Initialize the API client.
token - A String containing the API token (default:
COLLEGIATE_DIRECTORIES_TOKEN environment variable).
# File lib/collegiate_directories.rb, line 35 def initialize(token: ENV["COLLEGIATE_DIRECTORIES_TOKEN"]) @default_opts = { body: token.to_json } end
Public Instance Methods
Public: Return the coaches for a specific sport.
sport - The Integer ID of the sport or the String name of the sport.
Returns Hash. Raises CollegiateDirectories::ApiError
on error.
# File lib/collegiate_directories.rb, line 45 def coaches_for(sport) sport = sport_to_api(sport) response = self.class.post("/Coaches?sportId=#{sport}", @default_opts) response.parsed_response.tap(&CHECK_RESPONSE) end
Public: Return the sports the directory supports.
Returns Hash. Raises CollegiateDirectories::ApiError
on error.
# File lib/collegiate_directories.rb, line 56 def sports response = self.class.post("/Sports", @default_opts) response.parsed_response.tap(&CHECK_RESPONSE) end
Private Instance Methods
Private: Convert a String representation of a sport to the correct Integer ID.
sport - The Integer ID of the sport or the String name of the sport.
Returns Integer. Raises CollegiateDirectories::SportNotFound
on error.
# File lib/collegiate_directories.rb, line 70 def sport_to_api(sport) return sport if sport.is_a?(Integer) found = sports["Sports"].find { |o| o["Name"].casecmp(sport.to_s).zero? } raise SportNotFound, "#{sport} is an invalid sport" if found.nil? found["Id"] end