Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #2

Merged
merged 5 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
435 changes: 0 additions & 435 deletions ApiClient/API/ProductInformation.cs

This file was deleted.

490 changes: 490 additions & 0 deletions ApiClient/API/ProductInformation/ProductInformation.cs

Large diffs are not rendered by default.

171 changes: 171 additions & 0 deletions ApiClient/API/ProductInformation/ProductInformationJson.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
//-----------------------------------------------------------------------
//
// THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTIES OF ANY KIND, EXPRESS, IMPLIED, STATUTORY,
// OR OTHERWISE. EXPECT TO THE EXTENT PROHIBITED BY APPLICABLE LAW, DIGI-KEY DISCLAIMS ALL WARRANTIES,
// INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
// SATISFACTORY QUALITY, TITLE, NON-INFRINGEMENT, QUIET ENJOYMENT,
// AND WARRANTIES ARISING OUT OF ANY COURSE OF DEALING OR USAGE OF TRADE.
//
// DIGI-KEY DOES NOT WARRANT THAT THE SOFTWARE WILL FUNCTION AS DESCRIBED,
// WILL BE UNINTERRUPTED OR ERROR-FREE, OR FREE OF HARMFUL COMPONENTS.
//
//-----------------------------------------------------------------------

using System.Text.Json;

namespace ApiClient.API
{
public partial class ProductInformation
{
#region PartSearch

public async Task<JsonElement> KeywordSearchJson(string keyword, string[]? includes = null)
{
return JsonSerializer.Deserialize<JsonElement>(await KeywordSearch(keyword, includes));
}

public async Task<JsonElement> ProductDetailsJson(string digikeyPartNumber, string[]? includes = null)
{
return JsonSerializer.Deserialize<JsonElement>(await ProductDetails(digikeyPartNumber, includes));
}

public async Task<JsonElement> DigiReelPricingJson(string digikeyPartNumber, int requestedQuantity, string[]? includes = null)
{
return JsonSerializer.Deserialize<JsonElement>(await DigiReelPricing(digikeyPartNumber, requestedQuantity, includes));
}

public async Task<JsonElement> SuggestedPartsJson(string partNumber)
{
return JsonSerializer.Deserialize<JsonElement>(await SuggestedParts(partNumber));
}
public async Task<JsonElement> ManufacturersJson()
{
return JsonSerializer.Deserialize<JsonElement>(await Manufacturers());
}

public async Task<JsonElement> CategoriesJson()
{
return JsonSerializer.Deserialize<JsonElement>(await Categories());
}

public async Task<JsonElement> CategoriesByIDJson(int categoryID)
{
return JsonSerializer.Deserialize<JsonElement>(await CategoriesByID(categoryID));
}

#endregion

#region RecommendedParts

public async Task<JsonElement> RecommendedProductsJson(string digikeyPartNumber, int recordCount = 1, string[]? searchOptionList = null, bool excludeMarketPlaceProducts = false, string[]? includes = null)
{
return JsonSerializer.Deserialize<JsonElement>(await RecommendedProducts(digikeyPartNumber, recordCount, searchOptionList, excludeMarketPlaceProducts, includes));
}

#endregion

#region PackageTypeByQuantity

public async Task<JsonElement> PackageByQuantityJson(string digikeyPartNumber, int requestedQuantity, string? packagingPreference = null, string[]? includes = null)
{
return JsonSerializer.Deserialize<JsonElement>(await PackageByQuantity(digikeyPartNumber, requestedQuantity, packagingPreference, includes));
}

#endregion

#region ProductChangeNotifications

public async Task<JsonElement> ProductChangeNotificationsJson(string digikeyPartNumber, string[]? includes = null)
{
return JsonSerializer.Deserialize<JsonElement>(await ProductChangeNotifications(digikeyPartNumber, includes));
}

#endregion

#region ProductTracing

public async Task<JsonElement> ProductTracingDetailsJson(string tracingID)
{
return JsonSerializer.Deserialize<JsonElement>(await ProductTracingDetails(tracingID));
}

#endregion
}

public partial class ProductInformation<T3, T4>
{
#region PartSearch

public async Task<JsonElement> KeywordSearchJson(string keyword, T3 database, string[]? includes = null)
{
return JsonSerializer.Deserialize<JsonElement>(await KeywordSearch(keyword, database, includes));
}

public async Task<JsonElement> ProductDetailsJson(string digikeyPartNumber, T3 database, string[]? includes = null)
{
return JsonSerializer.Deserialize<JsonElement>(await ProductDetails(digikeyPartNumber, database, includes));
}

public async Task<JsonElement> DigiReelPricingJson(string digikeyPartNumber, int requestedQuantity, T3 database, string[]? includes = null)
{
return JsonSerializer.Deserialize<JsonElement>(await DigiReelPricing(digikeyPartNumber, requestedQuantity, database, includes));
}

public async Task<JsonElement> SuggestedPartsJson(string partNumber, T3 database)
{
return JsonSerializer.Deserialize<JsonElement>(await SuggestedParts(partNumber, database));
}
public async Task<JsonElement> ManufacturersJson(T3 database)
{
return JsonSerializer.Deserialize<JsonElement>(await Manufacturers(database));
}

public async Task<JsonElement> CategoriesJson(T3 database)
{
return JsonSerializer.Deserialize<JsonElement>(await Categories(database));
}

public async Task<JsonElement> CategoriesByIDJson(int categoryID, T3 database)
{
return JsonSerializer.Deserialize<JsonElement>(await CategoriesByID(categoryID, database));
}

#endregion

#region RecommendedParts

public async Task<JsonElement> RecommendedProductsJson(string digikeyPartNumber, T3 database, int recordCount = 1, string[]? searchOptionList = null, bool excludeMarketPlaceProducts = false, string[]? includes = null)
{
return JsonSerializer.Deserialize<JsonElement>(await RecommendedProducts(digikeyPartNumber, database, recordCount, searchOptionList, excludeMarketPlaceProducts, includes));
}

#endregion

#region PackageTypeByQuantity

public async Task<JsonElement> PackageByQuantityJson(string digikeyPartNumber, int requestedQuantity, T3 database, string? packagingPreference = null, string[]? includes = null)
{
return JsonSerializer.Deserialize<JsonElement>(await PackageByQuantity(digikeyPartNumber, requestedQuantity, database, packagingPreference, includes));
}

#endregion

#region ProductChangeNotifications

public async Task<JsonElement> ProductChangeNotificationsJson(string digikeyPartNumber, T3 database, string[]? includes = null)
{
return JsonSerializer.Deserialize<JsonElement>(await ProductChangeNotifications(digikeyPartNumber, database, includes));
}

#endregion

#region ProductTracing

public async Task<JsonElement> ProductTracingDetailsJson(string tracingID, T3 database)
{
return JsonSerializer.Deserialize<JsonElement>(await ProductTracingDetails(tracingID, database));
}

#endregion
}
}
166 changes: 166 additions & 0 deletions ApiClient/API/ProductInformation/ProductInformationParent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
//-----------------------------------------------------------------------
//
// THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTIES OF ANY KIND, EXPRESS, IMPLIED, STATUTORY,
// OR OTHERWISE. EXPECT TO THE EXTENT PROHIBITED BY APPLICABLE LAW, DIGI-KEY DISCLAIMS ALL WARRANTIES,
// INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
// SATISFACTORY QUALITY, TITLE, NON-INFRINGEMENT, QUIET ENJOYMENT,
// AND WARRANTIES ARISING OUT OF ANY COURSE OF DEALING OR USAGE OF TRADE.
//
// DIGI-KEY DOES NOT WARRANT THAT THE SOFTWARE WILL FUNCTION AS DESCRIBED,
// WILL BE UNINTERRUPTED OR ERROR-FREE, OR FREE OF HARMFUL COMPONENTS.
//
//-----------------------------------------------------------------------

using ApiClient.Models;
using System.Web;

namespace ApiClient.API
{
public class ProductInformationParent
{
public class ResourcePathParent(string? arg = null, string? route = null, string? resourcePath = null, string? resourcePathSuffix = null, string[]? includes = null, Dictionary<string, string>? otherParameters = null)
{
public string Route = route ?? string.Empty;
public string RouteParameter = arg ?? string.Empty;
public string ResourcePath = resourcePath ?? string.Empty;
public string ResourcePathSuffix = resourcePathSuffix ?? string.Empty;
public string Endpoint = arg ?? string.Empty;
internal string[]? _includes = includes;
internal Dictionary<string, string> _otherParameters = otherParameters ?? [];

public string Encoded = arg == null ? string.Empty : HttpUtility.UrlEncode(arg);

public string Path
{
get
{
var prefix = ResourcePath == string.Empty ? string.Empty : '/' + ResourcePath;
var endpoint = Endpoint == string.Empty ? string.Empty : '/' + Endpoint;
var suffix = ResourcePathSuffix == string.Empty ? string.Empty : '/' + ResourcePathSuffix;
var parameters = Parameters == string.Empty ? string.Empty : '?' + Parameters;
return $"{prefix}{endpoint}{suffix}{parameters}";
}
}

public string Parameters
{
get
{
var parameters = string.Empty;

foreach (KeyValuePair<string, string> entry in _otherParameters)
{
parameters += (parameters == null ? string.Empty : '&') + $"{HttpUtility.UrlEncode(entry.Key)}={HttpUtility.UrlEncode(entry.Value)}";
}

if (_includes != null)
{
var includesString = HttpUtility.UrlEncode(string.Join(",", _includes));
parameters += (parameters == null ? string.Empty : '&') + $"includes={includesString}";
}
return parameters;
}
}

public RequestSnapshot Snapshot(string result)
{
return new()
{
Route = Route,
RouteParameter = RouteParameter,
Parameters = Parameters,
Response = result
};
}
}

public class KeywordSearchParent(string keyword, string[]? includes = null) : ResourcePathParent(
keyword,
route: "KeywordSearch",
resourcePath: "Search/v3/Products/Keyword",
includes: includes)
{
new public string Path = "Search/v3/Products/Keyword";

public KeywordSearchRequest KeywordSearchRequest
{
get
{
return new()
{
Keywords = RouteParameter ?? "P5555-ND",
RecordCount = 25
};
}
}
}

public class ProductDetailsParent(string digikeyPartNumber, string[]? includes = null) : ResourcePathParent(
digikeyPartNumber,
route: "ProductDetails",
resourcePath: "Search/v3/Products",
includes: includes)
{ }

public class DigiReelPricingParent(string digikeyPartNumber, Dictionary<string, string>? otherParameters = null, string[]? includes = null) : ResourcePathParent(
digikeyPartNumber,
route: "DigiReelPricing",
resourcePath: "Search/v3/Products",
resourcePathSuffix: "DigiReelPricing",
includes: includes,
otherParameters: otherParameters)
{ }

public class SuggestedPartsParent(string partNumber) : ResourcePathParent(
partNumber,
route: "SuggestedParts",
resourcePath: "Search/v3/Products",
resourcePathSuffix: "WithSuggestedProducts")
{ }

public class ManufacturersParent() : ResourcePathParent(
route: "Manufacturers",
resourcePath: "Search/v3/Manufacturers")
{ }

public class CategoriesParent() : ResourcePathParent(
route: "Categories",
resourcePath: "Search/v3/Categories")
{ }

public class CategoriesByIDParent(int categoryID) : ResourcePathParent(
categoryID.ToString(),
route: "CategoriesByID",
resourcePath: "Search/v3/Categories")
{ }

public class RecommendedProductsParent(string digikeyPartNumber, Dictionary<string, string>? otherParameters = null, string[]? includes = null) : ResourcePathParent(
digikeyPartNumber,
route: "RecommendedProducts",
resourcePath: "Recommendations/v3/Products",
includes: includes,
otherParameters: otherParameters)
{ }

public class PackageByQuantityParent(string digikeyPartNumber, Dictionary<string, string>? otherParameters = null, string[]? includes = null) : ResourcePathParent(
digikeyPartNumber,
route: "PackageByQuantity",
resourcePath: "PackageTypeByQuantity/v3/Products",
includes: includes,
otherParameters: otherParameters)
{ }

public class ProductChangeNotificationsParent(string digikeyPartNumber, string[]? includes = null) : ResourcePathParent(
digikeyPartNumber,
route: "ProductChangeNotifications",
resourcePath: "ChangeNotifications/v3/Products",
includes: includes)
{ }

public class ProductTracingDetailsParent(string tracingID) : ResourcePathParent(
tracingID,
route: "ProductTracingDetails",
resourcePath: "ProductTracing/v1/Details")
{ }
}
}
Loading