warden-github 0.4.3 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/warden-github/user.rb +62 -0
- data/lib/warden-github/version.rb +1 -1
- data/spec/proxy_spec.rb +3 -2
- data/spec/spec_helper.rb +1 -1
- metadata +4 -4
data/lib/warden-github/user.rb
CHANGED
@@ -21,6 +21,68 @@ module Warden
|
|
21
21
|
def company
|
22
22
|
attribs['company']
|
23
23
|
end
|
24
|
+
|
25
|
+
# See if the user is a public member of the named organization
|
26
|
+
#
|
27
|
+
# name - the organization name
|
28
|
+
#
|
29
|
+
# Returns: true if the user is publicized as an org member
|
30
|
+
def publicized_organization_member?(org_name)
|
31
|
+
members = github_request("orgs/#{name}/public_members")
|
32
|
+
members.map { |org| org["login"] }.include?(login)
|
33
|
+
rescue RestClient::Forbidden, RestClient::Unauthorized, RestClient::ResourceNotFound => e
|
34
|
+
false
|
35
|
+
end
|
36
|
+
|
37
|
+
# See if the user is a member of the named organization
|
38
|
+
#
|
39
|
+
# name - the organization name
|
40
|
+
#
|
41
|
+
# Returns: true if the user has access, false otherwise
|
42
|
+
def organization_member?(name)
|
43
|
+
orgs = github_request("orgs/#{name}/members")
|
44
|
+
orgs.map { |org| org["login"] }.include?(github_user.login)
|
45
|
+
rescue RestClient::Forbidden, RestClient::Unauthorized, RestClient::ResourceNotFound => e
|
46
|
+
false
|
47
|
+
end
|
48
|
+
|
49
|
+
# See if the user is a member of the team id
|
50
|
+
#
|
51
|
+
# team_id - the team's id
|
52
|
+
#
|
53
|
+
# Returns: true if the user has access, false otherwise
|
54
|
+
def team_member?(team_id)
|
55
|
+
members = github_request("teams/#{team_id}/members")
|
56
|
+
members.map { |user| user["login"] }.include?(login)
|
57
|
+
rescue RestClient::Forbidden, RestClient::Unauthorized, RestClient::ResourceNotFound => e
|
58
|
+
false
|
59
|
+
end
|
60
|
+
|
61
|
+
# Send a V3 API GET request to path and parse the response body
|
62
|
+
#
|
63
|
+
# path - the path on api.github.com to hit
|
64
|
+
#
|
65
|
+
# Returns a parsed JSON response
|
66
|
+
#
|
67
|
+
# Examples
|
68
|
+
# github_request("/user")
|
69
|
+
# # => { 'login' => 'atmos', ... }
|
70
|
+
def github_request(path)
|
71
|
+
Yajl.load(github_raw_request(path))
|
72
|
+
end
|
73
|
+
|
74
|
+
# Send a V3 API GET request to path
|
75
|
+
#
|
76
|
+
# path - the path on api.github.com to hit
|
77
|
+
#
|
78
|
+
# Returns a rest client response object
|
79
|
+
#
|
80
|
+
# Examples
|
81
|
+
# github_raw_request("/user")
|
82
|
+
# # => RestClient::Response
|
83
|
+
def github_raw_request(path)
|
84
|
+
RestClient.get("#{github_api_uri}/#{path}", :params => { :access_token => token }, :accept => :json)
|
85
|
+
end
|
24
86
|
end
|
25
87
|
end
|
26
88
|
end
|
data/spec/proxy_spec.rb
CHANGED
@@ -5,14 +5,15 @@ describe "Warden::Github::Oauth::Proxy" do
|
|
5
5
|
sha = Digest::SHA1.hexdigest(Time.now.to_s)
|
6
6
|
@proxy = Warden::Github::Oauth::Proxy.new(sha[0..19], sha[0..39],
|
7
7
|
'user,public_repo,repo,gist',
|
8
|
+
'http://example.org',
|
8
9
|
'http://example.org/auth/github/callback')
|
9
10
|
end
|
10
11
|
|
11
12
|
it "returns an authorize url" do
|
12
13
|
uri = Addressable::URI.parse(@proxy.authorize_url)
|
13
14
|
|
14
|
-
uri.scheme.should eql('
|
15
|
-
uri.host.should eql('
|
15
|
+
uri.scheme.should eql('http')
|
16
|
+
uri.host.should eql('example.org')
|
16
17
|
|
17
18
|
params = uri.query_values
|
18
19
|
params['response_type'].should eql('code')
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: warden-github
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 4
|
10
|
+
version: 0.4.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Corey Donohoe
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-05-
|
18
|
+
date: 2012-05-29 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|