Module: MarketingCloudSDK::Soap

Includes:
Targeting
Included in:
Client
Defined in:
lib/marketingcloudsdk/soap.rb

Instance Attribute Summary collapse

Attributes included from Targeting

#access_token, #endpoint, #soap_endpoint

Instance Method Summary collapse

Methods included from Targeting

#cache_file, #get_soap_endpoint_from_file, #set_soap_endpoint_to_file

Methods included from HTTPRequest

#generate_uri, #request

Instance Attribute Details

#debugObject

, :internal_token



119
120
121
# File 'lib/marketingcloudsdk/soap.rb', line 119

def debug
  @debug
end

#wsdlObject

, :internal_token



119
120
121
# File 'lib/marketingcloudsdk/soap.rb', line 119

def wsdl
  @wsdl
end

Instance Method Details

#headerObject



123
124
125
126
127
128
129
# File 'lib/marketingcloudsdk/soap.rb', line 123

def header
  raise 'Require legacy token for soap header' unless internal_token
  {
    'oAuth' => {'oAuthToken' => internal_token},
    :attributes! => { 'oAuth' => { 'xmlns' => 'http://exacttarget.com' }}
  }
end

#soap_clientObject



139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/marketingcloudsdk/soap.rb', line 139

def soap_client
  self.refresh
  @soap_client = Savon.client(
    soap_header: header,
    wsdl: wsdl,
    endpoint: endpoint,
    wsse_auth: ["*", "*"],
    raise_errors: false,
    log: debug,
    open_timeout:180,
    read_timeout: 180,
    headers: {'User-Agent' => 'FuelSDK-Ruby-v' + MarketingCloudSDK::VERSION}
  )
end

#soap_configure(object_type, action, properties) ⇒ Object



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/marketingcloudsdk/soap.rb', line 175

def soap_configure  object_type, action, properties
  message = {}
  message['Action'] = action
  message['Configurations'] = {}
  if properties.is_a? Array then
    message['Configurations']['Configuration'] = []
    properties.each do |configItem|
      message['Configurations']['Configuration'] << configItem
    end
  else
    message['Configurations'] = {'Configuration' => properties}
  end
  message['Configurations'][:attributes!] = { 'Configuration' => { 'xsi:type' => ('tns:' + object_type) }}

  soap_request :configure, message
end

#soap_delete(object_type, properties) ⇒ Object



233
234
235
# File 'lib/marketingcloudsdk/soap.rb', line 233

def soap_delete object_type, properties
  soap_cud :delete, object_type, properties
end

#soap_describe(object_type) ⇒ Object



154
155
156
157
158
159
160
161
162
163
# File 'lib/marketingcloudsdk/soap.rb', line 154

def soap_describe object_type
  message = {
    'DescribeRequests' => {
      'ObjectDefinitionRequest' => {
        'ObjectType' => object_type
      }
    }
  }
  soap_request :describe, message
end

#soap_get(object_type, properties = nil, filter = nil) ⇒ Object



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/marketingcloudsdk/soap.rb', line 192

def soap_get object_type, properties=nil, filter=nil
  if properties.nil? or properties.empty?
    rsp = soap_describe object_type
    if rsp.success?
      properties = rsp.retrievable
    else
      rsp.instance_variable_set(:@message, "Unable to get #{object_type}") # back door update

      return rsp
    end
  elsif properties.kind_of? Hash
    properties = properties.keys
  elsif properties.kind_of? String
    properties = [properties]
  end

  message = {'ObjectType' => object_type, 'Properties' => properties}

  if filter and filter.kind_of? Hash
    message['Filter'] = filter
    message[:attributes!] = { 'Filter' => { 'xsi:type' => 'tns:SimpleFilterPart' } }

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

  soap_request :retrieve, message
end

#soap_patch(object_type, properties) ⇒ Object



229
230
231
# File 'lib/marketingcloudsdk/soap.rb', line 229

def soap_patch object_type, properties
  soap_cud :update, object_type, properties
end

#soap_perform(object_type, action, properties) ⇒ Object



165
166
167
168
169
170
171
172
# File 'lib/marketingcloudsdk/soap.rb', line 165

def soap_perform object_type, action, properties
  message = {}
  message['Action'] = action
  message['Definitions'] = {'Definition' => properties}
  message['Definitions'][:attributes!] = { 'Definition' => { 'xsi:type' => ('tns:' + object_type) }}

  soap_request :perform, message
end

#soap_post(object_type, properties) ⇒ Object



225
226
227
# File 'lib/marketingcloudsdk/soap.rb', line 225

def soap_post object_type, properties
  soap_cud :create, object_type, properties
end

#soap_put(object_type, properties) ⇒ Object



237
238
239
# File 'lib/marketingcloudsdk/soap.rb', line 237

def soap_put object_type, properties
  soap_cud :update, object_type, properties, true
end