Created
February 19, 2016 13:47
-
-
Save tijmenb/72806ef95aaefc1eb2b1 to your computer and use it in GitHub Desktop.
Download tags
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
source 'https://rubygems.org' | |
gem 'http' |
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
GEM | |
remote: https://rubygems.org/ | |
specs: | |
addressable (2.4.0) | |
domain_name (0.5.20160128) | |
unf (>= 0.0.5, < 1.0.0) | |
http (1.0.2) | |
addressable (~> 2.3) | |
http-cookie (~> 1.0) | |
http-form_data (~> 1.0.1) | |
http_parser.rb (~> 0.6.0) | |
http-cookie (1.0.2) | |
domain_name (~> 0.5) | |
http-form_data (1.0.1) | |
http_parser.rb (0.6.0) | |
unf (0.1.4) | |
unf_ext | |
unf_ext (0.0.7.2) | |
PLATFORMS | |
ruby | |
DEPENDENCIES | |
http | |
BUNDLED WITH | |
1.11.2 |
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 'http' | |
def get(url) | |
# puts "Downloading: #{url}" | |
JSON.parse(HTTP.get(url)) | |
end | |
top_level = get('https://www.gov.uk/api/content/topic') | |
result = top_level.clone | |
result['links']['children'] = top_level['links']['children'].map do |not_expanded| | |
second_level = get(not_expanded['api_url']) | |
grand_children = second_level['links']['children'].map do |not_expanded| | |
get(not_expanded['api_url']) | |
end | |
second_level['links']['children'] = grand_children | |
second_level | |
end | |
puts JSON.pretty_generate(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment