Class: NewStoreApi::PlatformEventDto

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

Overview

PlatformEventDto 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(name = nil, payload = nil, published_at = nil, tenant = nil) ⇒ PlatformEventDto

Returns a new instance of PlatformEventDto.



49
50
51
52
53
54
# File 'lib/new_store_api/models/platform_event_dto.rb', line 49

def initialize(name = nil, payload = nil, published_at = nil, tenant = nil)
  @name = name
  @payload = payload
  @published_at = published_at
  @tenant = tenant
end

Instance Attribute Details

#nameEventName1Enum

The name of the external event.

Returns:



15
16
17
# File 'lib/new_store_api/models/platform_event_dto.rb', line 15

def name
  @name
end

#payloadObject

The name of the external event.

Returns:

  • (Object)


19
20
21
# File 'lib/new_store_api/models/platform_event_dto.rb', line 19

def payload
  @payload
end

#published_atDateTime

Timestamp of the publishing of the event.

Returns:

  • (DateTime)


23
24
25
# File 'lib/new_store_api/models/platform_event_dto.rb', line 23

def published_at
  @published_at
end

#tenantString

Tenant identifier.

Returns:

  • (String)


27
28
29
# File 'lib/new_store_api/models/platform_event_dto.rb', line 27

def tenant
  @tenant
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/new_store_api/models/platform_event_dto.rb', line 57

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  name = hash.key?('name') ? hash['name'] : nil
  payload = hash.key?('payload') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:PlatformEventDtoPayload), hash['payload']
  ) : nil
  published_at = if hash.key?('published_at')
                   (DateTimeHelper.from_rfc3339(hash['published_at']) if hash['published_at'])
                 end
  tenant = hash.key?('tenant') ? hash['tenant'] : nil

  # Create object from extracted values.
  PlatformEventDto.new(name,
                       payload,
                       published_at,
                       tenant)
end

.namesObject

A mapping from model property names to API property names.



30
31
32
33
34
35
36
37
# File 'lib/new_store_api/models/platform_event_dto.rb', line 30

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['name'] = 'name'
  @_hash['payload'] = 'payload'
  @_hash['published_at'] = 'published_at'
  @_hash['tenant'] = 'tenant'
  @_hash
end

.nullablesObject

An array for nullable fields



45
46
47
# File 'lib/new_store_api/models/platform_event_dto.rb', line 45

def self.nullables
  []
end

.optionalsObject

An array for optional fields



40
41
42
# File 'lib/new_store_api/models/platform_event_dto.rb', line 40

def self.optionals
  []
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/new_store_api/models/platform_event_dto.rb', line 83

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.name,
                            ->(val) { EventName1Enum.validate(val) }) and
        UnionTypeLookUp.get(:PlatformEventDtoPayload)
                       .validate(value.payload) and
        APIHelper.valid_type?(value.published_at,
                              ->(val) { val.instance_of? DateTime }) and
        APIHelper.valid_type?(value.tenant,
                              ->(val) { val.instance_of? String })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['name'],
                          ->(val) { EventName1Enum.validate(val) }) and
      UnionTypeLookUp.get(:PlatformEventDtoPayload)
                     .validate(value['payload']) and
      APIHelper.valid_type?(value['published_at'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['tenant'],
                            ->(val) { val.instance_of? String })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



119
120
121
122
123
# File 'lib/new_store_api/models/platform_event_dto.rb', line 119

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} name: #{@name.inspect}, payload: #{@payload.inspect}, published_at:"\
  " #{@published_at.inspect}, tenant: #{@tenant.inspect}>"
end

#to_custom_published_atObject



77
78
79
# File 'lib/new_store_api/models/platform_event_dto.rb', line 77

def to_custom_published_at
  DateTimeHelper.to_rfc3339(published_at)
end

#to_sObject

Provides a human-readable string representation of the object.



112
113
114
115
116
# File 'lib/new_store_api/models/platform_event_dto.rb', line 112

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} name: #{@name}, payload: #{@payload}, published_at: #{@published_at},"\
  " tenant: #{@tenant}>"
end