Example #1
0
        /// <summary>
        /// Check if a repository is starred by the current authenticated user.
        /// </summary>
        /// <param name="owner">The owner of the repository</param>
        /// <param name="name">The name of the repository</param>
        /// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
        /// <returns>A <c>bool</c> representing the success of the operation</returns>
        public async Task <bool> CheckStarred(string owner, string name)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "name");

            try
            {
                var response = await Connection.GetAsync <object>(ApiUrls.Starred(owner, name), null, null)
                               .ConfigureAwait(false);

                return(response.StatusCode == HttpStatusCode.NoContent);
            }
            catch (NotFoundException)
            {
                return(false);
            }
        }
Example #2
0
        /// <summary>
        /// Checks if the gist is starred
        /// </summary>
        /// <remarks>
        /// http://developer.github.com/v3/gists/#check-if-a-gist-is-starred
        /// </remarks>
        /// <param name="id">The id of the gist</param>
        public async Task <bool> IsStarred(string id)
        {
            Ensure.ArgumentNotNullOrEmptyString(id, "id");

            try
            {
                var response = await Connection.GetAsync <object>(ApiUrls.StarGist(id), null, null)
                               .ConfigureAwait(false);

                if (response.StatusCode != HttpStatusCode.NotFound && response.StatusCode != HttpStatusCode.NoContent)
                {
                    throw new ApiException("Invalid Status Code returned. Expected a 204 or a 404", response.StatusCode);
                }
                return(response.StatusCode == HttpStatusCode.NoContent);
            }
            catch (NotFoundException)
            {
                return(false);
            }
        }
Example #3
0
        /// <summary>
        /// Checks to see if a user is an assignee for a repository.
        /// </summary>
        /// <param name="owner">The owner of the repository</param>
        /// <param name="name">The name of the repository</param>
        /// <param name="assignee">Username of the prospective assignee</param>
        /// <returns></returns>
        public async Task <bool> CheckAssignee(string owner, string name, string assignee)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "name");
            Ensure.ArgumentNotNullOrEmptyString(assignee, "assignee");

            try
            {
                var response = await Connection.GetAsync <object>(ApiUrls.CheckAssignee(owner, name, assignee), null, null);

                if (response.StatusCode != HttpStatusCode.NotFound && response.StatusCode != HttpStatusCode.NoContent)
                {
                    throw new ApiException("Invalid Status Code returned. Expected a 204 or a 404", response.StatusCode);
                }
                return(response.StatusCode == HttpStatusCode.NoContent);
            }
            catch (NotFoundException)
            {
                return(false);
            }
        }
Example #4
0
        /// <summary>
        /// Check if one user follows another user
        /// </summary>
        /// <param name="login">The login name of the user</param>
        /// <param name="following">The login name of the other user</param>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/users/followers/#check-if-one-user-follows-another">API documentation</a> for more information.
        /// </remarks>
        /// <returns>A <c>bool</c> representing the success of the operation.</returns>
        public async Task <bool> IsFollowing(string login, string following)
        {
            Ensure.ArgumentNotNullOrEmptyString(login, "login");
            Ensure.ArgumentNotNullOrEmptyString(following, "following");

            try
            {
                var response = await Connection.GetAsync <object>(ApiUrls.IsFollowing(login, following), null, null)
                               .ConfigureAwait(false);

                if (response.StatusCode != HttpStatusCode.NotFound && response.StatusCode != HttpStatusCode.NoContent)
                {
                    throw new ApiException("Invalid Status Code returned. Expected a 204 or a 404", response.StatusCode);
                }
                return(response.StatusCode == HttpStatusCode.NoContent);
            }
            catch (NotFoundException)
            {
                return(false);
            }
        }
Example #5
0
        /// <summary>
        /// Check is a user is publicly a member of the organization.
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/orgs/members/#check-public-membership">API documentation</a>
        /// for more information.
        /// </remarks>
        /// <param name="org">The login for the organization</param>
        /// <param name="user">The login for the user</param>
        /// <returns></returns>
        public async Task <bool> CheckMemberPublic(string org, string user)
        {
            Ensure.ArgumentNotNullOrEmptyString(org, "org");
            Ensure.ArgumentNotNullOrEmptyString(user, "user");

            try
            {
                var response = await Connection.GetAsync <object>(ApiUrls.CheckMemberPublic(org, user), null, null)
                               .ConfigureAwait(false);

                if (response.StatusCode != HttpStatusCode.NotFound &&
                    response.StatusCode != HttpStatusCode.NoContent)
                {
                    throw new ApiException("Invalid Status Code returned. Expected a 204 or a 404", response.StatusCode);
                }
                return(response.StatusCode == HttpStatusCode.NoContent);
            }
            catch (NotFoundException)
            {
                return(false);
            }
        }
Example #6
0
        /// <summary>
        /// Get the pull request merge status.
        /// </summary>
        /// <remarks>http://developer.github.com/v3/pulls/#get-if-a-pull-request-has-been-merged</remarks>
        /// <param name="owner">The owner of the repository</param>
        /// <param name="name">The name of the repository</param>
        /// <param name="number">The pull request number</param>
        /// <returns>True if the operation has been merged, false otherwise</returns>
        public async Task <bool> Merged(string owner, string name, int number)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "name");

            try
            {
                var response = await Connection.GetAsync <object>(ApiUrls.MergePullRequest(owner, name, number), null, null)
                               .ConfigureAwait(false);

                if (response.StatusCode != HttpStatusCode.NotFound &&
                    response.StatusCode != HttpStatusCode.NoContent)
                {
                    throw new ApiException("Invalid Status Code returned. Expected a 204 or 404", response.StatusCode);
                }
                return(response.StatusCode == HttpStatusCode.NoContent);
            }
            catch (NotFoundException)
            {
                return(false);
            }
        }
Example #7
0
        /// <summary>
        /// Checks if a user is a collaborator on a repo
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/repos/collaborators/#get">API documentation</a> for more information.
        /// </remarks>
        /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
        /// <returns><see cref="bool"/>True if user is a collaborator else false</returns>
        public async Task <bool> IsCollaborator(string owner, string repo, string user)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(repo, "repo");
            Ensure.ArgumentNotNullOrEmptyString(user, "user");

            var endpoint = "repos/{0}/{1}/collaborators/{2}".FormatUri(owner, repo, user);

            try
            {
                var response = await Connection.GetAsync <object>(endpoint, null, null)
                               .ConfigureAwait(false);

                if (response.StatusCode != HttpStatusCode.NotFound && response.StatusCode != HttpStatusCode.NoContent)
                {
                    throw new ApiException("Invalid Status Code returned. Expected a 204 or a 404", response.StatusCode);
                }
                return(response.StatusCode == HttpStatusCode.NoContent);
            }
            catch (NotFoundException)
            {
                return(false);
            }
        }