Module: ActiveZuora::Base
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/active_zuora/base.rb
Defined Under Namespace
Modules: ClassMethods
Class Attribute Summary collapse
-
.connection ⇒ Object
Returns the value of attribute connection.
Instance Method Summary collapse
- #add_zuora_errors(zuora_errors) ⇒ Object
- #build_xml(xml, soap, options = {}) ⇒ Object
- #fields_order(a, b) ⇒ Object
- #xml_field_names ⇒ Object
Class Attribute Details
.connection ⇒ Object
Returns the value of attribute connection.
12 13 14 |
# File 'lib/active_zuora/base.rb', line 12 def connection @connection end |
Instance Method Details
#add_zuora_errors(zuora_errors) ⇒ Object
59 60 61 62 63 |
# File 'lib/active_zuora/base.rb', line 59 def add_zuora_errors(zuora_errors) return if zuora_errors.blank? zuora_errors = [zuora_errors] unless zuora_errors.is_a?(Array) zuora_errors.each { |error| errors.add(:base, error[:message].capitalize) } end |
#build_xml(xml, soap, options = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/active_zuora/base.rb', line 34 def build_xml(xml, soap, ={}) namespace = .delete(:namespace) || self.namespace qualifier = soap.namespace_by_uri(namespace) custom_element_name = .delete(:element_name) element_name = custom_element_name || zuora_object_name attributes = .delete(:force_type) ? { "xsi:type" => "#{qualifier}:#{zuora_object_name}" } : {} xml.tag!(qualifier, element_name.to_sym, attributes) do xml_field_names.map { |field_name| get_field!(field_name) }.sort(&method(:fields_order)).each do |field| field.build_xml(xml, soap, send(field.name), ) end end end |
#fields_order(a, b) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/active_zuora/base.rb', line 49 def fields_order(a, b) if send(a.name) == nil send(b.name) == nil ? 0 : -1 elsif a.name.to_sym == :id send(b.name) == nil ? 1 : -1 else (b.name.to_sym == :id || send(b.name) == nil) ? 1 : 0 end end |
#xml_field_names ⇒ Object
27 28 29 30 31 32 |
# File 'lib/active_zuora/base.rb', line 27 def xml_field_names # Which field names should be rendered during build_xml. # Choose only field names that have been changed. # Make sure the order in fields is maintained. field_names & changed.map(&:to_sym) end |