Permalink
Browse files

add .org_member? and .org_public_member?

  • Loading branch information...
1 parent c85c83b commit de6019ee991e4ab9dfcca4e03867b634da799000 @joeyw joeyw committed Nov 29, 2012
Showing with 97 additions and 0 deletions.
  1. +45 −0 lib/octokit/client/organizations.rb
  2. +52 −0 spec/octokit/client/organizations_spec.rb
@@ -129,6 +129,51 @@ def organization_members(org, options={})
end
alias :org_members :organization_members
+ # Check if a user is a member of an organization.
+ #
+ # Use this to check if another user is a member of an organization that
+ # you are a member. If you are not in the organization you are checking,
+ # use .organization_public_member? instead.
+ #
+ # @param org [String] Organization GitHub username.
+ # @param user [String] GitHub username of the user to check.
+ #
+ # @return [Boolean] Is a member?
+ #
+ # @see http://developer.github.com/v3/orgs/members/#check-membership
+ #
+ # @example Check if a user is in your organization
+ # @client.organization_member?('your_organization', 'pengwynn')
+ # => false
+ def organization_member?(org, user, options={})
+ request(:get, "orgs/#{org}/members/#{user}", options).status == 204
+ rescue Octokit::NotFound
+ false
+ end
+ alias :org_member? :organization_member?
+
+ # Check if a user is a public member of an organization.
+ #
+ # If you are checking for membership of a user of an organization that
+ # you are in, use .organization_member? instead.
+ #
+ # @param org [String] Organization GitHub username.
+ # @param user [String] GitHub username of the user to check.
+ #
+ # @return [Boolean] Is a public member?
+ #
+ # @see http://developer.github.com/v3/orgs/members/#check-public-membership
+ #
+ # @example Check if a user is a hubbernaut
+ # @client.organization_public_member?('github', 'pengwynn')
+ # => true
+ def organization_public_member?(org, user, options={})
+ request(:get, "orgs/#{org}/public_members/#{user}", options).status == 204
+ rescue Octokit::NotFound
+ false
+ end
+ alias :org_public_member? :organization_public_member?
+
# List teams
#
# Requires authenticated organization member.
@@ -78,6 +78,58 @@
end
+ describe ".organization_member?" do
+
+ context "user is actually a member of the organization" do
+
+ it "returns true" do
+ stub_get("https://api.github.com/orgs/github/members/pengwynn").
+ to_return(:status => 204)
+ is_hubbernaut = @client.organization_member?('github', 'pengwynn')
+ expect(is_hubbernaut).to be_true
+ end
+
+ end
+
+ context "user is not actually a member of the organization" do
+
+ it "returns false" do
+ stub_get("https://api.github.com/orgs/github/members/joeyw").
+ to_return(:status => 404)
+ is_hubbernaut = @client.organization_member?('github', 'joeyw')
+ expect(is_hubbernaut).to be_false
+ end
+
+ end
+
+ end
+
+ describe ".organization_public_member?" do
+
+ context "user is actually a public member of the organization" do
+
+ it "returns true" do
+ stub_get("https://api.github.com/orgs/github/public_members/pengwynn").
+ to_return(:status => 204)
+ is_hubbernaut = @client.organization_public_member?('github', 'pengwynn')
+ expect(is_hubbernaut).to be_true
+ end
+
+ end
+
+ context "user is not actually a public member of the organization" do
+
+ it "returns false" do
+ stub_get("https://api.github.com/orgs/github/public_members/joeyw").
+ to_return(:status => 404)
+ is_hubbernaut = @client.organization_public_member?('github', 'joeyw')
+ expect(is_hubbernaut).to be_false
+ end
+
+ end
+
+ end
+
describe ".organization_teams" do
it "returns all teams for an organization" do

0 comments on commit de6019e

Please sign in to comment.