Skip to content

Commit

Permalink
Merge pull request #10 from kwtc/feature/project-structure-and-offer-…
Browse files Browse the repository at this point in the history
…search

Added get catalog by id
  • Loading branch information
kwtc authored Jul 14, 2024
2 parents ba5f6f7 + 6c488a7 commit e6b3e4b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ As the heading states this is a .NET API client for tjek.com
- [x] /v2/offers
- [x] /v2/offers/{offerId}
- [x] /v2/catalogs
- [ ] /v2/catalogs/{catalogId}
- [x] /v2/catalogs/{catalogId}
- [ ] /v2/catalogs/{catalogId}/pages
- [ ] /v2/catalogs/{catalogId}/hotspots
- [ ] /v2/catalogs/{catalogId}/page_decorations
Expand Down Expand Up @@ -50,7 +50,7 @@ public class MyService
_tjekClientConfig = tjekClientConfig.Value;
}

public Task MyMethod()
public void MyMethod()
{
var client = _httpClientFactory.CreateClient(Constants.HttpClientName);
}
Expand Down
5 changes: 5 additions & 0 deletions src/Kwtc.Tjek.Client.Abstractions/ITjekClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ public Task<IReadOnlyList<Catalog>> ListCatalogs(
int? offset = null,
string? orderBy = null,
CancellationToken cancellationToken = default);

/// <summary>
/// Get catalog by id
/// </summary>
public Task<Catalog?> GetCatalog(string id, CancellationToken cancellationToken = default);
}
18 changes: 18 additions & 0 deletions src/Kwtc.Tjek.Client/TjekClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,24 @@ public async Task<IReadOnlyList<Catalog>> ListCatalogs(string? dealerId = null,
return result ?? [];
}

public async Task<Catalog?> GetCatalog(string id, CancellationToken cancellationToken = default)
{
Guard.IsNotNullOrEmpty(id, nameof(id));

var client = this.httpClientFactory.CreateClient(Constants.HttpClientName);
var response = await client.GetAsync($"v2/catalogs/{id}", cancellationToken);

response.EnsureSuccessStatusCode();

var contentStream = await response.Content.ReadAsStreamAsync(cancellationToken);
if (contentStream.Length == 0)
{
throw new HttpRequestException(HttpRequestError.InvalidResponse, "Response content is empty");
}

return await JsonSerializer.DeserializeAsync<Catalog>(contentStream, cancellationToken: cancellationToken);
}

private static string BuildQueryString(IDictionary<string, string> parameters, StringBuilder builder)
{
var i = 0;
Expand Down

0 comments on commit e6b3e4b

Please sign in to comment.