Name: simulation/server
| 1: | #!/usr/bin/ruby |
| 2: | # Apache License, Version 2.0 |
| 3: | # |
| 4: | # Copyright (c) 2013 Juergen Mangler |
| 5: | # |
| 6: | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7: | # you may not use this file except in compliance with the License. |
| 8: | # You may obtain a copy of the License at |
| 9: | # |
| 10: | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11: | # |
| 12: | # Unless required by applicable law or agreed to in writing, software |
| 13: | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14: | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15: | # See the License for the specific language governing permissions and |
| 16: | # limitations under the License. |
| 17: | |
| 18: | require 'rubygems' |
| 19: | require 'riddl/server' |
| 20: | require 'riddl/utils/fileserve' |
| 21: | require 'json' |
| 22: | require File.expand_path(File.dirname(__FILE__) + '/lib/simulation') |
| 23: | require File.expand_path(File.dirname(__FILE__) + '/lib/bitsnpieces') |
| 24: | |
| 25: | Riddl::Server.new(File.dirname(__FILE__) + '/server.xml', :port => 9294) do |
| 26: | xmpp '[email protected]', 'adventure_simulation' |
| 27: | |
| 28: | accessible_description true |
| 29: | cross_site_xhr true |
| 30: | |
| 31: | interface 'events' do |
| 32: | run Simulation if post 'event' |
| 33: | run SimulationSave if post 'vote' |
| 34: | end |
| 35: | |
| 36: | interface 'simulation' do |
| 37: | run ListOfInstances if get |
| 38: | on resource '\d+' do |
| 39: | run ListOfSimulations if get |
| 40: | on resource '\d+' do |r| |
| 41: | run Riddl::Utils::FileServe, File.dirname(__FILE__) + '/instances/' + r[:r][0..1].join('/') + '/result.html' if get |
| 42: | on resource 'expectations' do |
| 43: | run Riddl::Utils::FileServe, File.dirname(__FILE__) + '/instances/' + r[:r][0..1].join('/') + '/expectations.txt' if get |
| 44: | end |
| 45: | on resource 'result' do |
| 46: | run Riddl::Utils::FileServe, File.dirname(__FILE__) + '/instances/' + r[:r][0..1].join('/') + '/result.txt' if get |
| 47: | end |
| 48: | on resource 'status' do |
| 49: | run GetStatus if get |
| 50: | end |
| 51: | on resource 'offset' do |
| 52: | run GetOffset if get |
| 53: | end |
| 54: | on resource 'question' do |
| 55: | run Riddl::Utils::FileServe, File.dirname(__FILE__) + '/instances/' + r[:r][0..1].join('/') + '/question.json' if get |
| 56: | run SetQuestionValue if put 'value' |
| 57: | end |
| 58: | end |
| 59: | end |
| 60: | end |
| 61: | end.loop! |
