Class: Kaui::Catalog

Inherits:
KillBillClient::Model::Catalog
  • Object
show all
Defined in:
app/models/kaui/catalog.rb

Class Method Summary collapse

Class Method Details

.build_ao_mapping(catalog) ⇒ Object


25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/kaui/catalog.rb', line 25

def build_ao_mapping(catalog)
  tmp = {}
  catalog.products.each do |p|
    p.available.each do |ap|
      if !tmp.has_key?(ap)
        tmp[ap] = []
      end
      tmp[ap] << p.name
    end
  end unless catalog.nil?
  tmp.map { |e,v| "#{e}:#{v.join(",")}" }.join(";")
end

.get_catalog_json(latest, requested_date, options) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/models/kaui/catalog.rb', line 7

def get_catalog_json(latest, requested_date, options)

  catalogs = KillBillClient::Model::Catalog.get_tenant_catalog_json(requested_date, options)
  return catalogs.length > 0 ? catalogs[catalogs.length - 1] : nil if latest

  # Order by latest
  result = []
  catalogs.sort! { |l, r| r.effective_date <=> l.effective_date }

  catalogs.each_with_index do |current_catalog, idx|
    result << {:version => idx,
               :version_date => current_catalog.effective_date,
               :currencies => current_catalog.currencies,
               :plans => build_existing_simple_plans(current_catalog)}
  end
  result
end

.get_catalog_xml(requested_date, options) ⇒ Object


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/models/kaui/catalog.rb', line 39

def get_catalog_xml(requested_date, options)

  catalog_xml = KillBillClient::Model::Catalog.get_tenant_catalog_xml(requested_date, options)

  parsed_catalog = parse_catalog_xml(catalog_xml)

  result = []
  parsed_catalog.keys.each_with_index do |version_date, i|
    entry = {}
    entry[:version] = i
    entry[:version_date] = version_date
    entry[:xml] = parsed_catalog[version_date]
    result << entry
  end
  result
end