Class: ET::Post

Inherits:
Constructor show all
Defined in:
lib/exact-target-api/post.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) ⇒ Post

Returns a new instance of Post.



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

def initialize(client, objType, props = nil)
  @results = []

  begin
    client.refreshToken

    obj = {
      'Objects' => props,
      attributes!: {'Objects' => {'xsi:type' => 'tns:' + objType}}
    }

    response = client.auth.call(:create, message: obj)

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