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 = nil, billing = SKIP) ⇒ GroupSettings

Returns a new instance of GroupSettings.



42
43
44
45
# File 'lib/advanced_billing/models/group_settings.rb', line 42

def initialize(target = nil, billing = SKIP)
  @target = target
  @billing = billing unless billing == SKIP
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.



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/advanced_billing/models/group_settings.rb', line 48

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']

  # Create object from extracted values.
  GroupSettings.new(target,
                    billing)
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.



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/advanced_billing/models/group_settings.rb', line 62

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