Class: ET::Get

Inherits:
Constructor show all
Defined in:
lib/exact-target-api/get.rb

Instance Attribute Summary

Attributes inherited from Constructor

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

Instance Method Summary collapse

Constructor Details

#initialize(client, objType, props = nil, filter = nil) ⇒ Get

Returns a new instance of Get.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/exact-target-api/get.rb', line 3

def initialize(client, objType, props = nil, filter = nil)
  @results = []
  client.refreshToken
  if !props
    resp = ET::Describe.new(client, objType)
    if resp
      props = []
      resp.results.map { |p|
        if p[:is_retrievable]
          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')
      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 = client.auth.call(:retrieve, message: {
    'RetrieveRequest' => obj
  })

  super(response)

  if @status
    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