Class: AdvancedBilling::CreateSegment

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

Overview

CreateSegment Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(pricing_scheme = nil, segment_property_1_value = SKIP, segment_property_2_value = SKIP, segment_property_3_value = SKIP, segment_property_4_value = SKIP, prices = SKIP) ⇒ CreateSegment



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/advanced_billing/models/create_segment.rb', line 78

def initialize(pricing_scheme = nil, segment_property_1_value = SKIP,
               segment_property_2_value = SKIP,
               segment_property_3_value = SKIP,
               segment_property_4_value = SKIP, prices = SKIP)
  @segment_property_1_value = segment_property_1_value unless segment_property_1_value == SKIP
  @segment_property_2_value = segment_property_2_value unless segment_property_2_value == SKIP
  @segment_property_3_value = segment_property_3_value unless segment_property_3_value == SKIP
  @segment_property_4_value = segment_property_4_value unless segment_property_4_value == SKIP
  @pricing_scheme = pricing_scheme
  @prices = prices unless prices == SKIP
end

Instance Attribute Details

#pricesArray[CreateOrUpdateSegmentPrice]

The handle for the pricing scheme. Available options: per_unit, volume, tiered, stairstep. See [Price Bracket Rules](help.chargify.com/products/product-components.html#price-br acket-rules) for an overview of pricing schemes.



48
49
50
# File 'lib/advanced_billing/models/create_segment.rb', line 48

def prices
  @prices
end

#pricing_schemeString

The handle for the pricing scheme. Available options: per_unit, volume, tiered, stairstep. See [Price Bracket Rules](help.chargify.com/products/product-components.html#price-br acket-rules) for an overview of pricing schemes.



41
42
43
# File 'lib/advanced_billing/models/create_segment.rb', line 41

def pricing_scheme
  @pricing_scheme
end

#segment_property_1_valueObject

A value that will occur in your events that you want to bill upon. The type of the value depends on the property type in the related event based billing metric.



16
17
18
# File 'lib/advanced_billing/models/create_segment.rb', line 16

def segment_property_1_value
  @segment_property_1_value
end

#segment_property_2_valueObject

A value that will occur in your events that you want to bill upon. The type of the value depends on the property type in the related event based billing metric.



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

def segment_property_2_value
  @segment_property_2_value
end

#segment_property_3_valueObject

A value that will occur in your events that you want to bill upon. The type of the value depends on the property type in the related event based billing metric.



28
29
30
# File 'lib/advanced_billing/models/create_segment.rb', line 28

def segment_property_3_value
  @segment_property_3_value
end

#segment_property_4_valueObject

A value that will occur in your events that you want to bill upon. The type of the value depends on the property type in the related event based billing metric.



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

def segment_property_4_value
  @segment_property_4_value
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



91
92
93
94
95
96
97
98
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
# File 'lib/advanced_billing/models/create_segment.rb', line 91

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.

  pricing_scheme =
    hash.key?('pricing_scheme') ? hash['pricing_scheme'] : nil
  segment_property_1_value = hash.key?('segment_property_1_value') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:CreateSegmentSegmentProperty1Value), hash['segment_property_1_value']
  ) : SKIP
  segment_property_2_value = hash.key?('segment_property_2_value') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:CreateSegmentSegmentProperty2Value), hash['segment_property_2_value']
  ) : SKIP
  segment_property_3_value = hash.key?('segment_property_3_value') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:CreateSegmentSegmentProperty3Value), hash['segment_property_3_value']
  ) : SKIP
  segment_property_4_value = hash.key?('segment_property_4_value') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:CreateSegmentSegmentProperty4Value), hash['segment_property_4_value']
  ) : SKIP
  # Parameter is an array, so we need to iterate through it

  prices = nil
  unless hash['prices'].nil?
    prices = []
    hash['prices'].each do |structure|
      prices << (CreateOrUpdateSegmentPrice.from_hash(structure) if structure)
    end
  end

  prices = SKIP unless hash.key?('prices')

  # Create object from extracted values.

  CreateSegment.new(pricing_scheme,
                    segment_property_1_value,
                    segment_property_2_value,
                    segment_property_3_value,
                    segment_property_4_value,
                    prices)
end

.namesObject

A mapping from model property names to API property names.



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

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['segment_property_1_value'] = 'segment_property_1_value'
  @_hash['segment_property_2_value'] = 'segment_property_2_value'
  @_hash['segment_property_3_value'] = 'segment_property_3_value'
  @_hash['segment_property_4_value'] = 'segment_property_4_value'
  @_hash['pricing_scheme'] = 'pricing_scheme'
  @_hash['prices'] = 'prices'
  @_hash
end

.nullablesObject

An array for nullable fields



74
75
76
# File 'lib/advanced_billing/models/create_segment.rb', line 74

def self.nullables
  []
end

.optionalsObject

An array for optional fields



63
64
65
66
67
68
69
70
71
# File 'lib/advanced_billing/models/create_segment.rb', line 63

def self.optionals
  %w[
    segment_property_1_value
    segment_property_2_value
    segment_property_3_value
    segment_property_4_value
    prices
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.



131
132
133
134
135
136
137
138
139
140
141
# File 'lib/advanced_billing/models/create_segment.rb', line 131

def self.validate(value)
  if value.instance_of? self
    return APIHelper.valid_type?(value.pricing_scheme,
                                 ->(val) { val.instance_of? String })
  end

  return false unless value.instance_of? Hash

  APIHelper.valid_type?(value['pricing_scheme'],
                        ->(val) { val.instance_of? String })
end