Class: ZendeskAppsSupport::Manifest
- Inherits:
-
Object
- Object
- ZendeskAppsSupport::Manifest
show all
- Defined in:
- lib/zendesk_apps_support.rb,
lib/zendesk_apps_support/manifest.rb,
lib/zendesk_apps_support/manifest/parameter.rb,
lib/zendesk_apps_support/manifest/location_options.rb,
lib/zendesk_apps_support/manifest/no_override_hash.rb
Defined Under Namespace
Classes: LocationOptions, NoOverrideHash, OverrideError, Parameter
Constant Summary
collapse
- LEGACY_URI_STUB =
'_legacy'
- RUBY_TO_JSON =
{
requirements_only: 'requirementsOnly',
marketing_only: 'marketingOnly',
version: 'version',
author: 'author',
name: 'name', experiments: 'experiments',
framework_version: 'frameworkVersion',
single_install: 'singleInstall',
signed_urls: 'signedUrls',
no_template: 'noTemplate',
default_locale: 'defaultLocale',
original_locations: 'location',
private: 'private',
oauth: 'oauth',
original_parameters: 'parameters',
domain_whitelist: 'domainWhitelist',
remote_installation_url: 'remoteInstallationURL',
terms_conditions_url: 'termsConditionsURL',
google_analytics_code: 'gaID'
}.freeze
Instance Method Summary
collapse
Constructor Details
#initialize(manifest_text) ⇒ Manifest
Returns a new instance of Manifest.
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
# 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
|
Instance Method Details
#app_class_properties ⇒ Object
79
80
81
82
83
84
85
86
87
|
# 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
|
#enabled_experiments ⇒ Object
118
119
120
|
# File 'lib/zendesk_apps_support/manifest.rb', line 118
def enabled_experiments
experiments.select { |_k, v| v }.keys
end
|
#iframe_only? ⇒ Boolean
105
106
107
|
# File 'lib/zendesk_apps_support/manifest.rb', line 105
def iframe_only?
framework_version && Gem::Version.new(framework_version) >= Gem::Version.new('2')
end
|
#location_options ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
|
# 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
|
#no_template? ⇒ Boolean
37
38
39
40
41
42
43
|
# File 'lib/zendesk_apps_support/manifest.rb', line 37
def no_template?
if no_template.is_a?(Array)
false
else
no_template
end
end
|
#no_template_locations ⇒ Object
45
46
47
|
# File 'lib/zendesk_apps_support/manifest.rb', line 45
def no_template_locations
no_template || []
end
|
#parameters ⇒ Object
109
110
111
112
113
114
115
116
|
# 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
|
#products ⇒ Object
49
50
51
52
53
54
55
56
57
58
|
# 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
|
#products_ignore_locations ⇒ Object
60
61
62
63
64
|
# 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
|
#unknown_hosts ⇒ Object
100
101
102
103
|
# 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
|
#unknown_locations(host) ⇒ Object
89
90
91
92
93
94
95
96
97
98
|
# 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
|