Class: CyberSourceMergedSpec::Response

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/cyber_source_merged_spec/models/response.rb

Overview

Response 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(resource: SKIP, http_status: SKIP, id: SKIP, errors: SKIP, additional_properties: nil) ⇒ Response

Returns a new instance of Response.



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/cyber_source_merged_spec/models/response.rb', line 59

def initialize(resource: SKIP, http_status: SKIP, id: SKIP, errors: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @resource = resource unless resource == SKIP
  @http_status = http_status unless http_status == SKIP
  @id = id unless id == SKIP
  @errors = errors unless errors == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#errorsArray[Error]

TMS token id associated with the response.

Returns:



32
33
34
# File 'lib/cyber_source_merged_spec/models/response.rb', line 32

def errors
  @errors
end

#http_statusInteger

Http status associated with the response.

Returns:

  • (Integer)


24
25
26
# File 'lib/cyber_source_merged_spec/models/response.rb', line 24

def http_status
  @http_status
end

#idString

TMS token id associated with the response.

Returns:

  • (String)


28
29
30
# File 'lib/cyber_source_merged_spec/models/response.rb', line 28

def id
  @id
end

#resourceString

TMS token type associated with the response. Possible Values:

  • customer
  • paymentInstrument
  • instrumentIdentifier
  • shippingAddress
  • tokenizedCard

Returns:

  • (String)


20
21
22
# File 'lib/cyber_source_merged_spec/models/response.rb', line 20

def resource
  @resource
end

Class Method Details

.from_element(root) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/cyber_source_merged_spec/models/response.rb', line 105

def self.from_element(root)
  resource = XmlUtilities.from_element(root, 'resource', String)
  http_status = XmlUtilities.from_element(root, 'httpStatus', Integer)
  id = XmlUtilities.from_element(root, 'id', String)
  errors = XmlUtilities.from_element_to_array(root, 'Error', Error)

  new(resource: resource,
      http_status: http_status,
      id: id,
      errors: errors,
      additional_properties: additional_properties)
end

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



72
73
74
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
# File 'lib/cyber_source_merged_spec/models/response.rb', line 72

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  resource = hash.key?('resource') ? hash['resource'] : SKIP
  http_status = hash.key?('httpStatus') ? hash['httpStatus'] : SKIP
  id = hash.key?('id') ? hash['id'] : 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 << (Error.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.
  Response.new(resource: resource,
               http_status: http_status,
               id: id,
               errors: errors,
               additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



35
36
37
38
39
40
41
42
# File 'lib/cyber_source_merged_spec/models/response.rb', line 35

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['resource'] = 'resource'
  @_hash['http_status'] = 'httpStatus'
  @_hash['id'] = 'id'
  @_hash['errors'] = 'errors'
  @_hash
end

.nullablesObject

An array for nullable fields



55
56
57
# File 'lib/cyber_source_merged_spec/models/response.rb', line 55

def self.nullables
  []
end

.optionalsObject

An array for optional fields



45
46
47
48
49
50
51
52
# File 'lib/cyber_source_merged_spec/models/response.rb', line 45

def self.optionals
  %w[
    resource
    http_status
    id
    errors
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



139
140
141
142
143
144
# File 'lib/cyber_source_merged_spec/models/response.rb', line 139

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} resource: #{@resource.inspect}, http_status: #{@http_status.inspect}, id:"\
  " #{@id.inspect}, errors: #{@errors.inspect}, additional_properties:"\
  " #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



132
133
134
135
136
# File 'lib/cyber_source_merged_spec/models/response.rb', line 132

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} resource: #{@resource}, http_status: #{@http_status}, id: #{@id}, errors:"\
  " #{@errors}, additional_properties: #{@additional_properties}>"
end

#to_xml_element(doc, root_name) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/cyber_source_merged_spec/models/response.rb', line 118

def to_xml_element(doc, root_name)
  root = doc.create_element(root_name)

  XmlUtilities.add_as_subelement(doc, root, 'resource', resource)
  XmlUtilities.add_as_subelement(doc, root, 'httpStatus', http_status)
  XmlUtilities.add_as_subelement(doc, root, 'id', id)
  XmlUtilities.add_array_as_subelement(doc, root, 'Error', errors)
  XmlUtilities.add_as_subelement(doc, root, 'additional_properties',
                                 additional_properties)

  root
end