Class: Kaui::AdminTenant
- Inherits:
-
KillBillClient::Model::Tenant
- Object
- KillBillClient::Model::Tenant
- Kaui::AdminTenant
- Defined in:
- app/models/kaui/admin_tenant.rb
Class Method Summary collapse
- .format_plugin_config(plugin_key, plugin_type, props) ⇒ Object
- .get_invoice_template(is_manual_pay, options = {}) ⇒ Object
-
.get_invoice_translations(options = {}) ⇒ Object
Return a map of locale => invoice translation content, for every invoice translation uploaded for the tenant.
-
.get_tenant_plugin_config(options) ⇒ Object
Return a map of plugin_name => config.
-
.kv?(candidate_string) ⇒ Boolean
checks if string could be parse as key value pair.
- .reformat_plugin_config(_plugin_type, props) ⇒ Object
- .upload_catalog(catalog_xml, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object
- .upload_catalog_translation(catalog_translation, locale, delete_if_exists, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object
- .upload_invoice_template(invoice_template, is_manual_pay, delete_if_exists, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object
- .upload_invoice_translation(invoice_translation, locale, delete_if_exists, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object
- .upload_overdue_config(overdue_config_xml, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object
- .upload_tenant_plugin_config(plugin_name, plugin_config, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object
-
.yaml?(candidate_string) ⇒ Boolean
checks if string could be parse as yaml.
Class Method Details
.format_plugin_config(plugin_key, plugin_type, props) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/models/kaui/admin_tenant.rb', line 57 def format_plugin_config(plugin_key, plugin_type, props) return nil if props.blank? return props['raw_config'].gsub(/\r\n?/, "\n") if props['raw_config'] if plugin_type == 'ruby' require 'yaml' props = reformat_plugin_config(plugin_type, props) hsh = {} hsh[plugin_key.to_sym] = {} props.each do |k, v| hsh[plugin_key.to_sym][k.to_sym] = v end hsh.to_yaml elsif plugin_type == 'java' props = reformat_plugin_config(plugin_type, props) res = '' props.each do |k, v| res = "#{res}#{k}=#{v}\n" end res else props['raw_config'] end end |
.get_invoice_template(is_manual_pay, options = {}) ⇒ Object
18 19 20 |
# File 'app/models/kaui/admin_tenant.rb', line 18 def get_invoice_template(is_manual_pay, = {}) KillBillClient::Model::Invoice.get_invoice_template(is_manual_pay, nil, ) end |
.get_invoice_translations(options = {}) ⇒ Object
Return a map of locale => invoice translation content, for every invoice translation uploaded for the tenant
27 28 29 30 31 32 33 34 |
# File 'app/models/kaui/admin_tenant.rb', line 27 def get_invoice_translations( = {}) raw_translations = KillBillClient::Model::Tenant.search_tenant_config('INVOICE_TRANSLATION_', ) raw_translations.each_with_object({}) do |e, hsh| locale = e.key.gsub('INVOICE_TRANSLATION_', '') hsh[locale] = e.values[0] end end |
.get_tenant_plugin_config(options) ⇒ Object
Return a map of plugin_name => config
45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/models/kaui/admin_tenant.rb', line 45 def get_tenant_plugin_config() raw_tenant_config = KillBillClient::Model::Tenant.search_tenant_config('PLUGIN_CONFIG_', ) raw_tenant_config.each_with_object({}) do |e, hsh| # Strip prefix '/PLUGIN_CONFIG_' plugin_name = e.key.gsub!('PLUGIN_CONFIG_', '') # Construct simple hash with one property (first value) hsh[plugin_name] = e.values[0] end end |
.kv?(candidate_string) ⇒ Boolean
checks if string could be parse as key value pair
112 113 114 115 116 117 118 119 |
# File 'app/models/kaui/admin_tenant.rb', line 112 def kv?(candidate_string) return false if candidate_string.blank? || yaml?(candidate_string) lines = candidate_string.split("\n") return false if lines.blank? lines.all? { |kv| kv.split('=').count >= 1 } end |
.reformat_plugin_config(_plugin_type, props) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'app/models/kaui/admin_tenant.rb', line 82 def reformat_plugin_config(_plugin_type, props) if props['raw_config'].present? new_props = {} props['raw_config'].split("\n").each do |p| line = p.split('=') new_props[line[0]] = line[1].blank? ? '' : line[1].delete("\r") end return new_props end props end |
.upload_catalog(catalog_xml, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object
6 7 8 |
# File 'app/models/kaui/admin_tenant.rb', line 6 def upload_catalog(catalog_xml, user = nil, reason = nil, comment = nil, = {}) KillBillClient::Model::Catalog.upload_tenant_catalog(catalog_xml, user, reason, comment, ) end |
.upload_catalog_translation(catalog_translation, locale, delete_if_exists, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object
36 37 38 |
# File 'app/models/kaui/admin_tenant.rb', line 36 def upload_catalog_translation(catalog_translation, locale, delete_if_exists, user = nil, reason = nil, comment = nil, = {}) KillBillClient::Model::Invoice.upload_catalog_translation(catalog_translation, locale, delete_if_exists, user, reason, comment, ) end |
.upload_invoice_template(invoice_template, is_manual_pay, delete_if_exists, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object
14 15 16 |
# File 'app/models/kaui/admin_tenant.rb', line 14 def upload_invoice_template(invoice_template, is_manual_pay, delete_if_exists, user = nil, reason = nil, comment = nil, = {}) KillBillClient::Model::Invoice.upload_invoice_template(invoice_template, is_manual_pay, delete_if_exists, user, reason, comment, ) end |
.upload_invoice_translation(invoice_translation, locale, delete_if_exists, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object
22 23 24 |
# File 'app/models/kaui/admin_tenant.rb', line 22 def upload_invoice_translation(invoice_translation, locale, delete_if_exists, user = nil, reason = nil, comment = nil, = {}) KillBillClient::Model::Invoice.upload_invoice_translation(invoice_translation, locale, delete_if_exists, user, reason, comment, ) end |
.upload_overdue_config(overdue_config_xml, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object
10 11 12 |
# File 'app/models/kaui/admin_tenant.rb', line 10 def upload_overdue_config(overdue_config_xml, user = nil, reason = nil, comment = nil, = {}) KillBillClient::Model::Overdue.upload_tenant_overdue_config_xml(overdue_config_xml, user, reason, comment, ) end |
.upload_tenant_plugin_config(plugin_name, plugin_config, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object
40 41 42 |
# File 'app/models/kaui/admin_tenant.rb', line 40 def upload_tenant_plugin_config(plugin_name, plugin_config, user = nil, reason = nil, comment = nil, = {}) KillBillClient::Model::Tenant.upload_tenant_plugin_config(plugin_name, plugin_config, user, reason, comment, ) end |
.yaml?(candidate_string) ⇒ Boolean
checks if string could be parse as yaml
97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'app/models/kaui/admin_tenant.rb', line 97 def yaml?(candidate_string) is_yaml = false return is_yaml if candidate_string.blank? begin is_yaml = !YAML.load(candidate_string).nil? is_yaml &&= YAML.load(candidate_string).instance_of?(Hash) rescue StandardError is_yaml = false end is_yaml end |