Skip to content

Instantly share code, notes, and snippets.

@differentreality
Last active February 9, 2018 21:59
Show Gist options
  • Save differentreality/e48b6d4d3bea7630026e6107da695cb4 to your computer and use it in GitHub Desktop.
Save differentreality/e48b6d4d3bea7630026e6107da695cb4 to your computer and use it in GitHub Desktop.
Stella Rouzi follow path from json response
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