diff --git a/app/controllers/pets_controller.rb b/app/controllers/pets_controller.rb new file mode 100644 index 00000000..fb37b2a7 --- /dev/null +++ b/app/controllers/pets_controller.rb @@ -0,0 +1,7 @@ +class PetsController < ActionController::Base + def show + @pet = Pet.load(params[:id]) + @pet.save + redirect_to @pet.wardrobe_url + end +end diff --git a/app/models/pet.rb b/app/models/pet.rb index aa173bfd..7383f48b 100644 --- a/app/models/pet.rb +++ b/app/models/pet.rb @@ -3,10 +3,11 @@ class Pet < ActiveRecord::Base AMF_SERVICE_NAME = 'CustomPetService' PET_VIEWER_METHOD = 'getViewerData' PET_NOT_FOUND_REMOTE_ERROR = 'PHP: Unable to retrieve records from the database.' + WARDROBE_PATH = '/wardrobe' belongs_to :pet_type - attr_reader :items + attr_reader :items, :pet_state def load! require 'ostruct' @@ -34,6 +35,21 @@ class Pet < ActiveRecord::Base true end + def wardrobe_url + uri = URI::HTTP.build({ + :host => RemoteImpressHost, + :path => WARDROBE_PATH, + :fragment => { + :name => self.name, + :color => self.pet_type.color.id, + :species => self.pet_type.species.id, + :state => self.pet_state.id, + :objects => self.items.map(&:id) + }.to_query + }) + uri.to_s + end + def before_save self.pet_type.save self.items.each(&:save) diff --git a/config/routes.rb b/config/routes.rb index df520a90..b2414ea3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,5 +9,7 @@ OpenneoImpressItems::Application.routes.draw do |map| match '/pet_types/:pet_type_id/swf_assets.json' => 'swf_assets#index', :as => :pet_type_swf_assets match '/species/:species_id/color/:color_id/pet_type.json' => 'pet_types#show' + resources :pets, :only => [:show] + match '/:id' => 'items#show', :as => :item end