Permalink
Browse files

actually use the new user methods

  • Loading branch information...
atmos committed May 29, 2012
1 parent ea1911e commit 84a49ab41cbfb68ed520ecf91197273420d65370
Showing with 25 additions and 6 deletions.
  1. +16 −4 lib/warden-github/user.rb
  2. +1 −1 lib/warden-github/version.rb
  3. +6 −1 spec/app.rb
  4. +2 −0 warden-github.gemspec
View
@@ -1,3 +1,6 @@
+require 'yajl'
+require 'rest-client'
+
module Warden
module Github
module Oauth
@@ -28,7 +31,7 @@ def company
#
# Returns: true if the user is publicized as an org member
def publicized_organization_member?(org_name)
- members = github_request("orgs/#{name}/public_members")
+ members = github_request("orgs/#{org_name}/public_members")
members.map { |org| org["login"] }.include?(login)
rescue RestClient::Forbidden, RestClient::Unauthorized, RestClient::ResourceNotFound => e
false
@@ -39,9 +42,9 @@ def publicized_organization_member?(org_name)
# name - the organization name
#
# Returns: true if the user has access, false otherwise
- def organization_member?(name)
- orgs = github_request("orgs/#{name}/members")
- orgs.map { |org| org["login"] }.include?(github_user.login)
+ def organization_member?(org_name)
+ orgs = github_request("orgs/#{org_name}/members")
+ orgs.map { |org| org["login"] }.include?(login)
rescue RestClient::Forbidden, RestClient::Unauthorized, RestClient::ResourceNotFound => e
false
end
@@ -83,6 +86,15 @@ def github_request(path)
def github_raw_request(path)
RestClient.get("#{github_api_uri}/#{path}", :params => { :access_token => token }, :accept => :json)
end
+
+ private
+ def github_api_uri
+ if ENV['GITHUB_OAUTH_API_DOMAIN']
+ ENV['GITHUB_OAUTH_API_DOMAIN']
+ else
+ "https://api.github.com"
+ end
+ end
end
end
end
@@ -1,5 +1,5 @@
module Warden
module Github
- VERSION = "0.4.4"
+ VERSION = "0.5.0"
end
end
View
@@ -32,7 +32,12 @@ def user
get '/' do
ensure_authenticated
- "Hello There, #{user.name}!"
+ <<-EOS
+ <h2>Hello There, #{user.name}!</h2>
+ <h3>Rails Org Member: #{user.organization_member?('rails')}.</h3>
+ <h3>Publicized Rails Org Member: #{user.publicized_organization_member?('rails')}.</h3>
+ <h3>Rails Committer Team Member: #{user.team_member?(632)}.</h3>
+ EOS
end
get '/redirect_to' do
View
@@ -18,6 +18,8 @@ Gem::Specification.new do |s|
s.add_dependency "json", "~>1.5"
s.add_dependency "warden", "~>1.0"
s.add_dependency "oauth2", "~>0.5.2"
+ s.add_dependency "rest-client", "~>1.6.1"
+ s.add_dependency "yajl-ruby", "~>1.1"
s.add_development_dependency "rack", "~>1.4.0"
s.add_development_dependency "rake"

0 comments on commit 84a49ab

Please sign in to comment.