class IronBank::Describe::Object

Describe an object in Zuora: name, label, fields, etc.

Attributes

doc[R]

Public Class Methods

from_connection(connection, name) click to toggle source
# File lib/iron_bank/describe/object.rb, line 18
def self.from_connection(connection, name)
  IronBank.logger.info "Describe (#{name})"
  xml = connection.get("v1/describe/#{name}").body
  new(Nokogiri::XML(xml))
rescue TypeError
  # NOTE: Zuora returns HTTP 401 (unauthorized) roughly 1 out of 3 times
  #       we make this call. Since this is a setup-only call and not a
  #       runtime one, we deemed it acceptable to keep retrying until it
  #       works.
  retry
rescue IronBank::InternalServerError
  # TODO: Need to properly store which object failed to be described by
  #       Zuora API and send a report to the console.
  nil
end
from_xml(doc) click to toggle source
# File lib/iron_bank/describe/object.rb, line 14
def self.from_xml(doc)
  new(doc)
end
new(doc) click to toggle source
# File lib/iron_bank/describe/object.rb, line 83
def initialize(doc)
  @doc = doc
end

Public Instance Methods

export() click to toggle source
# File lib/iron_bank/describe/object.rb, line 34
def export
  File.open(file_path, "w") { |file| file << doc.to_xml }
end
fields() click to toggle source
# File lib/iron_bank/describe/object.rb, line 49
def fields
  @fields ||= doc.xpath(".//fields/field").map do |node|
    IronBank::Describe::Field.from_xml(node)
  end
end
inspect() click to toggle source
# File lib/iron_bank/describe/object.rb, line 75
def inspect
  "#<#{self.class}:0x#{(object_id << 1).to_s(16)} #{name}>"
end
label() click to toggle source
# File lib/iron_bank/describe/object.rb, line 45
def label
  doc.at_xpath(".//object/label").text
end
name() click to toggle source
# File lib/iron_bank/describe/object.rb, line 38
def name
  node = doc.at_xpath(".//object/name")
  raise InvalidXML unless node

  node.text
end
query_custom_fields() click to toggle source
# File lib/iron_bank/describe/object.rb, line 59
def query_custom_fields
  @query_custom_fields ||= begin
    custom_fields = fields.select do |field|
      field.selectable? && field.custom?
    end

    custom_fields.map(&:name)
  end
end
query_fields() click to toggle source
# File lib/iron_bank/describe/object.rb, line 55
def query_fields
  @query_fields ||= fields.select(&:selectable?).map(&:name)
end

Private Instance Methods

file_path() click to toggle source
# File lib/iron_bank/describe/object.rb, line 87
def file_path
  File.expand_path "#{name}.xml", IronBank.configuration.schema_directory
end