module QuizApiClient::Services class QuizSessionService < BaseApiService def token(scope:, exp: nil, resource_id: nil) return unless allowed_scopes.include?(scope) generate_token(scope: scope, exp: exp, resource_id: resource_id) end def update(params:, default_token: nil) patch_to_quiz_api(params: params, token: token_for_api(default_token, scope_update, params[:id])) end def show(params:, default_token: nil) raise 'Quiz Session Id Required' unless params && params[:id] get_from_quiz_api(params: params, token: token_for_api(default_token, scope_show, params[:id])) end def scope_update 'quiz_session.update' end def scope_take 'quiz_session.take' end def scope_grade 'quiz_session.grade' end def scope_show 'quiz_session.show' end private def patch_to_quiz_api(params:, token:) client(token: token).patch( "/api/quiz_sessions/#{params[:id]}", quiz_session: params ) end def get_from_quiz_api(params:, token:) client(token: token).get( "/api/quiz_sessions/#{params[:id]}" ) end def allowed_scopes [ scope_grade, scope_take, scope_update, scope_show ] end end end