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) ⇒ Movement

Returns a new instance of Movement.



83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/advanced_billing/models/movement.rb', line 83

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)
  @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
end

Instance Attribute Details

#amount_formattedString

TODO: Write general description for this method

Returns:

  • (String)


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

def amount_formatted
  @amount_formatted
end

#amount_in_centsInteger

TODO: Write general description for this method

Returns:

  • (Integer)


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

def amount_in_cents
  @amount_in_cents
end

#breakoutsBreakouts

TODO: Write general description for this method

Returns:



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

def breakouts
  @breakouts
end

#categoryString

TODO: Write general description for this method

Returns:

  • (String)


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

def category
  @category
end

#descriptionString

TODO: Write general description for this method

Returns:

  • (String)


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

def description
  @description
end

#line_itemsArray[MovementLineItem]

TODO: Write general description for this method

Returns:



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

def line_items
  @line_items
end

#subscriber_nameString

TODO: Write general description for this method

Returns:

  • (String)


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

def subscriber_name
  @subscriber_name
end

#subscription_idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


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

def subscription_id
  @subscription_id
end

#timestampString

TODO: Write general description for this method

Returns:

  • (String)


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

def timestamp
  @timestamp
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



99
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
135
136
# File 'lib/advanced_billing/models/movement.rb', line 99

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.

  timestamp = hash.key?('timestamp') ? hash['timestamp'] : SKIP
  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

  # Create object from extracted values.

  Movement.new(timestamp,
               amount_in_cents,
               amount_formatted,
               description,
               category,
               breakouts,
               line_items,
               subscription_id,
               subscriber_name)
end

.namesObject

A mapping from model property names to API property names.



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

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



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

def self.nullables
  []
end

.optionalsObject

An array for optional fields



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

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