class Caren::Product < Caren::Base def self.keys [ :id, # Integer (Id of this product in Caren) :name, # String :description, # Text :care_provider_id, # Integer (Care provider id) :product_category_id, # Integer (Reference to product category; Caren id) :photo, # String :in_store, # Boolean (Use in store) :unit, # String (piece, minute, hour) :price, # Integer (in eurocents) :rounding, # Integer (in minutes) :min_amount, # Integer (in minutes) :status, # String (pending, active) :valid_from, # Date :valid_to # Date ] + super end def self.search key, value, session from_xml session.get( self.search_url(key,value) ) end def self.find id, session from_xml session.get(self.resource_url(id)) end def self.all session from_xml session.get(self.resource_url) end def create session session.post(self.resource_url, self.to_xml) end def update session session.put(self.resource_url(self.id), self.to_xml) end def update_photo photo_hash_or_path, session session.put(self.resource_url(self.id), self.to_photo_xml(photo_hash_or_path)) end def as_xml { :name => self.name, :description => self.description, :product_category_id => self.product_category_id, :in_store => self.in_store, :unit => self.unit, :price => self.price, :rounding => self.rounding, :min_amount => self.min_amount, :valid_from => self.valid_from, :valid_to => self.valid_to } end def to_photo_xml photo_hash_or_path builder = Builder::XmlMarkup.new photo = self.class.hash_from_image(photo_hash_or_path) xml = builder.product do |product| product.tag!("photo", photo[:content], "name" => photo[:name], "content-type" => photo[:content_type] ) if photo end end def self.array_root :products end def self.node_root :product end def self.resource_location "/api/pro/store/products/" end end