|
|
Documentation Wiki > Developer Documentation > Web Service Guide > Getting Started: Developers and the ExactTarget API > Connecting to the API using Ruby on Rails
Connecting to the API using Ruby on RailsFrom $1Table of contents(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 RailsYou 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. PrerequisitesYou must download and install the following gems in order to connect to the web service API via Ruby on Rails:
How to Connect to the Web Service API using Ruby on RailsFollow the directions below to connect to the web service API using Ruby on Rails: Sample CodeThe sample code below demonstrates how to connect and interact with the web service API. Generating DriversYou 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 ShellUse the following syntax to execute a Ruby on Rails file in a shell: ruby -d createSub.rb Authenticating your Environment to the Web Service APIUse 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:
Tags: (Edit tags)
|
|
Powered by MindTouch 2010 |