module Hippo::API::HelperMethods

Public Instance Methods

csrf_token() click to toggle source
# File lib/hippo/api/helper_methods.rb, line 15
def csrf_token
    Rack::Csrf.csrf_token(env)
end
data() click to toggle source
# File lib/hippo/api/helper_methods.rb, line 34
def data
    if request.content_type == 'application/json'
        @json_data ||= (
            body = request.body.read
            body.present? ? Oj.load(body) : {}
        )
    else
        request.params
    end
end
error_as_json() click to toggle source
# File lib/hippo/api/helper_methods.rb, line 23
def error_as_json
    error = request.env['sinatra.error']
    Hippo.logger.warn error.message
    Hippo.logger.warn error.backtrace.join("\n    ")
    API.to_json(
        success: false,
        errors:  { exception: error.message },
        message: error.message
    )
end
find_template(views, name, engine, &block) click to toggle source
Calls superclass method
# File lib/hippo/api/helper_methods.rb, line 54
def find_template(views, name, engine, &block)
    views.each{ |v| super(v, name, engine, &block) }
end
hippo_api_url() click to toggle source
# File lib/hippo/api/helper_methods.rb, line 19
def hippo_api_url
    Hippo.config.api_path
end
hippo_application_title() click to toggle source
# File lib/hippo/api/helper_methods.rb, line 4
def hippo_application_title
    Extensions.controlling.title
end
javascript_tags(*entries) click to toggle source
# File lib/hippo/api/helper_methods.rb, line 8
def javascript_tags(*entries)
    Root.webpack.wait_until_available
    entries.map { |entry|
        "<script src=\"#{Root.webpack.host}/assets/#{Root.webpack.file(entry)}\"></script>"
    }.join("\n")
end
json_reply(response) click to toggle source
# File lib/hippo/api/helper_methods.rb, line 49
def json_reply(response)
    content_type 'application/json'
    API.to_json(response)
end
request_origin() click to toggle source
# File lib/hippo/api/helper_methods.rb, line 45
def request_origin
    @request_origin ||= env['HTTP_ORIGIN']
end