Module: ZendeskAppsSupport::Validations::Manifest

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

Constant Summary collapse

REQUIRED_MANIFEST_FIELDS =
%w( author defaultLocale location frameworkVersion ).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



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/zendesk_apps_support/validations/manifest.rb', line 13

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 << invalid_location_error(manifest)
    errors << invalid_version_error(manifest, package)
    errors << oauth_error(manifest)
    errors << parameters_error(manifest)
    errors << invalid_hidden_parameter_error(manifest)
    errors << invalid_type_error(manifest)
    errors.compact!
  end
rescue MultiJson::DecodeError => e
  return [ValidationError.new(:manifest_not_json, :errors => e)]
end