Made progress on implementing some shops.
Performed some folder restructuring as well.
This commit is contained in:
		
							
								
								
									
										51
									
								
								Props-Modules/Props.Shop/Ebay/Actions/SearchRequest.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								Props-Modules/Props.Shop/Ebay/Actions/SearchRequest.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,51 @@ | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Net.Http; | ||||
| using System.Threading; | ||||
| using System.Threading.Tasks; | ||||
| using Props.Shop.Framework; | ||||
|  | ||||
| namespace Props.Shop.Ebay.Actions | ||||
| { | ||||
|     public class SearchRequest : IAsyncEnumerable<ProductListing> | ||||
|     { | ||||
|         private HttpClient http; | ||||
|         private string[] query; | ||||
|         public SearchRequest(HttpClient http, string[] query) | ||||
|         { | ||||
|             this.http = http ?? throw new ArgumentNullException("http"); | ||||
|             this.query = query ?? throw new ArgumentNullException("query"); | ||||
|         } | ||||
|  | ||||
|         public IAsyncEnumerator<ProductListing> GetAsyncEnumerator(CancellationToken cancellationToken = default) | ||||
|         { | ||||
|             throw new System.NotImplementedException(); | ||||
|         } | ||||
|  | ||||
|         public class Enumerator : IAsyncEnumerator<ProductListing> | ||||
|         { | ||||
|             private HttpClient http; | ||||
|             private string[] query; | ||||
|  | ||||
|             public Enumerator(HttpClient http, string[] query) | ||||
|             { | ||||
|                 this.http = http; | ||||
|                 this.query = query; | ||||
|             } | ||||
|  | ||||
|             public ProductListing Current { get; private set; } | ||||
|  | ||||
|             public ValueTask<bool> MoveNextAsync() | ||||
|             { | ||||
|                 // TODO: Implement this. | ||||
|                 throw new System.NotImplementedException(); | ||||
|             } | ||||
|             public ValueTask DisposeAsync() | ||||
|             { | ||||
|                 // TODO: Implement this. | ||||
|                 throw new System.NotImplementedException(); | ||||
|             } | ||||
|  | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,29 @@ | ||||
| using System.Collections; | ||||
| using System.Collections.Generic; | ||||
| using Newtonsoft.Json.Linq; | ||||
| using Props.Shop.Framework; | ||||
|  | ||||
| namespace Props.Shop.Ebay.Api.ItemSummary | ||||
| { | ||||
|     public class SearchResultParser | ||||
|     { | ||||
|         private dynamic data; | ||||
|         public int BeginIndex => data.offset; | ||||
|         public int EndIndex => BeginIndex + data.limit; | ||||
|         public IEnumerable<ProductListing> ProductListings { get; private set; } | ||||
|  | ||||
|         public SearchResultParser(string result) | ||||
|         { | ||||
|             data = JObject.Parse(result); | ||||
|  | ||||
|             List<ProductListing> parsed = new List<ProductListing>(); | ||||
|             foreach (dynamic itemSummary in data.itemSummaries) | ||||
|             { | ||||
|                 ProductListing listing = new ProductListing(); | ||||
|                 // TODO: Finish parsing the data. | ||||
|                 parsed.Add(listing); | ||||
|             } | ||||
|             ProductListings = parsed; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,57 @@ | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Text; | ||||
|  | ||||
| namespace Props.Shop.Ebay.Api.ItemSummary | ||||
| { | ||||
|     public class SearchUriBuilder | ||||
|     { | ||||
|         UriBuilder uriBuilder = new UriBuilder("/search"); | ||||
|         private HashSet<string> queries = new HashSet<string>(); | ||||
|         private bool autoCorrect = false; | ||||
|         private int? maxResults = 100; | ||||
|         private int? offset = 0; | ||||
|         public bool AutoCorrect | ||||
|         { | ||||
|             set | ||||
|             { | ||||
|                 autoCorrect = value; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public int? MaxResults | ||||
|         { | ||||
|             set | ||||
|             { | ||||
|                 maxResults = value; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public int? Offset | ||||
|         { | ||||
|             set | ||||
|             { | ||||
|                 offset = value; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public void AddSearchQuery(string query) | ||||
|         { | ||||
|             queries.Add(query); | ||||
|         } | ||||
|  | ||||
|         public Uri Build() | ||||
|         { | ||||
|             StringBuilder queryBuilder = new StringBuilder("q="); | ||||
|             queryBuilder.Append('('); | ||||
|             queryBuilder.AppendJoin(", ", queries); | ||||
|             queryBuilder.Append(')'); | ||||
|             uriBuilder.Query += queryBuilder.ToString(); | ||||
|  | ||||
|             if (autoCorrect) uriBuilder.Query += "&auto_correct=KEYWORD"; | ||||
|             if (maxResults.HasValue) uriBuilder.Query += "&limit=" + maxResults.Value; | ||||
|             if (offset.HasValue) uriBuilder.Query += "&offset=" + offset.Value; | ||||
|             return uriBuilder.Uri; | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										7
									
								
								Props-Modules/Props.Shop/Ebay/Configuration.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								Props-Modules/Props.Shop/Ebay/Configuration.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,7 @@ | ||||
| namespace Props.Shop.Ebay | ||||
| { | ||||
|     public class Configuration | ||||
|     { | ||||
|         public bool Sandbox { get; set; } = true; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										70
									
								
								Props-Modules/Props.Shop/Ebay/EbayShop.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										70
									
								
								Props-Modules/Props.Shop/Ebay/EbayShop.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,70 @@ | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Net.Http; | ||||
| using System.Text; | ||||
| using System.Text.Json; | ||||
| using Props.Shop.Framework; | ||||
|  | ||||
| namespace Props.Shop.Ebay | ||||
| { | ||||
|     public class EbayShop : IShop | ||||
|     { | ||||
|         private bool disposedValue; | ||||
|  | ||||
|         public string ShopName => "Ebay"; | ||||
|  | ||||
|         public string ShopDescription => "A multi-national online store host to consumer-to-consumer and business-to-consumer sales."; | ||||
|  | ||||
|         public string ShopModuleAuthor => "Reslate"; | ||||
|  | ||||
|         public SupportedFeatures SupportedFeatures => new SupportedFeatures( | ||||
|             true, | ||||
|             true, | ||||
|             true, | ||||
|             true, | ||||
|             true | ||||
|         ); | ||||
|  | ||||
|         Configuration configuration; | ||||
|  | ||||
|         private HttpClient httpClient; | ||||
|  | ||||
|         public IEnumerable<IOption> Initialize(byte[] data) | ||||
|         { | ||||
|             httpClient = new HttpClient(); | ||||
|             configuration = JsonSerializer.Deserialize<Configuration>(data); | ||||
|             return new List<IOption>() { | ||||
|                 new SandboxOption(configuration), | ||||
|             }; | ||||
|         } | ||||
|  | ||||
|         protected virtual void Dispose(bool disposing) | ||||
|         { | ||||
|             if (!disposedValue) | ||||
|             { | ||||
|                 if (disposing) | ||||
|                 { | ||||
|                     httpClient.Dispose(); | ||||
|                 } | ||||
|                 disposedValue = true; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public void Dispose() | ||||
|         { | ||||
|             Dispose(disposing: true); | ||||
|             GC.SuppressFinalize(this); | ||||
|         } | ||||
|  | ||||
|         public byte[] GetDataForPersistence() | ||||
|         { | ||||
|             return JsonSerializer.SerializeToUtf8Bytes(configuration); | ||||
|         } | ||||
|  | ||||
|         public IAsyncEnumerable<ProductListing> Search(string query, Filters filters) | ||||
|         { | ||||
|             // TODO: Implement the search system. | ||||
|             throw new NotImplementedException(); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										35
									
								
								Props-Modules/Props.Shop/Ebay/Options/SandboxOption.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								Props-Modules/Props.Shop/Ebay/Options/SandboxOption.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,35 @@ | ||||
| using System; | ||||
| using Props.Shop.Framework; | ||||
|  | ||||
| namespace Props.Shop.Ebay | ||||
| { | ||||
|     public class SandboxOption : IOption | ||||
|     { | ||||
|         private Configuration configuration; | ||||
|         public string Name => "Ebay Sandbox"; | ||||
|  | ||||
|         public string Description => "For development purposes, Ebay Sandbox allows use of Ebay APIs (with exceptions) in a sandbox environment before applying for production use."; | ||||
|  | ||||
|         public bool Required => true; | ||||
|  | ||||
|         public Type Type => typeof(bool); | ||||
|  | ||||
|         internal SandboxOption(Configuration configuration) | ||||
|         { | ||||
|             this.configuration = configuration; | ||||
|         } | ||||
|  | ||||
|         public string GetValue() | ||||
|         { | ||||
|             return configuration.Sandbox.ToString(); | ||||
|         } | ||||
|  | ||||
|         public bool SetValue(string value) | ||||
|         { | ||||
|             bool sandbox = false; | ||||
|             bool res = bool.TryParse(value, out sandbox); | ||||
|             configuration.Sandbox = sandbox; | ||||
|             return res; | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										15
									
								
								Props-Modules/Props.Shop/Ebay/Props.Shop.Ebay.csproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								Props-Modules/Props.Shop/Ebay/Props.Shop.Ebay.csproj
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,15 @@ | ||||
| <Project Sdk="Microsoft.NET.Sdk"> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <ProjectReference Include="..\Framework\Props.Shop.Framework.csproj" /> | ||||
|   </ItemGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> | ||||
|   </ItemGroup> | ||||
|  | ||||
|   <PropertyGroup> | ||||
|     <TargetFramework>net5.0</TargetFramework> | ||||
|   </PropertyGroup> | ||||
|  | ||||
| </Project> | ||||
		Reference in New Issue
	
	Block a user