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

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(pricing_scheme:, segment_property_1_value: SKIP, segment_property_2_value: SKIP, segment_property_3_value: SKIP, segment_property_4_value: SKIP, prices: SKIP, additional_properties: {}) ⇒ CreateSegment

Returns a new instance of CreateSegment.



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/advanced_billing/models/create_segment.rb', line 76

def initialize(pricing_scheme:, segment_property_1_value: SKIP,
               segment_property_2_value: SKIP,
               segment_property_3_value: SKIP,
               segment_property_4_value: SKIP, prices: SKIP,
               additional_properties: {})
  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end

  @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 identifier for the pricing scheme. See [Product Components](help.chargify.com/products/product-components.html) for an overview of pricing schemes.

Returns:



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

def prices
  @prices
end

#pricing_schemePricingScheme

The identifier for the pricing scheme. See [Product Components](help.chargify.com/products/product-components.html) for an overview of pricing schemes.

Returns:



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

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.

Returns:

  • (Object)


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.

Returns:

  • (Object)


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.

Returns:

  • (Object)


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.

Returns:

  • (Object)


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.



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
128
129
130
131
132
133
134
135
# File 'lib/advanced_billing/models/create_segment.rb', line 95

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')

  # Clean out expected properties from Hash.
  additional_properties = hash.reject { |k, _| names.value?(k) }

  # Create object from extracted values.
  CreateSegment.new(pricing_scheme: pricing_scheme,
                    segment_property_1_value: segment_property_1_value,
                    segment_property_2_value: segment_property_2_value,
                    segment_property_3_value: segment_property_3_value,
                    segment_property_4_value: segment_property_4_value,
                    prices: prices,
                    additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



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

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



72
73
74
# File 'lib/advanced_billing/models/create_segment.rb', line 72

def self.nullables
  []
end

.optionalsObject

An array for optional fields



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

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.

Parameters:

  • The (CreateSegment | Hash)

    value against the validation is performed.



139
140
141
142
143
144
145
146
147
148
149
# File 'lib/advanced_billing/models/create_segment.rb', line 139

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

  return false unless value.instance_of? Hash

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