class TeamApi::Api
Functions for generating JSON objects as part of an API
Constants
- BASEURL
Public Class Methods
add_self_links(site)
click to toggle source
# File lib/team_api/api.rb, line 34 def self.add_self_links(site) baseurl = self.baseurl site Config.endpoint_config.each do |endpoint_info| collection_name = endpoint_info['collection'] (site.data[collection_name] || {}).values.each do |item| slug = Canonicalizer.canonicalize item[endpoint_info['item_id']] item['self'] = File.join baseurl, collection_name, slug end end end
baseurl(site)
click to toggle source
Calculates the full URL prefix for every API endpoint, used to generate `self:` links. It is generated by concatenating the `url:` and `baseurl:` values from _config.yml, and the Api::BASEURL value, e.g. localhost:4001/api, team-api.18f.gov/public/api.
# File lib/team_api/api.rb, line 30 def self.baseurl(site) File.join site.config['url'], site.config['baseurl'], BASEURL end
generate_api(site)
click to toggle source
Generates all of the API endpoints.
site
-
Jekyll site object
# File lib/team_api/api.rb, line 16 def self.generate_api(site) impl = ApiImpl.new site, BASEURL generate_collection_endpoints impl generate_tag_category_endpoints impl impl.generate_schema_endpoint team_api_schema_location impl.generate_snippets_endpoints impl.generate_error_endpoint IndexPage.create site, impl.index_endpoints end
Private Class Methods
generate_collection_endpoints(impl)
click to toggle source
# File lib/team_api/api.rb, line 45 def self.generate_collection_endpoints(impl) Config.endpoint_config.each do |endpoint_info| impl.generate_index_endpoint_for_collection endpoint_info impl.generate_item_endpoints endpoint_info['collection'] end end
generate_tag_category_endpoints(impl)
click to toggle source
# File lib/team_api/api.rb, line 54 def self.generate_tag_category_endpoints(impl) %w(Skills Interests).each do |tag_category| impl.generate_tag_category_endpoint tag_category impl.generate_item_endpoints Canonicalizer.canonicalize(tag_category) end end
team_api_schema_location()
click to toggle source
# File lib/team_api/api.rb, line 63 def self.team_api_schema_location about_yml = Gem::Specification.find_by_name 'about_yml' if about_yml.nil? nil else "#{about_yml.gem_dir}/lib/about_yml/schema.json" end end