class RsUserPolicy::RightApi::MultiClient
Attributes
accounts[RW]
Public Class Methods
new(email, password, accounts)
click to toggle source
Creates RightApi::Client instances for each account ID supplied. If any supplied account ID is an enterprise master account, the child accounts are found and added to this MultiClient
as well.
@param [String] email Email address of a RightScale user with permissions to access the API @param [String] password Password of a RightScale user with permissions to access the API @param [Array<Integer>] accounts List of accounts for which to create RightApi::Client objects
# File lib/rs_user_policy/right_api/multi_client.rb, line 35 def initialize(email, password, accounts) @accounts ||= {} accounts.each do |account_id| client = ::RightApi::Client.new( :email => email, :password => password, :account_id => account_id ) this_account = { :client => client, :has_children => false, :resource => client.accounts(:id => account_id).show() } begin child_accounts = client.child_accounts.index this_account[:has_children] = true # NOTE: Assuming that children can not have grand children child_accounts.each do |child_account_res| # TODO: Looser coupling to the Utilities class here? child_account_id = RsUserPolicy::Utilities.id_from_href(child_account_res.href).to_i child_account = ::RightApi::Client.new( :email => email, :password => password, :account_id => child_account_id ) @accounts[child_account_id] = { :client => child_account, :has_children => false, :parent => account_id, :resource => child_account_res } end rescue ::RightApi::ApiError => e raise e unless e.message =~ /enterprise/ || e.message =~ /Permission denied/ end @accounts[account_id] = this_account end end
Public Instance Methods
[](account_id)
click to toggle source
# File lib/rs_user_policy/right_api/multi_client.rb, line 82 def [](account_id) @accounts[account_id] end
each() { |account_id, account| ... }
click to toggle source
# File lib/rs_user_policy/right_api/multi_client.rb, line 86 def each(&block) @accounts.each do |account_id,account| yield account_id, account end end
length()
click to toggle source
# File lib/rs_user_policy/right_api/multi_client.rb, line 74 def length @accounts.length end
size()
click to toggle source
# File lib/rs_user_policy/right_api/multi_client.rb, line 78 def size length end