Guest User

Untitled

a guest
May 16th, 2018
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. # app/metal/play_stat.rb
  2. # Allow the metal piece to run in isolation
  3. require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails)
  4.  
  5. class PlayStat
  6.  
  7. def self.call(env)
  8. @params = Rack::Request.new(env).params
  9.  
  10. if env["PATH_INFO"] =~ %r[^/player/stat] && env["REQUEST_METHOD"] == "POST"
  11.  
  12. # Parse the params
  13. constant = @params['play'].upcase
  14. begin
  15. altnet_stat_type = AltnetPlayStat.const_get(constant)
  16. track_stats_type = TrackStats.const_get(constant)
  17. rescue
  18. raise "Invalid stat type '#{@params['play']}'"
  19. end
  20. machine_guid = @params['machine_guid']
  21. altnet_object_id = @params['altnet_object_id']
  22.  
  23. # Record the play locally
  24. TrackStats.create!({
  25. 'stat_type' => track_stats_type,
  26. 'track_id' => @params['track_id']
  27. })
  28.  
  29. # Ping Altnet with the play
  30. stat = AltnetPlayStat.new(altnet_stat_type, altnet_object_id, machine_guid)
  31. [200, {"Content-Type" => "text/html"}, [stat.response]]
  32. else
  33. [404, {"Content-Type" => "text/html"}, ["Not Found"]]
  34. end
  35. end
  36. end
Add Comment
Please, Sign In to add comment