Class: MarketingCloudSDK::ET_Get

Inherits:
ET_Constructor show all
Defined in:
lib/new.rb

Instance Attribute Summary

Attributes inherited from ET_Constructor

#code, #message, #moreResults, #request_id, #results, #status

Instance Method Summary collapse

Constructor Details

#initialize(authStub, objType, props = nil, filter = nil) ⇒ ET_Get

Returns a new instance of ET_Get.



515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
# File 'lib/new.rb', line 515

def initialize(authStub, objType, props = nil, filter = nil)
  @results = []
  authStub.refreshToken
  if !props then
    resp = ET_Describe.new(authStub, objType)
    if resp then
      props = []
      resp.results.map { |p|
        if p[:is_retrievable] then
          props << p[:name]
        end
      }
    end
  end

  # If the properties is a hash, then we just want to use the keys
  if props.is_a? Hash then
    obj = {'ObjectType' => objType,'Properties' => props.keys}
  else
    obj = {'ObjectType' => objType,'Properties' => props}
  end

  if filter then
    if filter.has_key?('LogicalOperator') then
      obj['Filter'] = filter
      obj[:attributes!] = { 'Filter' => { 'xsi:type' => 'tns:ComplexFilterPart' }}
      obj['Filter'][:attributes!] = { 'LeftOperand' => { 'xsi:type' => 'tns:SimpleFilterPart' }, 'RightOperand' => { 'xsi:type' => 'tns:SimpleFilterPart' }}
    else
      obj['Filter'] = filter
      obj[:attributes!] = { 'Filter' => { 'xsi:type' => 'tns:SimpleFilterPart' } }
    end
  end

  response = authStub.auth.call(:retrieve, :message => {
      'RetrieveRequest' => obj
      })

  super(response)

  if @status then
    if @@body[:retrieve_response_msg][:overall_status] != "OK" && @@body[:retrieve_response_msg][:overall_status] != "MoreDataAvailable" then
      @status = false
      @message = @@body[:retrieve_response_msg][:overall_status]
    end

    @moreResults = false
    if @@body[:retrieve_response_msg][:overall_status] == "MoreDataAvailable" then
      @moreResults = true
    end

    if (!@@body[:retrieve_response_msg][:results].is_a? Hash) && (!@@body[:retrieve_response_msg][:results].nil?) then
      @results = @results + @@body[:retrieve_response_msg][:results]
    elsif  (!@@body[:retrieve_response_msg][:results].nil?)
      @results.push(@@body[:retrieve_response_msg][:results])
    end

    # Store the Last Request ID for use with continue
    @request_id = @@body[:retrieve_response_msg][:request_id]
  end
end