Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # app/metal/play_stat.rb
- # Allow the metal piece to run in isolation
- require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails)
- class PlayStat
- def self.call(env)
- @params = Rack::Request.new(env).params
- if env["PATH_INFO"] =~ %r[^/player/stat] && env["REQUEST_METHOD"] == "POST"
- # Parse the params
- constant = @params['play'].upcase
- begin
- altnet_stat_type = AltnetPlayStat.const_get(constant)
- track_stats_type = TrackStats.const_get(constant)
- rescue
- raise "Invalid stat type '#{@params['play']}'"
- end
- machine_guid = @params['machine_guid']
- altnet_object_id = @params['altnet_object_id']
- # Record the play locally
- TrackStats.create!({
- 'stat_type' => track_stats_type,
- 'track_id' => @params['track_id']
- })
- # Ping Altnet with the play
- stat = AltnetPlayStat.new(altnet_stat_type, altnet_object_id, machine_guid)
- [200, {"Content-Type" => "text/html"}, [stat.response]]
- else
- [404, {"Content-Type" => "text/html"}, ["Not Found"]]
- end
- end
- end
Add Comment
Please, Sign In to add comment