Created
June 14, 2012 23:14
-
-
Save jbpotonnier/2933598 to your computer and use it in GitHub Desktop.
Grep in gist description and display url
This file contains hidden or 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 'net/http' | |
require 'uri' | |
require 'json' | |
def github(*list) | |
URI('https://api.github.com/' + list.join('/')) | |
end | |
def get(uri) | |
request = Net::HTTP::Get.new uri.request_uri | |
Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http| | |
JSON::parse http.request(request).body | |
end | |
end | |
def find_gists(user) | |
get github 'users', user, 'gists' | |
end | |
def grep(user, arg) | |
gists = find_gists(user) | |
gists.select {|g| g['description'] =~ /#{arg}/}.map {|g| "- #{g['html_url']} : \n #{g['description']}" } | |
end | |
user = ARGV[0] | |
arg = ARGV[1] | |
puts grep(user, arg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment