Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'xmlrpc/server'
- require 'rubygems'
- require_gem 'activerecord'
- #set up active record
- @db_settings = YAML::load(IO.read("../config/database.yml"))
- curr_db = @db_settings["development"]
- ActiveRecord::Base.establish_connection(:adapter => curr_db["adapter"], :database => curr_db["database"],
- :host => curr_db["host"], :username => curr_db["username"], :password => curr_db["password"])
- #this should come from a config file
- MOVIE_BASE_DIR = 'C:\Dev\projects\training\code tutorials\movies'
- server = XMLRPC::Server.new(8080)
- server.add_handler("movie.getLessonMovies") do |name|
- puts "movie.getLessonMovies called with parameters #{name}"
- if(name.empty?)
- raise XMLRPC::FaultException.new(-99, "No lesson name given")
- else
- lesson = Lesson.find(:first,
- :conditions => ["name=?", name])
- puts "returning movie list: #{lesson.movies.split(",").collect{|movie| movie.strip}.join(',')}"
- [lesson.description, lesson.movies.split(",").collect{|movie| movie.strip}]
- end
- end
- server.add_handler("movie.getMovieInfo") do |name|
- puts "movie.getMovieInfo called with parameters '#{name.strip}'"
- if(name.empty?)
- raise XMLRPC::FaultException.new(-99, "No movie name given")
- else
- movieInfo = Movie.find( :first,
- :conditions => ["name=?", name.strip])
- if(movieInfo == nil)
- raise XMLRPC::FaultException.new(-99, "No movie was found with the name '#{name}'")
- else
- retVal = [movieInfo.name, movieInfo.description, movieInfo.frames, MOVIE_BASE_DIR + movieInfo.file]
- puts "returning #{retVal.join(',')}"
- retVal
- end
- end
- end
- server.set_default_handler do |name, *args|
- puts "Unknown XMLRPC method called, method: '#{name}', arguments: #{args}"
- raise XMLRPC::FaultException.new(-99, "Method #{name} missing or wrong number of parameters")
- end
- server.serve
Add Comment
Please, Sign In to add comment