Class: NewStoreApi::BaseModel

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

Overview

Base model. rubocop:disable all

Direct Known Subclasses

Actor, AdapterHttpTimeout, AddItemItemPrice, AddItemRequestBody, AddItemResponseBody, AddOnLinks, AddOnResource, AddReplaceOrTest, Address, Address1, AddressDataIeV1Dto, AddressDataNoV1Dto, AddressModel, AddressResponse, Adjustment, Allocation, Amount, AtpInsightsResponse, AtpKey, AuditEvent, AuditEventList, AuditEventReadOnly, AuditReadOnly, AuditResponse, AuditsResponse, AutomaticReroutingSettings, AvailabilityRow, AvalaraConfigCreateDto, AvalaraConfigDto, AvalaraConfigUpdateDto, AvalaraExemptionClassItemCreateDto, AvalaraExemptionClassItemDto, AvalaraExemptionClassItemUpdateDto, AxenaActivationDataV1Dto, BillingAddress, Body, BookingProduct, BookingProductCustoms, BookingResponseCost, BulkProfileLookupResponse, ByoCrmConfigRequest, ByoCrmConfigResponse, Canceled, CancellationPolicySettings, CancellationPolicySettingsValue, CapacityBasedRoutingSettings, CardDetails, CardPayment, CarriersConfig, CarriersConfigCarrier, Cart, CartDiscount, CartLinks, CartListItem, CartResource, CashDenominationDto, CashDenominationsResponseDto, CashDetails, CashPayment, CashboxConfigAxenaSeV1Dto, CashboxConfigEfstaPtV1Dto, CashboxConfigEpsonItV1Dto, CashboxConfigFiskaltrustAtV1Dto, CashboxConfigFiskaltrustDeV1Dto, CashboxConfigFiskaltrustFrV1Dto, CashboxConfigNewStoreBeV1Dto, CashboxConfigNewStoreEsV1Dto, CashboxConfigNewStoreInV1Dto, CashboxConfigNewStoreThV1Dto, CashboxConfigNewstoreIeV1Dto, CashboxConfigNewstoreNoV1Dto, CashboxConfigPosnetPlV1Dto, CashboxConfigYcsPrV1Dto, CashboxCreateV1Dto, CashboxCreatedV1Dto, CashboxGetV1Dto, CashboxListV1Dto, CashboxReleaseV1Dto, CashboxV1Dto, Catalog, ChangeCartRequestBody, ChangeItemRequestBody, ChangeItemResponseBody, ChangesResponseBody, Channel, Channel1, CheckoutFinancialDocumentsExchangeReceiptsRequest, CheckoutFinancialDocumentsSalesReceiptsRequest, CompleteZoneRequest, CompletionResponse, Condition, Conditions, Config, ConfigDto, ConfigModel, ConfigModelResponse, ConfigurationFeatureFlags, ConfigurationRequest, ConfigurationResponse, ContextV1Dto, Correlation, CountTaskLineItemResponse, CreateCartRequestBody, CreateDataRequest, CreateDataResponse, CreateIdentityProviderRequest, CreateImportRequest, CreateJobRequest, CreateOidcIdentityProviderConfig, CreatePackageTrackingCustomAdapter, CreatePackageTrackingEasypostAdapter, CreatePackageTypeRequest, CreatePaymentLinkRequest, CreateProfileRequest, CreateReservationRequestV1, CreateSamlIdentityProviderConfig, CreateSessionTokenRequest, CreateTagRequest, Current, CustomConfigAdditionalCreateDto, CustomConfigAdditionalDto, CustomConfigAdditionalUpdateDto, CustomConfigAuthenticationDto, CustomConfigCreateDto, CustomConfigDto, CustomConfigUpdateDto, CustomV0AvalaraConfigCreateDto, CustomV0AvalaraConfigDto, CustomV0AvalaraConfigUpdateDto, Customer, Customer1, CustomizationAdapterConfig, CustomizationAdapterConfigValue, Data, DeliveryDestination, DestinationRegion, DestinationRegion1, Discount, DownloadResponse, EasypostAdapterConfig, EnrichedQuotationItemDto, EnrichedQuotationTaxRateDto, EnrichedTransactionAddressDto, EnrichedTransactionDto, EnrichedTransactionItemDto, EpcBody, Error, EventCapturedDto, ExcludedProduct, ExemptionClassItemCreateDto, ExemptionClassItemDto, ExemptionClassItemExtendedDto, ExemptionClassItemUpdateDto, ExemptionClassMappingItV1Dto, Experiment, ExtAttrResource, ExtendOrderSGracePeriodTimer, ExtendedAttribute, ExtendedAttributeModel, ExternalAtpSettings, ExternalFulfillmentSettingsRequest, ExternalFulfillmentSettingsResponse, ExternalIdentifiers, ExternalIdentifiers1, ExternalTokenResponse, Failed, FallbackErrorDto, FiscalCountriesDto, FiscalReceiptResultV1Dto, FixedDiscount, FixedRateConfigCreateDto, FixedRateConfigDto, FixedRateConfigUpdateDto, Fulfillment1, FulfillmentAssignment, FulfillmentConfigDestinationRegion, FulfillmentConfigGetRoutingRulesSectionSampleResponse, FulfillmentConfigGetRoutingRulesSectionSampleResponse1, FulfillmentConfigGetRoutingRulesSectionSampleResponse2, FulfillmentConfigGetRoutingRulesSectionSampleResponse3, FulfillmentConfigRoute, FulfillmentConfigRoutingRules, FulfillmentConfigV2Body, FulfillmentNodeAssignment, FulfillmentNodeCustomsInfo, FulfillmentNodeCustomsInfoValue, FulfillmentOption, FulfillmentRequest, FulfillmentRequest1, FulfillmentRequestItemsStatesRequest, FulfillmentRequestLineItem, FulfillmentTaskDocument, FulfillmentTaskItemExternalIdentier, FulfillmentTaskItemModel, FulfillmentTaskModel, FutureAllocation, GenerateStaticOptionForDc, GetClientResponse, GetClientsResponse, GetConfigResponse, GetNotificationsResponse, GetPermissionsResponse, GetResponse, GetReturnReceiptRequest, GetRolesResponse, GetScopesResponse, GetShortingsModel, GetTaskModel, GetTransferTransactionResponse, GetUserinfoResponse, GetUsersByRoleResponse, GetUsersResponse, GiftWrapping, GiftWrapping1, HistoricalOrderShipment, HistoricalShippingOption, HttpResponseBody, IdentityProviderConfig, IdentityProviderResponse, IdentityProvidersResponse, ImportResponse, ImportSchemaCreated, ImportSchemaGet, ImportTagResponse, InjectedOrderAddress, InjectedOrderDiscountInfo, InjectedOrderDiscountInfo1, InjectedOrderExtendedAttribute, InjectedOrderItemIds, InjectedOrderItemTaxLine, InjectedOrderPayment, InjectedOrderRequest, InjectedOrderResponse, InjectedOrderRoutingStrategy, InjectedOrderRoutingStrategy1, InjectedOrderRoutingStrategy2, InjectedOrderShipment, InjectedOrderShipmentItem, InjectedOrderShipmentItemPrice, InjectedOrderShippingOption, InjectedOrderShippingOption1, InsightsActivitiesSchemaResponse, InsightsConfigResponse, IntegrationConfig, Item1, Item11, Item12, Item21, Item211, Item22, Item3, Item31, Item4, Item41, Item5, Item6, Item7, Item8, Item9, ItemDiscount, ItemLinks, ItemPrice, ItemResource, JobDownloadResponse, JobIdResponse, JobListResponse, JobResponse, LimitExceededWhen, LineItem, LineItem11, LineItem2, LineItem21, LineItem3, LineItemPrice, Link, ListAddressesResponse, ListCountTaskLineItemsResponse, ListImportTags, ListImportsResponse, ListProductZonesResponse, ListProfilesResponse, ListReservationsResponseV1, ListReservationsResponseV2, ListResponse, ListTagProfilesResponse, ListTagsResponse, ListZonesResponse, Localization, LocalizedReasonCode, LocationMapping, LocationMappingBody, LocationMappingsResponse, Meta, MetaData, MoveOrCopy, NotRoutedItemResponse, Notification, NotificationRequest, NotificationResponse, OAuthToken, OfflineCountriesConfigMetadataV1Dto, OfflineCountriesConfigUpdateV1Dto, OfflineCountriesConfigV1Dto, OfflineCountriesResponseV1Dto, OfflineCountriesUpdateRequestV1Dto, OfflineCountryConfigMetadataV1Dto, OfflineCountryConfigV1Dto, OperationError, OperationResponse, OperationTagsRequest, OptedIn, OptionProductCustoms, OrderCompletedDto, OrderConflictResolutionRequest, OrderConflictResolutionResponse, OrderFulfillmentRequestsResponse, OrderInjectionConfigurationBigSalesOrder, OrderInjectionConfigurationResponse, OrderInjectionTenantConfiguration, OrderRequest, OrderResponse, Origin, Original, PackageDimensions, PackageOption, PackageOptionDimensions, PackageOptionWeight, PackageTracking, PackageTypeResponse, PackageTypesResponse, PackageWeight, PackingTimeDuration, PaginatedResponse, PaginationInfo, PatchImportRequest, Payment, Payment1, PaymentLinkGetResponse, PaymentLinkRequest, PaymentLinkResponse, PercentageDiscount, PermalinkResponse, Permission, PlatformEventDto, PlatformStatusResponse, PosnetOnlineCommandLogV1Dto, PosnetOnlineCountersV1Dto, PostChargeRequest, PostChargeResponse, PostClientRequest, PostClientResponse, PostRolesRequest, PostSupportUsersRequest, PostUsersRequest, PresignedUrlRequest, PresignedUrlResponse, Price1, PriceOverride, Pricing, Problem, ProcessorMetadata, Product, Product1, ProductAttributes, Profile, ProfileDeleted, ProfileDeletionRequest, ProfileResponse, Profiles, Provider, ProviderRateSchema, PutRolesByIdRequest, PutRoutingRulesetResponse, PutRoutingRulesetResponse1, PutUsersByIdRequest, QuotationDto, QuotationItemDto, QuotationResultDto, QuotationTaxRateDto, QuotationTotalsDto, ReasonCodeInit, ReasonCodePatch, Recipients, RegistrationRequest, RegistrationResponse, RejectedReroutingSettings, Remove, RemoveItemResponseBody, ReplaceProviderRateSchema, Request, RequestContext, RequestCreateBookings, RequestCreateManifest, RequestPackage, RequestPackageCustoms, RequestRecipientAddress, RequestServiceLevelRates, RequestShippingOption, Rerouted, Reservation, ReservationConfigResponse, ReservationConfigUpdate, ReservationDetailsResponseV1, ReservationDetailsResponseV2, ReservationItemDetailsResponse, ReservationItemRequest, ReservationItemSummaryResponse, ReservationItemUpdate, ReservationSummaryResponseV1, ReservationSummaryResponseV2, ReservationUpdate, ReservationsPaginationInfo, ResponseBookedPackage, ResponseBookedPackageTransaction, ResponseCreateBookings, ResponseCreateManifest, ResponseCreateconfigurationbyname, ResponseCreatejob, ResponseDeliveryWindow, ResponseServiceLevelRates, ResponseShippingOption, ResponseShowBookings, ResponseShowconfigurationbyname, ResponseUnitItem, RetrieveBulkEmailLookupRequest, RetrieveBulkEmailLookupResponse, ReturnProcessedDto, ReturnReceiptResponse, ReverseCalculationQuotationItemDto, ReverseCalculationTransactionItemDto, Role, RoleItem, RouteTo, Routes, RoutesV1, RoutingDecisionTrace, RoutingDecisionTracePicked, RoutingInsights, RoutingInsightsActivity, RoutingInsightsCorrelation, RoutingInsightsData, RoutingInsightsFulfillmentRequests, RoutingInsightsRoutingStrategies, RoutingInsightsRoutingStrategy1, RoutingInsightsServiceLevels, RoutingOptionsRequest, RoutingOptionsResponse, RoutingRuleset, RoutingRuleset1, RoutingSimulationLineItem, RoutingSimulationRequestPayload, RoutingSimulationResponsePayload, RoutingStrategy, RoutingStrategy1, Rules, SalesOrder, SalesOrderAddress, SalesOrderCancellationRequest, SalesOrderCancellationResponse, SalesOrderCustomer, SalesOrderDetail, SalesOrderDetailResponse, SalesOrderDiscount, SalesOrderExtendedAttribute, SalesOrderExternalIdentifier, SalesOrderFulfillment, SalesOrderGiftWrapping, SalesOrderItem, SalesOrderItemPaymentHistory, SalesOrderItemShipment, SalesOrderItemV2, SalesOrderItems1, SalesOrderListResponse, SalesOrderListResponseV2, SalesOrderPrice1, SalesOrderPricesRequest, SalesOrderPricesResponse, SalesOrderProductAttributes, SalesOrderSerialNumbersRequest, SalesOrderSerialNumbersRequestItem, SalesOrderSerialNumbersRequestItemEpc, SalesOrderTaxLine, SalesOrderTotals, SalesOrderV2, Schema, SchemaForBulkCancelOrdersRequest, SchemaForBulkCancelOrdersResponse, ServiceLevelRate, ServiceLevels, SessionTokenResponse, SetFixServiceLevelShippingPrice, SettingsResponse, ShipmentLimitsRequest, ShipmentLimitsResponse, ShippingAddress, ShippingOfferUpdateSettings, ShippingOptionAudit, Shop, ShortingModel, ShowProviderRatesSchema, SignatureAtV1Dto, SignatureBeV1Dto, SignatureDeV1Dto, SignatureDummyV1Dto, SignatureEsV1Dto, SignatureFrV1Dto, SignatureIeV1Dto, SignatureInV1Dto, SignatureItV1Dto, SignatureItemAtV1Dto, SignatureItemDeV1Dto, SignatureItemFrV1Dto, SignatureNoV1Dto, SignaturePlV1Dto, SignaturePrV1Dto, SignaturePtV1Dto, SignatureResponseV1Dto, SignatureSeV1Dto, SignatureThV1Dto, SimulationRoutedItem, StockProductAvailabilityRequest, StockProductAvailabilityResponse, StockUnallocatedItemsRequest, StockUnallocatedItemsResponse, StoreConfigCreateDto, StoreConfigDto, StoreConfigListDto, StoreConfigUpdateDto, StoreConfigUpdateItV1Dto, StoreConfigUpdatePlV1Dto, StoreConfigUpdateV1Dto, StoreConfigV1Dto, StoreCreateV1Dto, StoreListV1Dto, StoreUpdateV1Dto, StoreV1Dto, Strategies, Subscription, SubscriptionRequest, SubscriptionResponse, SubscriptionsResponse, SupportAccessDetails, SupportedIdentityProvider, SupportedIdentityProviders, SwapTo, Swapped, SyncJobResponse, TagResponse, TaskPackage, TaskPackageItem, TaxExemption, TaxExemptionClassesDto, TaxInformation, TaxLine, TaxRateDto, TaxTotalsDto, TenantConfigCreateDto, TenantConfigDto, TenantConfigUpdateDto, TenantConfigV1Dto, TokenRequest, TokenResponse, TokensRequest, TokensResponse, TransactionAddressDto, TransactionDto, TransactionItemDto, TransactionMinV1Dto, TransactionTaxRateDto, TransactionUpdateDto, TransferDocumentResponse, TransferTransactionLineItemResponse, UpdateAddressRequest, UpdateIdentityProviderRequest, UpdateOidcIdentityProviderConfig, UpdatePackageTypeRequest, UpdateProfileRequest, UpdateSamlIdentityProviderConfig, UpdateServiceLevelRequest, UpdateTagRequest, UseCustomizableProviderRates, UsePrioritizedProviderRates, User, V0OrdersRequest, Value, VertexAdministrativeOriginCreateDto, VertexAdministrativeOriginDto, VertexAdministrativeOriginUpdateDto, VertexConfigCreateDto, VertexConfigDto, VertexConfigUpdateDto, VertexExemptionClassItemCreateDto, VertexExemptionClassItemDto, VertexExemptionClassItemUpdateDto, VertexFlexibleFieldConfigCreateDto, VertexFlexibleFieldConfigDto, VertexFlexibleFieldConfigUpdateDto, Warning, WriteAccepted, ZoneResponse

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/new_store_api/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/new_store_api/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/new_store_api/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/new_store_api/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/new_store_api/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/new_store_api/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/new_store_api/models/base_model.rb', line 104

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