Class: IBM::Cloud::SDK::BaseCollection
- Defined in:
- lib/ibm/cloud/sdk/vpc/base_collection.rb
Overview
Container that encapsulates the VPC API.
Direct Known Subclasses
VPC::FloatingIPs, VPC::FlowLogCollectors, VPC::IKEPolicies, VPC::INSTANCES::Actions, VPC::INSTANCES::FloatingIps, VPC::INSTANCES::NetworkInterfaces, VPC::INSTANCES::VolumeAttachments, VPC::IPSecPolicies, VPC::Images, VPC::InstanceProfiles, VPC::Instances, VPC::Keys, VPC::LOADBALANCER::Listeners, VPC::LOADBALANCER::Policies, VPC::LOADBALANCER::Rules, VPC::LoadBalancers, VPC::Members, VPC::NETWORKACL::Rules, VPC::NetworkACLs, VPC::OperatingSystems, VPC::Pools, VPC::PublicGateways, VPC::Regions, VPC::SECURITYGROUP::NetworkInterfaces, VPC::SECURITYGROUP::Rules, VPC::SecurityGroup, VPC::SecurityGroups, VPC::Subnets, VPC::VPCS::AddressPrefixes, VPC::VPCS::Routes, VPC::VPNGATEWAY::Connections, VPC::VPNGATEWAY::LocalCIDRs, VPC::VPNGATEWAY::PeerCIDRs, VPC::VPNGateways, VPC::VolumeProfiles, VPC::Volumes, VPC::Vpcs, VPC::Zones
Instance Attribute Summary
Attributes inherited from BaseVPC
#connection, #endpoint, #logger
Instance Method Summary collapse
-
#all ⇒ Enumerator
Get an iterable for the resource collection.
-
#count ⇒ Integer
Get the total count if it exists in the response.
-
#create(payload, payload_type = 'json') ⇒ IBM::Cloud::SDK::VPC::Response
A generic post method to create a resource on the collection.
-
#data ⇒ Array
Fetch all data and return in an array.
-
#fetch ⇒ IBM::Cloud::SDK::VPC::Response
Retrieve the collection from the cloud.
-
#has_count? ⇒ Boolean
Determine if the collection has a total_count key in its response.
-
#initialize(parent, endpoint, array_key: nil, child_class: nil) ⇒ BaseCollection
constructor
This class is used as a base for collection APIs.
-
#instance(id) ⇒ Object
Access a specific instance by either id or name depending on API.
-
#params(start: nil, limit: nil, resource_group: nil) ⇒ BaseCollection
A chainable method to set query filters on the collection.
Methods inherited from BaseVPC
#adhoc, #delete, #get, #patch, #post, #put, #url
Constructor Details
#initialize(parent, endpoint, array_key: nil, child_class: nil) ⇒ BaseCollection
This class is used as a base for collection APIs.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ibm/cloud/sdk/vpc/base_collection.rb', line 14 def initialize(parent, endpoint, array_key: nil, child_class: nil) # Setup empty base instance variables. @params = nil array_key ||= endpoint # Set the array key and child class. @array_key ||= array_key @instance ||= child_class super(parent, endpoint) end |
Instance Method Details
#all ⇒ Enumerator
Get an iterable for the resource collection.
50 51 52 |
# File 'lib/ibm/cloud/sdk/vpc/base_collection.rb', line 50 def all each_resource(url) end |
#count ⇒ Integer
Get the total count if it exists in the response. Returns nil otherwise.
68 69 70 |
# File 'lib/ibm/cloud/sdk/vpc/base_collection.rb', line 68 def count fetch.json&.fetch(:total_count) end |
#create(payload, payload_type = 'json') ⇒ IBM::Cloud::SDK::VPC::Response
A generic post method to create a resource on the collection.
76 77 78 |
# File 'lib/ibm/cloud/sdk/vpc/base_collection.rb', line 76 def create(payload, payload_type = 'json') adhoc(method: 'post', payload_type: payload_type, payload: payload) end |
#data ⇒ Array
Fetch all data and return in an array.
56 57 58 |
# File 'lib/ibm/cloud/sdk/vpc/base_collection.rb', line 56 def data all.to_a end |
#fetch ⇒ IBM::Cloud::SDK::VPC::Response
Retrieve the collection from the cloud.
44 45 46 |
# File 'lib/ibm/cloud/sdk/vpc/base_collection.rb', line 44 def fetch @data ||= get(params: @params) end |
#has_count? ⇒ Boolean
Determine if the collection has a total_count key in its response.
62 63 64 |
# File 'lib/ibm/cloud/sdk/vpc/base_collection.rb', line 62 def has_count? fetch.json&.key?(:total_count) end |
#instance(id) ⇒ Object
Access a specific instance by either id or name depending on API.
81 82 83 |
# File 'lib/ibm/cloud/sdk/vpc/base_collection.rb', line 81 def instance(id) @instance.new(self, id) end |
#params(start: nil, limit: nil, resource_group: nil) ⇒ BaseCollection
A chainable method to set query filters on the collection.
34 35 36 37 38 39 40 |
# File 'lib/ibm/cloud/sdk/vpc/base_collection.rb', line 34 def params(start: nil, limit: nil, resource_group: nil) @params = {} @params[:start] = start if start @params[:limit] = limit if limit @params[:resource_group] = resource_group if resource_group self end |