예제 #1
0
        //http://developer.github.com/v3/issues/#edit-an-issue
        public static IRestResponse <TIssue> EditIssue <TIssue>(this GithubRestApiClient client,
                                                                string RepoOwner, string Repo, long IssueNumber, string Title = null, string Body = null, string Asignee = null, string State = null, string[] Labels = null) where TIssue : new()
        {
            dynamic data = GetUpdateData(Title, Body, Asignee, State, Labels);

            var request = client.RequestFactory.CreateRequest(
                () =>
            {
                var req = new RestRequest("/repos/{owner}/{repo}/issues/{number}")
                {
                    Method        = Method.PATCH,
                    RequestFormat = DataFormat.Json
                };

                req.AddBody(data);
                req.AddUrlSegment("owner", RepoOwner);
                req.AddUrlSegment("repo", Repo);
                req.AddUrlSegment("number", IssueNumber.ToString());
                return(req);
            });

            var response = client.Execute <TIssue>(request);

            return(response);
        }
예제 #2
0
        //http://developer.github.com/v3/issues/comments/#create-a-comment
        //TODO: do we like this way of specifying URL parameters?  Should we require a Repo Object instead?
        public static IRestResponse <TComment> CreateComment <TComment>(this GithubRestApiClient client,
                                                                        string RepoOwner, string Repo, long Number, string CommentText) where TComment : new()
        {
            dynamic data = GetUpdateData(CommentText);

            var request = client.RequestFactory.CreateRequest(
                () =>
            {
                var req = new RestRequest("/repos/{owner}/{repo}/issues/{number}/comments")
                {
                    Method        = Method.POST,
                    RequestFormat = DataFormat.Json
                };

                req.AddBody(data);
                req.AddUrlSegment("owner", RepoOwner);
                req.AddUrlSegment("repo", Repo);
                req.AddUrlSegment("number", Number.ToString());
                return(req);
            });

            var response = client.Execute <TComment>(request);

            return(response);
        }
예제 #3
0
        /// <summary>
        /// Get the authenticated user
        /// </summary>
        /// <param name="client">The <see cref="GithubRestApiClient"/> instance to attach to.</param>
        /// <typeparam name="TIssue">The user model to serialise the JSON data into.</typeparam>
        /// <returns>A <see cref="IRestResponse{TIssue}"/> for the authenticated user.</returns>
        public static IRestResponse <T> GetUser <T>(this GithubRestApiClient client) where T : new()
        {
            Log.Info(() => "Making request for the authenticated user.");
            var request = client.RequestFactory.CreateRequest(() => new RestRequest("/user"));

            var response = client.Execute <T>(request);

            return(response);
        }
예제 #4
0
        /// <summary>
        /// Get a single user
        /// </summary>
        /// <param name="client">The <see cref="GithubRestApiClient"/> instance to attach to.</param>
        /// <param name="username">The user to get from GitHub.</param>
        public static IRestResponse <TUser> GetUser <TUser>(this GithubRestApiClient client, string username) where TUser : new()
        {
            var request = client.RequestFactory.CreateRequest("/users/{username}", Method.GET,
                                                              new[]
            {
                new KeyValuePair <string, string>("username",
                                                  username)
            });

            var response = client.Execute <TUser>(request);

            return(response);
        }
예제 #5
0
        /// <summary>
        /// Get all users
        /// </summary>
        /// <remarks>
        /// This provides a dump of every user, in the order that they signed up for GitHub.
        /// </remarks>
        /// <param name="client">The <see cref="GithubRestApiClient"/> instance to attach to.</param>
        /// <param name="id">The integer ID of the last User that you’ve seen.</param>
        /// <returns>A <see cref="IRestResponse"/> containing a chunk of users.</returns>
        public static IRestResponse GetUsers(this GithubRestApiClient client, string id = "")
        {
            var request = client.RequestFactory.CreateRequest(() =>
            {
                var req = new RestRequest("/users?since={id}")
                {
                    Method = Method.GET
                };
                req.AddUrlSegment("id",
                                  Convert.ToString(id,
                                                   CultureInfo.InvariantCulture));
                return(req);
            });
            var response = client.Execute(request);

            return(response);
        }
예제 #6
0
        /// <summary>
        /// List all issues across all the authenticated user’s visible repositories including owned repositories, member repositories, and organization repositories:  http://developer.github.com/v3/issues/#list-issues
        /// </summary>
        /// <param name="client">The <see cref="GithubRestApiClient"/> instance to attach to.</param>
        /// <typeparam name="TIssue">The issue model to serialise the JSON data into.</typeparam>
        /// <returns>A <see cref="IRestResponse{TIssue}"/> for the issues.</returns>
        public static IRestResponse <TIssue> GetIssues <TIssue>(this GithubRestApiClient client) where TIssue : new()
        {
            Log.Info(() => "Making request for the issues.");
            var request = client.RequestFactory.CreateRequest(
                () =>
            {
                var req = new RestRequest("/issues?filter={filter}")
                {
                    Method = Method.GET
                };
                req.AddUrlSegment("filter", "all");
                return(req);
            }
                );

            var response = client.Execute <TIssue>(request);

            return(response);
        }
        //http://developer.github.com/v3/repos/collaborators/#add-collaborator
        //Strange one, has no response object
        public static IRestResponse AddCollaborator(this GithubRestApiClient client,
                                                    string RepoOwner, string Repo, string UserID)
        {
            var request = client.RequestFactory.CreateRequest(
                () =>
            {
                var req = new RestRequest("/repos/{owner}/{repo}/collaborators/{user}")
                {
                    Method        = Method.PUT,
                    RequestFormat = DataFormat.Json
                };

                req.AddUrlSegment("owner", RepoOwner);
                req.AddUrlSegment("repo", Repo);
                req.AddUrlSegment("user", UserID);
                return(req);
            });

            var response = client.Execute(request);

            return(response);
        }
예제 #8
0
        public static IRestResponse <TUser> UpdateUser <TUser>(this GithubRestApiClient client,
                                                               string name     = "", string email = "", string blog = null, string company = "", string location = "",
                                                               string hireable = "", string bio   = "") where TUser : new()
        {
            dynamic data = GetUpdateData(name, email, blog, company, location, hireable, bio);

            var request = client.RequestFactory.CreateRequest(
                () =>
            {
                var req = new RestRequest("/user")
                {
                    Method        = Method.PATCH,
                    RequestFormat = DataFormat.Json
                };
                req.AddBody(data);
                return(req);
            });

            var response = client.Execute <TUser>(request);

            return(response);
        }