Class: IBM::Cloud::SDK::TAG::TagCollection

Inherits:
IBM::Cloud::SDKHTTP::BaseCollection show all
Defined in:
lib/ibm/cloud/sdk/tags/http/tag_collection.rb

Overview

The Base Collection for the Tags API.

Direct Known Subclasses

IBM::Cloud::SDK::Tags

Instance Attribute Summary

Attributes inherited from IBM::Cloud::SDKHTTP::BaseCollection

#connection, #endpoint, #logger, #token

Attributes included from IBM::Cloud::SDKHTTP::BaseHTTPMixin

#endpoint

Instance Method Summary collapse

Methods inherited from IBM::Cloud::SDKHTTP::BaseCollection

#all, #create, #data, #fetch, #initialize

Methods included from IBM::Cloud::SDKHTTP::BaseHTTPMixin

#adhoc, #delete, #get, #metadata, #patch, #post, #put, #unchecked_response, #url

Constructor Details

This class inherits a constructor from IBM::Cloud::SDKHTTP::BaseCollection

Instance Method Details

#attached_to(crn) ⇒ Object

Get all tags attached to a CRN.



64
65
66
67
68
# File 'lib/ibm/cloud/sdk/tags/http/tag_collection.rb', line 64

def attached_to(crn)
  return [] if crn.to_s.empty?

  params(attached_to: crn).all
end

#params(account_id: nil, tag_type: nil, full_data: false, providers: nil, attached_to: nil, offset: 0, limit: 100, timeout: nil, order_by_name: 'asc', attached_only: false) ⇒ Object

Set params on the next request.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ibm/cloud/sdk/tags/http/tag_collection.rb', line 25

def params(
  account_id: nil,
  tag_type: nil,
  full_data: false,
  providers: nil,
  attached_to: nil,
  offset: 0,
  limit: 100,
  timeout: nil,
  order_by_name: 'asc',
  attached_only: false
)
  @params ||= {}
  @params[:account_id] =  if 
  @params[:tag_type] = tag_type if tag_type && %w[user service].include?(tag_type)
  @params[:full_data] = full_data if full_data.instance_of?(TrueClass)
  @params[:providers] = providers if providers && %w[ghost ims].include?(providers)
  @params[:attached_to] = attached_to if attached_to
  @params[:offset] = offset if offset.positive?
  @params[:limit] = limit if limit && (1..1000).include?(limit) && limit != 100
  @params[:timeout] = timeout if timeout
  @params[:order_by_name] = order_by_name if order_by_name && %w[desc].include?(order_by_name)
  @params[:attached_only] = attached_only if attached_only.instance_of?(TrueClass)
  self
end

#reset_paramsObject

rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Layout/LineLength



52
53
54
# File 'lib/ibm/cloud/sdk/tags/http/tag_collection.rb', line 52

def reset_params
  @params = {}
end

#total_countInteger

Return the total count as retrieved from the API.



58
59
60
# File 'lib/ibm/cloud/sdk/tags/http/tag_collection.rb', line 58

def total_count
  fetch.json.[](:total_count)
end