Last active
February 9, 2018 21:59
-
-
Save differentreality/e48b6d4d3bea7630026e6107da695cb4 to your computer and use it in GitHub Desktop.
Stella Rouzi follow path from json response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mechanize' | |
require 'json' | |
url = 'http://letsrevolutionizetesting.com/challenge.json' | |
while url do | |
# Get content of page | |
connection = Mechanize.new | |
page = connection.get "#{url}" | |
content = JSON.parse(page.content) | |
# our json response looks like | |
# 'follow' => 'new-url' | |
# If we find the follow url, | |
# show it to user, and, well, follow it! | |
if path = content['follow'] | |
puts path | |
url = content['follow'].sub('?','.json?') | |
# If follow key is not found, | |
# show the page content | |
else | |
url = nil | |
puts content | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment