Class: Warden::GitHub::User
- Inherits:
-
Struct
- Object
- Struct
- Warden::GitHub::User
- Defined in:
- lib/warden/github/user.rb
Constant Summary collapse
- ATTRIBUTES =
%w[id login name gravatar_id email company site_admin].freeze
Instance Attribute Summary collapse
-
#attribs ⇒ Object
Returns the value of attribute attribs.
-
#token ⇒ Object
Returns the value of attribute token.
Class Method Summary collapse
Instance Method Summary collapse
-
#api ⇒ Object
Access the GitHub API from Octokit.
- #marshal_dump ⇒ Object
- #marshal_load(hash) ⇒ Object
-
#organization_member?(org_name) ⇒ Boolean
See if the user is a member of the named organization.
-
#organization_public_member?(org_name) ⇒ Boolean
(also: #publicized_organization_member?)
See if the user is a public member of the named organization.
-
#site_admin? ⇒ Boolean
Identify GitHub employees/staff members.
-
#team_member?(team_id) ⇒ Boolean
See if the user is a member of the team id.
Instance Attribute Details
#attribs ⇒ Object
Returns the value of attribute attribs
5 6 7 |
# File 'lib/warden/github/user.rb', line 5 def attribs @attribs end |
#token ⇒ Object
Returns the value of attribute token
5 6 7 |
# File 'lib/warden/github/user.rb', line 5 def token @token end |
Class Method Details
.load(access_token) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/warden/github/user.rb', line 8 def self.load(access_token) api = Octokit::Client.new(:oauth_token => access_token) data = Hash[api.user.to_hash.select { |k,_| ATTRIBUTES.include?(k) }] new(data, access_token) end |
Instance Method Details
#api ⇒ Object
Access the GitHub API from Octokit
Octokit is a robust client library for the GitHub API github.com/pengwynn/octokit
Returns a cached client object for easy use
87 88 89 90 91 92 |
# File 'lib/warden/github/user.rb', line 87 def api # Don't cache instance for now because of a ruby marshaling bug present # in MRI 1.9.3 (Bug #7627) that causes instance variables to be # marshaled even when explicitly specifying #marshal_dump. Octokit::Client.new(:login => login, :oauth_token => token) end |
#marshal_dump ⇒ Object
15 16 17 |
# File 'lib/warden/github/user.rb', line 15 def marshal_dump Hash[members.zip(values)] end |
#marshal_load(hash) ⇒ Object
19 20 21 |
# File 'lib/warden/github/user.rb', line 19 def marshal_load(hash) hash.each { |k,v| send("#{k}=", v) } end |
#organization_member?(org_name) ⇒ Boolean
See if the user is a member of the named organization
name - the organization name
Returns: true if the user has access, false otherwise
46 47 48 49 50 |
# File 'lib/warden/github/user.rb', line 46 def organization_member?(org_name) memberships.fetch_membership(:org, org_name) do api.organization_member?(org_name, login) end end |
#organization_public_member?(org_name) ⇒ Boolean Also known as: publicized_organization_member?
See if the user is a public member of the named organization
name - the organization name
Returns: true if the user is publicized as an org member
32 33 34 35 36 |
# File 'lib/warden/github/user.rb', line 32 def organization_public_member?(org_name) memberships.fetch_membership(:org_pub, org_name) do api.organization_public_member?(org_name, login) end end |
#site_admin? ⇒ Boolean
Identify GitHub employees/staff members.
Returns: true if the authenticated user is a GitHub employee, false otherwise
77 78 79 |
# File 'lib/warden/github/user.rb', line 77 def site_admin? site_admin || false end |
#team_member?(team_id) ⇒ Boolean
See if the user is a member of the team id
team_id - the team’s id
Returns: true if the user has access, false otherwise
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/warden/github/user.rb', line 57 def team_member?(team_id) memberships.fetch_membership(:team, team_id) do # TODO: Use next line as method body once pengwynn/octokit#206 is public. # api.team_member?(team_id, login) begin # A user is only able to query for team members if they're a member. # Thus, if querying does succeed, they will be in the list and # checking the list won't be necessary. api.team_members(team_id) true rescue Octokit::NotFound false end end end |