Sha256: 23947aff2dba5a7e1e2878b1d6ff9e395b9812714b9ef39035279ce9eaa4adf9

Contents?: true

Size: 1.69 KB

Versions: 1

Compression:

Stored size: 1.69 KB

Contents

require("etapi/calls/list")
require("etapi/calls/email")
require("etapi/calls/tracking")
require("etapi/calls/subscriber")

module ETAPI
  
  class Session
    
    # set default options
    DEFAULTS = {
      :api_method           => :xml,
      :use_s4               => false,
      :api_uri_xml          => "https://api.dc1.exacttarget.com/integrate.aspx",
      :api_uri_xml_s4       => "https://api.s4.exacttarget.com/integrate.aspx",
      :use_ssl              => true,
    }
    
    # allowed options
    ALLOWED_USE_S4_OPTIONS      = [true, false]
    
    # initialize a new exact target instance
    def initialize(*args)
      
      # merge options with configuration
      options     = args.extract_options!
      @username   = options[:username]    ||= ETAPI.username
      @password   = options[:password]    ||= ETAPI.password
      @use_s4     = options[:use_s4]      ||= ETAPI.use_s4     ||= DEFAULTS[:use_s4]
      @headers    = {"Content-Type" => "application/x-www-form-urlencoded", "Connection" => "close"}
      
      # check for required options
      raise ArgumentError, "* missing :username *" if @username.blank?
      raise ArgumentError, "* missing :password *" if @password.blank?
      raise ArgumentError, "* invalid :use_s4 | options => [true, false] *" unless ALLOWED_USE_S4_OPTIONS.include?(@use_s4)
      
      @api_uri = @use_s4 ? DEFAULTS[:api_uri_xml_s4] : DEFAULTS[:api_uri_xml]
      
      @api_wsdl = @api_uri if @use_s4
      
      # parse uri
      @api_uri   = URI.parse(@api_uri)
      @api_url   = Net::HTTP.new(@api_uri.host, @api_uri.port)
      
      # check for SSL (disabled)
      @api_url.use_ssl = options[:use_ssl] ||= DEFAULTS[:use_ssl]
      
    end
    
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
etapi-0.1.1 lib/etapi/exact_target.rb