Class: TeamApi::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/team_api/api.rb

Overview

Functions for generating JSON objects as part of an API

Constant Summary collapse

BASEURL =
'api'

Class Method Summary collapse

Class Method Details



34
35
36
37
38
39
40
41
42
43
# 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) ⇒ Object

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.



30
31
32
# 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) ⇒ Object

Generates all of the API endpoints.

site

Jekyll site object



16
17
18
19
20
21
22
23
24
# 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