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::INSTANCE::Actions, VPC::INSTANCE::FloatingIps, VPC::INSTANCE::NetworkInterfaces, VPC::INSTANCE::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.
-
#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.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ibm/cloud/sdk/vpc/base_collection.rb', line 16 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 (class << self; include ChildMixin; end) if child_class super(parent, endpoint) end |
Instance Method Details
#all ⇒ Enumerator
Get an iterable for the resource collection.
54 55 56 |
# File 'lib/ibm/cloud/sdk/vpc/base_collection.rb', line 54 def all each_resource(url) end |
#count ⇒ Integer
Get the total count if it exists in the response. Returns nil otherwise.
72 73 74 |
# File 'lib/ibm/cloud/sdk/vpc/base_collection.rb', line 72 def count fetch.json&.fetch(:total_count, nil) end |
#create(payload, payload_type = 'json') ⇒ IBM::Cloud::SDK::VPC::Response
A generic post method to create a resource on the collection.
80 81 82 |
# File 'lib/ibm/cloud/sdk/vpc/base_collection.rb', line 80 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.
60 61 62 |
# File 'lib/ibm/cloud/sdk/vpc/base_collection.rb', line 60 def data all.to_a end |
#fetch ⇒ IBM::Cloud::SDK::VPC::Response
Retrieve the collection from the cloud.
48 49 50 |
# File 'lib/ibm/cloud/sdk/vpc/base_collection.rb', line 48 def fetch @data ||= get(params: @params) end |
#has_count? ⇒ Boolean
Determine if the collection has a total_count key in its response.
66 67 68 |
# File 'lib/ibm/cloud/sdk/vpc/base_collection.rb', line 66 def has_count? fetch.json&.key?(:total_count) end |
#params(start: nil, limit: nil, resource_group: nil) ⇒ BaseCollection
A chainable method to set query filters on the collection.
38 39 40 41 42 43 44 |
# File 'lib/ibm/cloud/sdk/vpc/base_collection.rb', line 38 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 |