Class: RsUserPolicy::RightApi::MultiClient
- Inherits:
-
Object
- Object
- RsUserPolicy::RightApi::MultiClient
- Defined in:
- lib/rs_user_policy/right_api/multi_client.rb
Instance Attribute Summary collapse
-
#accounts ⇒ Object
Returns the value of attribute accounts.
Instance Method Summary collapse
- #[](account_id) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(email, password, accounts) ⇒ MultiClient
constructor
Creates RightApi::Client instances for each account ID supplied.
- #length ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(email, password, accounts) ⇒ MultiClient
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.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# 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. =~ /enterprise/ || e. =~ /Permission denied/ end @accounts[account_id] = this_account end end |
Instance Attribute Details
#accounts ⇒ Object
Returns the value of attribute accounts.
26 27 28 |
# File 'lib/rs_user_policy/right_api/multi_client.rb', line 26 def accounts @accounts end |
Instance Method Details
#[](account_id) ⇒ Object
82 83 84 |
# File 'lib/rs_user_policy/right_api/multi_client.rb', line 82 def [](account_id) @accounts[account_id] end |
#each(&block) ⇒ Object
86 87 88 89 90 |
# 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 ⇒ Object
74 75 76 |
# File 'lib/rs_user_policy/right_api/multi_client.rb', line 74 def length @accounts.length end |
#size ⇒ Object
78 79 80 |
# File 'lib/rs_user_policy/right_api/multi_client.rb', line 78 def size length end |