Connecting to the API using Ruby on Rails

From $1

    Doc-Wiki-BannerHK.png

    (Click the banner to go to the related Docs.Code.ExactTarget.com page.)

    This document contains conceptual and procedural information on connecting your development environment or other systems to the ExactTarget web service API using Ruby on Rails.

    Why Connect to the Web Service API using Ruby on Rails

    You can use the connection to the web service API to test your calls and perform various tasks, such as sending email and retrieving tracking information. 

    Prerequisites

    You must download and install the following gems in order to connect to the web service API via Ruby on Rails:

    • soap4r
    • wss4r
    • wsse

    How to Connect to the Web Service API using Ruby on Rails

    Follow the directions below to connect to the web service API using Ruby on Rails:

    Sample Code

    The sample code below demonstrates how to connect and interact with the web service API.

    Generating Drivers

    You can generate your own Ruby on Rails drivers using wsdl2ruby.rb and typing the following command in your command line.

    wsdl2ruby.rb --wsdl https://webservice.exacttarget.com/etframework.wsdl --type client --force

    Executing a Ruby on Rails File in a Shell

    Use the following syntax to execute a Ruby on Rails file in a shell:

    ruby -d createSub.rb

    Authenticating your Environment to the Web Service API

    Use the sample code below to authenticate your Ruby on Rails environment to the web service API:

    class WsseAuthHeader < SOAP::Header::SimpleHandler
        NAMESPACE = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'
        USERNAME  = 'USERNAME'
        PASSWORD  = 'PASSWORD'
     
        def initialize()
            super(XSD::QName.new(NAMESPACE, 'Security'))
        end
      
        def on_simple_outbound
            {"UsernameToken" => {"Username" => USERNAME, "Password" => PASSWORD}}
        end
    end
    
    #make sure everything is unicode-friendly, just in case
    XSD::Charset.encoding = 'UTF8'
    
    endpoints = {
        :S1=> 'https://webservice.exacttarget.com/Service.asmx',
        :S4=> 'https://webservice.s4.exacttarget.com/Service.asmx'
        :S6=> 'https://webservice.s6.exacttarget.com/Service.asmx'
    }
    
    # The default SOAP::DefaultEndpointUrl can be used or custom end point
    endpoint_url = endpoints[:indy] || Soap::DefaultEndpointUrl
    
    # Instantiate a new SOAP request
    $driver = Soap.new(endpoint_url)
    
    # enable debug output (showing SOAP XML) if you run this script with ruby -d
    $driver.wiredump_dev = STDOUT if $DEBUG
    
    # Append the authentication onto the SOAP Request
    $driver.headerhandler << WsseAuthHeader.new()

    You can fine additional sample code and development work at http://code.google.com/p/exacttarget-wsdl-ruby/.


    This page was last updated by Ryan Williams on Tue, 24 Jan 2012 13:23:05 GMT.

    If you require assistance with the ExactTarget application, please contact Global Support. If you wish to send Ryan direct feedback, fill out the form below:

     


    Was This Page Helpful?
    Suggestions or Comments:
    Name (optional):
    Email Address (optional):
    Enter 19505 backwards:
       
    Tags: (Edit tags)
    • No tags
     
    Comments (0)
    You must login to post a comment.

     
    Powered by MindTouch 2010
    Admin