Exemple #1
0
                /// <summary>
                /// Accepts the specified MergeRequest.
                /// </summary>
                /// <param name="_Config">The configuration.</param>
                /// <param name="_MergeRequest">The merge request.</param>
                /// <param name="_CommitMessage">The commit message (Optional).</param>
                /// <returns></returns>
                /// <exception cref="GitLabServerErrorException"></exception>
                public static MergeRequest Accept(Config _Config, MergeRequest _MergeRequest, string _CommitMessage = null)
                {
                    MergeRequest RetVal;

                    try
                    {
                        string URI = _Config.APIUrl + "/projects/" + _MergeRequest.project_id + "/merge_requests/" + _MergeRequest.id + "/merge?";

                        if (_CommitMessage != null)
                        {
                            URI += "&merge_commit_message=" + HttpUtility.UrlEncode(_CommitMessage);
                        }

                        HttpResponse <string> R = Unirest.put(URI)
                                                  .header("accept", "application/json")
                                                  .header("PRIVATE-TOKEN", _Config.APIKey)
                                                  .asString();

                        if (R.Code < 200 || R.Code >= 300)
                        {
                            throw new GitLabServerErrorException(R.Body, R.Code);
                        }
                        else
                        {
                            RetVal = JsonConvert.DeserializeObject <MergeRequest>(R.Body.ToString());
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    return(RetVal);
                }
Exemple #2
0
        public void WhenICallTheAPIWithUpdateParametersForUpdatingTheUserDetails()
        {
            HttpResponse <string> jsonResponseUpdateUser = Unirest.put(GivenIHaveTheAPIUrlToUpdateAUserSDetails()).header("Content-Type", "application/json").header("cache-control", "no-cache").body(jsonRead.JSonConvertUpdate()).asJson <string>();

            response       = jsonResponseUpdateUser.Body.ToString();
            responseStatus = jsonResponseUpdateUser.Code.ToString();
        }
Exemple #3
0
                /// <summary>
                /// Update a Project Label. At least one of NewName or NewColor must be specified
                /// </summary>
                /// <param name="_Config"></param>
                /// <param name="_Project"></param>
                /// <param name="_Label"></param>
                /// <param name="_NewName"></param>
                /// <param name="_NewColor"></param>
                /// <returns></returns>
                public static Label Update(Config _Config, Project _Project, Label _Label, string _NewName = null, string _NewColor = null)
                {
                    if (_NewName == null && _NewColor == null)
                    {
                        throw new ArgumentException("Color or New Name must be specified.");
                    }

                    string URI = _Config.APIUrl + "projects/" + _Project.id.ToString() + "/labels/"
                                 + "?name=" + HttpUtility.UrlEncode(_Label.name);

                    if (_NewName != null)
                    {
                        URI += "&new_name=" + HttpUtility.UrlEncode(_NewName);
                    }

                    if (_NewColor != null)
                    {
                        URI += "&color=" + HttpUtility.UrlEncode(_NewColor);
                    }

                    HttpResponse <string> R = Unirest.put(URI)
                                              .header("accept", "application/json")
                                              .header("PRIVATE-TOKEN", _Config.APIKey)
                                              .asString();

                    if (R.Code < 200 || R.Code >= 300)
                    {
                        throw new GitLabServerErrorException(R.Body, R.Code);
                    }
                    else
                    {
                        return(JsonConvert.DeserializeObject <Label>(R.Body));
                    }
                }
Exemple #4
0
                /// <summary>
                /// Updates the Milestone.
                /// </summary>
                /// <param name="_Config">The _ configuration.</param>
                /// <param name="_Project">The _ project.</param>
                /// <param name="_Milestone">The _ milestone.</param>
                /// <param name="_StateEvent">The _ state event.</param>
                /// <exception cref="GitLabServerErrorException"></exception>
                public static void Update(Config _Config, Project _Project, Milestone _Milestone, StateEvent _StateEvent = StateEvent.NONE)
                {
                    try
                    {
                        string URI = _Config.APIUrl + "projects/" + _Project.id.ToString() + "/milestones/" + _Milestone.id.ToString()
                                     + "?title=" + HttpUtility.UrlEncode(_Milestone.title)
                                     + "&description=" + HttpUtility.UrlEncode(_Milestone.description)
                                     + "&due_date=" + HttpUtility.UrlEncode(_Milestone.due_date);

                        if (_StateEvent != StateEvent.NONE)
                        {
                            URI += "&state_event=" + HttpUtility.UrlEncode(_StateEvent.ToString().ToLowerInvariant());
                        }

                        HttpResponse <string> R = Unirest.put(URI)
                                                  .header("accept", "application/json")
                                                  .header("PRIVATE-TOKEN", _Config.APIKey)
                                                  .asString();

                        if (R.Code < 200 || R.Code >= 300)
                        {
                            throw new GitLabServerErrorException(R.Body, R.Code);
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
Exemple #5
0
        /// <summary>
        /// saveSmsLinkGroup is a method that allows you to create an SMS link group. An SMS link group is an entity that contains one or several links. For SMS traffic coming from Voxbone to one of your DIDs, you need to link the DID to the link group so that the traffic can be routed to the appropriate destination. If several links are contained in the link group, the traffic will be load balanced according to the weight parameter defined in the links definition.
        /// </summary>
        /// <param name="name">Optional parameter: This is the name of the link group that you wish to create. There is no specific limitations except that the name should contain less than 255 characters.</param>
        /// <return>Returns the dynamic response from the API call</return>
        public async Task <dynamic> UpdateSaveSmsLinkGroupAsync(
            string name = null)
        {
            //the base uri for api requests
            string baseUri = Configuration.BaseUri;

            //prepare query string for API call
            StringBuilder queryBuilder = new StringBuilder(baseUri);

            queryBuilder.Append("/services/rest/configuration/smslinkgroup");


            //validate and preprocess url
            string queryUrl = APIHelper.CleanUrl(queryBuilder);

            //prepare and invoke the API call request to fetch the response
            HttpRequest request = Unirest.put(queryUrl)
                                  //append request with appropriate headers and parameters
                                  .header("User-Agent", "APIMATIC 2.0")
                                  .header("Accept", "application/json")
                                  .basicAuth(basicAuthUserName, basicAuthPassword)
                                  .body(name);

            //invoke request and get response
            HttpResponse <String> response = await request.asStringAsync();

            //Error handling using HTTP status codes
            if ((response.Code < 200) || (response.Code > 206)) //[200,206] = HTTP OK
            {
                throw new APIException(@"HTTP Response Not OK", response.Code);
            }

            return(APIHelper.JsonDeserialize <dynamic>(response.Body));
        }
Exemple #6
0
                /// <summary>
                /// Updates a project webhook on the GitLab server.
                /// </summary>
                /// <param name="_Config"></param>
                /// <param name="_Webhook"></param>
                /// <param name="_Project"></param>
                public static void Update(Config _Config, Webhook _Webhook, Project _Project)
                {
                    try
                    {
                        string URI = _Config.APIUrl + "/projects/" + _Project.id.ToString() + "/hooks/" + _Webhook.id;

                        URI += "?url=" + HttpUtility.UrlEncode(_Webhook.url)
                               + "&push_events=" + Convert.ToInt32(_Webhook.push_events).ToString()
                               + "&issues_events=" + Convert.ToInt32(_Webhook.issues_events).ToString()
                               + "&merge_requests_events=" + Convert.ToInt32(_Webhook.merge_requests_events).ToString()
                               + "&tag_push_events=" + Convert.ToInt32(_Webhook.tag_push_events).ToString()
                               + "&note_events=" + Convert.ToInt32(_Webhook.note_events).ToString()
                               + "&enable_ssl_verification=" + Convert.ToInt32(_Webhook.enable_ssl_verification).ToString();

                        HttpResponse <string> R = Unirest.put(URI)
                                                  .header("accept", "application/json")
                                                  .header("PRIVATE-TOKEN", _Config.APIKey)
                                                  .asString();

                        if (R.Code < 200 || R.Code >= 300)
                        {
                            throw new GitLabServerErrorException(R.Body, R.Code);
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
Exemple #7
0
        /// <summary>
        /// Update one or more objects
        /// </summary>
        /// <return>Returns the CustomersModel response from the API call</return>
        public async Task <CustomersModel> PutUpdateCustomersAsync()
        {
            //the base uri for api requests
            string baseUri = Configuration.BaseUri;

            //prepare query string for API call
            StringBuilder queryBuilder = new StringBuilder(baseUri);

            queryBuilder.Append("/Customers");


            //validate and preprocess url
            string queryUrl = APIHelper.CleanUrl(queryBuilder);

            //prepare and invoke the API call request to fetch the response
            HttpRequest request = Unirest.put(queryUrl)
                                  //append request with appropriate headers and parameters
                                  .header("User-Agent", "APIMATIC 2.0")
                                  .header("Accept", "application/json");

            //invoke request and get response
            HttpResponse <String> response = await request.asStringAsync();

            //Error handling using HTTP status codes
            if ((response.Code < 200) || (response.Code > 206)) //[200,206] = HTTP OK
            {
                throw new APIException(@"HTTP Response Not OK", response.Code);
            }

            return(APIHelper.JsonDeserialize <CustomersModel>(response.Body));
        }
Exemple #8
0
            /// <summary>
            /// Update any project
            /// </summary>
            /// <param name="_Config">Gitlab Config Object</param>
            /// <param name="_Project">Project object</param>
            /// <returns></returns>
            public static Project Update(Config _Config, Project _Project)
            {
                string URI = _Config.APIUrl + "projects/" + _Project.id.ToString()
                             + "?name=" + HttpUtility.UrlEncode(_Project.name)
                             + "&path=" + HttpUtility.UrlEncode(_Project.path)
                             + "&description=" + HttpUtility.UrlEncode(_Project.description);

                if (!String.IsNullOrWhiteSpace(_Project.default_branch))
                {
                    URI += "&default_branch=" + HttpUtility.UrlEncode(_Project.default_branch);
                }

                URI += "&issues_enabled=" + Convert.ToInt32(_Project.issues_enabled).ToString()
                       + "&merge_requests_enabled=" + Convert.ToInt32(_Project.merge_requests_enabled).ToString()
                       + "&builds_enabled=" + Convert.ToInt32(_Project.builds_enabled).ToString()
                       + "&wiki_enabled=" + Convert.ToInt32(_Project.wiki_enabled).ToString()
                       + "&snippets_enabled=" + Convert.ToInt32(_Project.snippets_enabled).ToString()
                       + "&visibility_level=" + Convert.ToInt64(_Project.visibility_level).ToString();

                HttpResponse <string> R = Unirest.put(URI)
                                          .header("accept", "application/json")
                                          .header("PRIVATE-TOKEN", _Config.APIKey)
                                          .asString();

                if (R.Code < 200 || R.Code >= 300)
                {
                    throw new GitLabServerErrorException(R.Body + " / " + URI, R.Code);
                }

                Project RetVal = JsonConvert.DeserializeObject <Project>(R.Body);

                return(RetVal);
            }
Exemple #9
0
                /// <summary>
                /// Update the properties of a project snippet
                /// </summary>
                /// <param name="_Config"></param>
                /// <param name="_Project"></param>
                /// <param name="_Snippet"></param>
                /// <param name="_NewCode"></param>
                /// <param name="_NewVisibilityLevel"></param>
                public static void Update(Config _Config, Project _Project, Snippet _Snippet, string _NewCode = null, VisibilityLevel _NewVisibilityLevel = VisibilityLevel.Undefined)
                {
                    try
                    {
                        string URI = _Config.APIUrl + "projects/" + _Project.id.ToString() + "/snippets/" + _Snippet.id.ToString()
                                     + "?title=" + HttpUtility.UrlEncode(_Snippet.title)
                                     + "&file_name=" + HttpUtility.UrlEncode(_Snippet.file_name);

                        if (_NewCode != null)
                        {
                            URI += "&code=" + HttpUtility.UrlEncode(_NewCode);
                        }

                        if (_NewVisibilityLevel != VisibilityLevel.Undefined)
                        {
                            URI += "&visibility_level=" + Convert.ToInt64(_NewVisibilityLevel).ToString();
                        }

                        HttpResponse <string> R = Unirest.put(URI)
                                                  .header("accept", "application/json")
                                                  .header("PRIVATE-TOKEN", _Config.APIKey)
                                                  .asString();

                        if (R.Code < 200 || R.Code >= 300)
                        {
                            throw new GitLabServerErrorException(R.Body, R.Code);
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
 public void Unirest_Should_Return_Correct_URL()
 {
     Unirest.get("http://localhost").URL.OriginalString.Should().Be("http://localhost");
     Unirest.post("http://localhost").URL.OriginalString.Should().Be("http://localhost");
     Unirest.delete("http://localhost").URL.OriginalString.Should().Be("http://localhost");
     Unirest.patch("http://localhost").URL.OriginalString.Should().Be("http://localhost");
     Unirest.put("http://localhost").URL.OriginalString.Should().Be("http://localhost");
 }
 public static void Unirest_Should_Return_Correct_URL()
 {
     Assert.Equal("http://localhost", Unirest.get("http://localhost").URL.OriginalString);
     Assert.Equal("http://localhost", Unirest.post("http://localhost").URL.OriginalString);
     Assert.Equal("http://localhost", Unirest.delete("http://localhost").URL.OriginalString);
     Assert.Equal("http://localhost", Unirest.patch("http://localhost").URL.OriginalString);
     Assert.Equal("http://localhost", Unirest.put("http://localhost").URL.OriginalString);
 }
 public static void Unirest_Should_Return_Correct_Verb()
 {
     Assert.Equal(HttpMethod.Get, Unirest.get("http://localhost").HttpMethod);
     Assert.Equal(HttpMethod.Post, Unirest.post("http://localhost").HttpMethod);
     Assert.Equal(HttpMethod.Delete, Unirest.delete("http://localhost").HttpMethod);
     Assert.Equal(new HttpMethod("PATCH"), Unirest.patch("http://localhost").HttpMethod);
     Assert.Equal(HttpMethod.Put, Unirest.put("http://localhost").HttpMethod);
 }
 public void Unirest_Should_Return_Correct_Verb()
 {
     Unirest.get("http://localhost").HttpMethod.Should().Be(HttpMethod.Get);
     Unirest.post("http://localhost").HttpMethod.Should().Be(HttpMethod.Post);
     Unirest.delete("http://localhost").HttpMethod.Should().Be(HttpMethod.Delete);
     Unirest.patch("http://localhost").HttpMethod.Should().Be(new HttpMethod("PATCH"));
     Unirest.put("http://localhost").HttpMethod.Should().Be(HttpMethod.Put);
 }
Exemple #14
0
                /// <summary>
                /// Saves the specified Issue on the GitLab server
                /// </summary>
                /// <param name="_Config">The configuration.</param>
                /// <param name="_Issue">The issue.</param>
                /// <param name="_StateEvent"></param>
                /// <returns></returns>
                public static Issue Update(Config _Config, Issue _Issue, StateEvent _StateEvent = StateEvent.None)
                {
                    string labels = null;
                    bool   first  = true;

                    if (_Issue.labels != null)
                    {
                        labels = "";

                        foreach (string l in _Issue.labels)
                        {
                            if (!first)
                            {
                                labels += ",";
                            }

                            labels += l;
                            first   = false;
                        }
                    }

                    string URI = _Config.APIUrl + "projects/" + _Issue.project_id.ToString() + "/issues/" + _Issue.id.ToString()
                                 + "?title=" + HttpUtility.UrlEncode(_Issue.title)
                                 + "&description=" + HttpUtility.UrlEncode(_Issue.description);

                    if (_Issue.assignee != null)
                    {
                        URI += "&assignee_id=" + _Issue.assignee.id;
                    }
                    if (_Issue.milestone != null)
                    {
                        URI += "&milestone_id=" + _Issue.milestone.id;
                    }
                    if (_Issue.labels != null)
                    {
                        URI += "&labels=" + HttpUtility.UrlEncode(labels);
                    }
                    if (_StateEvent != StateEvent.None)
                    {
                        URI += "&state_event=" + HttpUtility.UrlEncode(_StateEvent.ToString().ToLowerInvariant());
                    }

                    HttpResponse <string> R = Unirest.put(URI)
                                              .header("accept", "application/json")
                                              .header("PRIVATE-TOKEN", _Config.APIKey)
                                              .asString();

                    if (R.Code < 200 || R.Code >= 300)
                    {
                        throw new GitLabServerErrorException(R.Body, R.Code);
                    }
                    else
                    {
                        return(JsonConvert.DeserializeObject <Issue>(R.Body));
                    }
                }
            /// <summary>
            /// Updates a group team member to a specified access level.
            /// </summary>
            /// <param name="_Config"></param>
            /// <param name="_Group"></param>
            /// <param name="_User"></param>
            /// <param name="_AccessLevel"></param>
            public static void UpdateMember(Config _Config, Group _Group, User _User, Member.AccessLevel _AccessLevel)
            {
                string URI = _Config.APIUrl + "groups/" + _Group.id.ToString() + "/members/" + _User.id + "&access_level=" + Convert.ToInt64(_AccessLevel);

                HttpResponse <string> R = Unirest.put(URI)
                                          .header("accept", "application/json")
                                          .header("PRIVATE-TOKEN", _Config.APIKey)
                                          .asString();

                if (R.Code < 200 || R.Code >= 300)
                {
                    throw new GitLabServerErrorException(R.Body, R.Code);
                }
            }
        // .header("Content-Type", "application/json")
        public ClosePersonList CreatePutRequest(string personId, PersonRecord personToUpdate, string fbToken)
        {
            string url = String.Concat(URLSERVER, personId + "?authtoken=" + fbToken);

            HttpResponse <string> jsonResponse = Unirest.put(url)
                                                 .header("Content-Type", "application/json")
                                                 .body(personToUpdate.ToJson())
                                                 .asString();

            var closePersonsList = JsonConvert.DeserializeObject <ClosePersonList>(jsonResponse.Body);


            return(closePersonsList);
        }
Exemple #17
0
                /// <summary>
                /// Updates a comment.
                /// </summary>
                /// <param name="_Config">The _ configuration.</param>
                /// <param name="_MergeRequest">The _ merge request.</param>
                /// <param name="_Note">The _ note.</param>
                /// <returns></returns>
                public static Note UpdateComment(Config _Config, MergeRequest _MergeRequest, Note _Note)
                {
                    string URI = _Config.APIUrl + "projects/" + _MergeRequest.project_id.ToString() + "/merge_requests/" + _MergeRequest.id + "/notes/" + _Note.id
                                 + "?body=" + HttpUtility.UrlEncode(_Note.body);


                    HttpResponse <string> R = Unirest.put(URI)
                                              .header("accept", "application/json")
                                              .header("PRIVATE-TOKEN", _Config.APIKey)
                                              .asString();

                    if (R.Code < 200 || R.Code >= 300)
                    {
                        throw new GitLabServerErrorException(R.Body, R.Code);
                    }
                    else
                    {
                        return(JsonConvert.DeserializeObject <Note>(R.Body));
                    }
                }
Exemple #18
0
            /// <summary>
            /// Updates a project team member to a specified access level.
            /// </summary>
            /// <param name="_Config"></param>
            /// <param name="_Project"></param>
            /// <param name="_User"></param>
            /// <param name="_AccessLevel"></param>
            public static void UpdateMember(Config _Config, Project _Project, User _User, Member.AccessLevel _AccessLevel)
            {
                //OWNER access level only valid for groups according to https://docs.gitlab.com/ce/api/access_requests.html
                if (_AccessLevel > Member.AccessLevel.MASTER)
                {
                    _AccessLevel = Member.AccessLevel.MASTER;
                }

                string URI = _Config.APIUrl + "projects/" + _Project.id.ToString() + "/members/" + _User.id + "&access_level=" + Convert.ToInt64(_AccessLevel);

                HttpResponse <string> R = Unirest.put(URI)
                                          .header("accept", "application/json")
                                          .header("PRIVATE-TOKEN", _Config.APIKey)
                                          .asString();

                if (R.Code < 200 || R.Code >= 300)
                {
                    throw new GitLabServerErrorException(R.Body, R.Code);
                }
            }
            public static void UnBlock(Config _Config, User _User)
            {
                try
                {
                    string URI = _Config.APIUrl + "users/" + _User.id.ToString() + "/unblock";

                    HttpResponse <string> R = Unirest.put(URI)
                                              .header("accept", "application/json")
                                              .header("PRIVATE-TOKEN", _Config.APIKey)
                                              .asString();

                    if (R.Code < 200 || R.Code >= 300)
                    {
                        throw new GitLabServerErrorException(R.Body, R.Code);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        /// <summary>
        /// uploadProofOfAddress is a method that allows you to separately upload a proof of address after the address is created (the upload is done automatically during the address creation if the document is specified).
        /// </summary>
        /// <param name="regulationAddressId">Optional parameter: The identifier of the regulation address.</param>
        /// <return>Returns the dynamic response from the API call</return>
        public async Task <dynamic> UploadProofOfAddressAsync(
            string regulationAddressId = null)
        {
            //the base uri for api requests
            string baseUri = Configuration.BaseUri;

            //prepare query string for API call
            StringBuilder queryBuilder = new StringBuilder(baseUri);

            queryBuilder.Append("/services/rest/regulation/address/{regulationAddressId}/proof");

            //process optional template parameters
            APIHelper.AppendUrlWithTemplateParameters(queryBuilder, new Dictionary <string, object>()
            {
                { "regulationAddressId", regulationAddressId }
            });

            //validate and preprocess url
            string queryUrl = APIHelper.CleanUrl(queryBuilder);

            //prepare and invoke the API call request to fetch the response
            HttpRequest request = Unirest.put(queryUrl)
                                  //append request with appropriate headers and parameters
                                  .header("User-Agent", "APIMATIC 2.0")
                                  .header("Accept", "application/json")
                                  .header("Content-Type:", "multipart/form-data;boundary=XXX")
                                  .basicAuth(basicAuthUserName, basicAuthPassword);

            //invoke request and get response
            HttpResponse <String> response = await request.asStringAsync();

            //Error handling using HTTP status codes
            if ((response.Code < 200) || (response.Code > 206)) //[200,206] = HTTP OK
            {
                throw new APIException(@"HTTP Response Not OK", response.Code);
            }

            return(APIHelper.JsonDeserialize <dynamic>(response.Body));
        }
Exemple #21
0
 public static HttpRequest Put(string url, long timeout = 30)
 {
     return(Unirest.put(Config.ServerUrl + url, timeout).AddRTCHead());
 }
Exemple #22
0
        /*
         * Executes the queries to the PassKit API
         */
        private string doQuery(string httpMethod, string endpoint, string payload = "")
        {
            string url = this.apiUrl + "/" + this.apiVersion + "/" + endpoint;

            HttpResponse <string> response = null;

            try
            {
                string authHeader = "PKAuth " + generateJWT();

                // Put a 5 time retry in place in case of API throttling.
                for (var i = 0; i < 5; i++)
                {
                    switch (httpMethod)
                    {
                    case "GET":
                        response = Unirest.get(url)
                                   .header("Authorization", authHeader)
                                   .asString();
                        break;

                    case "PUT":
                        if (payload != "")
                        {
                            response = Unirest.put(url)
                                       .header("Authorization", authHeader)
                                       .header("Content-Type", "application/json")
                                       .body(payload)
                                       .asString();
                        }
                        else
                        {
                            response = Unirest.put(url)
                                       .header("Authorization", authHeader)
                                       .asString();
                        }
                        break;

                    case "POST":
                        if (payload != "")
                        {
                            response = Unirest.post(url)
                                       .header("Authorization", authHeader)
                                       .header("Content-Type", "application/json")
                                       .body(payload)
                                       .asString();
                        }
                        else
                        {
                            response = Unirest.post(url)
                                       .header("Authorization", authHeader)
                                       .asString();
                        }
                        break;
                    }

                    // on success break loop and return body.
                    if (response.Code == 200)
                    {
                        break;
                    }

                    if (response.Code != 503 && response.Code == 500 && response.Code != 429)
                    {
                        throw new Exception("PassKit returned unexpected error. Code: " + response.Code + ". " +
                                            "URL: " + url + ". Request Payload: " + payload + ". " +
                                            "Request Response: " + response.Body + ".");
                    }
                    // Sleep 200ms
                    System.Threading.Thread.Sleep(200);
                }

                // It either reaches this on success, or after 5 retries. In case it's not success, then return
                // the latest error.
                if (response.Code != 200)
                {
                    throw new Exception("PassKit returned unexpected error after 5 retries. Code: " + response.Code + ". " +
                                        "URL: " + url + ". Request Payload: " + payload + ". " +
                                        "Request Response: " + response.Body + ".");
                }

                return(response.Body);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
            /// <summary>
            /// Modifies an existing user. Only administrators can change attributes of a user.
            /// </summary>
            /// <param name="_Config"></param>
            /// <param name="_User"></param>
            /// <param name="_Password"></param>
            public static void Update(Config _Config, User _User, string _Password = null)
            {
                string URI = _Config.APIUrl + "users/" + _User.id.ToString()
                             + "?email=" + HttpUtility.UrlEncode(_User.email)
                             + "&username="******"&name=" + HttpUtility.UrlEncode(_User.name);

                if (!String.IsNullOrWhiteSpace(_Password))
                {
                    URI += "&password="******"&skype=" + HttpUtility.UrlEncode(_User.skype);
                }
                if (!String.IsNullOrWhiteSpace(_User.linkedin))
                {
                    URI += "&linkedin=" + HttpUtility.UrlEncode(_User.linkedin);
                }
                if (!String.IsNullOrWhiteSpace(_User.twitter))
                {
                    URI += "&twitter=" + HttpUtility.UrlEncode(_User.twitter);
                }
                if (!String.IsNullOrWhiteSpace(_User.web_url))
                {
                    URI += "&web_url=" + HttpUtility.UrlEncode(_User.web_url);
                }
                if (!String.IsNullOrWhiteSpace(_User.website_url))
                {
                    URI += "&website_url=" + HttpUtility.UrlEncode(_User.website_url);
                }
                if (_User.projects_limit >= 0)
                {
                    URI += "&projects_limit=" + _User.projects_limit.ToString();
                }
                if (!String.IsNullOrWhiteSpace(_User.extern_uid))
                {
                    URI += "&extern_uid=" + HttpUtility.UrlEncode(_User.extern_uid);
                }
                if (!String.IsNullOrWhiteSpace(_User.provider))
                {
                    URI += "&provider=" + HttpUtility.UrlEncode(_User.provider);
                }
                if (!String.IsNullOrWhiteSpace(_User.bio))
                {
                    URI += "&bio=" + HttpUtility.UrlEncode(_User.bio);
                }

                URI += "&admin=" + Convert.ToInt32(_User.is_admin).ToString();
                URI += "&can_create_group=" + Convert.ToInt32(_User.can_create_group).ToString();

                HttpResponse <string> R = Unirest.put(URI)
                                          .header("accept", "application/json")
                                          .header("PRIVATE-TOKEN", _Config.APIKey)
                                          .asString();

                if (R.Code < 200 || R.Code >= 300)
                {
                    throw new GitLabServerErrorException(R.Body, R.Code);
                }
            }
Exemple #24
0
                /// <summary>
                /// Update Merge Request
                /// </summary>
                /// <param name="_Config"></param>
                /// <param name="_MergeRequest"></param>
                /// <param name="_TargetBranch"></param>
                /// <param name="_Title"></param>
                /// <param name="_Description"></param>
                /// <param name="_Asignee"></param>
                /// <param name="_Labels"></param>
                /// <returns></returns>
                public static MergeRequest Update(Config _Config, MergeRequest _MergeRequest, string _TargetBranch = null, string _Title = null
                                                  , string _Description = null, User _Asignee = null, string[] _Labels = null, StateEvent _StateEvent = StateEvent.None)
                {
                    MergeRequest RetVal;

                    try
                    {
                        bool   first = true;
                        string ls    = "";

                        foreach (string l in _Labels)
                        {
                            if (!first)
                            {
                                ls += ",";
                            }

                            ls   += l;
                            first = false;
                        }

                        string URI = _Config.APIUrl + "/projects/" + _MergeRequest.project_id + "/merge_requests/" + _MergeRequest.id + "?";

                        if (_TargetBranch != null)
                        {
                            URI += "&target_branch=" + HttpUtility.UrlEncode(_TargetBranch);
                        }
                        if (_Title != null)
                        {
                            URI += "&title=" + HttpUtility.UrlEncode(_Title);
                        }
                        if (_Asignee != null)
                        {
                            URI += "&assignee_id=" + _Asignee.id.ToString();
                        }
                        if (_Description != null)
                        {
                            URI += "&description=" + HttpUtility.UrlEncode(_Description);
                        }
                        if (_Labels != null)
                        {
                            URI += "&labels=" + HttpUtility.UrlEncode(ls);
                        }
                        if (_StateEvent != StateEvent.None)
                        {
                            URI += "&state_event=" + _StateEvent.ToString().ToLowerInvariant();
                        }

                        HttpResponse <string> R = Unirest.put(URI)
                                                  .header("accept", "application/json")
                                                  .header("PRIVATE-TOKEN", _Config.APIKey)
                                                  .asString();

                        if (R.Code < 200 || R.Code >= 300)
                        {
                            throw new GitLabServerErrorException(R.Body, R.Code);
                        }
                        else
                        {
                            RetVal = JsonConvert.DeserializeObject <MergeRequest>(R.Body.ToString());
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    return(RetVal);
                }