Skip to content

Commit

Permalink
Legacy trading API get item added.
Browse files Browse the repository at this point in the history
  • Loading branch information
shafaqat-ali-cms365 committed Jun 27, 2024
1 parent 2d3c1bd commit 673b1cc
Show file tree
Hide file tree
Showing 14 changed files with 198 additions and 15 deletions.
12 changes: 12 additions & 0 deletions EbaySharp/Controllers/EbayController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
using EbaySharp.Entities.Sell.Inventory.Offer;
using EbaySharp.Entities.Sell.Metadata.Marketplace;
using EbaySharp.Entities.Sell.Stores.Store;
using EbaySharp.Entities.TraditionalSelling.Trading;

namespace EbaySharp.Controllers
{


public class EbayController
{
private string accessToken;
Expand Down Expand Up @@ -219,5 +222,14 @@ public async Task<CategoryTree> GetCategoryTree(string CategoryTreeId)
}

#endregion

#region TRADING

public async Task<GetSellerListResponse> GetItems(int pageNumber, int entriesPerPage, string endTimeFrom, string endTimeTo)
{
return await new TradingController(accessToken).GetItems(pageNumber, entriesPerPage, endTimeFrom, endTimeTo);
}

#endregion
}
}
40 changes: 40 additions & 0 deletions EbaySharp/Controllers/TradingController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using EbaySharp.Entities.TraditionalSelling.Trading;
using EbaySharp.Source;
using System.Text;
using System.Xml.Linq;

namespace EbaySharp.Controllers
{
class TradingController
{
private string accessToken;
public TradingController(string accessToken)
{
this.accessToken = accessToken;
}
public async Task<GetSellerListResponse> GetItems(int pageNumber, int entriesPerPage, string endTimeFrom, string endTimeTo)
{
XNamespace ns = "urn:ebay:apis:eBLBaseComponents";
XDocument xmlDocument = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XElement(ns + "GetSellerListRequest", new XAttribute("xmlns", ns),
new XElement("RequesterCredentials",
new XElement("eBayAuthToken", accessToken)
),
new XElement("GranularityLevel", "Coarse"),
new XElement("EndTimeFrom", endTimeFrom),
new XElement("EndTimeTo", endTimeTo),
new XElement("Pagination",
new XElement("EntriesPerPage", entriesPerPage),
new XElement("PageNumber", pageNumber)
)
)
);
var memory = new MemoryStream();
xmlDocument.Save(memory);
string xmlText = Encoding.UTF8.GetString(memory.ToArray()).Replace("xmlns=\"\"", "");

return await new RequestExecuter().ExecuteLegacyPostRequest<GetSellerListResponse>(Constants.TRADIONAL.CALLS.GetSellerList, xmlText);
}
}
}
2 changes: 1 addition & 1 deletion EbaySharp/EbaySharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<ApplicationIcon>EbaySharp_ico.ico</ApplicationIcon>
<PackageID>CMS365.EbaySharp</PackageID>
<Title>EbaySharp</Title>
<Version>6.6.3</Version>
<Version>6.6.4</Version>
<Authors>Shafaqat Ali</Authors>
<Company>CMS365 PTY LTD</Company>
<Description>EbaySharp is a .NET library that enables you to authenticate and make REST API calls to eBay. It's used for creating listings and managing orders using C# and .NET</Description>
Expand Down
11 changes: 11 additions & 0 deletions EbaySharp/Entities/TraditionalSelling/Trading/Errors.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace EbaySharp.Entities.TraditionalSelling.Trading
{
public class Errors
{
public string ShortMessage { get; set; }
public string LongMessage { get; set; }
public int ErrorCode { get; set; }
public string SeverityCode { get; set; }
public string ErrorClassification { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace EbaySharp.Entities.TraditionalSelling.Trading
{
public class GetSellerListRequest
{
public List<LegacyItem> ItemArray { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using EbaySharp.Entities.Common;

namespace EbaySharp.Entities.TraditionalSelling.Trading
{
//[System.SerializableAttribute()]
//[System.ComponentModel.DesignerCategoryAttribute("code")]
//[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "urn:ebay:apis:eBLBaseComponents")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "urn:ebay:apis:eBLBaseComponents", IsNullable = false)]
public partial class GetSellerListResponse
{
[System.Xml.Serialization.XmlArrayItemAttribute("Item", IsNullable = false)]
public List<LegacyItem> ItemArray { get; set; }
public string Ack { get; set; }
public bool HasMoreItems { get; set; }
public int ItemsPerPage { get; set; }
public PaginationResult PaginationResult { get; set; }
public Errors Errors { get; set; }

}
}
14 changes: 14 additions & 0 deletions EbaySharp/Entities/TraditionalSelling/Trading/LegacyItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using EbaySharp.Entities.Common;

namespace EbaySharp.Entities.TraditionalSelling.Trading
{
public class LegacyItem
{
public string ItemID { get; set; }
public string SKU { get; set; }
public int Quantity { get; set; }
public SellingStatus SellingStatus { get; set; }
public CountryCodeEnum Country { get; set; }
public ListingDetails ListingDetails { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace EbaySharp.Entities.TraditionalSelling.Trading
{
public class ListingDetails
{
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace EbaySharp.Entities.TraditionalSelling.Trading
{
public class PaginationResult
{
public int TotalNumberOfPages { get; set; }
public int TotalNumberOfEntries { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace EbaySharp.Entities.TraditionalSelling.Trading
{
public class SellingStatus
{
public int QuantitySold { get; set; }
public double CurrentPrice { get; set; }
public string ListingStatus { get; set; }
}
}
8 changes: 8 additions & 0 deletions EbaySharp/Source/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,13 @@ internal struct METHODS
}
}
}
internal struct TRADIONAL
{
internal const string ENDPOINT_URL = "/ws/api.dll";
internal struct CALLS
{
public const string GetSellerList = "GetSellerList";
}
}
}
}
3 changes: 1 addition & 2 deletions EbaySharp/Source/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Text.Json;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace EbaySharp.Source
Expand Down
30 changes: 29 additions & 1 deletion EbaySharp/Source/RequestExecuter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
namespace EbaySharp.Source
using System.IO;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Serialization;

namespace EbaySharp.Source
{
internal class RequestExecuter
{
Expand Down Expand Up @@ -59,6 +64,25 @@ private async Task<T> executePostRequest<T>(string requestUrl, string authHeader
}
throw new Exception((new { error = responseContent.DeserializeToObject<object>(), payload = JSONPayload?.DeserializeToObject<object>() }).SerializeToJson());
}
private async Task<T> executeLegacyPostRequest<T>(string callName, string payload)
{
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, $"{Constants.API_SERVER_URL}{Constants.TRADIONAL.ENDPOINT_URL}");
request.Headers.Add("X-EBAY-API-SITEID", "15");
request.Headers.Add("X-EBAY-API-COMPATIBILITY-LEVEL", "967");
request.Headers.Add("X-EBAY-API-CALL-NAME", callName);
var content = new StringContent(payload, null, "application/xml");
request.Content = content;
var response = await client.SendAsync(request);
string responseContent = await response.Content.ReadAsStringAsync();
XmlSerializer ser = new XmlSerializer(typeof(T));
T type;
using (XmlReader reader = XmlReader.Create(new StringReader(responseContent)))
{
type = (T)ser.Deserialize(reader);
}
return type;
}
//private async Task executePostRequest(string requestUrl, string authHeaderValue, List<KeyValuePair<string, string>>? keyValuePayload, string? JSONPayload, string? contentLanguage)
//{
// HttpResponseMessage response = await executeRequest(HttpMethod.Post, requestUrl, authHeaderValue, contentLanguage, keyValuePayload, JSONPayload);
Expand All @@ -82,6 +106,10 @@ public async Task<T> ExecutePostRequest<T>(string requestUrl, string authHeaderV
{
return await executePostRequest<T>(requestUrl, authHeaderValue, keyValuePayload, null, null);
}
public async Task<T> ExecuteLegacyPostRequest<T>(string callName, string payload)
{
return await executeLegacyPostRequest<T>(callName, payload);
}
public async Task<T> ExecutePostRequest<T>(string requestUrl, string authHeaderValue, string? JSONPayload, string? contentLanguage)
{
return await executePostRequest<T>(requestUrl, authHeaderValue, null, JSONPayload, contentLanguage);
Expand Down
41 changes: 30 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ Install-Package CMS365.EbaySharp

# API support

| EbaySharp version | eBay REST API version |
| ----------------- | --------------------------|
| 6.6.X | Analytics API v1_beta.0.0 |
| | Browse API v1.19.7 |
| | Finances API v1.17.2 |
| | Fulfillment API v1.20.4 |
| | Inventory API v1.17.4 |
| | Metadata API v1.7.1 |
| | Stores API v1 |
| | Taxonomy API v1.0.1 |
| EbaySharp version | eBay REST API version |
| ----------------- | ----------------------------|
| 6.6.X | Analytics API v1_beta.0.0 |
| | Browse API v1.19.7 |
| | Finances API v1.17.2 |
| | Fulfillment API v1.20.4 |
| | Inventory API v1.17.4 |
| | Metadata API v1.7.1 |
| | Stores API v1 |
| | Taxonomy API v1.0.1 |
| | Trading API (Legacy) v1363 |

EbaySharp currently supports the following Ebay REST APIs:

Expand Down Expand Up @@ -93,6 +94,9 @@ EbaySharp currently supports the following Ebay REST APIs:
- [Stores](#stores)
- [Store](#Store)
- [Get store categories](#get-store-categories)
- [Trading](#trading)
- [Standard Listing Calls](#standard-listing-calls)
- [GetSellerList](#GetSellerList)

# Access and Security

Expand Down Expand Up @@ -598,6 +602,21 @@ You can find more detail [here](https://developer.ebay.com/api-docs/sell/stores/
EbaySharp.Controllers.EbayController ebayController = new EbaySharp.Controllers.EbayController(clientCredentials.AccessToken);
StoreCategories storeCategories = await ebayController.GetStoreCategories();
```

## Trading
You can see a list of Trading call categories [here](https://developer.ebay.com/devzone/xml/docs/reference/ebay/index.html)
### Standard Listing Calls
#### GetSellerList
You can find more detail [here](https://developer.ebay.com/devzone/xml/docs/reference/ebay/GetSellerList.html)
```C#
EbaySharp.Controllers.EbayController ebayController = new EbaySharp.Controllers.EbayController(clientCredentials.AccessToken);
int pageNumber = 0;
bool hasMoreResults = true;
while (hasMoreResults)
{
GetSellerListResponse getSellerListResponse = await ebayController.GetItems(pageNumber, 200, DateTime.Now.AddDays(-87).ToString("O"), DateTime.Now.AddDays(33).ToString("O"));
hasMoreResults = getSellerListResponse.HasMoreItems;
//Process items response here.
}
```


0 comments on commit 673b1cc

Please sign in to comment.