Class: AdvancedBilling::Movement

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

Overview

Movement Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(timestamp: SKIP, amount_in_cents: SKIP, amount_formatted: SKIP, description: SKIP, category: SKIP, breakouts: SKIP, line_items: SKIP, subscription_id: SKIP, subscriber_name: SKIP, additional_properties: {}) ⇒ Movement

Returns a new instance of Movement.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/advanced_billing/models/movement.rb', line 84

def initialize(timestamp: SKIP, amount_in_cents: SKIP,
               amount_formatted: SKIP, description: SKIP, category: SKIP,
               breakouts: SKIP, line_items: SKIP, subscription_id: SKIP,
               subscriber_name: SKIP, additional_properties: {})
  @timestamp = timestamp unless timestamp == SKIP
  @amount_in_cents = amount_in_cents unless amount_in_cents == SKIP
  @amount_formatted = amount_formatted unless amount_formatted == SKIP
  @description = description unless description == SKIP
  @category = category unless category == SKIP
  @breakouts = breakouts unless breakouts == SKIP
  @line_items = line_items unless line_items == SKIP
  @subscription_id = subscription_id unless subscription_id == SKIP
  @subscriber_name = subscriber_name unless subscriber_name == SKIP

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

Instance Attribute Details

#amount_formattedString

TODO: Write general description for this method

Returns:

  • (String)


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

def amount_formatted
  @amount_formatted
end

#amount_in_centsInteger

TODO: Write general description for this method

Returns:

  • (Integer)


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

def amount_in_cents
  @amount_in_cents
end

#breakoutsBreakouts

TODO: Write general description for this method

Returns:



35
36
37
# File 'lib/advanced_billing/models/movement.rb', line 35

def breakouts
  @breakouts
end

#categoryString

TODO: Write general description for this method

Returns:

  • (String)


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

def category
  @category
end

#descriptionString

TODO: Write general description for this method

Returns:

  • (String)


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

def description
  @description
end

#line_itemsArray[MovementLineItem]

TODO: Write general description for this method

Returns:



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

def line_items
  @line_items
end

#subscriber_nameString

TODO: Write general description for this method

Returns:

  • (String)


47
48
49
# File 'lib/advanced_billing/models/movement.rb', line 47

def subscriber_name
  @subscriber_name
end

#subscription_idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


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

def subscription_id
  @subscription_id
end

#timestampDateTime

TODO: Write general description for this method

Returns:

  • (DateTime)


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

def timestamp
  @timestamp
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/advanced_billing/models/movement.rb', line 105

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  timestamp = if hash.key?('timestamp')
                (DateTimeHelper.from_rfc3339(hash['timestamp']) if hash['timestamp'])
              else
                SKIP
              end
  amount_in_cents =
    hash.key?('amount_in_cents') ? hash['amount_in_cents'] : SKIP
  amount_formatted =
    hash.key?('amount_formatted') ? hash['amount_formatted'] : SKIP
  description = hash.key?('description') ? hash['description'] : SKIP
  category = hash.key?('category') ? hash['category'] : SKIP
  breakouts = Breakouts.from_hash(hash['breakouts']) if hash['breakouts']
  # Parameter is an array, so we need to iterate through it
  line_items = nil
  unless hash['line_items'].nil?
    line_items = []
    hash['line_items'].each do |structure|
      line_items << (MovementLineItem.from_hash(structure) if structure)
    end
  end

  line_items = SKIP unless hash.key?('line_items')
  subscription_id =
    hash.key?('subscription_id') ? hash['subscription_id'] : SKIP
  subscriber_name =
    hash.key?('subscriber_name') ? hash['subscriber_name'] : SKIP

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

  # Create object from extracted values.
  Movement.new(timestamp: timestamp,
               amount_in_cents: amount_in_cents,
               amount_formatted: amount_formatted,
               description: description,
               category: category,
               breakouts: breakouts,
               line_items: line_items,
               subscription_id: subscription_id,
               subscriber_name: subscriber_name,
               additional_properties: hash)
end

.namesObject

A mapping from model property names to API property names.



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/advanced_billing/models/movement.rb', line 50

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['timestamp'] = 'timestamp'
  @_hash['amount_in_cents'] = 'amount_in_cents'
  @_hash['amount_formatted'] = 'amount_formatted'
  @_hash['description'] = 'description'
  @_hash['category'] = 'category'
  @_hash['breakouts'] = 'breakouts'
  @_hash['line_items'] = 'line_items'
  @_hash['subscription_id'] = 'subscription_id'
  @_hash['subscriber_name'] = 'subscriber_name'
  @_hash
end

.nullablesObject

An array for nullable fields



80
81
82
# File 'lib/advanced_billing/models/movement.rb', line 80

def self.nullables
  []
end

.optionalsObject

An array for optional fields



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/advanced_billing/models/movement.rb', line 65

def self.optionals
  %w[
    timestamp
    amount_in_cents
    amount_formatted
    description
    category
    breakouts
    line_items
    subscription_id
    subscriber_name
  ]
end

Instance Method Details

#to_custom_timestampObject



152
153
154
# File 'lib/advanced_billing/models/movement.rb', line 152

def to_custom_timestamp
  DateTimeHelper.to_rfc3339(timestamp)
end