API Guide

Table Of Contents
6
Usage Examples
The following examples use a simple Ruby module called ASM which utilizes the publicly available
RestClient gem to perform the HTTP requests. This module contains utilities to generate the security
headers so we can focus on the API calls themselves. See Appendix C for detailed information on using
and configuring the ASM module.
In addition to the API requests, there is sometimes significant XML processing required to prepare the
request bodies or parse the responses. A utility module ASM::Payload is provided for simple get/set
operations on XML document elements and simple load/save operations on XML files for use as starting
templates and intermediate data storage between API calls. This module is not required but is useful for
simplifying the example code that follows.
Timezone
Get the current timezone
require 'ASMConfig'
# Get timezone settings
url = ASM::API::URI("/Timezone")
response = ASM::API::sign {
RestClient.get url
}
# Save it for future use as a payload
payload = ASM::Payload.from_xml(response)
payload.save_xml('timezone.xml')
Here we utilize a block construct to sign our request. All RestClient invocations inside the sign block will
automatically be signed. The url is specified simply as ‘/Timezone’ because ASM has already been
configured with the base path prefix /Asm/V1. The response object as XML is:
<timeZone>
<timeZone>(UTC-06:00) Central Time (US & Canada)</timeZone>
<timeZoneId>11</timeZoneId>
</timeZone>
which we saved in the file ‘timezone.xml’ as a payload used in the next example to set the timezone.
18