野球選手マスタの情報を検索するサービスの公開方法
次に、野球選手マスタの情報を検索するサービスを公開します。
Ruby on Railsでウェブサービスを公開するためには、APIクラスとコントローラクラスの2つを作成する必要があります。mst_baseball_player_service_api
クラスは、「app/apis」フォルダの配下に作成してください。
「mst_baseball_player_service_controller.rb」の、find_all
メソッドで野球選手マスタの全レコードを取得し、MstBaseballPlayerServiceApiのapi_method :find_all
で、その定義をウェブサービスとして公開しています。AIR側のクラスは、このfind_all
を呼び出すことで野球選手の情報を取得します。
module XmlrpcStruct class MstBaseballPlayer < ActionWebService::Struct member :id, :integer member :player_name, :string member :uniform_number, :string member :profile, :string member :record, :string member :comment, :string member :pitcher_flag, :string member :win_count, :string member :defeat_count, :string member :save_count, :string member :earned_run_average, :string member :games_started, :string member :batting_average, :string member :home_run, :string member :ribby, :string member :base_steal, :string member :main_image_path, :string member :detail_image_path, :string member :expanded_image_path, :string end end class MstBaseballPlayerServiceApi < ActionWebService::API::Base api_method :find_all, :returns => [[MstBaseballPlayer]] api_method :create, :expects=>[{:arg_mst_baseball_player =>XmlrpcStruct::MstBaseballPlayer}], :returns=>[:string] api_method :update, :expects=>[{:arg_mst_baseball_player =>XmlrpcStruct::MstBaseballPlayer}], :returns=>[:string] api_method :destroy, :expects=>[{:arg_mst_baseball_player =>XmlrpcStruct::MstBaseballPlayer}], :returns=>[:string] end
class MstBaseballPlayerServiceController < ApplicationController wsdl_service_name 'MstBaseballPlayerService' web_service_api 'MstBaseballPlayerService' web_service_scaffold :invoke #------------------------------------------------------------------ # 野球選手マスタの全レコードを取得します。 #------------------------------------------------------------------ def find_all MstBaseballPlayer.find(:all) end #------------------------------------------------------------------ # 野球選手マスタのレコードを新規作成します。 #------------------------------------------------------------------ def create(arg_mst_baseball_player) mst_baseball_player = MstBaseballPlayer.new mst_baseball_player.player_name = arg_mst_baseball_player.player_name mst_baseball_player.uniform_number = arg_mst_baseball_player.uniform_number mst_baseball_player.profile = arg_mst_baseball_player.profile mst_baseball_player.record = arg_mst_baseball_player.record mst_baseball_player.comment = arg_mst_baseball_player.comment mst_baseball_player.pitcher_flag = arg_mst_baseball_player.pitcher_flag mst_baseball_player.win_count = arg_mst_baseball_player.win_count mst_baseball_player.defeat_count = arg_mst_baseball_player.defeat_count mst_baseball_player.save_count = arg_mst_baseball_player.save_count mst_baseball_player.earned_run_average = arg_mst_baseball_player.earned_run_average mst_baseball_player.games_started = arg_mst_baseball_player.games_started mst_baseball_player.batting_average = arg_mst_baseball_player.batting_average mst_baseball_player.home_run = arg_mst_baseball_player.home_run mst_baseball_player.ribby = arg_mst_baseball_player.ribby mst_baseball_player.base_steal = arg_mst_baseball_player.base_steal mst_baseball_player.main_image_path = arg_mst_baseball_player.main_image_path mst_baseball_player.detail_image_path = arg_mst_baseball_player.detail_image_path mst_baseball_player.expanded_image_path = arg_mst_baseball_player.expanded_image_path if mst_baseball_player.save return "Succeeded" else return "Failed" end end #------------------------------------------------------------------ # 野球選手マスタのレコードを更新します。 #------------------------------------------------------------------ def update(arg_mst_baseball_player) mst_baseball_player = MstBaseballPlayer.find(arg_mst_baseball_player.id) unless mst_baseball_player return "Not Found." end mst_baseball_player.player_name = arg_mst_baseball_player.player_name mst_baseball_player.uniform_number = arg_mst_baseball_player.uniform_number mst_baseball_player.profile = arg_mst_baseball_player.profile mst_baseball_player.record = arg_mst_baseball_player.record mst_baseball_player.comment = arg_mst_baseball_player.comment mst_baseball_player.pitcher_flag = arg_mst_baseball_player.pitcher_flag mst_baseball_player.win_count = arg_mst_baseball_player.win_count mst_baseball_player.defeat_count = arg_mst_baseball_player.defeat_count mst_baseball_player.save_count = arg_mst_baseball_player.save_count mst_baseball_player.earned_run_average = arg_mst_baseball_player.earned_run_average mst_baseball_player.games_started = arg_mst_baseball_player.games_started mst_baseball_player.batting_average = arg_mst_baseball_player.batting_average mst_baseball_player.home_run = arg_mst_baseball_player.home_run mst_baseball_player.ribby = arg_mst_baseball_player.ribby mst_baseball_player.base_steal = arg_mst_baseball_player.base_steal mst_baseball_player.main_image_path = arg_mst_baseball_player.main_image_path mst_baseball_player.detail_image_path = arg_mst_baseball_player.detail_image_path mst_baseball_player.expanded_image_path = arg_mst_baseball_player.expanded_image_path if mst_baseball_player.update return "Succeeded" else return "Failed" end end #------------------------------------------------------------------ # 野球選手マスタのレコードを削除します。 #------------------------------------------------------------------ def destroy(arg_mst_baseball_player) mst_baseball_player = MstBaseballPlayer.find(arg_mst_baseball_player.id) if mst_baseball_player.destroy return "Succeeded" else return "Failed" end end end
「http://localhost:3000/mst_baseball_player_service/invoke」から作成したウェブサービスをテストできます。
後篇では
以上で、Ruby on Railsを使ったマスタメンテナンスアプリケーションは完成です。後篇では、このデータを表示させるクライアントツールをAIRで作成していきます。
参考資料
- 『Railsレシピ』 Chad Fowler 著、長瀬 嘉秀・ 永田 渉 編集、株式会社テクノロジックアート翻訳、オライリー・ジャパン、2006年12月
- 『ActionScript 3.0 Cookbook』 Joey Lott・ Darron Schall・ Keith Peters 著、Oreilly & Associates Inc、2006年10月
- 『ActionScript 3.0アニメーション』 Keith Peters 著、永井 勝則 翻訳、ボーンデジタル、2007年10月
- 『Rails Cookbook』 Rob Orsini 著、2007年1月
- 川o・-・)<2nd life『ActionWebServiceでxmlrpcサービスを作る』 2005年11月
- DO Ruby!『RMagickの使い方』 2007年12月
- Katawara.*『RMagickをインストールしてみる(Windows)』 2008年1月