7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/github_organizations_scraper/cli.rb', line 7
def self.execute(stdout, arguments=[])
options = {}
parser = OptionParser.new do |opts|
opts.banner = <<-BANNER.gsub(/^ /,'')
Display the members of an organisation account on GitHub.
Usage: #{File.basename($0)} [options]
Options are:
BANNER
opts.separator ""
opts.on("-j", "--json",
"Display results in JSON format") { options[:json] = true }
opts.on("-h", "--help",
"Show this help message.") { stdout.puts opts; exit }
opts.parse!(arguments)
end
account = arguments.shift
html = Net::HTTP.get(URI.parse("http://github.com/#{account}"))
doc = Nokogiri::HTML(html)
members = doc.search("ul.org-members li").map do |member|
login = member.search("h4 a").text
if member.search("h4 em").text =~ /\((.*)\)/
name = $1
end
repo_summary = member.search("p").text
{ :login => login, :name => name, :repo_summary => repo_summary }
end
if options[:json]
display_members_json(stdout, members)
else
display_members_tty(stdout, members)
end
end
|