I am trying to create an instance variable that contains the list of URLs in the given JSON Return from that call (https://en.wikipedia.org/w/api.php?action=query&titles=World&generator=images&gimlimit=10&prop=imageinfo&iiprop=url|dimensions|mime&format=json)
In the first instance when i accessing the object individually using i get the correct value. If however iterate to get multiple values i am getting.
undefined method `[]' for nil:NilClass (NoMethodError) error
@links=[]
@description= @data_hash["query"]["pages"]["-1"]["imageinfo"][0]["url"] #Works ok
url = ("https://en.wikipedia.org/w/api.php?action=query&titles=World&generator=images&gimlimit=10&prop=imageinfo&iiprop=url|dimensions|mime&format=json")
uri = URI(url)
response = Net::HTTP.get(uri)
@data_hash= JSON.parse(response)
["url"]
@data_hash["query"]["pages"].map { |i|
i.map { |e|
@links<< e['imageinfo'][0]
}
}