class ZendeskAppsSupport::Manifest
Constants
- LEGACY_LOCATION_OBJECT
- LEGACY_URI_STUB
- RUBY_TO_JSON
Attributes
Public Class Methods
Source
# File lib/zendesk_apps_support/manifest.rb, line 122 def initialize(manifest_text) m = parse_json(manifest_text) RUBY_TO_JSON.each do |ruby, json| instance_variable_set(:"@#{ruby}", m[json]) end @requirements_only ||= false @marketing_only ||= false @single_install ||= false @private = m.fetch('private', true) @signed_urls ||= false @no_template ||= false @experiments ||= {} set_locations_and_hosts end
Public Instance Methods
Source
# File lib/zendesk_apps_support/manifest.rb, line 79 def app_class_properties { experiments: experiments, location: locations, noTemplate: no_template_locations, singleInstall: single_install?, signedUrls: signed_urls? }.reject { |_k, v| v.nil? } end
Source
# File lib/zendesk_apps_support/manifest.rb, line 118 def enabled_experiments experiments.select { |_k, v| v }.keys end
Source
# File lib/zendesk_apps_support/manifest.rb, line 105 def iframe_only? framework_version && Gem::Version.new(framework_version) >= Gem::Version.new('2') end
Source
# File lib/zendesk_apps_support/manifest.rb, line 66 def location_options @location_options ||= locations.flat_map do |product_key, locations| product = Product.find_by(name: product_key) locations.map do |location_key, location_options| location = product && Location.find_by(product_code: product.code, name: location_key) options_with_defaults = { 'signed' => signed_urls? }.merge(location_options) Manifest::LocationOptions.new(location, options_with_defaults) end end end
Source
# File lib/zendesk_apps_support/manifest.rb, line 37 def no_template? if no_template.is_a?(Array) false else no_template end end
Source
# File lib/zendesk_apps_support/manifest.rb, line 45 def no_template_locations no_template || [] end
Source
# File lib/zendesk_apps_support/manifest.rb, line 109 def parameters @parameters ||= begin parameter_array = @original_parameters.is_a?(Array) ? @original_parameters : [] parameter_array.map do |parameter_hash| Parameter.new(parameter_hash) end end end
Source
# File lib/zendesk_apps_support/manifest.rb, line 49 def products @products ||= if requirements_only? [ Product::SUPPORT ] elsif marketing_only? products_ignore_locations || [ Product::SUPPORT ] else products_from_locations end end
Source
# File lib/zendesk_apps_support/manifest.rb, line 60 def products_ignore_locations locations.keys.map do |product_name| Product.find_by(name: product_name) end end
Source
# File lib/zendesk_apps_support/manifest.rb, line 100 def unknown_hosts @unknown_hosts ||= @used_hosts - Product::PRODUCTS_AVAILABLE.flat_map { |p| [p.name, p.legacy_name] } end
Source
# File lib/zendesk_apps_support/manifest.rb, line 89 def unknown_locations(host) product = Product.find_by(name: host) if locations.key?(host) product_locations = Location.where(product_code: product.code) locations[host].keys.uniq - product_locations.map(&:name) else [] end end
Private Instance Methods
Source
# File lib/zendesk_apps_support/manifest.rb, line 192 def parse_json(manifest_text) parser_opts = { object_class: Manifest::NoOverrideHash } JSON.parse(manifest_text, parser_opts) end
Source
# File lib/zendesk_apps_support/manifest.rb, line 144 def products_from_locations location_options.map { |lo| lo.location && lo.location.product_code } .compact .uniq .map { |code| Product.find_by(code: code) } end
Source
# File lib/zendesk_apps_support/manifest.rb, line 171 def replace_legacy_locations(original_locations) NoOverrideHash.new.tap do |new_locations_obj| Product::PRODUCTS_AVAILABLE.each do |product| product_key = product.name.to_s legacy_key = product.legacy_name.to_s value_for_product = original_locations.fetch(product_key, original_locations[legacy_key]) value_for_product && new_locations_obj[product_key] = replace_string_uris(value_for_product) end end end
Source
# File lib/zendesk_apps_support/manifest.rb, line 182 def replace_string_uris(product_locations) product_locations.each_with_object({}) do |(k, v), new_locations| new_locations[k] = if v.is_a? Hash v else { 'url' => v } end end end
Source
# File lib/zendesk_apps_support/manifest.rb, line 151 def set_locations_and_hosts @locations = case original_locations when Hash @used_hosts = original_locations.keys replace_legacy_locations original_locations when Array @used_hosts = ['support'] new_locations = NoOverrideHash[original_locations.map { |location| [ location, LEGACY_LOCATION_OBJECT ] }] { 'support' => new_locations } when String @used_hosts = ['support'] { 'support' => { original_locations => LEGACY_LOCATION_OBJECT } } # TODO: error out for numbers and Booleans else # NilClass @used_hosts = ['support'] { 'support' => {} } end end