本文整理汇总了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));
}
示例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;
}
示例3: PlatronClient
public PlatronClient(IConnection connection)
{
Ensure.ArgumentNotNull(connection, "connection");
_connection = new ApiConnection(connection);
ResultUrl = new ResultUrlClient(_connection);
}
示例4: ResultUrlClient
public ResultUrlClient(ApiConnection connection)
{
Ensure.ArgumentNotNull(connection, nameof(connection));
Ensure.ArgumentNotNull(connection.Callback, nameof(connection.Callback));
_callback = connection.Callback;
}
示例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);
}
示例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));
}
示例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() }
};
}
示例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);
}
示例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();
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}