Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added ajax

  • Loading branch information...
commit 64c54af83f9551d1e72a907e1bb1be2d7bf12964 1 parent 96e3739
@chrismatthieu authored
Showing with 40 additions and 16 deletions.
  1. +40 −16 githubchat.rb
View
56 githubchat.rb
@@ -6,14 +6,23 @@
use Rack::Session::Cookie
use OmniAuth::Builder do
- provider :github, '74a1475d7f5564343099', 'f8310520720f56e931f086d519c435d800c6997a' #github chat
- # provider :github, '25abed0273f2d33bd9a5', '5e1f21c1830c3c1a2816df2b1a1d798779763ce8' #testing
+ # provider :github, '74a1475d7f5564343099', 'f8310520720f56e931f086d519c435d800c6997a' #github chat
+ provider :github, '25abed0273f2d33bd9a5', '5e1f21c1830c3c1a2816df2b1a1d798779763ce8' #testing
end
get '/' do
if session[:user]
- html = "<h1>GitHub Issues Chat</h1><p>Hello #{session[:user][:name]}! (<a href=\"/logout\">logout</a>)</p><p>Identify a user and repo:</p>"
+ html = "<html><head><script src='http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js'></script><script>
+ $(document).ready(function() {
+ $('#btn').click(function(event){
+ $.get('/issuesajax', {user: $(user).val(), repo : $(repo).val()}, function(data) {
+ $('#answer').html(data);
+ });
+ });
+ });</script></head>"
+
+ html << "<body><h1>GitHub Issues Chat</h1><p><img src='https://secure.gravatar.com/avatar/#{session[:user][:gravatar_id]}?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png' width='50'> #{session[:user][:name]}! (<a href=\"/logout\">logout</a>)</p><p>Identify a user and repo:<br/>"
# # List Followers
# response = RestClient.get 'https://api.github.com/user/followers?access_token=' + session[:token]
@@ -22,7 +31,7 @@
# html << "<img src=\"#{follower['avatar_url']}\" width=\"25\"> #{follower['login']}<br/>" rescue ""
# end
- html << '<form action="/issues">User: <input type="text" name="user"> Repo: <input type="text" name="repo"><input type="submit" value="submit">'
+ html << 'User: <input type="text" id="user"> Repo: <input type="text" id="repo"><input name="btn" id="btn" type="button" value="Submit"></p><div id="answer"></div></body></html>'
html
@@ -34,26 +43,40 @@
end
-get '/issues' do
-
+# get '/issues' do
+#
+# user = params[:user]
+# repo = params[:repo]
+#
+# html = "<h1>GitHub Issues Chat</h1><p><img src='https://secure.gravatar.com/avatar/#{session[:user][:gravatar_id]}?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png' width='50'> #{session[:user][:name]}! (<a href=\"/\">home</a> | <a href=\"/logout\">logout</a>)<br/>Select an issue:</p>"
+#
+# response = RestClient.get 'https://api.github.com/repos/' + user + '/' + repo + '/issues'
+# issues = JSON.parse(response.body)
+# issues.each do |issue|
+# html << "<img src='#{issue['user']['avatar_url']}' title='#{issue['user']['login']}' width='25'></a> "
+#
+# html << "<a href=\"#{user}/#{repo}/issues/#{issue['number']}\">#{issue['number']}</a> #{issue['title']}<br/>"
+#
+# end
+#
+# html
+#
+# end
+
+get '/issuesajax' do
user = params[:user]
repo = params[:repo]
-
- html = "<h1>GitHub Issues Chat</h1><p>Hello #{session[:user][:name]}! (<a href=\"/\">home</a> | <a href=\"/logout\">logout</a>)</p><p>Select an issue:</p>"
-
response = RestClient.get 'https://api.github.com/repos/' + user + '/' + repo + '/issues'
- issues = JSON.parse(response.body)
+ issues = JSON.parse(response.body)
+ html = ""
issues.each do |issue|
html << "<img src='#{issue['user']['avatar_url']}' title='#{issue['user']['login']}' width='25'></a> "
-
- html << "<a href=\"#{user}/#{repo}/issues/#{issue['number']}\">#{issue['number']}</a> #{issue['title']}<br/>"
-
+ html << "<a href=\"#{user}/#{repo}/issues/#{issue['number']}\">#{issue['number']}</a> #{issue['title']}<br/>"
end
-
html
-
end
+
get '/:user/:repo/issues/:id' do
user = params[:user]
repo = params[:repo]
@@ -141,7 +164,7 @@
</head>
<body>'
- html << "<h1>GitHub Issues Chat</h1><p>Hello #{session[:user][:name]}! (<a href=\"/\">home</a> | <a href=\"/issues?user=#{user}&repo=#{repo}\">Issues</a> | <a href=\"/logout\">logout</a>)</p><p></p>"
+ html << "<h1>GitHub Issues Chat</h1><p><img src='https://secure.gravatar.com/avatar/#{session[:user][:gravatar_id]}?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png' width='50'> #{session[:user][:name]}! (<a href=\"/\">home</a> | <a href=\"/logout\">logout</a>)</p><p></p>"
response = RestClient.get 'https://api.github.com/repos/' + user + '/' + repo + '/issues/' + id
issue = JSON.parse(response.body)
@@ -172,6 +195,7 @@
omniauth['user_info']['name'] ? @authhash[:name] = omniauth['user_info']['name'] : @authhash[:name] = ''
omniauth['extra']['user_hash']['id'] ? @authhash[:uid] = omniauth['extra']['user_hash']['id'].to_s : @authhash[:uid] = ''
omniauth['provider'] ? @authhash[:provider] = omniauth['provider'] : @authhash[:provider] = ''
+ omniauth['extra']['user_hash']['gravatar_id'] ? @authhash[:gravatar_id] = omniauth['extra']['user_hash']['gravatar_id'].to_s : @authhash[:gravatar_id] = ''
session[:user] = @authhash
session[:token] = omniauth['credentials']['token']
Please sign in to comment.
Something went wrong with that request. Please try again.