Beispiel #1
0
        public void EditRepository(EditRepositoryRequest request)
        {
            try {
                var uri = request.CreateUri(BaseUrl);
                var webRequest = CreateRequest (uri);
                webRequest.Method = "PATCH";
                webRequest.UserAgent = "DotNet-GithubAPI";

                var payload = request.Entity;
                var requestStream = webRequest.GetRequestStream();
                var serializer = new DataContractJsonSerializer (typeof(RepositoryPatch));
                serializer.WriteObject(requestStream, payload);

                var webResponse = (HttpWebResponse) webRequest.GetResponse ();
                HandleEditRepositoryResponse(request, webResponse);
            }
            catch(WebException webException) {
                var webResponse = (HttpWebResponse)  webException.Response;
                HandleEditRepositoryResponse(request, webResponse);
            }
            catch(Exception exception) {
                throw;
            }
        }
Beispiel #2
0
        protected void HandleEditRepositoryResponse(EditRepositoryRequest request, HttpWebResponse webResponse)
        {
            int status = (int) webResponse.StatusCode;
            var responseStream = webResponse.GetResponseStream ();
            DataContractJsonSerializer serializer = null;

            if (status == 200 && request.On200 != null)
            {
                serializer = new DataContractJsonSerializer (typeof(Repository));
                Repository result = (Repository) serializer.ReadObject (responseStream);
                request.On200(result);
            }
            else if(request.OnOther != null)
            {
                request.OnOther(webResponse);
            }
        }