Module: Core::Helpers::Declarators

Included in:
Controllers::Base
Defined in:
lib/core/helpers/declarators.rb

Overview

This helpers module is a bit larger than the others as it provides methods to declare routes whithin a service, performing needed checks and filters.

Author:

Instance Method Summary collapse

Instance Method Details

#api_route(verb, path, premium: false, scopes: [], &block) ⇒ Object

Main method to declare new routes, persisting them in the database and declaring it in the Sinatra application with the needed before checks.

Parameters:

  • verb (String)

    the HTTP method for the route.

  • path (String)

    the whole URI with parameters for the route.

  • options (Hash)

    the additional options for the route.



16
17
18
19
20
21
22
23
24
# File 'lib/core/helpers/declarators.rb', line 16

def api_route(verb, path, premium: false, scopes: [], &block)
  send(verb, path) do
    scope_objects = fetch_scopes(scopes + ['data::usage'])
    appli = application(premium: premium)
    check_app_scopes(appli, scope_objects)
    check_token_scopes(token, scope_objects)
    instance_eval(&block)
  end
end