當前位置: 首頁>>代碼示例>>C#>>正文


C# ApiConnection類代碼示例

本文整理匯總了C#中ApiConnection的典型用法代碼示例。如果您正苦於以下問題:C# ApiConnection類的具體用法?C# ApiConnection怎麽用?C# ApiConnection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ApiConnection類屬於命名空間,在下文中一共展示了ApiConnection類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: EnsuresArgumentNotNull

 public async Task EnsuresArgumentNotNull()
 {
     var getUri = new Uri("anything", UriKind.Relative);
     var client = new ApiConnection(Substitute.For<IConnection>());
     await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get<object>(null));
     await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get<object>(getUri, new Dictionary<string, string>(), null));
 }
開發者ID:alexgyori,項目名稱:octokit.net,代碼行數:7,代碼來源:ApiConnectionTests.cs

示例2: page

        public List<Developer> page(int page = 1, int size = 40)
        {
            var credentials = new Octokit.Credentials(ConfigurationManager.AppSettings["user_git"], ConfigurationManager.AppSettings["pass_git"]);
            Octokit.Connection connection = new Connection(new ProductHeaderValue("DevStore"));
            Octokit.ApiConnection apiConn = new ApiConnection(connection);
            Octokit.SearchUsersRequest search = new SearchUsersRequest("a");
            search.AccountType = AccountSearchType.User;
            search.PerPage = size;
            search.Page = page;
            Octokit.UsersClient userCliente = new UsersClient(apiConn);
            Octokit.SearchClient searchUserService = new SearchClient(apiConn);
            SearchUsersResult usersResult = searchUserService.SearchUsers(search).Result;
            Octokit.GitHubClient gitClient = new GitHubClient(connection);
            Octokit.UsersClient userClient = new UsersClient(apiConn);
            List<Developer> developers = (from userGit in usersResult.Items
                                          select new Developer
                                          {
                                              User = userGit.Login,
                                              UrlAvatar = userGit.AvatarUrl.ToString(),
                                              TotalRepo = userGit.PublicRepos,
                                              TotalFollowers = userGit.Followers,
                                              Price = ((userGit.PublicRepos * pesoTotalRepository) + (userGit.Followers * pesoTotalFollowers)) / (pesoTotalRepository + pesoTotalFollowers)
                                          }).ToList();

            return developers;
        }
開發者ID:milkidis,項目名稱:devstore,代碼行數:26,代碼來源:DeveloperService.cs

示例3: PlatronClient

        public PlatronClient(IConnection connection)
        {
            Ensure.ArgumentNotNull(connection, "connection");
            _connection = new ApiConnection(connection);

            ResultUrl = new ResultUrlClient(_connection);
        }
開發者ID:alex-erygin,項目名稱:Platron.Client,代碼行數:7,代碼來源:PlatronClient.cs

示例4: ResultUrlClient

        public ResultUrlClient(ApiConnection connection)
        {
            Ensure.ArgumentNotNull(connection, nameof(connection));
            Ensure.ArgumentNotNull(connection.Callback, nameof(connection.Callback));

            _callback = connection.Callback;
        }
開發者ID:alex-erygin,項目名稱:Platron.Client,代碼行數:7,代碼來源:ResultUrlClient.cs

示例5: GitHubClient

        /// <summary>
        /// Create a new instance of the GitHub API v3 client using the specified connection.
        /// </summary>
        /// <param name="connection">The underlying <seealso cref="IConnection"/> used to make requests</param>
        public GitHubClient(IConnection connection)
        {
            Ensure.ArgumentNotNull(connection, "connection");

            Connection = connection;
            var apiConnection = new ApiConnection(connection);
            Activity = new ActivitiesClient(apiConnection);
            Authorization = new AuthorizationsClient(apiConnection);
            Deployment = new DeploymentsClient(apiConnection);
            Enterprise = new EnterpriseClient(apiConnection);
            Gist = new GistsClient(apiConnection);
            Git = new GitDatabaseClient(apiConnection);
            Issue = new IssuesClient(apiConnection);
            Migration = new MigrationClient(apiConnection);
            Miscellaneous = new MiscellaneousClient(connection);
            Notification = new NotificationsClient(apiConnection);
            Oauth = new OauthClient(connection);
            Organization = new OrganizationsClient(apiConnection);
            PullRequest = new PullRequestsClient(apiConnection);
            Repository = new RepositoriesClient(apiConnection);
            Search = new SearchClient(apiConnection);
            SshKey = new SshKeysClient(apiConnection);
            User = new UsersClient(apiConnection);
            Reaction = new ReactionsClient(apiConnection);
        }
開發者ID:RadicalLove,項目名稱:octokit.net,代碼行數:29,代碼來源:GitHubClient.cs

示例6: Can_hit_endpoint_if_I_pass_credentials_into_api

		public async Task Can_hit_endpoint_if_I_pass_credentials_into_api()
		{
			IApi api = new ApiConnection();
			var request = api.Create<Status>();
			var status = await request.Please();

			Assert.That(status, Is.Not.Null);
			Assert.That(status.ServerTime.Day, Is.EqualTo(DateTime.Now.Day));
		}
開發者ID:danhaller,項目名稱:SevenDigital.Api.Schema,代碼行數:9,代碼來源:ApiSetupCredentialPassingTests.cs

示例7: Initialize

        /// <summary>
        /// Initialize the API using the config.json file.
        /// </summary>
        public virtual void Initialize(int userId, string token)
        {
            _connection = new ApiConnection(userId, token);
            _marketHoursDatabase = MarketHoursDatabase.FromDataFolder();

            //Allow proper decoding of orders from the API.
            JsonConvert.DefaultSettings = () => new JsonSerializerSettings
            {
                Converters = { new OrderJsonConverter() }
            };
        }
開發者ID:aajtodd,項目名稱:Lean,代碼行數:14,代碼來源:Api.cs

示例8: GetMe

        public async static Task<UserData> GetMe(ApiConnection connection)
        {
            var request = new HttpRequestMessage(HttpMethod.Get, connection.Endpoints.Me);
            request.Headers.Add(connection.Endpoints.Headers.ApiKey, connection.Token);
            request.Headers.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue(content_type));

            var client = new HttpClient();
            var response = await client.SendAsync(request);
            var content = await response.Content.ReadAsStringAsync();

            return new UserData(content);
        }
開發者ID:kenlefeb,項目名稱:AgileZen,代碼行數:12,代碼來源:Api.cs

示例9: 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

示例10: MakesHtmlRequest

            public async Task MakesHtmlRequest()
            {
                var getUri = new Uri("anything", UriKind.Relative);
                IApiResponse<string> response = new ApiResponse<string>(new Response(), "<html />");
                var connection = Substitute.For<IConnection>();
                connection.GetHtml(Args.Uri, null).Returns(Task.FromResult(response));
                var apiConnection = new ApiConnection(connection);

                var data = await apiConnection.GetHtml(getUri);

                Assert.Equal("<html />", data);
                connection.Received().GetHtml(getUri);
            }
開發者ID:alexgyori,項目名稱:octokit.net,代碼行數:13,代碼來源:ApiConnectionTests.cs

示例11: MakesGetRequestForItem

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

                var data = await apiConnection.Get<object>(getUri);

                Assert.Same(response.Body, data);
                connection.Received().GetResponse<object>(getUri);
            }
開發者ID:alexgyori,項目名稱:octokit.net,代碼行數:13,代碼來源:ApiConnectionTests.cs

示例12: MakesGetRequestForItemWithAcceptsOverride

            public async Task MakesGetRequestForItemWithAcceptsOverride()
            {
                var getUri = new Uri("anything", UriKind.Relative);
                var accepts = "custom/accepts";
                IResponse<object> response = new ApiResponse<object> { BodyAsObject = new object() };
                var connection = Substitute.For<IConnection>();
                connection.GetAsync<object>(Args.Uri, null, Args.String).Returns(Task.FromResult(response));
                var apiConnection = new ApiConnection(connection);

                var data = await apiConnection.Get<object>(getUri, null, accepts);

                Assert.Same(response.BodyAsObject, data);
                connection.Received().GetAsync<object>(getUri, null, accepts);
            }
開發者ID:rajwilkhu,項目名稱:octokit.net,代碼行數:14,代碼來源:ApiConnectionTests.cs

示例13: GitHubClient

        /// <summary>
        /// Create a new instance of the GitHub API v3 client using the specified connection.
        /// </summary>
        /// <param name="connection">The underlying <seealso cref="IConnection"/> used to make requests.</param>
        public GitHubClient(IConnection connection)
        {
            Ensure.ArgumentNotNull(connection, "connection");

            Connection = connection;
            var apiConnection = new ApiConnection(connection);
            Authorization = new AuthorizationsClient(apiConnection);
            Issue = new IssuesClient(apiConnection);
            Miscellaneous = new MiscellaneousClient(connection);
            Notification = new NotificationsClient(apiConnection);
            Organization = new OrganizationsClient(apiConnection);
            Repository = new RepositoriesClient(apiConnection);
            Release = new ReleasesClient(apiConnection);
            User = new UsersClient(apiConnection);
            SshKey = new SshKeysClient(apiConnection);
        }
開發者ID:ninjanye,項目名稱:octokit.net,代碼行數:20,代碼來源:GitHubClient.cs

示例14: MakesGetRequestForAllItems

            public async Task MakesGetRequestForAllItems()
            {
                var getAllUri = new Uri("anything", UriKind.Relative);
                var links = new Dictionary<string, Uri>();
                var scopes = new List<string>();
                IResponse<List<object>> response = new ApiResponse<List<object>>
                {
                    ApiInfo = new ApiInfo(links, scopes, scopes, "etag", new RateLimit(new Dictionary<string, string>())),
                    BodyAsObject = new List<object> {new object(), new object()}
                };
                var connection = Substitute.For<IConnection>();
                connection.GetAsync<List<object>>(Args.Uri, null, null).Returns(Task.FromResult(response));
                var apiConnection = new ApiConnection(connection);

                var data = await apiConnection.GetAll<object>(getAllUri);

                Assert.Equal(2, data.Count);
                connection.Received().GetAsync<List<object>>(getAllUri, null, null);
            }
開發者ID:ninjanye,項目名稱:octokit.net,代碼行數:19,代碼來源:ApiConnectionTests.cs

示例15: GitHubClient

        /// <summary>
        /// Create a new instance of the GitHub API v3 client using the specified connection.
        /// </summary>
        /// <param name="connection">The underlying <seealso cref="IConnection"/> used to make requests</param>
        public GitHubClient(IConnection connection)
        {
            Ensure.ArgumentNotNull(connection, "connection");

            Connection = connection;
            var apiConnection = new ApiConnection(connection);
            Authorization = new AuthorizationsClient(apiConnection);
            Activity = new ActivitiesClient(apiConnection);
            Blob = new BlobsClient(apiConnection);
            Issue = new IssuesClient(apiConnection);
            Miscellaneous = new MiscellaneousClient(connection);
            Notification = new NotificationsClient(apiConnection);
            Organization = new OrganizationsClient(apiConnection);
            Repository = new RepositoriesClient(apiConnection);
            Gist = new GistsClient(apiConnection);
            Release = new ReleasesClient(apiConnection);
            User = new UsersClient(apiConnection);
            SshKey = new SshKeysClient(apiConnection);
            GitDatabase = new GitDatabaseClient(apiConnection);
            Tree = new TreesClient(apiConnection);
            Search = new SearchClient(apiConnection);
        }
開發者ID:rgmills,項目名稱:octokit.net,代碼行數:26,代碼來源:GitHubClient.cs


注:本文中的ApiConnection類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。