class Neutrino::AudiomaticRails::NeutrinoAudiomaticController
Public Instance Methods
auth_strategy()
click to toggle source
# File lib/neutrino_audiomatic_rails/controllers/neutrino_audiomatic_controller.rb, line 42 def auth_strategy auth = case Neutrino::AudiomaticRails.routes[@snake_klass][:auth_strategy] when :reference then reference = params[:ref] !@snake_klass.find_by(reference: reference).nil? when :signature then unless Rails.env.test? or Rails.env.development? Neutrino::AudiomaticRails::HMAC.check_hash_url(request) else true end end unless auth render nothing: true, status:403 and return end end
chose_model(models, mountedas)
click to toggle source
# File lib/neutrino_audiomatic_rails/controllers/neutrino_audiomatic_controller.rb, line 73 def chose_model(models, mountedas) url = params[:url] model = models.each { |model| return model if model.send(mountedas.to_sym).url == url }.first model end
download()
click to toggle source
# File lib/neutrino_audiomatic_rails/controllers/neutrino_audiomatic_controller.rb, line 15 def download model = @snake_klass.to_s id = params[:id] send_file "#{Rails.root}/tmp/audio/#{model}/#{id}" end
find_model()
click to toggle source
# File lib/neutrino_audiomatic_rails/controllers/neutrino_audiomatic_controller.rb, line 60 def find_model model = case Neutrino::AudiomaticRails.routes[@snake_klass][:auth_strategy] when :reference then reference = params[:ref] @snake_klass.find_by(reference: reference) when :signature then id = params[:id] @snake_klass.find(id) end render nothing: true, status:400 and return if model.nil? model end
set_model()
click to toggle source
# File lib/neutrino_audiomatic_rails/controllers/neutrino_audiomatic_controller.rb, line 10 def set_model klass = request.path[/audiomatic\/(\w+)/, 1] @snake_klass = klass.camelize.constantize end
update()
click to toggle source
# File lib/neutrino_audiomatic_rails/controllers/neutrino_audiomatic_controller.rb, line 21 def update model = find_model audiomatic_ans = params[:result] logs = audiomatic_ans.map do |answer| model._save_to answer.to_hash end logs.each { |log| Rails.logger.error(log) unless log == true } model.block_analyze = true if model.save render nothing: true, status: 200 else render nothing: true, status: 400 end end
verify_audiomatic()
click to toggle source
# File lib/neutrino_audiomatic_rails/controllers/neutrino_audiomatic_controller.rb, line 36 def verify_audiomatic unless Rails.env.test? || Rails.env.development? || Neutrino::AudiomaticRails::HMAC.verify_response(request) render nothing: true, status:403 and return end end