Module: ExactTarget
- Extended by:
- ResponseClasses
- Defined in:
- lib/exact_target.rb,
lib/exact_target/error.rb,
lib/exact_target/configuration.rb,
lib/exact_target/request_builder.rb,
lib/exact_target/response_classes.rb,
lib/exact_target/response_handler.rb
Overview
The ExactTarget library is a ruby implementation of the ExactTarget email marketing api. It allows for list/subscriber management, email creation, and job initiation.
Defined Under Namespace
Modules: ResponseClasses Classes: Configuration, Error, RequestBuilder, ResponseHandler
Constant Summary collapse
- VERSION =
File.read(File. '../../CHANGELOG', __FILE__)[/v([\d\.]+)\./, 1]
- LOG_PREFIX =
"** [ExactTarget] "
Class Attribute Summary collapse
-
.builder ⇒ Object
The builder object is responsible for building the xml for any given request.
-
.configuration ⇒ Object
A ExactTarget configuration object.
-
.handler ⇒ Object
The handler object is responsible for handling the xml response and returning response data.
Class Method Summary collapse
- .call(method, *args, &block) ⇒ Object
- .configure(username = nil, password = nil) {|configuration| ... } ⇒ Object
- .log(level, message) ⇒ Object
- .send_to_exact_target(request) ⇒ Object
- .verify_configure ⇒ Object
Methods included from ResponseClasses
class_from_et_attributes, class_template, extended
Class Attribute Details
.builder ⇒ Object
The builder object is responsible for building the xml for any given request
29 30 31 |
# File 'lib/exact_target.rb', line 29 def builder @builder end |
.configuration ⇒ Object
A ExactTarget configuration object. Must act like a hash and return sensible values for all ExactTarget configuration options. See ExactTarget::Configuration.
37 38 39 |
# File 'lib/exact_target.rb', line 37 def configuration @configuration end |
.handler ⇒ Object
The handler object is responsible for handling the xml response and returning response data
33 34 35 |
# File 'lib/exact_target.rb', line 33 def handler @handler end |
Class Method Details
.call(method, *args, &block) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/exact_target.rb', line 58 def call(method, *args, &block) verify_configure request = builder.send(method, *args, &block) log :debug, "#{LOG_PREFIX}REQUEST: #{request}" response = send_to_exact_target(request) log :debug, "#{LOG_PREFIX}RESPONSE: #{response}" response = parse_response_xml(response) handler.send(method, response) end |
.configure(username = nil, password = nil) {|configuration| ... } ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/exact_target.rb', line 39 def configure(username=nil, password=nil) self.configuration ||= Configuration.new configuration.username = username if username configuration.password = password if password yield(configuration) if block_given? self.builder = RequestBuilder.new(configuration) self.handler = ResponseHandler.new(configuration) nil end |
.log(level, message) ⇒ Object
53 54 55 56 |
# File 'lib/exact_target.rb', line 53 def log(level, ) verify_configure configuration.logger.send(level, ) unless configuration.logger.nil? end |
.send_to_exact_target(request) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/exact_target.rb', line 72 def send_to_exact_target(request) verify_configure uri = URI.parse "#{configuration.base_url}?qf=xml&xml=#{URI.escape request}" http = net_http_or_proxy.new(uri.host, uri.port) http.use_ssl = configuration.secure? http.open_timeout = configuration.http_open_timeout http.read_timeout = configuration.http_read_timeout resp = http.get(uri.request_uri) if resp.is_a?(Net::HTTPSuccess) resp.body else resp.error! end end |
.verify_configure ⇒ Object
49 50 51 |
# File 'lib/exact_target.rb', line 49 def verify_configure raise "ExactTarget must be configured before using" if configuration.nil? or !configuration.valid? end |