Class: UspsApi::IndiciaMetadata

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

Overview

Metadata for the generated indicia.

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(sku: SKIP, postage: SKIP, fees: SKIP, weight: SKIP, indicia_imi: SKIP, additional_properties: nil) ⇒ IndiciaMetadata

Returns a new instance of IndiciaMetadata.



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/usps_api/models/indicia_metadata.rb', line 61

def initialize(sku: SKIP, postage: SKIP, fees: SKIP, weight: SKIP,
               indicia_imi: SKIP, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @sku = sku unless sku == SKIP
  @postage = postage unless postage == SKIP
  @fees = fees unless fees == SKIP
  @weight = weight unless weight == SKIP
  @indicia_imi = indicia_imi unless indicia_imi == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#feesArray[Fee11]

Fees associated to the mailpiece.

Returns:



23
24
25
# File 'lib/usps_api/models/indicia_metadata.rb', line 23

def fees
  @fees
end

#indicia_imiString

Base64 encoded string of the binary data used to create the Intelligent Mail Indicia (IMI) Data Matrix.

Returns:

  • (String)


32
33
34
# File 'lib/usps_api/models/indicia_metadata.rb', line 32

def indicia_imi
  @indicia_imi
end

#postageFloat

Amount of postage required, does not include insurance or other extra service fees.

Returns:

  • (Float)


19
20
21
# File 'lib/usps_api/models/indicia_metadata.rb', line 19

def postage
  @postage
end

#skuString

Pricing SKU

Returns:

  • (String)


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

def sku
  @sku
end

#weightFloat

The mailpiece weight, in ounces.

Returns:

  • (Float)


27
28
29
# File 'lib/usps_api/models/indicia_metadata.rb', line 27

def weight
  @weight
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



75
76
77
78
79
80
81
82
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
# File 'lib/usps_api/models/indicia_metadata.rb', line 75

def self.from_hash(hash)
  return nil unless hash

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

  fees = SKIP unless hash.key?('fees')
  weight = hash.key?('weight') ? hash['weight'] : SKIP
  indicia_imi = hash.key?('indiciaIMI') ? hash['indiciaIMI'] : SKIP

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  IndiciaMetadata.new(sku: sku,
                      postage: postage,
                      fees: fees,
                      weight: weight,
                      indicia_imi: indicia_imi,
                      additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



35
36
37
38
39
40
41
42
43
# File 'lib/usps_api/models/indicia_metadata.rb', line 35

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['sku'] = 'SKU'
  @_hash['postage'] = 'postage'
  @_hash['fees'] = 'fees'
  @_hash['weight'] = 'weight'
  @_hash['indicia_imi'] = 'indiciaIMI'
  @_hash
end

.nullablesObject

An array for nullable fields



57
58
59
# File 'lib/usps_api/models/indicia_metadata.rb', line 57

def self.nullables
  []
end

.optionalsObject

An array for optional fields



46
47
48
49
50
51
52
53
54
# File 'lib/usps_api/models/indicia_metadata.rb', line 46

def self.optionals
  %w[
    sku
    postage
    fees
    weight
    indicia_imi
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



118
119
120
121
122
123
# File 'lib/usps_api/models/indicia_metadata.rb', line 118

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} sku: #{@sku.inspect}, postage: #{@postage.inspect}, fees: #{@fees.inspect},"\
  " weight: #{@weight.inspect}, indicia_imi: #{@indicia_imi.inspect}, additional_properties:"\
  " #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



111
112
113
114
115
# File 'lib/usps_api/models/indicia_metadata.rb', line 111

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} sku: #{@sku}, postage: #{@postage}, fees: #{@fees}, weight: #{@weight},"\
  " indicia_imi: #{@indicia_imi}, additional_properties: #{@additional_properties}>"
end