Class: ExactTargetSDK::Client
- Inherits:
-
Object
- Object
- ExactTargetSDK::Client
- Defined in:
- lib/exact_target_sdk/client.rb
Overview
Provides an object-oriented API to ExactTarget’s Web Service API (docs.code.exacttarget.com/020_Web_Service_Guide)
With few exceptions, ruby conventions for capitalization are ignored and those outlined in the guide linked above are used. This is done in an attempt to be as transparent as possible, so that the API may be used by referring only to the guide linked above.
Instance Method Summary collapse
-
#Create(*args) ⇒ Object
Invokes the Create method.
-
#Delete(*args) ⇒ Object
Invokes the Delete method.
-
#initialize(options = {}) ⇒ Client
constructor
Constructs a client.
- #logger ⇒ Object
-
#Perform(action, *args) ⇒ Object
Invokes the Perform method.
-
#Retrieve(object_type_name, filter, *properties) ⇒ Object
Invokes the Retrieve method.
-
#Update(*args) ⇒ Object
Invokes the Update method.
Constructor Details
#initialize(options = {}) ⇒ Client
Constructs a client.
Any of the options documented in ExactTargetSDK#config may be overridden using the options parameter.
Since ExactTarget’s API is stateless, constructing a client object will not make any remote calls.
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/exact_target_sdk/client.rb', line 23 def initialize( = {}) self.config = { }.merge!(ExactTargetSDK.config).merge!() Savon.configure do |c| c.logger = config[:logger] c.raise_errors = false end initialize_client! end |
Instance Method Details
#Create(*args) ⇒ Object
Invokes the Create method.
The provided arguments should each be sub-classes of APIObject, and each provided object will be created in order.
Possible exceptions are:
HTTPError if an HTTP error (such as a timeout) occurs
SOAPFault if a SOAP fault occurs
Timeout if there is a timeout waiting for the response
InvalidAPIObject if any of the provided objects don't pass validation
Returns a CreateResponse object.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/exact_target_sdk/client.rb', line 47 def Create(*args) # TODO: implement and accept CreateOptions api_objects = args response = execute_request 'Create' do |xml| xml.CreateRequest do xml.Options # TODO: support CreateOptions api_objects.each do |api_object| xml.Objects "xsi:type" => api_object.type_name do api_object.render!(xml) end end end end CreateResponse.new(response) end |
#Delete(*args) ⇒ Object
Invokes the Delete method.
The provided arguments should each be sub-classes of APIObject, and each provided object will be updated in order.
Possible exceptions are:
HTTPError if an HTTP error (such as a timeout) occurs
SOAPFault if a SOAP fault occurs
Timeout if there is a timeout waiting for the response
InvalidAPIObject if any of the provided objects don't pass validation
Returns a DeleteResponse object.
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/exact_target_sdk/client.rb', line 150 def Delete(*args) # TODO: implement and accept DeleteOptions api_objects = args response = execute_request 'Delete' do |xml| xml.DeleteRequest do xml.Options # TODO: support DeleteOptions api_objects.each do |api_object| xml.Objects "xsi:type" => api_object.type_name do api_object.render!(xml) end end end end DeleteResponse.new(response) end |
#logger ⇒ Object
206 207 208 |
# File 'lib/exact_target_sdk/client.rb', line 206 def logger config[:logger] end |
#Perform(action, *args) ⇒ Object
Invokes the Perform method.
The provided arguments should each be definitions that are sub-classes of APIObject.
Possible exceptions are:
HTTPError if an HTTP error (such as a timeout) occurs
SOAPFault if a SOAP fault occurs
Timeout if there is a timeout waiting for the response
InvalidAPIObject if any of the provided objects don't pass validation
Returns a PerformResponse object.
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/exact_target_sdk/client.rb', line 182 def Perform(action, *args) # TODO: implement and accept PerformOptions definitions = args response = execute_request 'Perform' do |xml| xml.PerformRequestMsg do xml.Action action xml.Definitions do definitions.each do |definition| xml.Definition "xsi:type" => definition.type_name do definition.render!(xml) end end end xml.Options # TODO: support PerformOptions end end PerformResponse.new(response) end |
#Retrieve(object_type_name, filter, *properties) ⇒ Object
Invokes the Retrieve method.
Note that this implementation abstracts away the useless RetrieveRequest sub-wrapper, and introduces a RequestResponse wrapper to contain the output parameters.
Does not currently support requests that have too many results for one batch.
Possible exceptions are:
HTTPError if an HTTP error (such as a timeout) occurs
SOAPFault if a SOAP fault occurs
Timeout if there is a timeout waiting for the response
InvalidAPIObject if any of the provided objects don't pass validation
Returns a RetrieveResponse object.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/exact_target_sdk/client.rb', line 83 def Retrieve(object_type_name, filter, *properties) object_type_name = object_type_name.type_name if object_type_name.respond_to?(:type_name) response = execute_request 'Retrieve' do |xml| xml.RetrieveRequestMsg do xml.RetrieveRequest do xml.Options xml.ObjectType object_type_name properties.each do |property| xml.Properties(property) end xml.Filter "xsi:type" => filter.type_name do filter.render!(xml) end end end end RetrieveResponse.new(response) end |
#Update(*args) ⇒ Object
Invokes the Update method.
The provided arguments should each be sub-classes of APIObject, and each provided object will be updated in order.
Possible exceptions are:
HTTPError if an HTTP error (such as a timeout) occurs
SOAPFault if a SOAP fault occurs
Timeout if there is a timeout waiting for the response
InvalidAPIObject if any of the provided objects don't pass validation
Returns an UpdateResponse object.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/exact_target_sdk/client.rb', line 118 def Update(*args) # TODO: implement and accept UpdateOptions api_objects = args response = execute_request 'Update' do |xml| xml.UpdateRequest do xml.Options # TODO: support UpdateOptions api_objects.each do |api_object| xml.Objects "xsi:type" => api_object.type_name do api_object.render!(xml) end end end end UpdateResponse.new(response) end |