Method: Verizon::StatusResponse.from_hash

Defined in:
lib/verizon/models/status_response.rb

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/verizon/models/status_response.rb', line 56

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.

  request_id = hash.key?('requestId') ? hash['requestId'] : SKIP
  status = hash.key?('status') ? hash['status'] : SKIP
  # Parameter is an array, so we need to iterate through it

  subrequests = nil
  unless hash['subrequests'].nil?
    subrequests = []
    hash['subrequests'].each do |structure|
      subrequests << (Subrequest.from_hash(structure) if structure)
    end
  end

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

  # Create object from extracted values.

  StatusResponse.new(request_id,
                     status,
                     subrequests)
end