API Guide
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 conguring the ASM module.
In addition to the API requests, there is sometimes signicant 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 les 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 specied simply as ‘/Timezone’ because ASM has already been congured with the base path prex /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 le ‘timezone.xml’ as a payload used in the next example to set the timezone.
Set the current timezone
Here we utilize the simple XML utility class called ASM::Payload to do simple manipulations of our XML.
require 'ASMConfig'
payload = ASM::Payload.load_xml('timezone.xml')
payload.set('timeZoneId','15')
# Set Timezone
response = ASM::API::sign {
16