/softlayer-ruby

A module and class factory for SoftLayer's customer portal API

Primary LanguageRubyBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

This is a module and class factory for SoftLayer's customer portal API (http://sldn.softlayer.com ).  See the rdoc documentation and the sample directory for usage details.

The factory creates classes as they are declared.  As a group:

SLAPICLASSES = [ 'SoftLayer::Account' ]
SLAPISERVICES = [ 'SoftLayer_Billing_Item', 'SoftLayer_Network_Storage' ]
SoftLayer::declareClasses(:ruby => SLAPICLASSES, :soap => SLAPISERVICES)

Or one at a time:

SoftLayer::ClassFactory(:class => 'SoftLayer::Account')

Objects are then created and used like normal Ruby objects:

account = SoftLayer::Account.new(:user => AUTH_USER, :key => AUTH_KEY, :initParam => ACCT_ID)
puts account.getBalance

The object's associated Type is available like a Hash:

puts account['email']

Object Masks:

account.objectMask = { 'allBillingItems' => nil }
pp account['allBillingItems']


API user and key is cached after first use (but can be overridden on a per object basis):

SLAPISERVICES = [ 'SoftLayer_Account', 'SoftLayer_Billing_Item', 'SoftLayer_Network_Storage' ]
SoftLayer::declareClasses(:soap => SLAPISERVICES)

account = SoftLayer::Account.new(:user => AUTH_USER, :key => AUTH_KEY, :initParam => ACCT_ID)
account.objectMask={ 'allBillingItems' => nil, 'nasNetworkStorage' => nil }
account['allBillingItems'].each do |bi|
	billingItem = SoftLayer::Billing::Item.new(:initParam => bi['id'])
	pp billingItem.getLocation['longName']
end

account['nasNetworkStorage'].each do |n|
	nas = SoftLayer::Network::Storage.new(:user => OTHER_AUTH_USER, :key => OTHER_AUTH_KEY, :initParam => n['id'])
	pp nas.capacityGb
end

Result Limits:

account.getAllBillingItems(:limit => [X,Y]) do |bia|
	( blah )
end

Such that bia is an array containing X or fewer elements; blah executes on each batch until there's no more.  

Without a block, should return the 5 elements offset from Y:

bia = account.getAllBillingItems(:limit => [5,Y])
bia.size <= 5