From YiPs Wiki (i powered)

XMLService: Connection

(click to open)

Quick Page Table of Contents

Scanning…

Ruby Toolkit Don: Establishing a Connection

XMLSERVICERubyDonWork

XMLService requires a connection. The connection method parameters can contain:

  1. all detailed options
  2. simply reference your existing Rails database.yml configuration for the ibm_db ActiveRecord adapter.

The following ruby code, for example, creates a connection to the current IBMi and then prints the output from the QTIME system value on the shell console:

require 'xmlservice'
ActiveXMLService::Base.establish_connection(
  connection: 'ActiveRecord', adapter: 'ibm_db', database: '*LOCAL',
  username: 'USER400', password: 'secret'
)
wrksysval = XMLService::I_SH.new("system -i 'WRKSYSVAL SYSVAL(QTIME) OUTPUT(*PRINT)'")
wrksysval.xmlservice
puts wrksysval.out_xml

But, if you are in the context of a Rails application that has an ibm_db adapter already configured in database.yml, the establish connection method need only be passed the connection adapter type of ActiveRecord. The following shows how to run the WRKSYSVAL command from a Rails console:

/YOUR_RAILS_APP> rails console
irb(main):001:0>  require 'xmlservice'
irb(main):001:0>  ActiveXMLService::Base.establish_connection connection: 'ActiveRecord'
irb(main):001:0>  cmd = XMLService::I_SH.new("system -i 'WRKSYSVAL SYSVAL(QTIME) OUTPUT(*PRINT)'")
irb(main):001:0>  cmd.xmlservice
irb(main):001:0>  puts cmd.out_xml
Retrieved from http://youngiprofessionals.com/wiki/index.php/XMLService/Connection
Page last modified on December 17, 2013, at 02:56 PM EST