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.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/marketo_api/client.rb', line 72

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.



28
29
30
# File 'lib/marketo_api/client.rb', line 28

def api_version
  @api_version
end

#endpointObject (readonly)

The computed endpoint for Marketo.



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

def endpoint
  @endpoint
end

#errorObject (readonly)

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



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

def error
  @error
end

#logger=(value) ⇒ Object (writeonly)

Sets the logger.



25
26
27
# File 'lib/marketo_api/client.rb', line 25

def logger=(value)
  @logger = value
end

#subdomainObject (readonly)

The subdomain for interacting with Marketo.



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

def subdomain
  @subdomain
end

#wsdlObject (readonly)

The WSDL used for interacting with Marketo.



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

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.



114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/marketo_api/client.rb', line 114

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)


89
90
91
# File 'lib/marketo_api/client.rb', line 89

def error?
  !!@error
end