Class: IronBank::Describe::Object
- Inherits:
-
Object
- Object
- IronBank::Describe::Object
- Defined in:
- lib/iron_bank/describe/object.rb
Overview
Describe an object in Zuora: name, label, fields, etc.
Defined Under Namespace
Classes: InvalidXML
Class Method Summary collapse
Instance Method Summary collapse
- #export ⇒ Object
- #fields ⇒ Object
- #inspect ⇒ Object
- #label ⇒ Object
- #name ⇒ Object
- #query_custom_fields ⇒ Object
- #query_fields ⇒ Object
- #related ⇒ Object
Class Method Details
.from_connection(connection, name) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# 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) ⇒ Object
14 15 16 |
# File 'lib/iron_bank/describe/object.rb', line 14 def self.from_xml(doc) new(doc) end |
Instance Method Details
#export ⇒ Object
34 35 36 |
# File 'lib/iron_bank/describe/object.rb', line 34 def export File.open(file_path, "w") { |file| file << doc.to_xml } end |
#fields ⇒ Object
49 50 51 52 53 |
# 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 ⇒ Object
75 76 77 |
# File 'lib/iron_bank/describe/object.rb', line 75 def inspect "#<#{self.class}:0x#{(object_id << 1).to_s(16)} #{name}>" end |
#label ⇒ Object
45 46 47 |
# File 'lib/iron_bank/describe/object.rb', line 45 def label doc.at_xpath(".//object/label").text end |
#name ⇒ Object
38 39 40 41 42 43 |
# 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 ⇒ Object
59 60 61 62 63 64 65 66 67 |
# 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 ⇒ Object
55 56 57 |
# File 'lib/iron_bank/describe/object.rb', line 55 def query_fields @query_fields ||= fields.select(&:selectable?).map(&:name) end |