Class: MarketoAPI::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/marketo_api/client.rb

Overview

The client to the Marketo SOAP API.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Client

Creates a client to talk to the Marketo SOAP API.

Required Configuration Parameters

The required configuration parameters can be found in your Marketo dashboard, under Admin / Integration / SOAP API.

api_subdomain

The endpoint subdomain.

api_version

The endpoint version.

user_id

The user iD for SOAP integration.

encryption_key

The encryption key for SOAP integration.

Version 1.0 will make these values defaultable through environment variables.

Savon Configuration Parameters

These affect how Savon interacts with the HTTP server.

read_timeout

The timeout for reading from the server. Defaults to 90.

open_timeout

The timeout for opening the connection. Defaults to 90.

pretty_print_xml

How the SOAP XML should be written. Defaults to true.

ssl_verify_mode

How to verify SSL keys. This version defaults to none. Version 1.0 will default to normal verification.

headers

Headers to use. Defaults to Connection: Keep-Alive. Version 1.0 will enforce at least this value.

Version 1.0 will require that these options be provided under a savon key.



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/marketo_api/client.rb', line 77

def initialize(config = {})
  config = DEFAULT_CONFIG.merge(config)
  @api_version = config.delete(:api_version).freeze
  @subdomain = config.delete(:api_subdomain).freeze

  @logger = config.delete(:logger)

  user_id = config.delete(:user_id)
  encryption_key = config.delete(:encryption_key)
  @auth = AuthHeader.new(user_id, encryption_key)

  @wsdl = "http://app.marketo.com/soap/mktows/#{api_version}?WSDL".freeze
  @endpoint = "https://#{subdomain}.mktoapi.com/soap/mktows/#{api_version}".freeze
  @savon = Savon.client(config.merge(wsdl: wsdl, endpoint: endpoint))
end

Instance Attribute Details

#api_versionObject (readonly)

The targeted Marketo SOAP API version.



33
34
35
# File 'lib/marketo_api/client.rb', line 33

def api_version
  @api_version
end

#endpointObject (readonly)

The computed endpoint for Marketo.



39
40
41
# File 'lib/marketo_api/client.rb', line 39

def endpoint
  @endpoint
end

#errorObject (readonly)

If the most recent call resulted in an exception, it will be captured here.



42
43
44
# File 'lib/marketo_api/client.rb', line 42

def error
  @error
end

#logger=(value) ⇒ Object (writeonly)

Sets the logger.



30
31
32
# File 'lib/marketo_api/client.rb', line 30

def logger=(value)
  @logger = value
end

#subdomainObject (readonly)

The subdomain for interacting with Marketo.



35
36
37
# File 'lib/marketo_api/client.rb', line 35

def subdomain
  @subdomain
end

#wsdlObject (readonly)

The WSDL used for interacting with Marketo.



37
38
39
# File 'lib/marketo_api/client.rb', line 37

def wsdl
  @wsdl
end

Instance Method Details

#call(web_method, params) ⇒ Object

Perform a SOAP API request with a properly formatted params message object.

Warning: This method is for internal use by descendants of MarketoAPI::ClientProxy. It should not be called by external users.



119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/marketo_api/client.rb', line 119

def call(web_method, params) #:nodoc:
  @error = nil
  @savon.call(
    web_method,
    message: params,
    soap_header: { 'ns1:AuthenticationHeader' => @auth.signature }
  ).to_hash
rescue Exception => e
  @error = e
  @logger.log(e) if @logger
  nil
end

#error?Boolean

Indicates the presence of an error from the last call.

Returns:

  • (Boolean)


94
95
96
# File 'lib/marketo_api/client.rb', line 94

def error?
  !!@error
end