当前位置: 首页>>代码示例>>C#>>正文


C# ApiConnection.Post方法代码示例

本文整理汇总了C#中ApiConnection.Post方法的典型用法代码示例。如果您正苦于以下问题:C# ApiConnection.Post方法的具体用法?C# ApiConnection.Post怎么用?C# ApiConnection.Post使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ApiConnection的用法示例。


在下文中一共展示了ApiConnection.Post方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Execute

        public override async Task Execute(string[] parameters, IResponse response)
        {
            if (parameters.Length < 5)
            {
                await response.Send($"I don't understand '{string.Join(" ", parameters.Select(x => "[" + x + "]"))}'.");
                return;
            }
            var repo = parameters[1];
            var issueNumberString = parameters[2];
            var from = parameters[3];
            var to = parameters[4];

            string accessToken;

            if (!TryGetCredential("github-accesstoken", out accessToken))
            {
                await response.Send("I couldnt find a github access token in your credentials. If you add one I will be able to create the pull request on your behalf. Does it sound good? Here are the instructions https://github.com/Particular/Housekeeping/wiki/Generate-GitHub-access-token-for-PBot");

                return;
            }

            var client = GitHubClientBuilder.Build(accessToken);

            var apiConnection = new ApiConnection(client.Connection);

            int issueNumber;
            if (!int.TryParse(issueNumberString, out issueNumber))
            {
                await response.Send("Issue number should be a valid number dude!");
                return;
            }
            try
            {

                var result = await apiConnection.Post<PullRequest>(ApiUrls.PullRequests("Particular", repo), new ConvertedPullRequest
                {
                    Issue = issueNumber.ToString(),
                    Head = from,
                    Base = to
                }, null, "application/json");
                await response.Send($"Issue {issueNumber} has been converted into a pull request {result.HtmlUrl}.");
            }
            catch (NotFoundException)
            {
                response.Send("Sorry, GitHub could not find the issue or repository you are talking about.").ConfigureAwait(false).GetAwaiter().GetResult();
            }
            catch (ApiValidationException ex)
            {
                const string errorMessage = "Sorry, your request was rejected by GitHub as invalid.";
                response.Send(string.Join(Environment.NewLine, errorMessage, ex.GetExtendedErrorMessage())).ConfigureAwait(false).GetAwaiter().GetResult();
            }
        }
开发者ID:adamralph,项目名称:PBot,代码行数:52,代码来源:ConvertIssueToPullRequest.cs

示例2: EnsuresArgumentsNotNull

            public async Task EnsuresArgumentsNotNull()
            {
                var postUri = new Uri("", UriKind.Relative);
                var connection = new ApiConnection(Substitute.For<IConnection>());

                // 1 parameter overload
                await Assert.ThrowsAsync<ArgumentNullException>(() => connection.Post(null));

                // 2 parameter overload
                await Assert.ThrowsAsync<ArgumentNullException>(() => connection.Post<object>(null, new object()));
                await Assert.ThrowsAsync<ArgumentNullException>(() => connection.Post<object>(postUri, null));

                // 3 parameters
                await Assert.ThrowsAsync<ArgumentNullException>(() => connection.Post<object>(null, new MemoryStream(), "anAccept", "some-content-type"));
                await Assert.ThrowsAsync<ArgumentNullException>(() => connection.Post<object>(postUri, null, "anAccept", "some-content-type"));
            }
开发者ID:alexgyori,项目名称:octokit.net,代码行数:16,代码来源:ApiConnectionTests.cs

示例3: MakesUploadRequest

            public async Task MakesUploadRequest()
            {
                var uploadUrl = new Uri("anything", UriKind.Relative);
                IApiResponse<string> response = new ApiResponse<string>(new Response(), "the response");
                var connection = Substitute.For<IConnection>();
                connection.Post<string>(Args.Uri, Arg.Any<Stream>(), Args.String, Args.String)
                    .Returns(Task.FromResult(response));
                var apiConnection = new ApiConnection(connection);
                var rawData = new MemoryStream();

                await apiConnection.Post<string>(uploadUrl, rawData, "accepts", "content-type");

                connection.Received().Post<string>(uploadUrl, rawData, "accepts", "content-type");
            }
开发者ID:alexgyori,项目名称:octokit.net,代码行数:14,代码来源:ApiConnectionTests.cs

示例4: MakesPostRequestWithSuppliedData

            public async Task MakesPostRequestWithSuppliedData()
            {
                var postUri = new Uri("anything", UriKind.Relative);
                var sentData = new object();
                IApiResponse<object> response = new ApiResponse<object>(new Response(), new object());
                var connection = Substitute.For<IConnection>();
                connection.Post<object>(Args.Uri, Args.Object, null, null).Returns(Task.FromResult(response));
                var apiConnection = new ApiConnection(connection);

                var data = await apiConnection.Post<object>(postUri, sentData);

                Assert.Same(data, response.Body);
                connection.Received().Post<object>(postUri, sentData, null, null);
            }
开发者ID:alexgyori,项目名称:octokit.net,代码行数:14,代码来源:ApiConnectionTests.cs

示例5: MakesPostRequestWithoutData

            public async Task MakesPostRequestWithoutData()
            {
                var postUri = new Uri("anything", UriKind.Relative);
                var statusCode = HttpStatusCode.Accepted;
                var connection = Substitute.For<IConnection>();
                connection.Post(Args.Uri).Returns(Task.FromResult(statusCode));
                var apiConnection = new ApiConnection(connection);

                await apiConnection.Post(postUri);

                connection.Received().Post(postUri);
            }
开发者ID:alexgyori,项目名称:octokit.net,代码行数:12,代码来源:ApiConnectionTests.cs


注:本文中的ApiConnection.Post方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。