Reputation: 95
I am getting the following data after API request and not sure how to get link
from the data. Anyone help?
#<ExampleApi::Results::GetTemporaryLinkResult:0x00007f9edf280c78
@data={"metadata"=>{"name"=>"test.jpg", "id"=>"id:xxxxxxxx",
"link"=>"https://example.com/apitl/1/AnHQ08SIuxh9cdXL1q-EpG8L"}>
Upvotes: 0
Views: 126
Reputation: 8561
Its a Hash and you can retrieve by the key
@data["metadata"]["link"]
Edited
class ExamplerResult
attr_accessor :data
def initialize()
@data = {"metadata"=>{"name"=>"test.jpg", "id"=>"id:xxxxxxxx", "link"=>"https://example.com/apitl/1/AnHQ08SIuxh9cdXL1q-EpG8L"}}
end
end
data = ExamplerResult.new.data
data["metadata"]["link"]
Upvotes: 2
Reputation: 941
For Hash you can use dig
from ruby 2.3
@data.dig("metadata", "link")
to retrieve (nested) keys
Reference link https://ruby-doc.org/core-2.3.0_preview1/Hash.html#method-i-dig
Upvotes: 0