Class: ApiReference::BaseModel

Inherits:
CoreLibrary::BaseModel
  • Object
show all
Defined in:
lib/api_reference/models/base_model.rb

Overview

Base model. rubocop:disable all

Direct Known Subclasses

AccountingProvider, AccountingProviderConfig, AccountingSyncConfiguration, AddAdjustmentIntervalParams, AddAmendmentCreditLedgerEntryRequestParams, AddCreditTopUpRequestParams, AddDecrementCreditLedgerEntryRequestParams, AddEditPriceIntervalParams, AddExpirationChangeCreditLedgerEntryRequestParams, AddIncrementCreditLedgerEntryRequestParams, AddPlanAdjustmentParams, AddPlanPriceParams, AddPriceIntervalParams, AddSubscriptionAdjustmentParams, AddSubscriptionPriceParams, AddVoidCreditLedgerEntryRequestParams, Address, AddressInput, AdjustmentInterval, AffectedBlock, AggregatedCost, Alert, Alerts, Allocation, AmendEventResult, AmendedEvent, AmendmentLedgerEntry, AmountDiscount, AmountDiscountCreationParams, AmountDiscountInterval, ApiPaginationParams, ApplyParams, AutoCollection, Backfill, Backfills, BalanceAlertStatus, BillableMetric, BillableMetricMinified, BillableMetricSimple, BillableMetricTiny, BillableMetrics, BillingCycleAnchorConfiguration, BillingCycleConfiguration, BlockPriceFilter, BulkConfig, BulkPrice, BulkTier, BulkTierWithProration, BulkWithFiltersConfig, BulkWithFiltersConfig1, BulkWithFiltersPrice, BulkWithFiltersTier, BulkWithProrationConfig, BulkWithProrationConfig1, BulkWithProrationPrice, CancelSubscriptionParams, ChangedSubscriptionResources, ConstraintViolationError, ConversionRateTier, ConversionRateTieredConfig, ConversionRateUnitConfig, CostsRequestParams, Coupon, CouponQueryParams, CouponRedemption, Coupons, CreateCreditNoteParams, CreateCustomerAlertRequestParams, CreateInvoiceLineItemParams, CreateOneOffInvoiceParams, CreateSubscriptionAlertRequestParams, CreatedInvoice, CreditBlock, CreditBlockAllocation, CreditBlockExpiryLedgerEntry, CreditBlockInvoicesResponse, CreditLedgerEntries, CreditNote, CreditNoteDiscount, CreditNoteDiscountAppliesToPrice, CreditNoteLineItem, CreditNoteLineItemDiscount, CreditNoteLineItemParams, CreditNoteSummary, CreditNoteTiny, CreditNotes, CumulativeGroupedAllocationConfig, CumulativeGroupedAllocationConfig1, CumulativeGroupedAllocationPrice, CumulativeGroupedBulkConfig, CumulativeGroupedBulkConfig1, CumulativeGroupedBulkDimensionValue, CumulativeGroupedBulkPrice, CustomExpiration, Customer, CustomerBalanceTransaction, CustomerBalanceTransactions, CustomerCosts, CustomerCreditBalance, CustomerCreditBalances, CustomerHierarchy, CustomerHierarchy2, CustomerHierarchyConfig, CustomerMinified, CustomerTaxId, Customers, DailyCreditAllowanceConfig, DailyCreditAllowanceConfig1, DailyCreditAllowanceMatrixValue, DailyCreditAllowancePrice, DeactivateLicense, Debug, DecrementLedgerEntry, DeprecatedEventResult, DimensionalPriceConfiguration, DimensionalPriceGroup, DimensionalPriceGroups, DiscountOverride, DuplicateResourceCreationError, EditAdjustmentIntervalParams, EditCustomer, EditDimensionalPriceGroup, EditPlan, EditPriceIntervalParams, EvaluateMultiplePriceResource, EvaluateMultiplePricesBody, EvaluateMultiplePricesWithPreviewEventsBody, EvaluatePriceBody, EvaluatePriceGroup, EvaluatePriceResource, EvaluatePriceResourceForMultiplePrice, Event, EventOutputConfig, EventOutputConfig1, EventOutputPrice, EventSearchCriteria, EventVolume, EventVolumeParams, EventVolumes, Events, ExpirationChangeLedgerEntry, FeatureNotAvailableError, FetchCustomerCreditBlocksQueryParams, FetchCustomerCreditLedgerQueryParams, FetchLicenseByExternalId, FetchSubscriptionScheduleQueryParams, FetchUpcomingInvoiceParams, FilterRule, FixedFeeQuantityChange, FixedFeeQuantityScheduleEntry, FixedFeeQuantityTransition, GroupedAllocationConfig, GroupedAllocationConfig1, GroupedAllocationPrice, GroupedSubscriptionUsage, GroupedSubscriptionUsageRecord, GroupedTieredConfig, GroupedTieredConfig1, GroupedTieredPackagePrice, GroupedTieredPackagePricingConfig, GroupedTieredPackagePricingConfig1, GroupedTieredPackageTierItem, GroupedTieredPrice, GroupedTieredTier, GroupedWithMeteredMinimumConfig, GroupedWithMeteredMinimumConfig1, GroupedWithMeteredMinimumPrice, GroupedWithMeteredMinimumScalingFactorItem, GroupedWithMeteredMinimumUnitAmountItem, GroupedWithMinMaxThresholdsConfig, GroupedWithMinMaxThresholdsConfig1, GroupedWithMinMaxThresholdsPrice, GroupedWithProratedMinimumConfig, GroupedWithProratedMinimumConfig1, GroupedWithProratedMinimumPrice, IncrementCreditLedgerEntryInvoiceSettings, IncrementLedgerEntry, IngestEvent, IngestEventIdempotencyKeyOnly, IngestQueryParams, IngestRequestBody, IngestionResponse, Invoice, InvoiceLineItem, InvoiceLineItemParams, InvoiceMinified, InvoiceSummary, InvoiceSummarys, InvoiceTiny, Invoices, IssueInvoiceRequestParams, Item, ItemExternalConnection, ItemSlim, Items, LicenseApiResource, LicenseApiResources, LicenseType, LicenseTypeMinified, LicenseTypes, LicenseUsage, LicenseUsageByExternalIdQueryParams, LicenseUsageByTypeQueryParams, LicenseUsageQueryParams, LicenseUsages, ListAlertsQueryParams, ListCreditNotesParams, ListCustomerBalanceTransactionsQueryParams, ListCustomersQueryParams, ListInvoicesParams, ListLicensesParams, ListMetricsQueryParams, ListPlansQueryParams, ListSubscriptionChangesQueryParams, ListSubscriptionsQueryParams, MapItemRequestParams, MarkAsPaidRequestParams, MatrixCell, MatrixConfig, MatrixPrice, MatrixSubLineItem, MatrixValue, MatrixWithAllocationConfig, MatrixWithAllocationConfig1, MatrixWithAllocationPrice, MatrixWithAllocationValueItem, MatrixWithDisplayNameConfig, MatrixWithDisplayNameConfig1, MatrixWithDisplayNamePrice, MatrixWithDisplayNameUnitAmountItem, MatrixWithThresholdDiscountsConfig, MatrixWithThresholdDiscountsConfig1, MatrixWithThresholdDiscountsPrice, MaxGroupTieredPackageConfig, MaxGroupTieredPackageConfig1, MaxGroupTieredPackagePrice, MaxGroupTieredTierItem, Maximum, MaximumInterval, MeteredAllowanceConfig, MeteredAllowanceConfig1, MeteredAllowancePrice, MetricGroup, Minimum, MinimumCompositeConfig, MinimumCompositeConfig1, MinimumCompositePrice, MinimumInterval, MonetaryAmountDiscountAdjustment, MonetaryMaximumAdjustment, MonetaryMinimumAdjustment, MonetaryPercentageDiscountAdjustment, MonetaryTieredPercentageDiscountAdjustment, MonetaryUsageDiscountAdjustment, MutatedSubscription, NewAccountingSyncConfiguration, NewAllocationPrice, NewAmountDiscount, NewAnrokConfiguration, NewAvalaraTaxConfiguration, NewBackfill, NewBillableMetric, NewBillingCycleConfiguration, NewCoupon, NewCouponAmountDiscount, NewCouponPercentageDiscount, NewCustomer, NewCustomerBalanceTransaction, NewDimensionalPriceConfiguration, NewDimensionalPriceGroup, NewFloatingBulkPrice, NewFloatingBulkWithFiltersPrice, NewFloatingBulkWithProrationPrice, NewFloatingCumulativeGroupedAllocationPrice, NewFloatingCumulativeGroupedBulkPrice, NewFloatingDailyCreditAllowancePrice, NewFloatingEventOutputPrice, NewFloatingGroupedAllocationPrice, NewFloatingGroupedTieredPackagePrice, NewFloatingGroupedTieredPrice, NewFloatingGroupedWithMeteredMinimumPrice, NewFloatingGroupedWithMinMaxThresholdsPrice, NewFloatingGroupedWithProratedMinimumPrice, NewFloatingMatrixPrice, NewFloatingMatrixWithAllocationPrice, NewFloatingMatrixWithDisplayNamePrice, NewFloatingMatrixWithThresholdDiscountsPrice, NewFloatingMaxGroupTieredPackagePrice, NewFloatingMeteredAllowancePrice, NewFloatingMinimumCompositePrice, NewFloatingPackagePrice, NewFloatingPackageWithAllocationPrice, NewFloatingPercentCompositePrice, NewFloatingScalableMatrixWithTieredPricingPrice, NewFloatingScalableMatrixWithUnitPricingPrice, NewFloatingThresholdTotalAmountPrice, NewFloatingTieredPackagePrice, NewFloatingTieredPackageWithMinimumPrice, NewFloatingTieredPrice, NewFloatingTieredWithMinimumPrice, NewFloatingTieredWithProrationPrice, NewFloatingUnitPrice, NewFloatingUnitWithPercentPrice, NewFloatingUnitWithProrationPrice, NewItem, NewLicense, NewLicenseAllocation, NewLicenseAllocationUnitPrice, NewLicenseType, NewLicenseTypeConfiguration, NewMaximum, NewMinimum, NewNumeralConfiguration, NewPercentageDiscount, NewPlan, NewPlanBulkPrice, NewPlanBulkWithFiltersPrice, NewPlanBulkWithProrationPrice, NewPlanCumulativeGroupedAllocationPrice, NewPlanCumulativeGroupedBulkPrice, NewPlanDailyCreditAllowancePrice, NewPlanEventOutputPrice, NewPlanGroupedAllocationPrice, NewPlanGroupedTieredPackagePrice, NewPlanGroupedTieredPrice, NewPlanGroupedWithMeteredMinimumPrice, NewPlanGroupedWithMinMaxThresholdsPrice, NewPlanGroupedWithProratedMinimumPrice, NewPlanMatrixPrice, NewPlanMatrixWithAllocationPrice, NewPlanMatrixWithDisplayNamePrice, NewPlanMatrixWithThresholdDiscountsPrice, NewPlanMaxGroupTieredPackagePrice, NewPlanMeteredAllowancePrice, NewPlanMinimumCompositePrice, NewPlanPackagePrice, NewPlanPackageWithAllocationPrice, NewPlanPercentCompositePrice, NewPlanPhase, NewPlanScalableMatrixWithTieredPricingPrice, NewPlanScalableMatrixWithUnitPricingPrice, NewPlanThresholdTotalAmountPrice, NewPlanTieredPackagePrice, NewPlanTieredPackageWithMinimumPrice, NewPlanTieredPrice, NewPlanTieredWithMinimumPrice, NewPlanTieredWithProrationPrice, NewPlanUnitPrice, NewPlanUnitWithPercentPrice, NewPlanUnitWithProrationPrice, NewPlanVersion, NewPortalSession, NewReportingConfiguration, NewSphereConfiguration, NewStripeTaxConfiguration, NewSubscription, NewSubscriptionBulkPrice, NewSubscriptionBulkWithFiltersPrice, NewSubscriptionBulkWithProrationPrice, NewSubscriptionCumulativeGroupedAllocationPrice, NewSubscriptionCumulativeGroupedBulkPrice, NewSubscriptionDailyCreditAllowancePrice, NewSubscriptionEventOutputPrice, NewSubscriptionGroupedAllocationPrice, NewSubscriptionGroupedTieredPackagePrice, NewSubscriptionGroupedTieredPrice, NewSubscriptionGroupedWithMeteredMinimumPrice, NewSubscriptionGroupedWithMinMaxThresholdsPrice, NewSubscriptionGroupedWithProratedMinimumPrice, NewSubscriptionMatrixPrice, NewSubscriptionMatrixWithAllocationPrice, NewSubscriptionMatrixWithDisplayNamePrice, NewSubscriptionMatrixWithThresholdDiscountsPrice, NewSubscriptionMaxGroupTieredPackagePrice, NewSubscriptionMeteredAllowancePrice, NewSubscriptionMinimumCompositePrice, NewSubscriptionPackagePrice, NewSubscriptionPackageWithAllocationPrice, NewSubscriptionPercentCompositePrice, NewSubscriptionScalableMatrixWithTieredPricingPrice, NewSubscriptionScalableMatrixWithUnitPricingPrice, NewSubscriptionThresholdTotalAmountPrice, NewSubscriptionTieredPackagePrice, NewSubscriptionTieredPackageWithMinimumPrice, NewSubscriptionTieredPrice, NewSubscriptionTieredWithMinimumPrice, NewSubscriptionTieredWithProrationPrice, NewSubscriptionUnitPrice, NewSubscriptionUnitWithPercentPrice, NewSubscriptionUnitWithProrationPrice, NewTaxJarConfiguration, NewTieredPercentageDiscount, NewTieredPercentageDiscountTier, NewTopUpInvoiceSettings, NewTopUpInvoiceSettings2, NewUsageDiscount, OtherSubLineItem, PackageConfig, PackagePrice, PackageWithAllocationConfig, PackageWithAllocationConfig1, PackageWithAllocationPrice, PaginationMetadata, PayInvoiceParams, PaymentAttempt, PaymentConfiguration, PaymentConfigurationItem, PaymentMethod, PerPriceCost, PercentCompositeConfig, PercentCompositeConfig1, PercentCompositePrice, PercentageDiscount, PercentageDiscountCreationParams, PercentageDiscountInterval, PercentageTier, PingResponse, Plan, PlanMinified, PlanMinifiedWithVersion, PlanPhase, PlanPhaseAmountDiscountAdjustment, PlanPhaseMaximumAdjustment, PlanPhaseMinimumAdjustment, PlanPhasePercentageDiscountAdjustment, PlanPhaseTieredPercentageDiscountAdjustment, PlanPhaseUsageDiscountAdjustment, PlanVersion, PlanVersionChange, PlanVersionChanges, PlanVersionPhase, Plans, PortalSession, PreviewEvent, PriceEvaluationRequest, PriceFilter, PriceGroup, PriceInterval, PriceIntervalFixedFeeQuantityTransitionParams, Prices, Product, QuantityOnlyOverridePrice, RedeemCouponParams, RemovePlanAdjustmentParams, RemovePlanPriceParams, RemoveSubscriptionAdjustmentParams, RemoveSubscriptionPriceParams, ReplacePlanAdjustmentParams, ReplacePlanPriceParams, ReplaceSubscriptionAdjustmentParams, ReplaceSubscriptionPriceParams, ReportingConfiguration, RequestTooLargeError, RequestValidationError, ResourceNotFoundError, ResourceTooLargeError, ScalableMatrixWithTieredPricingConfig, ScalableMatrixWithTieredPricingConfig1, ScalableMatrixWithTieredPricingPrice, ScalableMatrixWithTieredScalingFactor, ScalableMatrixWithTieredTierEntry, ScalableMatrixWithUnitPricingConfig, ScalableMatrixWithUnitPricingConfig1, ScalableMatrixWithUnitPricingPrice, ScalableMatrixWithUnitScalingFactor, SetDefaultVersion, SubLineItemGrouping, SubLineItemMatrixConfig, Subscription, SubscriptionChangeListResponse, SubscriptionChangeListResponses, SubscriptionChangeMinified, SubscriptionChangeResponse, SubscriptionCosts, SubscriptionMinified, SubscriptionPlanChange, SubscriptionScheduleItem, SubscriptionScheduleItems, SubscriptionTrialInfo, SubscriptionUsageRequestParams, Subscriptions, TaxAmount, Threshold, ThresholdDiscountGroup, ThresholdOverride, ThresholdOverrideParams, ThresholdTotalAmountConfig, ThresholdTotalAmountConfig1, ThresholdTotalAmountPrice, Tier, TierSubLineItem, TierSubLineItemTierConfig, TieredConfig, TieredConversionRateConfig, TieredPackagePrice, TieredPackagePricingConfig, TieredPackagePricingConfig1, TieredPackagePricingWithMinimumConfig, TieredPackagePricingWithMinimumConfig1, TieredPackageTierItem, TieredPackageWithMinimumPrice, TieredPackageWithMinimumTierItem, TieredPercentageDiscount, TieredPercentageDiscountInterval, TieredPrice, TieredPricingWithMinimumConfig, TieredPricingWithMinimumConfig1, TieredPricingWithMinimumTierItem, TieredTotalThreshold, TieredWithMinimumPrice, TieredWithProrationConfig, TieredWithProrationConfig1, TieredWithProrationPrice, TieredWithProrationTier, TooManyResultsError, TopUp, TopUpInvoiceSettings, TopUpInvoiceSettings2, TopUps, TrialConfig, TrialDiscount, TriggerSubscriptionPhaseParams, UngroupedSubscriptionUsage, UngroupedSubscriptionUsageRecord, UnitConfig, UnitConversionRateConfig, UnitPrice, UnitWithPercentConfig, UnitWithPercentConfig1, UnitWithPercentPrice, UnitWithProrationConfig, UnitWithProrationConfig1, UnitWithProrationPrice, UnscheduleFixedFeeQuantityChangeParams, UpcomingInvoice, UpdateAlertQueryParams, UpdateAlertRequestParams, UpdateInvoiceRequestParams, UpdateMetricRequestParams, UpdatePriceRequestParams, UpdateSubscriptionParams, UpdateTrialRequestParams, UrlNotFound, Usage, UsageDiscount, UsageDiscountCreationParams, UsageDiscountInterval, ValidationError, VoidInitiatedLedgerEntry, VoidLedgerEntry

Instance Method Summary collapse

Instance Method Details

#check_for_conflict(name, existing_prop_names) ⇒ Object

Checks if an additional property conflicts with a model's existing property.

Raises:

  • (ArgumentError)


80
81
82
83
84
# File 'lib/api_reference/models/base_model.rb', line 80

def check_for_conflict(name, existing_prop_names)
  return unless existing_prop_names.key?(name)

  raise ArgumentError, "An additional property key, '#{name}' conflicts with one of the model's properties"
end

#process_additional_properties(additional_properties, existing_prop_names) ⇒ Object

Processes additional properties, ensuring no conflicts with existing properties.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/api_reference/models/base_model.rb', line 63

def process_additional_properties(additional_properties, existing_prop_names)
  hash = {}
  additional_properties.each do |name, value|
    check_for_conflict(name, existing_prop_names)

    hash[name] = if value.is_a?(Array)
                   process_array(value)
                 elsif value.is_a?(Hash)
                   process_hash(value)
                 else
                   process_basic_value(value)
                 end
  end
  hash
end

#process_array(value) ⇒ Object

Processes an array of values, recursively calling to_hash on BaseModel objects.



87
88
89
# File 'lib/api_reference/models/base_model.rb', line 87

def process_array(value)
  value.map { |v| v.is_a?(BaseModel) ? v.to_hash : v }
end

#process_basic_value(value) ⇒ Object

Processes a basic value (non-array, non-hash).



99
100
101
# File 'lib/api_reference/models/base_model.rb', line 99

def process_basic_value(value)
  value.is_a?(BaseModel) ? value.to_hash : value
end

#process_hash(value) ⇒ Object

Processes a hash of values, recursively calling to_hash on BaseModel objects.



92
93
94
95
96
# File 'lib/api_reference/models/base_model.rb', line 92

def process_hash(value)
  value.transform_values do |v|
    v.is_a?(BaseModel) ? v.to_hash : v
  end
end

#to_hashObject

Returns a Hash representation of the current object.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/api_reference/models/base_model.rb', line 11

def to_hash
  # validating the model being serialized
  self.class.validate(self) if self.class.respond_to?(:validate)

  hash = {}
  instance_variables.each do |name|
    value = instance_variable_get(name)
    name = name[1..]
    if name == 'additional_properties'
      additional_properties = process_additional_properties(value, self.class.names)
      hash.merge!(additional_properties)
    else
      key = self.class.names.key?(name) ? self.class.names[name] : name
      optional_fields = self.class.optionals
      nullable_fields = self.class.nullables
      if value.nil?
        next unless nullable_fields.include?(name)

        if !optional_fields.include?(name) && !nullable_fields.include?(name)
          raise ArgumentError,
                "`#{name}` cannot be nil in `#{self.class}`. Please specify a valid value."
        end
      end

      hash[key] = nil
      unless value.nil?
        if respond_to?("to_custom_#{name}")
          if (value.instance_of? Array) || (value.instance_of? Hash)
            params = [hash, key]
            hash[key] = send("to_custom_#{name}", *params)
          else
            hash[key] = send("to_custom_#{name}")
          end
        elsif respond_to?("to_union_type_#{name}")
          hash[key] = send("to_union_type_#{name}")
        elsif value.instance_of? Array
          hash[key] = value.map { |v| v.is_a?(BaseModel) ? v.to_hash : v }
        elsif value.instance_of? Hash
          hash[key] = {}
          value.each do |k, v|
            hash[key][k] = v.is_a?(BaseModel) ? v.to_hash : v
          end
        else
          hash[key] = value.is_a?(BaseModel) ? value.to_hash : value
        end
      end
    end
  end
  hash
end

#to_json(options = {}) ⇒ Object

Returns a JSON representation of the curent object.



104
105
106
107
# File 'lib/api_reference/models/base_model.rb', line 104

def to_json(options = {})
  hash = to_hash
  hash.to_json(options)
end