Class: Apipie::ApipiesController

Inherits:
ActionController::Base
  • Object
show all
Includes:
ActionView::Context, ApipieHelper
Defined in:
app/controllers/apipie/apipies_controller.rb

Instance Method Summary collapse

Methods included from ApipieHelper

#heading

Instance Method Details

#apipie_checksumObject



91
92
# File 'app/controllers/apipie/apipies_controller.rb', line 91

def apipie_checksum
end

#authenticateObject



11
12
13
14
15
# File 'app/controllers/apipie/apipies_controller.rb', line 11

def authenticate
  if Apipie.configuration.authenticate
    instance_eval(&Apipie.configuration.authenticate)
  end
end

#indexObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/controllers/apipie/apipies_controller.rb', line 18

def index
  params[:version] ||= Apipie.configuration.default_version

  get_format

  if params[:type].to_s == 'swagger' && params[:format].to_s == 'json'
    head :forbidden and return if Apipie.configuration.authorize
    should_render_swagger = true
  end

  respond_to do |format|

    if Apipie.configuration.use_cache?
      render_from_cache
      return
    end

    @language = get_language

    Apipie.load_documentation if Apipie.configuration.reload_controllers? || !Rails.application.config.eager_load

    I18n.locale = @language

    if should_render_swagger
      prev_warning_value = Apipie.configuration.generator.swagger.suppress_warnings
      begin
        Apipie.configuration.generator.swagger.suppress_warnings = true
        @doc = Apipie.to_swagger_json(params[:version], params[:resource], params[:method], @language)
      ensure
        Apipie.configuration.generator.swagger.suppress_warnings = prev_warning_value
      end
    else
      @doc = Apipie.to_json(params[:version], params[:resource], params[:method], @language)
      @doc = authorized_doc
    end

    format.json do
      if @doc
        render :json => @doc
      else
        head :not_found
      end
    end

    format.html do
      unless @doc
        render 'apipie_404', :status => 404
        return
      end

      @versions = Apipie.available_versions
      @doc = @doc[:docs]
      @doc[:link_extension] = (@language ? ".#{@language}" : '')+Apipie.configuration.link_extension
      if @doc[:resources].blank?
        render "getting_started" and return
      end
      @resource = @doc[:resources].first if params[:resource].present?
      @method = @resource[:methods].first if params[:method].present?
      @languages = Apipie.configuration.languages

      if @resource && @method
        render 'method'
      elsif @resource
        render 'resource'
      elsif params[:resource].present? || params[:method].present?
        render 'apipie_404', :status => 404
      else
        render 'index'
      end
    end
  end
end