Class: Caren::Store::Billable

Inherits:
Base
  • Object
show all
Defined in:
lib/caren/store/billable.rb

Instance Attribute Summary

Attributes inherited from Base

#attributes, #original_xml

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

from_xml, hash_from_image, init_dependent_objects, #initialize, #node_root, #resource_url, resource_url, search_url, #to_xml, to_xml

Constructor Details

This class inherits a constructor from Caren::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Caren::Base

Class Method Details

.all(session) ⇒ Object



43
44
45
# File 'lib/caren/store/billable.rb', line 43

def self.all session
  from_xml session.get(self.resource_url)
end

.array_rootObject



100
101
102
# File 'lib/caren/store/billable.rb', line 100

def self.array_root
  :billables
end

.find(id, session) ⇒ Object



39
40
41
# File 'lib/caren/store/billable.rb', line 39

def self.find id, session
  from_xml session.get(self.resource_url(id))
end

.keysObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/caren/store/billable.rb', line 3

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_sales_tax_in_cents,   # Integer
    :currency,                        # String (EUR,USD)
    :rounding,                        # Integer (in seconds)
    :min_amount,                      # Integer (in seconds)
    :default_amount,                  # Integer (in seconds)
    :piece_duration,                  # Integer (in seconds)
    :sales_tax_in_promillage,         # Integer
    :type,                            # String (Store::Product,Store::Service,Store::ChatSession)
    :status,                          # String (pending, active)
    :send_reminder_in_advance,        # Integer (in seconds)
    :plannable_by_subject,            # Boolean
    :plannable_margin_before,         # Integer (in seconds)
    :plannable_margin_after,          # Integer (in seconds)
    :plannable_max_duration,          # Integer (in seconds)
    :plannable_comment_above,         # Text
    :plannable_description_required,  # Boolean
    :valid_from,                      # Date
    :valid_to,                        # Date
    :timeline_id                      # Integer
  ] + super
end

.node_rootObject



104
105
106
# File 'lib/caren/store/billable.rb', line 104

def self.node_root
  :billable
end

.resource_locationObject



108
109
110
# File 'lib/caren/store/billable.rb', line 108

def self.resource_location
  "/api/pro/store/billables"
end

.search(key, value, session) ⇒ Object



35
36
37
# File 'lib/caren/store/billable.rb', line 35

def self.search key, value, session
  from_xml session.get( self.search_url(key,value) )
end

Instance Method Details

#as_xmlObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/caren/store/billable.rb', line 63

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_sales_tax_in_cents => self.price_with_sales_tax_in_cents,
    :currency => self.currency,
    :type => self.type,
    :rounding => self.rounding,
    :sales_tax_in_promillage => self.sales_tax_in_promillage,
    :external_id => self.external_id,
    :piece_duration => self.piece_duration,
    :min_amount => self.min_amount,
    :default_amount => self.default_amount,
    :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,
    :plannable_max_duration => self.plannable_max_duration,
    :plannable_comment_above => self.plannable_comment_above,
    :plannable_description_required => self.plannable_description_required,
    :valid_from => self.valid_from,
    :valid_to => self.valid_to,
    :timeline_id => self.timeline_id
  }
end

#create(session) ⇒ Object



47
48
49
# File 'lib/caren/store/billable.rb', line 47

def create session
  self.class.from_xml session.post(self.resource_url, self.to_xml)
end

#delete(session) ⇒ Object



59
60
61
# File 'lib/caren/store/billable.rb', line 59

def delete session
  session.delete self.class.resource_url(self.id)
end

#to_photo_xml(photo_hash_or_path) ⇒ Object



92
93
94
95
96
97
98
# File 'lib/caren/store/billable.rb', line 92

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", Base64.encode64(photo[:content]), "name" => photo[:name], "content-type" => photo[:content_type], "type" => "file" ) if photo
  end
end

#update(session) ⇒ Object



51
52
53
# File 'lib/caren/store/billable.rb', line 51

def update session
  self.class.from_xml session.put(self.resource_url(self.id), self.to_xml)
end

#update_photo(photo_hash_or_path, session) ⇒ Object



55
56
57
# File 'lib/caren/store/billable.rb', line 55

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