Class: UspsApi::SummarySuccessResponse

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

Overview

SummarySuccessResponse 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(campaign_id: SKIP, total_barcodes: SKIP, total_barcodes_added: SKIP, total_barcodes_failed: SKIP, errors: SKIP, additional_properties: nil) ⇒ SummarySuccessResponse

Returns a new instance of SummarySuccessResponse.



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

def initialize(campaign_id: SKIP, total_barcodes: SKIP,
               total_barcodes_added: SKIP, total_barcodes_failed: SKIP,
               errors: SKIP, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @campaign_id = campaign_id unless campaign_id == SKIP
  @total_barcodes = total_barcodes unless total_barcodes == SKIP
  @total_barcodes_added = total_barcodes_added unless total_barcodes_added == SKIP
  @total_barcodes_failed = total_barcodes_failed unless total_barcodes_failed == SKIP
  @errors = errors unless errors == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#campaign_idString

Unique identifier for the campaign.

Returns:

  • (String)


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

def campaign_id
  @campaign_id
end

#errorsArray[Error4]

The total number of barcodes that failed to be added to the campaign via the callback key transaction.

Returns:



33
34
35
# File 'lib/usps_api/models/summary_success_response.rb', line 33

def errors
  @errors
end

#total_barcodesFloat

The total number of barcodes in the callback key transaction.

Returns:

  • (Float)


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

def total_barcodes
  @total_barcodes
end

#total_barcodes_addedFloat

The total number of barcodes successfully added to the campaign via the callback key transaction.

Returns:

  • (Float)


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

def total_barcodes_added
  @total_barcodes_added
end

#total_barcodes_failedFloat

The total number of barcodes that failed to be added to the campaign via the callback key transaction.

Returns:

  • (Float)


28
29
30
# File 'lib/usps_api/models/summary_success_response.rb', line 28

def total_barcodes_failed
  @total_barcodes_failed
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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
109
110
111
112
# File 'lib/usps_api/models/summary_success_response.rb', line 77

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  campaign_id = hash.key?('campaignID') ? hash['campaignID'] : SKIP
  total_barcodes = hash.key?('totalBarcodes') ? hash['totalBarcodes'] : SKIP
  total_barcodes_added =
    hash.key?('totalBarcodesAdded') ? hash['totalBarcodesAdded'] : SKIP
  total_barcodes_failed =
    hash.key?('totalBarcodesFailed') ? hash['totalBarcodesFailed'] : SKIP
  # Parameter is an array, so we need to iterate through it
  errors = nil
  unless hash['errors'].nil?
    errors = []
    hash['errors'].each do |structure|
      errors << (Error4.from_hash(structure) if structure)
    end
  end

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

  # 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.
  SummarySuccessResponse.new(campaign_id: campaign_id,
                             total_barcodes: total_barcodes,
                             total_barcodes_added: total_barcodes_added,
                             total_barcodes_failed: total_barcodes_failed,
                             errors: errors,
                             additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



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

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['campaign_id'] = 'campaignID'
  @_hash['total_barcodes'] = 'totalBarcodes'
  @_hash['total_barcodes_added'] = 'totalBarcodesAdded'
  @_hash['total_barcodes_failed'] = 'totalBarcodesFailed'
  @_hash['errors'] = 'errors'
  @_hash
end

.nullablesObject

An array for nullable fields



58
59
60
# File 'lib/usps_api/models/summary_success_response.rb', line 58

def self.nullables
  []
end

.optionalsObject

An array for optional fields



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

def self.optionals
  %w[
    campaign_id
    total_barcodes
    total_barcodes_added
    total_barcodes_failed
    errors
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



124
125
126
127
128
129
130
# File 'lib/usps_api/models/summary_success_response.rb', line 124

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} campaign_id: #{@campaign_id.inspect}, total_barcodes:"\
  " #{@total_barcodes.inspect}, total_barcodes_added: #{@total_barcodes_added.inspect},"\
  " total_barcodes_failed: #{@total_barcodes_failed.inspect}, errors: #{@errors.inspect},"\
  " additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



115
116
117
118
119
120
121
# File 'lib/usps_api/models/summary_success_response.rb', line 115

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} campaign_id: #{@campaign_id}, total_barcodes: #{@total_barcodes},"\
  " total_barcodes_added: #{@total_barcodes_added}, total_barcodes_failed:"\
  " #{@total_barcodes_failed}, errors: #{@errors}, additional_properties:"\
  " #{@additional_properties}>"
end