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

57 lines
1.4 KiB
C#

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;
}
}
}