What I need is the value of URL from the PUT request.
Here is the result of the PUT request.
Response: {"result":{"attempts":1,"url":null}}
I can't tell where is the problem.
loop do
response = HTTParty.put("#{API_ENDPOINT}/challenges", headers: { 'X-Challenge-Id' => challenge_id })
puts "Response: #{response}"
if response['error']
puts "Error: #{response['error']}"
elsif response.key?('result')
result = response['result']
attempts = result['attempts']
url = result['url']
if attempts.zero?
puts "Challenge failed. Attempts: #{attempts}"
elsif url.nil?
puts "Challenge succeeded but no URL available. Attempts: #{attempts}"
else
puts "Challenge succeeded. Attempts: #{attempts}"
puts "URL with keyword: #{API_ENDPOINT}#{url}"
end
break
end
end
The thing I want to do, Start a challenge by making a POST HTTP request to/challenges. At the scheduled invocation time (actives_at) time in the response, an HTTP request is sent as PUT to/challenges. At this time, it is necessary to give the challenge ID (id) to the X-Challenge-Id header.
I tried to print out the error message but seems the challenge succeeded just no URL available.
You need parse JSON from string to hash
After that you can process response