Class: AdvancedBilling::ApplyDebitNoteEvent

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

Overview

ApplyDebitNoteEvent Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(id:, timestamp:, invoice:, event_type: InvoiceEventType::APPLY_DEBIT_NOTE, event_data:, additional_properties: {}) ⇒ ApplyDebitNoteEvent

Returns a new instance of ApplyDebitNoteEvent.



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

def initialize(id:, timestamp:, invoice:,
               event_type: InvoiceEventType::APPLY_DEBIT_NOTE, event_data:,
               additional_properties: {})
  @id = id
  @timestamp = timestamp
  @invoice = invoice
  @event_type = event_type
  @event_data = event_data

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

Instance Attribute Details

#event_dataApplyDebitNoteEventData

Example schema for an ‘apply_debit_note` event



31
32
33
# File 'lib/advanced_billing/models/apply_debit_note_event.rb', line 31

def event_data
  @event_data
end

#event_typeInvoiceEventType

TODO: Write general description for this method

Returns:



27
28
29
# File 'lib/advanced_billing/models/apply_debit_note_event.rb', line 27

def event_type
  @event_type
end

#idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


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

def id
  @id
end

#invoiceInvoice

TODO: Write general description for this method

Returns:



23
24
25
# File 'lib/advanced_billing/models/apply_debit_note_event.rb', line 23

def invoice
  @invoice
end

#timestampDateTime

TODO: Write general description for this method

Returns:

  • (DateTime)


19
20
21
# File 'lib/advanced_billing/models/apply_debit_note_event.rb', line 19

def timestamp
  @timestamp
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/advanced_billing/models/apply_debit_note_event.rb', line 70

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  id = hash.key?('id') ? hash['id'] : nil
  timestamp = if hash.key?('timestamp')
                (DateTimeHelper.from_rfc3339(hash['timestamp']) if hash['timestamp'])
              end
  invoice = Invoice.from_hash(hash['invoice']) if hash['invoice']
  event_type = hash['event_type'] ||= InvoiceEventType::APPLY_DEBIT_NOTE
  event_data = ApplyDebitNoteEventData.from_hash(hash['event_data']) if hash['event_data']

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

  # Create object from extracted values.
  ApplyDebitNoteEvent.new(id: id,
                          timestamp: timestamp,
                          invoice: invoice,
                          event_type: event_type,
                          event_data: event_data,
                          additional_properties: hash)
end

.namesObject

A mapping from model property names to API property names.



34
35
36
37
38
39
40
41
42
# File 'lib/advanced_billing/models/apply_debit_note_event.rb', line 34

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['id'] = 'id'
  @_hash['timestamp'] = 'timestamp'
  @_hash['invoice'] = 'invoice'
  @_hash['event_type'] = 'event_type'
  @_hash['event_data'] = 'event_data'
  @_hash
end

.nullablesObject

An array for nullable fields



50
51
52
# File 'lib/advanced_billing/models/apply_debit_note_event.rb', line 50

def self.nullables
  []
end

.optionalsObject

An array for optional fields



45
46
47
# File 'lib/advanced_billing/models/apply_debit_note_event.rb', line 45

def self.optionals
  []
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/advanced_billing/models/apply_debit_note_event.rb', line 100

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.id,
                            ->(val) { val.instance_of? Integer }) and
        APIHelper.valid_type?(value.timestamp,
                              ->(val) { val.instance_of? DateTime }) and
        APIHelper.valid_type?(value.invoice,
                              ->(val) { Invoice.validate(val) },
                              is_model_hash: true) and
        APIHelper.valid_type?(value.event_type,
                              ->(val) { InvoiceEventType.validate(val) }) and
        APIHelper.valid_type?(value.event_data,
                              ->(val) { ApplyDebitNoteEventData.validate(val) },
                              is_model_hash: true)
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['id'],
                          ->(val) { val.instance_of? Integer }) and
      APIHelper.valid_type?(value['timestamp'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['invoice'],
                            ->(val) { Invoice.validate(val) },
                            is_model_hash: true) and
      APIHelper.valid_type?(value['event_type'],
                            ->(val) { InvoiceEventType.validate(val) }) and
      APIHelper.valid_type?(value['event_data'],
                            ->(val) { ApplyDebitNoteEventData.validate(val) },
                            is_model_hash: true)
  )
end

Instance Method Details

#to_custom_timestampObject



94
95
96
# File 'lib/advanced_billing/models/apply_debit_note_event.rb', line 94

def to_custom_timestamp
  DateTimeHelper.to_rfc3339(timestamp)
end