Connect to Adobe Experience Manager Data in Ruby

Jerod Johnson
Jerod Johnson
Director, Technology Evangelism
Connect to Adobe Experience Manager data in Ruby with ruby-dbi, dbd-odbc, and ruby-odbc.

The CData ODBC Driver for Adobe Experience Manager makes it easy to integrate connectivity to live Adobe Experience Manager data in Ruby. This article shows how to create a simple Ruby app that connects to Adobe Experience Manager data, executes a query, and displays the results.

Create an ODBC Connection to Adobe Experience Manager Data

If you have not already, first specify connection properties in an ODBC DSN (data source name). This is the last step of the driver installation. You can use the Microsoft ODBC Data Source Administrator to create and configure ODBC DSNs.

The driver connects to Adobe Experience Manager (AEM) instances that expose the JCR repository over WebDAV. It supports both on-premises AEM and AEM as a Cloud Service deployments.

To establish a connection, set the following properties:

  • URL: The WebDAV-enabled JCR server URL.
    • AEM as a Cloud Service: https://author-pXXXXX-eXXXXX.adobeaemcloud.com/crx/server
    • Local development: http://localhost:4502/crx/server
  • User: Your AEM username.
  • Password: Your AEM password.

Note: Tables are dynamically generated based on the JCR repository structure. Ensure that the configured user has sufficient permissions to access the required content paths in the AEM repository.

Installing Ruby and Necessary Gems

If you do not have Ruby installed, refer to the Ruby installation page. With Ruby installed, you will need to install the ruby-dbi, dbd-odbc, and ruby-odbc gems:

gem install dbi
gem install dbd-odbc
gem install ruby-odbc

Create a Ruby App with Connectivity to Adobe Experience Manager Data

Create a new Ruby file (for example: AdobeExperienceManagerSelect.rb) and open it in a text editor. Copy the following code into your file:

#connect to the DSN
require 'dbi'
cnxn = DBI.connect('DBI:ODBC:CData AdobeExperienceManager Source','','')

#execute a SELECT query and store the result set
resultSet = cnxn.execute("SELECT Id, Name FROM Content WHERE Name = 'example'")

#display the names of the columns
resultSet.column_names.each do |name|
  print name, "\t"
end
puts

#display the results
while row = resultSet.fetch do
  (0..resultSet.column_names.size - 1).each do |n|
    print row[n], "\t"
  end
  puts
end
resultSet.finish

#close the connection
cnxn.disconnect if cnxn

With the file completed, you are ready to display your Adobe Experience Manager data with Ruby. To do so, simply run your file from the command line:

ruby AdobeExperienceManagerSelect.rb
Writing SQL-92 queries to Adobe Experience Manager allows you to quickly and easily incorporate Adobe Experience Manager data into your own Ruby applications. Download a free trial today!

Ready to get started?

Download a free trial of the Adobe Experience Manager ODBC Driver to get started:

 Download Now

Learn more:

Adobe Experience Manager Icon Adobe Experience Manager ODBC Driver

The Adobe Experience Manager ODBC Driver is a powerful tool that allows you to connect with live data from Adobe Experience Manager, directly from any applications that support ODBC connectivity.

Access Adobe Experience Manager data like you would a database - read, write, and update Adobe Experience Manager 0, etc. through a standard ODBC Driver interface.