Class: UspsApi::LabelsExtraServiceResponse

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/usps_api/models/labels_extra_service_response.rb

Overview

Extra services requested on the container

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: SKIP, sku: SKIP, price: SKIP, warnings: SKIP) ⇒ LabelsExtraServiceResponse

Returns a new instance of LabelsExtraServiceResponse.



53
54
55
56
57
58
# File 'lib/usps_api/models/labels_extra_service_response.rb', line 53

def initialize(name: SKIP, sku: SKIP, price: SKIP, warnings: SKIP)
  @name = name unless name == SKIP
  @sku = sku unless sku == SKIP
  @price = price unless price == SKIP
  @warnings = warnings unless warnings == SKIP
end

Instance Attribute Details

#nameString

Name of the extra service.

Returns:

  • (String)


14
15
16
# File 'lib/usps_api/models/labels_extra_service_response.rb', line 14

def name
  @name
end

#priceFloat

The price for the extra service.

Returns:

  • (Float)


22
23
24
# File 'lib/usps_api/models/labels_extra_service_response.rb', line 22

def price
  @price
end

#skuString

SKU of the extra service.

Returns:

  • (String)


18
19
20
# File 'lib/usps_api/models/labels_extra_service_response.rb', line 18

def sku
  @sku
end

#warningsArray[Warning]

Warnings and additional details around the Extra Services.

Returns:



26
27
28
# File 'lib/usps_api/models/labels_extra_service_response.rb', line 26

def warnings
  @warnings
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/usps_api/models/labels_extra_service_response.rb', line 61

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  name = hash.key?('name') ? hash['name'] : SKIP
  sku = hash.key?('SKU') ? hash['SKU'] : SKIP
  price = hash.key?('price') ? hash['price'] : SKIP
  # Parameter is an array, so we need to iterate through it
  warnings = nil
  unless hash['warnings'].nil?
    warnings = []
    hash['warnings'].each do |structure|
      warnings << (Warning.from_hash(structure) if structure)
    end
  end

  warnings = SKIP unless hash.key?('warnings')

  # Create object from extracted values.
  LabelsExtraServiceResponse.new(name: name,
                                 sku: sku,
                                 price: price,
                                 warnings: warnings)
end

.namesObject

A mapping from model property names to API property names.



29
30
31
32
33
34
35
36
# File 'lib/usps_api/models/labels_extra_service_response.rb', line 29

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['name'] = 'name'
  @_hash['sku'] = 'SKU'
  @_hash['price'] = 'price'
  @_hash['warnings'] = 'warnings'
  @_hash
end

.nullablesObject

An array for nullable fields



49
50
51
# File 'lib/usps_api/models/labels_extra_service_response.rb', line 49

def self.nullables
  []
end

.optionalsObject

An array for optional fields



39
40
41
42
43
44
45
46
# File 'lib/usps_api/models/labels_extra_service_response.rb', line 39

def self.optionals
  %w[
    name
    sku
    price
    warnings
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



88
89
90
91
92
93
94
# File 'lib/usps_api/models/labels_extra_service_response.rb', line 88

def self.validate(value)
  return true if value.instance_of? self

  return false unless value.instance_of? Hash

  true
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



103
104
105
106
107
# File 'lib/usps_api/models/labels_extra_service_response.rb', line 103

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

#to_sObject

Provides a human-readable string representation of the object.



97
98
99
100
# File 'lib/usps_api/models/labels_extra_service_response.rb', line 97

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} name: #{@name}, sku: #{@sku}, price: #{@price}, warnings: #{@warnings}>"
end