Skip to content

SatSearchService

Sam Gerene edited this page May 21, 2018 · 2 revisions

The SatSearchService is the meat and potatoes of the satsearch-API. It is the class that should be used by API developers to perform queries on the satsearch API. The SatSearchService implements the ISatSearchService interface and is injectable using MEF.

The ISatSearchService exposes the following methods:

  • Task<SupplierResult> SupplierResult: Gets all the suppliers encapsulated in SupplierResult from the satsearch API
  • Task<Supplier> Supplier: Gets the the full details of a specific Supplier from the satsearch API
  • Task<IEnumerable<Supplier>> Suppliers: Gets all the suppliers from the satsearch API
  • Task<IEnumerable<Category>> Categories: Gets all the categories from the SatSearch service.
  • Task<IEnumerable<Model.AttributeType>> AttributeTypes: Gets all the attribute types from the SatSearch service.
  • Task<ProductResult> Search: Perform a search query on a SatSearch service using query parameters as search filter.
  • Task<Product> Product: Retrieves the full product details from the satsearch service

The following example demonstrates how a products can be searched filtering on a category and supplier:

// use the Credentials to access the online API
var uri = new Uri("https://api.satsearch.co");
var credentials = new Credentials("API-Token", "your-Application-Token", uri);

// The HttpClientService and SatSearchSerializer are instantiated here, but can also be injected using MEF
var httpClientService = new HttpClientService();
var satSearchSerializer = new SatSearchSerializer();

// instantiate the SatSearchService
var satSearchService = new SatSearchService(httpClientService, satSearchSerializer);

// query the API for all existing suppliers AND get the first supplier to use in a later Product search:
var supplierResult = await satSearchService.SupplierResult(this.credentials, new CancellationToken());
var supplier = supplierResult.Data.First();

var categories = await satSearchService.Categories(this.credentials, new CancellationToken());
var category = categories.First(); 

var searchParameter = new SearchParameter();
searchParameter.Categories = new List<Category> { category.Children }; // The API support category filtering on sub categories, not on so-called top-categories
searchParameter.Suppliers = new List<Supplier> { supplier };

var productResult = await satSearchService.Search(this.credentials, new CancellationToken(), searchParameter);

foreach (var product in productResult.Data)
{
    Console.WriteLine(product.Name);
}

satsearch-SDK

  1. Home
  2. Documentation Overview
  3. Getting your API tokens
  4. Roadmap

Library guts explained

  1. Credentials
  2. HttpClientService
  3. Serializer
  4. SatSearchService

Clone this wiki locally