Skip to content

Instantly share code, notes, and snippets.

@mmrwoods
Created January 21, 2014 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmrwoods/8540848 to your computer and use it in GitHub Desktop.
Save mmrwoods/8540848 to your computer and use it in GitHub Desktop.
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]
@deepj
Copy link

deepj commented Jan 22, 2014

return on the end is Ruby antipattern :)

@mmrwoods
Copy link
Author

Haha, thanks Martin ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment