Class: ET::Patch

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

Instance Attribute Summary

Attributes inherited from Constructor

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

Instance Method Summary collapse

Constructor Details

#initialize(authStub, objType, props = nil) ⇒ Patch

Returns a new instance of Patch.



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
# File 'lib/exact-target-api/patch.rb', line 3

def initialize(authStub, objType, props = nil)
  @results = []
  begin
    authStub.refreshToken
    if props.is_a? Array
      obj = {
        'Objects' => [],
        :attributes! => { 'Objects' => { 'xsi:type' => ('tns:' + objType) } }
      }
      props.each{ |p|
        obj['Objects'] << p
      }
    else
      obj = {
        'Objects' => props,
        :attributes! => { 'Objects' => { 'xsi:type' => ('tns:' + objType) } }
      }
    end

    response = authStub.auth.call(:update, :message => obj)

  ensure
    super(response)
    if @status
      if @body[:update_response][:overall_status] != "OK"
        @status = false
      end
      if !@body[:update_response][:results].is_a? Hash then
        @results = @results + @body[:update_response][:results]
      else
        @results.push(@body[:update_response][:results])
      end
    end
  end
end