-
-
Save mraaroncruz/9466732 to your computer and use it in GitHub Desktop.
Beginning of SOLID refactoring talk
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
#!/usr/bin/env ruby | |
require 'uri' | |
require 'net/http' | |
require 'json' | |
USER = "pferdefleisch" | |
def get_gists current_page | |
uri = URI("https://api.github.com/users/#{USER}/gists?page=#{current_page}") | |
res = Net::HTTP.get_response(uri) | |
JSON.parse(res.body) | |
end | |
def print_welcome | |
puts "Choose a gist" | |
puts "---------------------------------" | |
end | |
def print_gists_for_current_page page=1 | |
gists = get_gists page | |
gists.each_with_index do |g, i| | |
n = ((page - 1) * 30) | |
puts "%i. %s" % [i+n, g["description"]] | |
end | |
print "Which number? (or 'n' gets more results)" | |
input = gets.strip | |
if input == "n" | |
print_gists_for_current_page page+1 | |
else | |
puts "Thank you!" | |
n = (page - 1) * 30 | |
`open #{gists[input.to_i - n]["html_url"]}` | |
end | |
end | |
print_welcome | |
print_gists_for_current_page |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment