Created
October 1, 2011 02:43
-
-
Save roothybrid7/1255520 to your computer and use it in GitHub Desktop.
dot access and refering to subscript of attributes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# coding: utf-8 | |
require 'rubygems' | |
require 'right_resource' | |
# Server Array Response data sample | |
xml = '<server-array> | |
<active type="boolean">false</active> | |
<array-type>queue</array-type> | |
<description > mydesc </description> | |
<elasticity-function>sqs_queue_size</elasticity-function> | |
<nickname>Array for "Transcoding" (Queue)</nickname> | |
<href>http://my.rightscale.com/api/acct/1/server_arrays/1</href> | |
<server-template-href>http://my.rightscale.com/api/acct/1/ec2_server_templates/1</server-template-href> | |
<indicator-href>http://my.rightscale.com/api/acct/1/sqs_queues/1</indicator-href> | |
<audit-queue-href nil="true"/> | |
<deployment-href>http://my.rightscale.com/api/acct/1/deployments/1</deployment-href> | |
<ec2-ssh-key-href>http://my.rightscale.com/api/acct/1/ec2_ssh_keys/1844</ec2-ssh-key-href> | |
<ec2-security-groups-href>http://my.rightscale.com/api/acct/1/ec2_security_groups/159</ec2-security-groups-href> | |
<voters-tag>foo</voters-tag> | |
</server-array>' | |
data = RightResource::Formats::XmlFormat.decode(xml) | |
ServerArray.connection = RightResource::Connection.new | |
rs_array_hash = ServerArray.correct_attributes(data['server_array']) | |
rs_array_obj = ServerArray.new(rs_array_hash) | |
# Get Server Array attributes | |
pp rs_array_obj.attributes | |
=begin | |
{:active=>false, | |
:ec2_security_groups_href=> | |
"http://my.rightscale.com/api/acct/1/ec2_security_groups/159", | |
:elasticity_function=>"sqs_queue_size", | |
:indicator_href=>"http://my.rightscale.com/api/acct/1/sqs_queues/1", | |
:server_template_href=> | |
"http://my.rightscale.com/api/acct/1/ec2_server_templates/1", | |
:description=>" mydesc ", | |
:deployment_href=>"http://my.rightscale.com/api/acct/1/deployments/1", | |
:ec2_ssh_key_href=>"http://my.rightscale.com/api/acct/1/ec2_ssh_keys/1844", | |
:href=>"http://my.rightscale.com/api/acct/1/server_arrays/1", | |
:voters_tag=>"foo", | |
:nickname=>"Array for \"Transcoding\" (Queue)", | |
:audit_queue_href=>nil, | |
:array_type=>"queue"} | |
=end | |
# dot access -> attributes member | |
pp rs_array_obj.attributes[:deployment_href] | |
#=> "http://my.rightscale.com/api/acct/1/deployments/1" | |
pp rs_array_obj.deployment_href | |
#=> "http://my.rightscale.com/api/acct/1/deployments/1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment