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.
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/zendesk_apps_support/manifest.rb', line 115
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
72
73
74
75
76
77
78
79
80
|
# File 'lib/zendesk_apps_support/manifest.rb', line 72
def app_class_properties
{
experiments: experiments,
location: locations,
noTemplate: no_template_locations,
singleInstall: single_install?,
signedUrls: signed_urls?
}.select { |_k, v| !v.nil? }
end
|
#enabled_experiments ⇒ Object
111
112
113
|
# File 'lib/zendesk_apps_support/manifest.rb', line 111
def enabled_experiments
experiments.select { |_k, v| v }.keys
end
|
#iframe_only? ⇒ Boolean
98
99
100
|
# File 'lib/zendesk_apps_support/manifest.rb', line 98
def iframe_only?
Gem::Version.new(framework_version) >= Gem::Version.new('2')
end
|
#location_options ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/zendesk_apps_support/manifest.rb', line 59
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
36
37
38
39
40
41
42
|
# File 'lib/zendesk_apps_support/manifest.rb', line 36
def no_template?
if no_template.is_a?(Array)
false
else
no_template
end
end
|
#no_template_locations ⇒ Object
44
45
46
|
# File 'lib/zendesk_apps_support/manifest.rb', line 44
def no_template_locations
no_template || []
end
|
#parameters ⇒ Object
102
103
104
105
106
107
108
109
|
# File 'lib/zendesk_apps_support/manifest.rb', line 102
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
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/zendesk_apps_support/manifest.rb', line 48
def products
@products ||=
if requirements_only?
[ Product::SUPPORT ]
elsif marketing_only?
products_ignore_locations || [ Product::SUPPORT ]
else
products_from_locations
end
end
|
#unknown_hosts ⇒ Object
93
94
95
96
|
# File 'lib/zendesk_apps_support/manifest.rb', line 93
def unknown_hosts
@unknown_hosts ||=
@used_hosts - Product::PRODUCTS_AVAILABLE.flat_map { |p| [p.name, p.legacy_name] }
end
|
#unknown_locations(host) ⇒ Object
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/zendesk_apps_support/manifest.rb', line 82
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
|