Module: KillBillClient::Model::TagHelper

Included in:
Account, Bundle, Invoice, InvoiceItem, InvoicePayment, Payment, Subscription
Defined in:
lib/killbill_client/models/helpers/tag_helper.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

AUTO_PAY_OFF_ID =
'00000000-0000-0000-0000-000000000001'
AUTO_INVOICING_OFF_ID =
'00000000-0000-0000-0000-000000000002'
OVERDUE_ENFORCEMENT_OFF_ID =
'00000000-0000-0000-0000-000000000003'
WRITTEN_OFF_ID =
'00000000-0000-0000-0000-000000000004'
MANUAL_PAY_ID =
'00000000-0000-0000-0000-000000000005'
TEST_ID =
'00000000-0000-0000-0000-000000000006'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



118
119
120
# File 'lib/killbill_client/models/helpers/tag_helper.rb', line 118

def self.included(klass)
  klass.extend ClassMethods
end

Instance Method Details

#add_tag(tag_name, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/killbill_client/models/helpers/tag_helper.rb', line 12

def add_tag(tag_name, user = nil, reason = nil, comment = nil, options = {})
  tag_definition = TagDefinition.find_by_name(tag_name, 'NONE', options)
  if tag_definition.nil?
    tag_definition             = TagDefinition.new
    tag_definition.name        = tag_name
    tag_definition.description = 'TagDefinition automatically created by the Kill Bill Ruby client library'
    tag_definition             = TagDefinition.create(user, options)
  end

  add_tag_from_definition_id(tag_definition.id, user, reason, comment, options)
end

#add_tag_from_definition_id(tag_definition_id, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object



45
46
47
# File 'lib/killbill_client/models/helpers/tag_helper.rb', line 45

def add_tag_from_definition_id(tag_definition_id, user = nil, reason = nil, comment = nil, options = {})
  add_tags_from_definition_ids([tag_definition_id], user, reason, comment, options)
end

#control_tag?(control_tag_definition_id, options) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
56
57
# File 'lib/killbill_client/models/helpers/tag_helper.rb', line 53

def control_tag?(control_tag_definition_id, options)
  tags(false, 'NONE', options).any? do |t|
    t.tag_definition_id == control_tag_definition_id
  end
end

#remove_tag(tag_name, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object



24
25
26
27
28
29
# File 'lib/killbill_client/models/helpers/tag_helper.rb', line 24

def remove_tag(tag_name, user = nil, reason = nil, comment = nil, options = {})
  tag_definition = TagDefinition.find_by_name(tag_name, 'NONE', options)
  return nil if tag_definition.nil?

  remove_tag_from_definition_id(tag_definition.id, user, reason, comment, options)
end

#remove_tag_from_definition_id(tag_definition_id, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object



49
50
51
# File 'lib/killbill_client/models/helpers/tag_helper.rb', line 49

def remove_tag_from_definition_id(tag_definition_id, user = nil, reason = nil, comment = nil, options = {})
  remove_tags_from_definition_ids([tag_definition_id], user, reason, comment, options)
end

#set_tags(tag_definition_ids, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/killbill_client/models/helpers/tag_helper.rb', line 31

def set_tags(tag_definition_ids, user = nil, reason = nil, comment = nil, options = {})
  begin
    current_tag_definition_ids = tags(false, 'NONE', options).map { |tag| tag.tag_definition_id }
  rescue KillBillClient::API::NotFound
    current_tag_definition_ids = []
  end

  tags_to_remove = current_tag_definition_ids - tag_definition_ids
  tags_to_add = tag_definition_ids - current_tag_definition_ids

  remove_tags_from_definition_ids(tags_to_remove.uniq, user, reason, comment, options) unless tags_to_remove.empty?
  add_tags_from_definition_ids(tags_to_add.uniq, user, reason, comment, options) unless tags_to_add.empty?
end