public async Task <Currency> GetAsync(string code, CurrencyRequest request) { Requires.ArgumentNotNull(request, nameof(request)); var currencyLink = await _linkFactory.CreateLinkAsync($"currencies/{code}").ConfigureAwait(_halClient); return(await _halClient.GetAsync <Currency>(currencyLink, request).ConfigureAwait(_halClient)); }
public async Task <Venue> GetAsync(int venueId, VenueRequest request) { var root = await _halClient.GetRootAsync().ConfigureAwait(_halClient); var venueLink = new Link { HRef = $"{root.VenuesLink.HRef}/{venueId}" }; return(await _halClient.GetAsync <Venue>(venueLink, request).ConfigureAwait(_halClient)); }
public async Task <Event> GetAsync(int eventId, EventRequest request) { Requires.ArgumentNotNull(request, nameof(request)); var root = await _halClient.GetRootAsync().ConfigureAwait(_halClient); var eventsLink = new Link { HRef = $"{root.SelfLink.HRef}/events/{eventId}" }; return(await _halClient.GetAsync <Event>(eventsLink, request).ConfigureAwait(_halClient)); }
public async Task <Listing> GetAsync(int listingId, ListingRequest request) { Requires.ArgumentNotNull(request, nameof(request)); var root = await _halClient.GetRootAsync().ConfigureAwait(_halClient); var listingLink = new Link { HRef = $"{root.SelfLink.HRef}/listings/{listingId}" }; return(await _halClient.GetAsync <Listing>(listingLink, request).ConfigureAwait(_halClient)); }
private static ReadAllPage ReadAllBackwardsInternal(IHalClient client, bool prefetch) { var resource = client.Current.First(); var pageInfo = resource.Data <HalReadAllPage>(); var streamMessages = Convert( resource.Embedded .Where(r => r.Rel == Constants.Relations.Message) .ToArray(), client, prefetch); var readAllPage = new ReadAllPage( pageInfo.FromPosition, pageInfo.NextPosition, pageInfo.IsEnd, ReadDirection.Backward, async(position, cancellationToken) => ReadAllBackwardsInternal( await client.GetAsync(resource, Constants.Relations.Previous, cancellationToken), prefetch), streamMessages); return(readAllPage); }
public async Task <Category> GetAsync(int categoryId, CategoryRequest request) { Requires.ArgumentNotNull(request, nameof(request)); var categoryLink = await _linkFactory.CreateLinkAsync($"categories/{categoryId}").ConfigureAwait(_halClient); return(await _halClient.GetAsync <Category>(categoryLink, request).ConfigureAwait(_halClient)); }
public async Task <User> GetAsync(UserRequest request, CancellationToken cancellationToken) { var root = await _halClient.GetRootAsync().ConfigureAwait(_halClient); return(await _halClient.GetAsync <User>( root.UserLink, request, cancellationToken).ConfigureAwait(_halClient)); }
private static async Task <ChangedResources <T> > GetChangedResourcesInternalAsync <T>( this IHalClient client, Link link, IDictionary <string, string> parameters, IDictionary <string, IEnumerable <string> > headers, CancellationToken cancellationToken) where T : Resource { Requires.ArgumentNotNull(client, nameof(client)); Requires.ArgumentNotNull(link, nameof(link)); var currentLink = link; var currentParameters = new Dictionary <string, string>(parameters ?? new Dictionary <string, string>()); // Increase page-size to reduce the number of round-trips var maxPageSize = "10000"; if (currentParameters.ContainsKey("page_size")) { currentParameters["page_size"] = maxPageSize; } else { currentParameters.Add("page_size", maxPageSize); } var items = new List <T>(); var deletedItems = new List <T>(); while (true) { cancellationToken.ThrowIfCancellationRequested(); var currentPage = await client.GetAsync <PagedResource <T> >( currentLink, currentParameters, headers, cancellationToken).ConfigureAwait(client.Configuration); items.AddRange(currentPage.Items); if (currentPage.DeletedItems != null) { deletedItems.AddRange(currentPage.DeletedItems); } if (currentPage.NextLink == null) { // This is the last page break; } // Stop passing parameters on subsequent calls since the "next" links // will already be assembled with all the parameters needed currentParameters = null; currentLink = currentPage.NextLink; } return(new ChangedResources <T>(items, deletedItems, currentLink)); }
private static ReadStreamPage ReadStreamBackwardsInternal( IHalClient client, StreamId streamId, int fromVersionInclusive, bool prefetchJsonData) { var resource = client.Current.First(); if (client.StatusCode == HttpStatusCode.NotFound) { return(new ReadStreamPage( streamId, PageReadStatus.StreamNotFound, fromVersionInclusive, -1, -1, -1, ReadDirection.Backward, true)); } var pageInfo = resource.Data <HalReadPage>(); var streamMessages = Convert( resource.Embedded .Where(r => r.Rel == Constants.Relations.Message) .ToArray(), client, prefetchJsonData); var readStreamPage = new ReadStreamPage( streamId, PageReadStatus.Success, pageInfo.FromStreamVersion, pageInfo.NextStreamVersion, pageInfo.LastStreamVersion, pageInfo.LastStreamPosition, ReadDirection.Backward, pageInfo.IsEnd, async(nextVersion, token) => ReadStreamBackwardsInternal( await client.GetAsync(resource, Constants.Relations.Previous), streamId, pageInfo.LastStreamVersion, prefetchJsonData), streamMessages); return(readStreamPage); }
private static ReadStreamPage ReadStreamForwardsInternal( IHalClient client, StreamId streamId, int fromVersionInclusive, bool prefetchJsonData) { var resource = client.Current.First(); if (client.StatusCode == HttpStatusCode.NotFound) { return(new ReadStreamPage( streamId, PageReadStatus.StreamNotFound, fromVersionInclusive, -1, -1, -1, ReadDirection.Forward, true)); } var pageInfo = resource.Data <HalReadPage>(); var streamMessages = Convert( resource.Embedded .Where(r => r.Rel == Constants.Relations.Message) .Reverse() .ToArray(), client, prefetchJsonData); var readStreamPage = new ReadStreamPage( streamId, PageReadStatus.Success, pageInfo.FromStreamVersion, pageInfo.NextStreamVersion, pageInfo.LastStreamVersion, pageInfo.LastStreamPosition, ReadDirection.Forward, pageInfo.IsEnd, ReadNextStreamPage, streamMessages); return(readStreamPage); async Task <ReadStreamPage> ReadNextStreamPage(int nextVersion, CancellationToken ct) => resource.Links.Any(link => link.Rel == Constants.Relations.Next) ? ReadStreamForwardsInternal( await client.GetAsync(resource, Constants.Relations.Next), streamId, pageInfo.LastStreamVersion, prefetchJsonData) : new ReadStreamPage( streamId, PageReadStatus.Success, pageInfo.LastStreamVersion, nextVersion, pageInfo.LastStreamVersion, pageInfo.LastStreamPosition, ReadDirection.Forward, true, ReadNextStreamPage); }
public async Task <Webhook> GetAsync(int webhookId, WebhookRequest request) { var webhookLink = await _linkFactory.CreateLinkAsync($"webhooks/{webhookId}").ConfigureAwait(_halClient); return(await _halClient.GetAsync <Webhook>(webhookLink, request).ConfigureAwait(_halClient)); }
public async Task <Sale> GetAsync(int saleId, SaleRequest request) { var saleLink = await _linkFactory.CreateLinkAsync($"sales/{saleId}").ConfigureAwait(_halClient); return(await _halClient.GetAsync <Sale>(saleLink, request).ConfigureAwait(_halClient)); }
public static Task <IHalClient> GetAsync(this IHalClient client, IResource resource, string rel) => client.GetAsync(resource, rel, null, null);
public async Task <Shipments> GetAsync(int saleId, ShipmentRequest request) { var shipmentsLink = await _linkFactory.CreateLinkAsync($"sales/{saleId}/shipments").ConfigureAwait(_halClient); return(await _halClient.GetAsync <Shipments>(shipmentsLink, request).ConfigureAwait(_halClient)); }
public async Task <SellerListing> GetAsync(int sellerListingId, SellerListingRequest request) { var listingLink = await _linkFactory.CreateLinkAsync($"sellerlistings/{sellerListingId}").ConfigureAwait(_halClient); return(await _halClient.GetAsync <SellerListing>(listingLink, request).ConfigureAwait(_halClient)); }
public static Task <IHalClient> GetAsync( this IHalClient client, IResource resource, string rel, object parameters) => client.GetAsync(resource, rel, parameters, null);
public async Task <PaymentMethod> GetAsync(int paymentMethodId, PaymentMethodRequest request) { var paymentMethodLink = await _linkFactory.CreateLinkAsync($"paymentMethods/{paymentMethodId}").ConfigureAwait(_halClient); return(await _halClient.GetAsync <PaymentMethod>(paymentMethodLink, request).ConfigureAwait(_halClient)); }
public async Task <Purchase> GetAsync(int purchaseId, PurchaseRequest request) { var purchaseLink = await _linkFactory.CreateLinkAsync($"purchases/{purchaseId}").ConfigureAwait(_halClient); return(await _halClient.GetAsync <Purchase>(purchaseLink, request).ConfigureAwait(_halClient)); }
private static async Task <string> GetPayload( IHalClient client, IResource streamMessage, CancellationToken cancellationToken) => (await client.GetAsync(streamMessage, Constants.Relations.Self, cancellationToken)) .Current.FirstOrDefault()?.Data <HttpStreamMessage>()?.Payload?.ToString();
public async Task <Address> GetAsync(int addressId) { var addressLink = await _linkFactory.CreateLinkAsync($"addresses/{addressId}").ConfigureAwait(_halClient); return(await _halClient.GetAsync <Address>(addressLink).ConfigureAwait(_halClient)); }