Skip to content

Instantly share code, notes, and snippets.

@neonichu
Created May 25, 2015 13:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neonichu/465391e44617bd5975ce to your computer and use it in GitHub Desktop.
Save neonichu/465391e44617bd5975ce to your computer and use it in GitHub Desktop.
GitHop web app
require 'githop'
require 'sinatra'
def githop_html(user)
config = {
'bigquery' => {
'client_id' => ENV['BIGQUERY_CLIENT_ID'],
'service_email' => ENV['BIGQUERY_SERVICE_EMAIL'],
'keyfile' => ENV['BIGQUERY_KEYFILE'],
'project_id' => ENV['BIGQUERY_PROJECT_ID']
}
}
result = GitHop.hop(config, user)
result = GitHop.pretty_print(result, user) unless result['rows'].nil?
if result.is_a?(Array) && result.count > 0
html(result.join("\n"))
else
html("No events found, but #{user} surely had an awesome day nevertheless :)")
end
end
def html(string)
<<-EOF
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>GitHop</title>
</head>
<body><pre>#{string}</pre></body>
</html>
EOF
end
get '/' do
githop_html('orta')
end
get '/:user' do |user|
githop_html(user)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment