In previous posts, we introduced libraries in PHP, Node.js and C# for working with the REST API. Today, we’re going to start a library in Ruby. The library is available on github and is open to the community. Please note this is a work in progress and the goal is to have the community contribute to and help evolve the project.


Let's get started with a simple request to the REST API using Ruby.


require 'net/https'

https = Net::HTTP.new('secure.eloqua.com', 443)
https.use_ssl = true
https.verify_mode = OpenSSL::SSL::VERIFY_PEER

request = Net::HTTP::Get.new('/API/REST/1.0/assets/emails?search=*Demand*&page=1&count=50&depth=minimal')
request.basic_auth 'site\user', 'password'

response = https.request(request)



Now, let's look at the same request using the library.


require('eloqua-ruby-request')
eloquaRequest = EloquaRequest.new('site', 'user', 'password')
response = eloquaRequest.get('/assets/emails?search=Demand*&page=1&count=50&depth=minimal')



The response for this call looks as follows :

  {  
 "elements": [  
        {  
 "type": "Email", 
 "currentStatus": "Draft",  
 "id": "86013", 
 "createdAt": "1370981173",  
 "createdBy": "9", 
 "depth": "minimal", 
 "folderId": "1422", 
 "name": "Demand.html",  
 "permissions": "fullControl",  
 "updatedAt": "1370981173",  
 "updatedBy": "9", 
 "htmlContent": {  
 "type": "RawHtmlContent",  
 "contentSource": "upload"  
          }  
        },  
        {  
 "type": "Email", 
 "currentStatus": "Draft",  
 "id": "69830", 
 "createdAt": "1362380717",  
 "createdBy": "244", 
 "depth": "minimal", 
 "folderId": "1422", 
          "name": "Demand Sample",  
 "permissions": "fullControl",  
 "updatedAt": "1362380784",  
 "updatedBy": "244", 
 "htmlContent": {  
 "type": "RawHtmlContent",  
 "contentSource": "upload"  
          }  
        },  
       ...  
      ],  
 "page": 1,  
 "pageSize": 10,  
 "total": 130  
}  


Please note that the REST API is not yet public and the code samples available here are my own work. I'll be glad to help support and fix issues in the code, but please understand that Eloqua will not be able to support this.

 

Thanks,
Fred