Class: NewStoreApi::CreatePackageTrackingCustomAdapter

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

Overview

CreatePackageTrackingCustomAdapter 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(status = nil, tracking_code = nil, updated_at = nil, reason = SKIP) ⇒ CreatePackageTrackingCustomAdapter

Returns a new instance of CreatePackageTrackingCustomAdapter.



54
55
56
57
58
59
60
# File 'lib/new_store_api/models/create_package_tracking_custom_adapter.rb', line 54

def initialize(status = nil, tracking_code = nil, updated_at = nil,
               reason = SKIP)
  @reason = reason unless reason == SKIP
  @status = status
  @tracking_code = tracking_code
  @updated_at = updated_at
end

Instance Attribute Details

#reasonString

TODO: Write general description for this method

Returns:

  • (String)


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

def reason
  @reason
end

#statusTrackingStatusEnum

TODO: Write general description for this method

Returns:



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

def status
  @status
end

#tracking_codeString

TODO: Write general description for this method

Returns:

  • (String)


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

def tracking_code
  @tracking_code
end

#updated_atDateTime

Set by carrier. It is the time at which the event has been recorded/generated by the carrier.

Returns:

  • (DateTime)


28
29
30
# File 'lib/new_store_api/models/create_package_tracking_custom_adapter.rb', line 28

def updated_at
  @updated_at
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  status = hash.key?('status') ? hash['status'] : nil
  tracking_code = hash.key?('tracking_code') ? hash['tracking_code'] : nil
  updated_at = if hash.key?('updated_at')
                 (DateTimeHelper.from_rfc3339(hash['updated_at']) if hash['updated_at'])
               end
  reason = hash.key?('reason') ? hash['reason'] : SKIP

  # Create object from extracted values.
  CreatePackageTrackingCustomAdapter.new(status,
                                         tracking_code,
                                         updated_at,
                                         reason)
end

.namesObject

A mapping from model property names to API property names.



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

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['reason'] = 'reason'
  @_hash['status'] = 'status'
  @_hash['tracking_code'] = 'tracking_code'
  @_hash['updated_at'] = 'updated_at'
  @_hash
end

.nullablesObject

An array for nullable fields



48
49
50
51
52
# File 'lib/new_store_api/models/create_package_tracking_custom_adapter.rb', line 48

def self.nullables
  %w[
    reason
  ]
end

.optionalsObject

An array for optional fields



41
42
43
44
45
# File 'lib/new_store_api/models/create_package_tracking_custom_adapter.rb', line 41

def self.optionals
  %w[
    reason
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



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/create_package_tracking_custom_adapter.rb', line 87

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.status,
                            ->(val) { TrackingStatusEnum.validate(val) }) and
        APIHelper.valid_type?(value.tracking_code,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.updated_at,
                              ->(val) { val.instance_of? DateTime })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['status'],
                          ->(val) { TrackingStatusEnum.validate(val) }) and
      APIHelper.valid_type?(value['tracking_code'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['updated_at'],
                            ->(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/create_package_tracking_custom_adapter.rb', line 119

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} reason: #{@reason.inspect}, status: #{@status.inspect}, tracking_code:"\
  " #{@tracking_code.inspect}, updated_at: #{@updated_at.inspect}>"
end

#to_custom_updated_atObject



81
82
83
# File 'lib/new_store_api/models/create_package_tracking_custom_adapter.rb', line 81

def to_custom_updated_at
  DateTimeHelper.to_rfc3339(updated_at)
end

#to_sObject

Provides a human-readable string representation of the object.



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

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} reason: #{@reason}, status: #{@status}, tracking_code: #{@tracking_code},"\
  " updated_at: #{@updated_at}>"
end