Created
January 21, 2014 14:14
-
-
Save mmrwoods/8540848 to your computer and use it in GitHub Desktop.
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 'active_support' | |
require 'hirb' | |
require 'debugger' | |
user = 'thickpaddy' # FIXME: get from argv | |
def send_request(url, content=nil) | |
curl_opts = ["--max-time 30", "--silent"] | |
if content | |
curl_opts << "--header 'Content-Type: application/json'" | |
curl_opts << "--data '#{ActiveSupport::JSON.encode(content)}'" | |
end | |
response = `curl #{curl_opts.join(' ')} #{url}` | |
return ActiveSupport::JSON.decode(response) | |
end | |
def download(url, saveas) | |
curl_opts = ["--max-time 30", "--silent", "--location"] | |
curl_opts << "--output #{saveas}" | |
`curl #{curl_opts.join(' ')} #{url}` | |
end | |
downloaded = [] | |
repos = send_request("https://api.github.com/users/#{user}/repos?per_page=100") | |
repos.each do |repo| | |
puts "Downloading #{repo['name']}..." | |
download "https://github.com/#{user}/#{repo['name']}/archive/master.tar.gz", "tmp/#{repo['name']}.tar.gz" | |
downloaded << { | |
name: repo['name'], | |
description: repo['description'], | |
fork: repo['fork'] | |
} | |
end | |
gists = send_request("https://api.github.com/users/#{user}/gists?per_page=100") | |
gists.each do |gist| | |
puts "Downloading gist#{gist['id']}..." | |
download "https://gist.github.com/#{user}/#{gist['id']}/download", "tmp/gist#{gist['id']}.tar.gz" | |
downloaded << { | |
name: "gist#{gist['id']}", | |
description: gist['description'] | |
} | |
end | |
extend Hirb::Console | |
table downloaded, :fields => [:name, :description, :fork] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
return on the end is Ruby antipattern :)