Class: NewStoreApi::Reservation

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

Overview

Reservation 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(created_at = nil, expires_at = nil, item_uuid = nil, order_uuid = nil) ⇒ Reservation

Returns a new instance of Reservation.



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

def initialize(created_at = nil, expires_at = nil, item_uuid = nil,
               order_uuid = nil)
  @created_at = created_at
  @expires_at = expires_at
  @item_uuid = item_uuid
  @order_uuid = order_uuid
end

Instance Attribute Details

#created_atDateTime

Timestamp at which reservation was created

Returns:

  • (DateTime)


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

def created_at
  @created_at
end

#expires_atDateTime

Timestamp at which reservation will expire

Returns:

  • (DateTime)


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

def expires_at
  @expires_at
end

#item_uuidString

The uuid of the order item.

Returns:

  • (String)


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

def item_uuid
  @item_uuid
end

#order_uuidString

The uuid of the order.

Returns:

  • (String)


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

def order_uuid
  @order_uuid
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  created_at = if hash.key?('created_at')
                 (DateTimeHelper.from_rfc3339(hash['created_at']) if hash['created_at'])
               end
  expires_at = if hash.key?('expires_at')
                 (DateTimeHelper.from_rfc3339(hash['expires_at']) if hash['expires_at'])
               end
  item_uuid = hash.key?('item_uuid') ? hash['item_uuid'] : nil
  order_uuid = hash.key?('order_uuid') ? hash['order_uuid'] : nil

  # Create object from extracted values.
  Reservation.new(created_at,
                  expires_at,
                  item_uuid,
                  order_uuid)
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/reservation.rb', line 30

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['created_at'] = 'created_at'
  @_hash['expires_at'] = 'expires_at'
  @_hash['item_uuid'] = 'item_uuid'
  @_hash['order_uuid'] = 'order_uuid'
  @_hash
end

.nullablesObject

An array for nullable fields



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

def self.nullables
  []
end

.optionalsObject

An array for optional fields



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

def self.optionals
  []
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



94
95
96
97
98
# File 'lib/new_store_api/models/reservation.rb', line 94

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} created_at: #{@created_at.inspect}, expires_at: #{@expires_at.inspect},"\
  " item_uuid: #{@item_uuid.inspect}, order_uuid: #{@order_uuid.inspect}>"
end

#to_custom_created_atObject



78
79
80
# File 'lib/new_store_api/models/reservation.rb', line 78

def to_custom_created_at
  DateTimeHelper.to_rfc3339(created_at)
end

#to_custom_expires_atObject



82
83
84
# File 'lib/new_store_api/models/reservation.rb', line 82

def to_custom_expires_at
  DateTimeHelper.to_rfc3339(expires_at)
end

#to_sObject

Provides a human-readable string representation of the object.



87
88
89
90
91
# File 'lib/new_store_api/models/reservation.rb', line 87

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} created_at: #{@created_at}, expires_at: #{@expires_at}, item_uuid:"\
  " #{@item_uuid}, order_uuid: #{@order_uuid}>"
end