Sha256: c21ad3f64dac394237a9325a3e0ea2955faf62793e9bc31c863f22f927742a04

Contents?: true

Size: 1.42 KB

Versions: 14

Compression:

Stored size: 1.42 KB

Contents

module Swaggard
  class SwaggerController < ApplicationController

    before_action :authorize

    def index
      respond_to do |format|
        format.html do
          @authentication_type = Swaggard.configuration.authentication_type
          @authentication_key = Swaggard.configuration.authentication_key
          @authentication_value = Swaggard.configuration.authentication_value.respond_to?(:call) ?
                                    Swaggard.configuration.authentication_value.call :
                                    Swaggard.configuration.authentication_value

          render :index, layout: false
        end

        format.json do
          render json: get_swaggard_doc_json
        end
      end
    end

    protected

    def authorize
      unless Swaggard.configuration.access_username.blank?
        authenticate_or_request_with_http_basic do |username, password|
          username == Swaggard.configuration.access_username && password == Swaggard.configuration.access_password
        end
      end
    end

    def get_swaggard_doc_json
      if Swaggard.configuration.use_cache
        doc_json = Rails.cache.fetch('swaggard_doc_json')
        if doc_json.blank?
          doc_json = Swaggard.get_doc(request.host_with_port).to_json
          Rails.cache.write('swaggard_doc_json', doc_json)
        end
        doc_json
      else
        Swaggard.get_doc(request.host_with_port).to_json
      end
    end

  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
swaggard-1.5.1 app/controllers/swaggard/swagger_controller.rb
swaggard-1.5.0 app/controllers/swaggard/swagger_controller.rb
swaggard-1.4.0 app/controllers/swaggard/swagger_controller.rb
swaggard-1.3.0 app/controllers/swaggard/swagger_controller.rb
swaggard-1.2.0 app/controllers/swaggard/swagger_controller.rb
swaggard-1.1.1 app/controllers/swaggard/swagger_controller.rb
swaggard-1.1.0 app/controllers/swaggard/swagger_controller.rb
swaggard-1.0.2 app/controllers/swaggard/swagger_controller.rb
swaggard-1.0.1 app/controllers/swaggard/swagger_controller.rb
swaggard-1.0.0 app/controllers/swaggard/swagger_controller.rb
swaggard-0.5.4 app/controllers/swaggard/swagger_controller.rb
swaggard-0.5.3 app/controllers/swaggard/swagger_controller.rb
swaggard-0.5.2 app/controllers/swaggard/swagger_controller.rb
swaggard-0.5.1 app/controllers/swaggard/swagger_controller.rb