Class: MarketoAPI::Client
- Inherits:
-
Object
- Object
- MarketoAPI::Client
- Defined in:
- lib/marketo_api/client.rb
Overview
The client to the Marketo SOAP API.
Instance Attribute Summary collapse
-
#api_version ⇒ Object
readonly
The targeted Marketo SOAP API version.
-
#endpoint ⇒ Object
readonly
The computed endpoint for Marketo.
-
#error ⇒ Object
readonly
If the most recent call resulted in an exception, it will be captured here.
-
#logger ⇒ Object
writeonly
Sets the logger.
-
#subdomain ⇒ Object
readonly
The subdomain for interacting with Marketo.
-
#wsdl ⇒ Object
readonly
The WSDL used for interacting with Marketo.
Instance Method Summary collapse
-
#call(web_method, params) ⇒ Object
Perform a SOAP API request with a properly formatted params message object.
-
#error? ⇒ Boolean
Indicates the presence of an error from the last call.
-
#initialize(config = {}) ⇒ Client
constructor
Creates a client to talk to the Marketo SOAP API.
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.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/marketo_api/client.rb', line 71 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_version ⇒ Object (readonly)
The targeted Marketo SOAP API version.
27 28 29 |
# File 'lib/marketo_api/client.rb', line 27 def api_version @api_version end |
#endpoint ⇒ Object (readonly)
The computed endpoint for Marketo.
33 34 35 |
# File 'lib/marketo_api/client.rb', line 33 def endpoint @endpoint end |
#error ⇒ Object (readonly)
If the most recent call resulted in an exception, it will be captured here.
36 37 38 |
# File 'lib/marketo_api/client.rb', line 36 def error @error end |
#logger=(value) ⇒ Object (writeonly)
Sets the logger.
24 25 26 |
# File 'lib/marketo_api/client.rb', line 24 def logger=(value) @logger = value end |
#subdomain ⇒ Object (readonly)
The subdomain for interacting with Marketo.
29 30 31 |
# File 'lib/marketo_api/client.rb', line 29 def subdomain @subdomain end |
#wsdl ⇒ Object (readonly)
The WSDL used for interacting with Marketo.
31 32 33 |
# File 'lib/marketo_api/client.rb', line 31 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.
113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/marketo_api/client.rb', line 113 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.
88 89 90 |
# File 'lib/marketo_api/client.rb', line 88 def error? !!@error end |