class IronBank::Describe::ExcludedFields

Returns an array of non-queryable fields for the given object in the current Zuora tenant, despites Zuora clearly marking these fields as `<selectable>true</true>` in their Describe API… /rant

Constants

FAULT_FIELD_MESSAGES
INVALID_OBJECT_ID

Attributes

last_failed_fields[R]
object_name[R]

Public Class Methods

call(object_name:) click to toggle source
# File lib/iron_bank/describe/excluded_fields.rb, line 37
def self.call(object_name:)
  new(object_name).call
end
new(object_name) click to toggle source
# File lib/iron_bank/describe/excluded_fields.rb, line 56
def initialize(object_name)
  @object_name        = object_name
  @last_failed_fields = nil
end

Public Instance Methods

call() click to toggle source
# File lib/iron_bank/describe/excluded_fields.rb, line 41
def call
  remove_last_failure_fields until valid_query?

  (excluded_fields - single_resource_query_fields).sort
end

Private Instance Methods

excluded_fields() click to toggle source
# File lib/iron_bank/describe/excluded_fields.rb, line 65
def excluded_fields
  @excluded_fields ||= object.excluded_fields.dup
end
extract_fields_from_exception(exception) click to toggle source
# File lib/iron_bank/describe/excluded_fields.rb, line 96
def extract_fields_from_exception(exception)
  message = exception.message

  raise "Could not parse error message: #{message}" unless FAULT_FIELD_MESSAGES.match(message)

  failed_fields = Regexp.last_match.
                  captures.
                  compact.
                  map { |capture| capture.delete(" ") }

  info "Invalid fields '#{failed_fields}' for #{object_name} query"

  failed_fields
end
object() click to toggle source
# File lib/iron_bank/describe/excluded_fields.rb, line 61
def object
  IronBank::Resources.const_get(object_name)
end
remove_last_failure_fields() click to toggle source
# File lib/iron_bank/describe/excluded_fields.rb, line 69
def remove_last_failure_fields
  query_fields = object.query_fields

  failed_fields = query_fields.select do |field|
    last_failed_fields.any? { |failed| field.casecmp?(failed) }
  end

  excluded_fields.push(*failed_fields)

  # Remove the field for the next query
  query_fields.delete_if { |field| failed_fields.include?(field) }
end
valid_query?() click to toggle source
# File lib/iron_bank/describe/excluded_fields.rb, line 82
def valid_query?
  # Querying using the ID (which is an indexed field) should return an
  # empty collection very quickly when successful
  object.where({ id: INVALID_OBJECT_ID })

  info "Successful query for #{object_name}"

  true
rescue IronBank::InternalServerError, IronBank::BadRequestError => e
  @last_failed_fields = extract_fields_from_exception(e)

  false
end