Class: AdvancedBilling::GroupSettings

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

Overview

GroupSettings Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(target:, billing: SKIP, additional_properties: {}) ⇒ GroupSettings

Returns a new instance of GroupSettings.



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

def initialize(target:, billing: SKIP, additional_properties: {})
  @target = target
  @billing = billing unless billing == SKIP

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

Instance Attribute Details

#billingGroupBilling

Optional attributes related to billing date and accrual. Note: Only applicable for new subscriptions.

Returns:



20
21
22
# File 'lib/advanced_billing/models/group_settings.rb', line 20

def billing
  @billing
end

#targetGroupTarget

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

Returns:



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

def target
  @target
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  target = GroupTarget.from_hash(hash['target']) if hash['target']
  billing = GroupBilling.from_hash(hash['billing']) if hash['billing']

  # Clean out expected properties from Hash.
  names.each_value { |k| hash.delete(k) }

  # Create object from extracted values.
  GroupSettings.new(target: target,
                    billing: billing,
                    additional_properties: hash)
end

.namesObject

A mapping from model property names to API property names.



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

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

.nullablesObject

An array for nullable fields



38
39
40
# File 'lib/advanced_billing/models/group_settings.rb', line 38

def self.nullables
  []
end

.optionalsObject

An array for optional fields



31
32
33
34
35
# File 'lib/advanced_billing/models/group_settings.rb', line 31

def self.optionals
  %w[
    billing
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (GroupSettings | Hash)

    value against the validation is performed.



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

def self.validate(value)
  if value.instance_of? self
    return APIHelper.valid_type?(value.target,
                                 ->(val) { GroupTarget.validate(val) },
                                 is_model_hash: true)
  end

  return false unless value.instance_of? Hash

  APIHelper.valid_type?(value['target'],
                        ->(val) { GroupTarget.validate(val) },
                        is_model_hash: true)
end