API Guide

10
Appendix C -Ruby Code Usage
Several conguration options are available for the ASM Ruby module. In order to run the code examples, minimally one will need to
set the username, password, and baseURI in the le AsmCong.rb
require 'ASM'
require 'XMLPayload'
ASM::API::userName = 'admin'
ASM::API::password = 'abc123'
ASM::API::debug = false
# Globally enable automatic signing of all RestClient requests
#ASM::API::autoEnableAuth
ASM::API::baseURI = 'https://localhost/Api/V1'
# XMLPayload is a simple module to help process XML payloads
ASM::Payload.basePath = './xml_payloads'
# Set this to false if want to ignore problems with self-signed certs.
ASM::API::sslVerify = false
# hack to deal with self-signed certificates
module RestClient
class Request
def self.execute(args, & block)
unless ASM::API::sslVerify
args[:verify_ssl] = false
end
new(args).execute(& block)
end
end
end
The following Ruby code illustrates several methods for conguring ASM and signing requests.
require 'ASM'
ASM::API::userName = 'admin'
ASM::API::password = 'abc123'
ASM::API::baseURI = 'http://localhost/Api/V1'
# Fetch a service template by name
url = ASM::API::URI('/ServiceTemplate')
template_name = 'uploaded'
template_filter = "eq,name,#{template_name}"
# Enable auto signing for all RestClient calls
ASM::API::enableAutoAuth
result = RestClient.get url, {:params=>{:filter=>template_filter}}
# Disable auto signing for all RestClient calls
ASM::API::disableAutoAuth
result = RestClient.get url, {:params=>{:filter=>template_filter}}
# Sign a single request
148