Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/glacials/splits-io. a speedrunning data store and analysis engine splits.io
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273class Api::V4::ApplicationController < ActionController::Base prepend_before_action :set_cors_headers before_action :force_ssl, if: -> { Rails.application.config.use_ssl }
def options headers['Allow'] = 'POST, PUT, DELETE, GET, OPTIONS' end
private
def set_cors_headers headers.merge!( 'Access-Control-Allow-Origin' => '*', 'Access-Control-Allow-Methods' => '*', 'Access-Control-Request-Method' => '*', 'Access-Control-Allow-Headers' => 'origin, X-Requested-With, Content-Type, Accept, Authorization' ) end
def build_link_headers(links) links.map do |link| "<#{link[:url]}>; rel=\"#{link[:rel]}\"" end.join(', ') end
def force_ssl if !request.ssl? render status: 301, json: {error: "The Splits I/O API is only accessible over HTTPS."} end end
def not_found(collection_name) { status: 404, json: { error: "No #{collection_name} with ID #{params[collection_name]} found." } } end
def set_category @category = Category.find(params[:category]) rescue ActiveRecord::RecordNotFound render not_found(:category) end
def set_game @game = Game.find_by!(shortname: params[:game]) rescue ActiveRecord::RecordNotFound render not_found(:game) end
def set_runner @runner = User.with_runs.find_by!(name: params[:runner]) rescue ActiveRecord::RecordNotFound render not_found(:runner) end
def set_run @run = Run.find36(params[:run]) rescue ActiveRecord::RecordNotFound render not_found(:run) end
def verify_ownership! if params[:claim_token].blank? head 401 elsif params[:claim_token] != @run.claim_token head 403 end endend