Class: ShellDataReportingApIs::BaseModel

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

Overview

Base model.

Direct Known Subclasses

AccountAccess, AccountRequest, AccountResponse, AccountResponseAccountsItems, Accounts, Address, AssociatedAccount, AuditRequest, AuditResponse, AuditResponseAuditsItems, BankAccount, BonusConfiguration, BonusHistory, CardDayTimeRestrictions, CardExceptions, CardGroupRequest, CardGroupResponse, CardGroupResponseCardGroupsItems, CardTypeRequest, CardTypeResponse, CardTypeResponseCustomerCardTypesItems, CardTypeResponseError, CardUsageRestrictions, CardUsageSummaryRequest, CardUsageSummaryResponse, ColCoAccess, CurrentVolume, CustomerContract, CustomerDetailRequest, CustomerDetailResponse, CustomerPriceListRequest, CustomerPriceListResponse, DefaultError, DefaultErrorFault, DefaultErrorFaultDetail, DeliveryAddresses, Detail, EIDAccess, EIDDocument, EIDDocumentResponse, EIDDownloadReq, EIDDownloadRequest, EIDSearchReq, EIDSearchRequest, ErrorDetails, ErrorObject, ErrorStatus, ErrorUserAccess, ErrorUserAccessError, ExceptionProduct, ExceptionSiteLocation, Fault, FeeItem, FeeItemSummaryAllOf0, FeeRuleLocation, FeeRuleProduct, FeeRuleTier, FeeSummaryResponse, FeesFeeRuleTiers, Filters, FinanceCurrency, FinanceCurrency2, FleetmanagementV1UserLoggedinuserRequest, FuelConsumptionCard, FuelConsumptionData, FuelConsumptionRequest, FuelConsumptionResponse, InvoiceDatesData, InvoiceDatesRequest, InvoiceDatesRequestFilters, InvoiceDatesResponseData, InvoiceDistributionMethod, InvoiceDownloadReq, InvoiceDownloadRequest, InvoiceSearchAdditionalDocument, InvoiceSearchDetails, InvoiceSearchRequest, InvoiceSearchRequestFilters, InvoiceSearchResponse, InvoiceSummaryDetails, InvoiceSummaryRequest, InvoiceSummaryRequestFilters, InvoiceSummaryResponse, InvoicesSummaries, LastStatementOfAccount, LastStatementOfAccount2, Location, LoggedInUserRequest, LoggedInUserResponse, MonthlyInvoiceTrend, MultiPricedTransactionRequest, MultiPricedTransactionRequestAccountsItems, MultiPricedTransactionResponse, MultiPricedTransactionResponseTransactionsItems, OAuthToken, PINAdviceTypes, PastStatementOfAccounts, PayerAccess, PayerDetails, PayerRequest, PayerResponse, Payers, PaymentsSinceLastSOA, PriceList, PriceTransSummaryRequest, PriceTransactionRequest, PricedRequestData, PricedResponseData, PricedTransSummaryResponse, PricedTransSummaryResponseTransactionsSummaryItems, PricedTransactionItemsLocationItems, PricedTransactionRequestV2, PricedTransactionResponse, PricedTransactionResponseTransactionsItems, PricedTransactionResponseV2, PricingCurrentVolume, PricingHistory, PurchaseCategories, RecentTransactionReq, RecentTransactionRequest, RecentTransactions, RecentTransactionsResponse, Role, SearchDocReq, SearchDocumentsInvoice, SearchDocumentsRequest, SearchDocumentsResponse, SearchSOAReq, SearchStatementOfAccount, SearchStatementOfAccountRequest, SearchStatementOfAccountResponse, SiteLocation, StatementOfAccountRequest, StatementOfAccountRequestFilters, StatementOfAccountResp, StatementOfAccountResponse, Tier, TransactionExceptions, TransactionExceptionsRequest, TransactionExceptionsResponse, TransactionFeesRequest, TransactionFeesResponse, UpdateOdometer, UpdateOdometerReference, UpdateOdometerRequest, UpdateOdometerResponse, UsageSummary, VolumeBasedBonusRequest, VolumeBasedBonusResponse, VolumeBasedPricingRequest, VolumeBasedPricingResponse

Instance Method Summary collapse

Instance Method Details

#to_hashObject

Returns a Hash representation of the current object.



10
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
# File 'lib/shell_data_reporting_ap_is/models/base_model.rb', line 10

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..]
    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
  hash
end

#to_json(options = {}) ⇒ Object

Returns a JSON representation of the curent object.



57
58
59
60
# File 'lib/shell_data_reporting_ap_is/models/base_model.rb', line 57

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