class TeamApi::ApiImpl

Attributes

baseurl[RW]
data[RW]
index_endpoints[RW]
site[RW]

Public Class Methods

new(site, baseurl) click to toggle source
# File lib/team_api/api_impl.rb, line 12
def initialize(site, baseurl)
  @site = site
  @data = site.data
  @index_endpoints = []
  @baseurl = baseurl
end

Public Instance Methods

envelop(endpoint, items) click to toggle source
# File lib/team_api/api_impl.rb, line 23
def envelop(endpoint, items)
  return if items.nil? || items.empty?
  { 'self' => self_link(endpoint), 'results' => items }
end
generate_error_endpoint() click to toggle source
# File lib/team_api/api_impl.rb, line 91
def generate_error_endpoint
  generate_errors_endpoint
  generate_errors_index_summary_endpoint
end
generate_index_endpoint(endpoint, title, description, items) click to toggle source
# File lib/team_api/api_impl.rb, line 28
def generate_index_endpoint(endpoint, title, description, items)
  return if items.nil? || items.empty?
  Endpoint.create site, "#{baseurl}/#{endpoint}", items
  index_endpoints << {
    'endpoint' => endpoint, 'title' => title, 'description' => description
  }
end
generate_index_endpoint_for_collection(endpoint_info) click to toggle source
# File lib/team_api/api_impl.rb, line 61
def generate_index_endpoint_for_collection(endpoint_info)
  collection = endpoint_info['collection']
  generate_index_endpoint(
    endpoint_info['collection'], endpoint_info['title'],
    endpoint_info['description'],
    envelop(collection, (data[collection] || {}).values))
end
generate_item_endpoints(collection_name) click to toggle source
# File lib/team_api/api_impl.rb, line 69
def generate_item_endpoints(collection_name)
  (data[collection_name] || {}).each do |identifier, value|
    identifier = Canonicalizer.canonicalize(identifier)
    url = "#{baseurl}/#{collection_name}/#{identifier}"
    Endpoint.create site, url, value
  end
end
generate_schema_endpoint(schema_file_location) click to toggle source
# File lib/team_api/api_impl.rb, line 36
def generate_schema_endpoint(schema_file_location)
  items = {}
  unless schema_file_location.nil? || schema_file_location.empty?
    about_yml_schema_file = File.read schema_file_location
    items = items.merge({ 'about_yml' => JSON.parse(about_yml_schema_file) })
  end

  local_schema_files.each do |filename|
    file = File.join File.dirname(__FILE__), filename
    schema = JSON.parse(File.read(file))
    items = items.merge schema
  end

  generate_index_endpoint('schemas', 'Schemas',
    'Schemas used to parse .about.yml and team member .yml files',
    items)
end
generate_snippets_endpoints() click to toggle source
# File lib/team_api/api_impl.rb, line 84
def generate_snippets_endpoints
  generate_latest_snippet_endpoint
  generate_snippets_by_date_endpoints
  generate_snippets_by_user_endpoints
  generate_snippets_index_summary_endpoint
end
generate_tag_category_endpoint(category) click to toggle source
# File lib/team_api/api_impl.rb, line 54
def generate_tag_category_endpoint(category)
  canonicalized = Canonicalizer.canonicalize(category)
  generate_index_endpoint(canonicalized, category,
    "Index of team members by #{category.downcase}",
    envelop(canonicalized, (data[canonicalized] || {}).values))
end
local_schema_files() click to toggle source
# File lib/team_api/api_impl.rb, line 77
def local_schema_files
  %w(
    snippet_schema.json
    team_member_schema.json
  )
end