Class: IpwhoApi::IpGeoResponse

Inherits:
Struct
  • Object
show all
Defined in:
lib/ipwho.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#dataObject

Returns the value of attribute data

Returns:

  • (Object)

    the current value of data



190
191
192
# File 'lib/ipwho.rb', line 190

def data
  @data
end

#messageObject

Returns the value of attribute message

Returns:

  • (Object)

    the current value of message



190
191
192
# File 'lib/ipwho.rb', line 190

def message
  @message
end

#successObject

Returns the value of attribute success

Returns:

  • (Object)

    the current value of success



190
191
192
# File 'lib/ipwho.rb', line 190

def success
  @success
end

Class Method Details

.from_hash(hash) ⇒ Object



191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/ipwho.rb', line 191

def self.from_hash(hash)
  data_obj = nil
  if hash["data"].is_a?(Hash)
    # Bulk: normalise responseArray
    if hash["data"]["responseArray"].is_a?(Array)
      data_obj = hash["data"].dup
      data_obj["responseArray"] = hash["data"]["responseArray"].map { |item| IpGeoResponse.from_hash(item) }
      data_obj = OpenStruct.new(data_obj)
    else
      data_obj = GeoData.from_hash(hash["data"])
    end
  end
  new(success: hash["success"], data: data_obj, message: hash["message"])
end