class Nexmo::OAS::Renderer::API

Public Class Methods

load_business_yaml() click to toggle source
# File lib/nexmo/oas/renderer/app.rb, line 65
def self.load_business_yaml
  raise "Application requires a 'config/business_info.yml' file to be defined inside the documentation path." if defined?(NexmoDeveloper::Application) && !File.exist?("#{Rails.configuration.docs_base_path}/config/business_info.yml")

  if defined?(NexmoDeveloper::Application) && File.exist?("#{Rails.configuration.docs_base_path}/config/business_info.yml")
    @url ||= begin
      config = YAML.load_file("#{Rails.configuration.docs_base_path}/config/business_info.yml")
      config['oas_url']
    end
  else
    'https://www.github.com/nexmo/api-specification/blob/master/definitions'
  end
end

Public Instance Methods

check_oas_constraints!(definition) click to toggle source
# File lib/nexmo/oas/renderer/app.rb, line 85
def check_oas_constraints!(definition)
  return unless defined?(NexmoDeveloper::Application)

  pass unless OpenApiConstraint.match?(definition)
end
check_redirect!() click to toggle source
# File lib/nexmo/oas/renderer/app.rb, line 78
def check_redirect!
  return unless defined?(NexmoDeveloper::Application)

  redirect_path = Redirector.find(request)
  redirect(redirect_path) if redirect_path
end
parse_params(extension) click to toggle source
# File lib/nexmo/oas/renderer/app.rb, line 47
def parse_params(extension)
  extensions = extension.split('.')
  case extensions.size
  when 1
    { definition: extensions.first }
  when 2
    if extensions.second.match?(/v\d+/)
      { definition: extensions.first, version: extensions.second }
    else
      { definition: extensions.first, format: extensions.second }
    end
  when 3
    { definition: extensions.first, version: extensions.second, format: extensions.last }
  else
    {}
  end
end
set_code_language() click to toggle source
# File lib/nexmo/oas/renderer/app.rb, line 112
def set_code_language
  return if params[:code_language] == 'templates'

  @code_language = params[:code_language]
end
set_document() click to toggle source
# File lib/nexmo/oas/renderer/app.rb, line 165
def set_document
  @document = if params[:code_language] == 'templates'
                'verify/templates'
              elsif params[:code_language] == 'ncco'
                'voice/ncco'
              elsif ::Nexmo::Markdown::CodeLanguage.exists?(params[:code_language])
                params[:document]
              else
                "#{params[:document]}/#{params[:code_language]}"
              end
end
set_theme() click to toggle source
# File lib/nexmo/oas/renderer/app.rb, line 118
def set_theme
  persisted_theme = nil

  if defined?(NexmoDeveloper::Application)
    session[:persisted_theme] = params[:theme] if params[:theme]
    persisted_theme = session[:persisted_theme]
  end

  @theme = params[:theme] || persisted_theme

  @theme = 'light' unless %w[light dark].include?(@theme)

  @theme_light = @theme == 'light'

  alternate_theme = @theme == 'light' ? 'dark' : 'light'
  @theme_link = "#{request.path_info}?theme=#{alternate_theme}"
  @theme_link = "/api#{@theme_link}" if defined?(NexmoDeveloper::Application)
end