class Markety::Client

All of the Markety::Command modules are mixed in to Client, so see the documentation for those modules.

Attributes

target_workspace[R]

Public Class Methods

new(access_key, secret_key, end_point, options = {}) click to toggle source

Supported options:

  • :log (bool) - enable/disable Savon logging (default: true)

  • :target_workspace (string) - name of workspace to use, if any

# File lib/markety/client.rb, line 20
def initialize(access_key, secret_key, end_point, options = {})
  api_version = options.fetch(:api_version, '2_3')

  @client = Savon.client do
    endpoint end_point
    wsdl "http://app.marketo.com/soap/mktows/#{api_version}?WSDL"
    namespaces({"xmlns:ns1" => "http://www.marketo.com/mktows/"})
    env_namespace "SOAP-ENV"
    pretty_print_xml true
    log options.fetch(:log, false)
  end

  @auth_header = Markety::AuthenticationHeader.new(access_key, secret_key)
  @client_options = {}
  @client_options[:target_workspace] = options.has_key?(:target_workspace) ? options[:target_workspace] : {}
end

Private Instance Methods

request(cmd_type, message, header) click to toggle source
# File lib/markety/client.rb, line 55
def request(cmd_type, message, header)
  @client.call(cmd_type, message: message, soap_header: header)
end
send_request(cmd_type, message) click to toggle source
# File lib/markety/client.rb, line 39
def send_request(cmd_type, message)
  @auth_header.set_time(DateTime.now)

  header_hash = @auth_header.to_hash
  if cmd_type==:sync_lead && @target_workspace
    header_hash.merge!({ "ns1:MktowsContextHeader"=>{"targetWorkspace"=>@target_workspace}})
  end

  begin
    response = request(cmd_type, message, header_hash) #returns a Savon::Response
  rescue Savon::SOAPFault => e
    response = e
  end
  Markety::Response::ResponseFactory.create_response(cmd_type,response)
end