props/Props-Modules/Props.Shop/Adafruit/AdafruitShop.cs
Harrison Deng e0756e0967 Made progress on implementing some shops.
Performed some folder restructuring as well.
2021-07-24 00:03:32 -05:00

69 lines
1.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text.Json;
using Props.Shop.Adafruit.Api;
using Props.Shop.Framework;
namespace Props.Shop.Adafruit
{
public class AdafruitShop : IShop
{
private ProductListingManager productListingManager;
private Configuration configuration;
private HttpClient http;
private bool disposedValue;
public string ShopName => "Adafruit";
public string ShopDescription => "A electronic component online hardware company.";
public string ShopModuleAuthor => "Reslate";
public SupportedFeatures SupportedFeatures => new SupportedFeatures(
false,
false,
false,
false,
true
);
public byte[] GetDataForPersistence()
{
return JsonSerializer.SerializeToUtf8Bytes(configuration);
}
public IEnumerable<IOption> Initialize(byte[] data)
{
http = new HttpClient();
http.BaseAddress = new Uri("http://www.adafruit.com/api");
configuration = JsonSerializer.Deserialize<Configuration>(data);
this.productListingManager = new ProductListingManager();
return null;
}
public IAsyncEnumerable<ProductListing> Search(string query, Filters filters)
{
return productListingManager.Search(query, configuration.Similarity, http);
}
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
http.Dispose();
}
disposedValue = true;
}
}
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}