class Coursemology::Evaluator::Models::Base
Attributes
api_token[RW]
api_user_email[RW]
Public Class Methods
initialize()
click to toggle source
# File lib/coursemology/evaluator/models/base.rb, line 7 def initialize Flexirest::Base.perform_caching = false default_config = Flexirest::Base.faraday_config Flexirest::Base.faraday_config do |faraday| # +follow_redirects+ must be added before declaring the adapter. See faraday_middleware#32, # last comment. faraday.response :follow_redirects default_config.call(faraday) end end
Private Class Methods
fix_put_parameters(key, _, param)
click to toggle source
Fixes the request parameters when executing a POST, PATCH or PUT.
@param [String] key The key to prefix all attributes with. @param [Request] param The request parameter to prepend the key with.
# File lib/coursemology/evaluator/models/base.rb, line 38 def self.fix_put_parameters(key, _, param) param.post_params = { key => param.post_params } unless param.post_params.empty? end
model_key(key)
click to toggle source
Sets the key of the model. This is the key that all attributes are nested under, the same as the require
directive in the controller of the web application.
@param [String] key The key to prefix all attributes with.
# File lib/coursemology/evaluator/models/base.rb, line 27 def self.model_key(key) before_request do |name, param| fix_put_parameters(key, name, param) if [:post, :patch, :put].include?(param.method[:method]) end end
Private Instance Methods
add_authentication(_, request)
click to toggle source
Adds the authentication email and token to the request.
# File lib/coursemology/evaluator/models/base.rb, line 46 def add_authentication(_, request) request.headers['X-User-Email'] = self.class.api_user_email request.headers['X-User-Token'] = self.class.api_token end