Sha256: e7e0ec49d202149f43c1ebca96a95c9cbc0b87c5fb74f4381dcdbbf6e2aa4d7d

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

module Swaggard
  class SwaggerController < ApplicationController

    before_filter :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

          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

2 entries across 2 versions & 1 rubygems

Version Path
swaggard-0.4.0 app/controllers/swaggard/swagger_controller.rb
swaggard-0.3.0 app/controllers/swaggard/swagger_controller.rb