Module: Apipie

Extended by:
Helpers
Defined in:
lib/apipie/dsl_definition.rb,
lib/apipie/errors.rb,
lib/apipie/markup.rb,
lib/apipie/helpers.rb,
lib/apipie/railtie.rb,
lib/apipie/routing.rb,
lib/apipie/version.rb,
lib/apipie/extractor.rb,
lib/apipie/validator.rb,
lib/apipie/application.rb,
lib/apipie/apipie_module.rb,
lib/apipie/configuration.rb,
lib/apipie/see_description.rb,
lib/apipie/client/generator.rb,
lib/apipie/extractor/writer.rb,
lib/apipie/routes_formatter.rb,
lib/apipie/error_description.rb,
lib/apipie/param_description.rb,
lib/apipie/static_dispatcher.rb,
lib/apipie/extractor/recorder.rb,
lib/apipie/method_description.rb,
lib/apipie/extractor/collector.rb,
lib/apipie/resource_description.rb,
lib/generators/apipie/views_generator.rb,
app/controllers/apipie/apipies_controller.rb,
lib/apipie/middleware/checksum_in_headers.rb,
lib/generators/apipie/install/install_generator.rb

Overview

Middleware for rails app that adds checksum of JSON in the response headers which can help client to realize when JSON has changed

Add the following to your application.rb

require 'apipie/middleware/checksum_in_headers'
# Add JSON checksum in headers for smarter caching
config.middleware.use "Apipie::Middleware::ChecksumInHeaders"

And in your apipie initializer allow checksum calculation

Apipie.configuration.update_checksum = true

and reload documentation

Apipie.reload_documentation

By default the header is added to requests on /api and /apipie only It can be changed with

Apipie.configuration.checksum_path = ['/prefix/api']

If set to nil the header is added always

Defined Under Namespace

Modules: Client, DSL, Extractor, Helpers, Markup, Middleware, Routing, Validator Classes: ApipiesController, Application, Configuration, DefinedParamError, Error, ErrorDescription, FileHandler, InstallGenerator, MethodDescription, ParamDescription, ParamError, ParamInvalid, ParamMissing, Railtie, ResourceDescription, RoutesFormatter, SeeDescription, StaticDispatcher, UnknownParam, ViewsGenerator

Constant Summary collapse

VERSION =
'0.3.4'

Instance Attribute Summary

Attributes included from Helpers

#url_prefix

Class Method Summary collapse

Methods included from Helpers

full_url, include_javascripts, include_stylesheets, markup_to_html, request_script_name, request_script_name=

Class Method Details

.api_base_url(version = nil) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/apipie/apipie_module.rb', line 44

def self.api_base_url(version = nil)
  if api_base_url_version_valid? version
    self.configuration.api_base_url[version]
  elsif api_base_url_version_valid? Apipie.configuration.default_version
    self.configuration.api_base_url[Apipie.configuration.default_version]
  else
    "/api"
  end
end

.api_base_url_version_valid?(version) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/apipie/apipie_module.rb', line 58

def self.api_base_url_version_valid?(version)
  version && self.configuration.api_base_url.has_key?(version)
end

.appObject



7
8
9
# File 'lib/apipie/apipie_module.rb', line 7

def self.app
  @application ||= Apipie::Application.new
end

.app_info(version = nil) ⇒ Object

get application description for given or default version



34
35
36
37
38
39
40
41
42
# File 'lib/apipie/apipie_module.rb', line 34

def self.app_info(version = nil)
  if app_info_version_valid? version
    Apipie.markup_to_html(self.configuration.app_info[version])
  elsif app_info_version_valid? Apipie.configuration.default_version
    Apipie.markup_to_html(self.configuration.app_info[Apipie.configuration.default_version])
  else
    "Another API description"
  end
end

.app_info_version_valid?(version) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/apipie/apipie_module.rb', line 54

def self.app_info_version_valid?(version)
  version && self.configuration.app_info.has_key?(version)
end

.configurationObject



25
26
27
# File 'lib/apipie/apipie_module.rb', line 25

def self.configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



21
22
23
# File 'lib/apipie/apipie_module.rb', line 21

def self.configure
  yield configuration
end

.debug(message) ⇒ Object



29
30
31
# File 'lib/apipie/apipie_module.rb', line 29

def self.debug(message)
  puts message if Apipie.configuration.debug
end

.method_missing(method, *args, &block) ⇒ Object

all calls delegated to Apipie::Application instance



17
18
19
# File 'lib/apipie/apipie_module.rb', line 17

def self.method_missing(method, *args, &block)
  app.respond_to?(method) ? app.send(method, *args, &block) : super
end

.record(record) ⇒ Object



62
63
64
# File 'lib/apipie/apipie_module.rb', line 62

def self.record(record)
  Apipie::Extractor.start record
end

.to_json(version = nil, resource_name = nil, method_name = nil, lang = nil) ⇒ Object



11
12
13
14
# File 'lib/apipie/apipie_module.rb', line 11

def self.to_json(version = nil, resource_name = nil, method_name = nil, lang = nil)
  version ||= Apipie.configuration.default_version
  app.to_json(version, resource_name, method_name, lang)
end