Class: AdvancedBilling::MovementLineItem

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

Overview

MovementLineItem Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(product_id: SKIP, component_id: SKIP, price_point_id: SKIP, name: SKIP, mrr: SKIP, mrr_movements: SKIP, quantity: SKIP, prev_quantity: SKIP, recurring: SKIP, additional_properties: {}) ⇒ MovementLineItem

Returns a new instance of MovementLineItem.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/advanced_billing/models/movement_line_item.rb', line 91

def initialize(product_id: SKIP, component_id: SKIP, price_point_id: SKIP,
               name: SKIP, mrr: SKIP, mrr_movements: SKIP, quantity: SKIP,
               prev_quantity: SKIP, recurring: SKIP,
               additional_properties: {})
  @product_id = product_id unless product_id == SKIP
  @component_id = component_id unless component_id == SKIP
  @price_point_id = price_point_id unless price_point_id == SKIP
  @name = name unless name == SKIP
  @mrr = mrr unless mrr == SKIP
  @mrr_movements = mrr_movements unless mrr_movements == SKIP
  @quantity = quantity unless quantity == SKIP
  @prev_quantity = prev_quantity unless prev_quantity == SKIP
  @recurring = recurring unless recurring == SKIP

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

Instance Attribute Details

#component_idInteger

For Product (or “baseline”) line items, this field will have a value of ‘0`.

Returns:

  • (Integer)


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

def component_id
  @component_id
end

#mrrInteger

For Product (or “baseline”) line items, this field will have a value of ‘0`.

Returns:

  • (Integer)


34
35
36
# File 'lib/advanced_billing/models/movement_line_item.rb', line 34

def mrr
  @mrr
end

#mrr_movementsArray[MRRMovement]

For Product (or “baseline”) line items, this field will have a value of ‘0`.

Returns:



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

def mrr_movements
  @mrr_movements
end

#nameString

For Product (or “baseline”) line items, this field will have a value of ‘0`.

Returns:

  • (String)


29
30
31
# File 'lib/advanced_billing/models/movement_line_item.rb', line 29

def name
  @name
end

#prev_quantityInteger

For Product (or “baseline”) line items, this field will have a value of ‘0`.

Returns:

  • (Integer)


49
50
51
# File 'lib/advanced_billing/models/movement_line_item.rb', line 49

def prev_quantity
  @prev_quantity
end

#price_point_idInteger

For Product (or “baseline”) line items, this field will have a value of ‘0`.

Returns:

  • (Integer)


24
25
26
# File 'lib/advanced_billing/models/movement_line_item.rb', line 24

def price_point_id
  @price_point_id
end

#product_idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


14
15
16
# File 'lib/advanced_billing/models/movement_line_item.rb', line 14

def product_id
  @product_id
end

#quantityInteger

For Product (or “baseline”) line items, this field will have a value of ‘0`.

Returns:

  • (Integer)


44
45
46
# File 'lib/advanced_billing/models/movement_line_item.rb', line 44

def quantity
  @quantity
end

#recurringTrueClass | FalseClass

When ‘true`, the line item’s MRR value will contribute to the ‘plan` breakout. When `false`, the line item contributes to the `usage` breakout.

Returns:

  • (TrueClass | FalseClass)


54
55
56
# File 'lib/advanced_billing/models/movement_line_item.rb', line 54

def recurring
  @recurring
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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_line_item.rb', line 112

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  product_id = hash.key?('product_id') ? hash['product_id'] : SKIP
  component_id = hash.key?('component_id') ? hash['component_id'] : SKIP
  price_point_id =
    hash.key?('price_point_id') ? hash['price_point_id'] : SKIP
  name = hash.key?('name') ? hash['name'] : SKIP
  mrr = hash.key?('mrr') ? hash['mrr'] : SKIP
  # Parameter is an array, so we need to iterate through it
  mrr_movements = nil
  unless hash['mrr_movements'].nil?
    mrr_movements = []
    hash['mrr_movements'].each do |structure|
      mrr_movements << (MRRMovement.from_hash(structure) if structure)
    end
  end

  mrr_movements = SKIP unless hash.key?('mrr_movements')
  quantity = hash.key?('quantity') ? hash['quantity'] : SKIP
  prev_quantity = hash.key?('prev_quantity') ? hash['prev_quantity'] : SKIP
  recurring = hash.key?('recurring') ? hash['recurring'] : SKIP

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

  # Create object from extracted values.
  MovementLineItem.new(product_id: product_id,
                       component_id: component_id,
                       price_point_id: price_point_id,
                       name: name,
                       mrr: mrr,
                       mrr_movements: mrr_movements,
                       quantity: quantity,
                       prev_quantity: prev_quantity,
                       recurring: recurring,
                       additional_properties: hash)
end

.namesObject

A mapping from model property names to API property names.



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/advanced_billing/models/movement_line_item.rb', line 57

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['product_id'] = 'product_id'
  @_hash['component_id'] = 'component_id'
  @_hash['price_point_id'] = 'price_point_id'
  @_hash['name'] = 'name'
  @_hash['mrr'] = 'mrr'
  @_hash['mrr_movements'] = 'mrr_movements'
  @_hash['quantity'] = 'quantity'
  @_hash['prev_quantity'] = 'prev_quantity'
  @_hash['recurring'] = 'recurring'
  @_hash
end

.nullablesObject

An array for nullable fields



87
88
89
# File 'lib/advanced_billing/models/movement_line_item.rb', line 87

def self.nullables
  []
end

.optionalsObject

An array for optional fields



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

def self.optionals
  %w[
    product_id
    component_id
    price_point_id
    name
    mrr
    mrr_movements
    quantity
    prev_quantity
    recurring
  ]
end