Module: ZendeskAppsSupport::Validations::Manifest

Defined in:
lib/zendesk_apps_support/validations/manifest.rb

Constant Summary collapse

REQUIRED_MANIFEST_FIELDS =
%w( author defaultLocale ).freeze
OAUTH_REQUIRED_FIELDS =
%w( client_id client_secret authorize_uri access_token_uri ).freeze
LOCATIONS_AVAILABLE =
%w( top_bar nav_bar ticket_sidebar new_ticket_sidebar user_sidebar ).freeze
TYPES_AVAILABLE =
%w( text password checkbox url number multiline hidden ).freeze

Class Method Summary collapse

Class Method Details

.call(package) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/zendesk_apps_support/validations/manifest.rb', line 12

def call(package)
  manifest = package.files.find { |f| f.relative_path == 'manifest.json' }

  return [ValidationError.new(:missing_manifest)] unless manifest

  manifest = MultiJson.load(manifest.read)

  [].tap do |errors|
    errors << missing_keys_error(manifest)
    errors << default_locale_error(manifest, package)
    errors << oauth_error(manifest)
    errors << parameters_error(manifest)
    errors << invalid_hidden_parameter_error(manifest)
    errors << invalid_type_error(manifest)
    errors << name_as_parameter_name_error(manifest)

    if manifest['requirementsOnly']
      package.requirements_only = true

      errors << ban_location(manifest)
      errors << ban_framework_version(manifest)
    else
      errors << missing_location_error(package)
      errors << invalid_location_error(manifest)
      errors << duplicate_location_error(manifest)
      errors << missing_framework_version(manifest)
      errors << invalid_version_error(manifest, package)
    end

    errors.compact!
  end
rescue MultiJson::DecodeError => e
  return [ValidationError.new(:manifest_not_json, errors: e)]
end