Module: ActiveZuora::BatchSubscribe

Extended by:
ActiveSupport::Concern
Included in:
CollectionProxy
Defined in:
lib/active_zuora/batch_subscribe.rb

Instance Method Summary collapse

Instance Method Details

#batch_subscribeObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/active_zuora/batch_subscribe.rb', line 18

def batch_subscribe
  raise "object must be an ActiveZuora::CollectionProxy object instance" unless self.zuora_object_name == "CollectionProxy"
  self.result = self.class.connection.request(:subscribe) do |soap|
    soap.body do |xml| 
      inject(xml) do |memo, el|
        el.build_xml(xml, soap, 
          :namespace => soap.namespace,
          :element_name => :subscribes,
          :force_type => true)
      end
    end
  end[:subscribe_response][:result]
  
  self.result = [result] unless result.is_a?(Array)
  result.each_with_index do |result, i|
    self.records[i].result = result
    if result[:success]
      #we assume order is maintained by zuora.  is it?
      self.records[i]..id = result[:account_id]
      self.records[i].subscription_data.subscription.id = result[:subscription_id]
      self.records[i].clear_changed_attributes
      @status = true
    else
      add_zuora_errors(result[:errors])
      @status = false
    end
  end
  @status
end

#batch_subscribe!Object



48
49
50
# File 'lib/active_zuora/batch_subscribe.rb', line 48

def batch_subscribe!
  raise "Could not batch subscribe: #{errors.full_messages.join ', '}" unless batch_subscribe
end