class Caren::Billable < Caren::Base def self.keys [ :id, # Integer (Id of this product in Caren) :external_id, # Integer (Your id) :name, # String :description, # Text :care_provider_id, # Integer (Care provider id) :billable_category_id, # Integer (Reference to product category; Caren id) :photo, # String :in_store, # Boolean (Use in store) :unit, # String (piece, minute, hour) :price_with_vat_in_cents, # Integer :currency, # String (EUR,USD) :rounding, # Integer (in minutes) :min_amount, # Integer (in minutes) :default_amount, # Integer (in minutes) :vat_promillage, # Integer :type, # String (Product,Service,ChatSession) :status, # String (pending, active) :send_reminder_subject, # Boolean :send_reminder_person, # Boolean :send_reminder_in_advance,# Integer (in minutes) :plannable_by_subject, # Boolean :plannable_margin_before, # Integer (in minutes) :plannable_margin_after, # Integer (in minutes) :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 self.class.from_xml session.post(self.resource_url, self.to_xml) end def update session self.class.from_xml session.put(self.resource_url(self.id), self.to_xml) end def update_photo photo_hash_or_path, session self.class.from_xml 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, :billable_category_id => self.billable_category_id, :in_store => self.in_store, :unit => self.unit, :photo => self.photo, :price_with_vat_in_cents => self.price_with_vat_in_cents, :currency => self.currency, :type => self.type, :rounding => self.rounding, :vat_promillage => self.vat_promillage, :external_id => self.external_id, :min_amount => self.min_amount, :default_amount => self.default_amount, :send_reminder_subject => self.send_reminder_subject, :send_reminder_person => self.send_reminder_person, :send_reminder_in_advance => self.send_reminder_in_advance, :plannable_by_subject => self.plannable_by_subject, :plannable_margin_before => self.plannable_margin_before, :plannable_margin_after => self.plannable_margin_after, :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.billable do |billable| billable.tag!("photo", photo[:content], "name" => photo[:name], "content-type" => photo[:content_type] ) if photo end end def self.array_root :billables end def self.node_root :billable end def self.resource_location "/api/pro/store/billables" end end