本文整理汇总了C#中IApi.Create方法的典型用法代码示例。如果您正苦于以下问题:C# IApi.Create方法的具体用法?C# IApi.Create怎么用?C# IApi.Create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IApi
的用法示例。
在下文中一共展示了IApi.Create方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Use7DigitalApi
private static async Task Use7DigitalApi(IApi api, int artistId)
{
// -- artist/details
var artist = await api.Create<Artist>()
.WithArtistId(artistId)
.Please();
Console.WriteLine("Artist \"{0}\" selected", artist.Name);
Console.WriteLine("Website url is {0}", artist.Url);
Console.WriteLine();
// -- artist/toptracks
var artistTopTracks = await api.Create<ArtistTopTracks>()
.WithArtistId(artistId)
.Please();
Console.WriteLine("Top Track: {0}", artistTopTracks.Tracks.FirstOrDefault().Title);
Console.WriteLine();
// -- artist/browse
const string searchValue = "Radio";
var artistBrowse = await Api<ArtistBrowse>
.Create
.WithLetter(searchValue)
.Please();
Console.WriteLine("Browse on \"{0}\" returns: {1}", searchValue, artistBrowse.Artists.FirstOrDefault().Name);
Console.WriteLine();
// -- artist/search
var artistSearch = await api.Create<ArtistSearch>()
.WithQuery(searchValue)
.WithPageNumber(1)
.WithPageSize(10)
.Please();
Console.WriteLine("Artist Search on \"{0}\" returns: {1} items", searchValue, artistSearch.TotalItems);
Console.WriteLine();
// -- release/search
var releaseSearch = await api.Create<ReleaseSearch>()
.WithQuery(searchValue)
.WithPageNumber(1)
.WithPageSize(10)
.Please();
Console.WriteLine("Release search on \"{0}\" returns: {1} items", searchValue, releaseSearch.TotalItems);
Console.WriteLine();
await DoParalellSearches(api, searchValue);
// -- Debug uri
string currentUri = api.Create<ReleaseSearch>()
.WithQuery("Test").EndpointUrl;
Console.WriteLine("Release search hits: {0}", currentUri);
try
{
// -- Deliberate error response
Console.WriteLine("Trying artist/details without artistId parameter...");
await api.Create<Artist>().Please();
}
catch (ApiResponseException ex)
{
Console.WriteLine("{0} : {1}", ex, ex.Message);
}
try
{
// -- Deliberate unauthorized response
Console.WriteLine("Trying user/locker without any credentials...");
await api.Create<Locker>().Please();
}
catch (ArgumentException ex)
{
Console.WriteLine("{0} : {1}", ex, ex.Message);
}
}
示例2: DoParalellSearches
private static async Task DoParalellSearches(IApi api, string searchValue)
{
// queue up two requests -
// note that "await" is not used here - we get the task not the response
var page1Task = api.Create<ReleaseSearch>()
.WithQuery(searchValue)
.WithPageNumber(1)
.WithPageSize(10)
.Please();
var page2Task = api.Create<ReleaseSearch>()
.WithQuery(searchValue)
.WithPageNumber(2)
.WithPageSize(10)
.Please();
// wait for both to complete
await Task.WhenAll(new[] {page1Task, page2Task});
var page1Results = page1Task.Result;
var page2Results = page2Task.Result;
Console.WriteLine("Two release searches on \"{0}\" returns: {1} items in page 1 and {2} items in page 2", searchValue,
page1Results.Results.Count, page2Results.Results.Count);
}