Class: AdvancedBilling::GroupTarget

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/advanced_billing/models/group_target.rb

Overview

Attributes of the target customer who will be the responsible payer of the created subscription. Required.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #get_additional_properties, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(type:, id: SKIP, additional_properties: {}) ⇒ GroupTarget

Returns a new instance of GroupTarget.



43
44
45
46
47
48
49
50
51
# File 'lib/advanced_billing/models/group_target.rb', line 43

def initialize(type:, id: SKIP, additional_properties: {})
  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end

  @type = type
  @id = id unless id == SKIP
end

Instance Attribute Details

#idInteger

The id of the target customer or subscription to group the existing subscription with. Ignored and should not be included if type is “self” , “parent”, or “eldest”

Returns:

  • (Integer)


21
22
23
# File 'lib/advanced_billing/models/group_target.rb', line 21

def id
  @id
end

#typeGroupTargetType

The type of object indicated by the id attribute.

Returns:



15
16
17
# File 'lib/advanced_billing/models/group_target.rb', line 15

def type
  @type
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/advanced_billing/models/group_target.rb', line 54

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  type = hash.key?('type') ? hash['type'] : nil
  id = hash.key?('id') ? hash['id'] : SKIP

  # Clean out expected properties from Hash.
  additional_properties = hash.reject { |k, _| names.value?(k) }

  # Create object from extracted values.
  GroupTarget.new(type: type,
                  id: id,
                  additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



24
25
26
27
28
29
# File 'lib/advanced_billing/models/group_target.rb', line 24

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['type'] = 'type'
  @_hash['id'] = 'id'
  @_hash
end

.nullablesObject

An array for nullable fields



39
40
41
# File 'lib/advanced_billing/models/group_target.rb', line 39

def self.nullables
  []
end

.optionalsObject

An array for optional fields



32
33
34
35
36
# File 'lib/advanced_billing/models/group_target.rb', line 32

def self.optionals
  %w[
    id
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (GroupTarget | Hash)

    value against the validation is performed.



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/advanced_billing/models/group_target.rb', line 72

def self.validate(value)
  if value.instance_of? self
    return APIHelper.valid_type?(value.type,
                                 ->(val) { GroupTargetType.validate(val) })
  end

  return false unless value.instance_of? Hash

  APIHelper.valid_type?(value['type'],
                        ->(val) { GroupTargetType.validate(val) })
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



92
93
94
95
96
# File 'lib/advanced_billing/models/group_target.rb', line 92

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} type: #{@type.inspect}, id: #{@id.inspect}, additional_properties:"\
  " #{get_additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



85
86
87
88
89
# File 'lib/advanced_billing/models/group_target.rb', line 85

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} type: #{@type}, id: #{@id}, additional_properties:"\
  " #{get_additional_properties}>"
end