Skip to main content
Code Review

Return to Question

replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

This is a follow up from my previous post: Basic API wrapper around a Restful service Basic API wrapper around a Restful service

I'm writing a basic wrapper around a restful service that returns a list of Stores. Naturally, I want to make it completely testable (that's a major requirement!).

I have split out my TopmanClient class so that just deals with the rest client bits (using RestSharp).

I then inject the TopmanClient class into my TopmanRepository:

public class TopmanClient : ITopmanClient
{
 private readonly IRestClient _restClient;
 private const string BaseUrl = "https://public.Topman.com/";
 private const string AcceptTenant = "uk";
 private const string AcceptLanguage = "en-GB";
 public TopmanClient()
 {
 _restClient = new RestClient(BaseUrl);
 
 _restClient.AddDefaultHeader("Accept-Tenant", AcceptTenant);
 _restClient.AddDefaultHeader("Accept-Language", AcceptLanguage);
 }
 public IRestRequest Request(string url)
 {
 return new RestRequest(url);
 }
 public IRestResponse<T> Execute<T>(IRestRequest request) where T : new()
 {
 return _restClient.Execute<T>(request);
 }
}
public class TopmanRepository : ITopmanRepository<Store>
{
 private readonly ITopmanClient _topmanClient;
 public TopmanRepository(ITopmanClient topmanClient)
 {
 _topmanClient = topmanClient;
 }
 
 public List<Store> Get(string query)
 {
 var request = _topmanClient.Request("stores");
 request.RootElement = "Stores";
 request.AddQueryParameter("q", query);
 var response = _topmanClient.Execute<List<Store>>(request);
 return response.Data;
 }
}

This is a follow up from my previous post: Basic API wrapper around a Restful service

I'm writing a basic wrapper around a restful service that returns a list of Stores. Naturally, I want to make it completely testable (that's a major requirement!).

I have split out my TopmanClient class so that just deals with the rest client bits (using RestSharp).

I then inject the TopmanClient class into my TopmanRepository:

public class TopmanClient : ITopmanClient
{
 private readonly IRestClient _restClient;
 private const string BaseUrl = "https://public.Topman.com/";
 private const string AcceptTenant = "uk";
 private const string AcceptLanguage = "en-GB";
 public TopmanClient()
 {
 _restClient = new RestClient(BaseUrl);
 
 _restClient.AddDefaultHeader("Accept-Tenant", AcceptTenant);
 _restClient.AddDefaultHeader("Accept-Language", AcceptLanguage);
 }
 public IRestRequest Request(string url)
 {
 return new RestRequest(url);
 }
 public IRestResponse<T> Execute<T>(IRestRequest request) where T : new()
 {
 return _restClient.Execute<T>(request);
 }
}
public class TopmanRepository : ITopmanRepository<Store>
{
 private readonly ITopmanClient _topmanClient;
 public TopmanRepository(ITopmanClient topmanClient)
 {
 _topmanClient = topmanClient;
 }
 
 public List<Store> Get(string query)
 {
 var request = _topmanClient.Request("stores");
 request.RootElement = "Stores";
 request.AddQueryParameter("q", query);
 var response = _topmanClient.Execute<List<Store>>(request);
 return response.Data;
 }
}

This is a follow up from my previous post: Basic API wrapper around a Restful service

I'm writing a basic wrapper around a restful service that returns a list of Stores. Naturally, I want to make it completely testable (that's a major requirement!).

I have split out my TopmanClient class so that just deals with the rest client bits (using RestSharp).

I then inject the TopmanClient class into my TopmanRepository:

public class TopmanClient : ITopmanClient
{
 private readonly IRestClient _restClient;
 private const string BaseUrl = "https://public.Topman.com/";
 private const string AcceptTenant = "uk";
 private const string AcceptLanguage = "en-GB";
 public TopmanClient()
 {
 _restClient = new RestClient(BaseUrl);
 
 _restClient.AddDefaultHeader("Accept-Tenant", AcceptTenant);
 _restClient.AddDefaultHeader("Accept-Language", AcceptLanguage);
 }
 public IRestRequest Request(string url)
 {
 return new RestRequest(url);
 }
 public IRestResponse<T> Execute<T>(IRestRequest request) where T : new()
 {
 return _restClient.Execute<T>(request);
 }
}
public class TopmanRepository : ITopmanRepository<Store>
{
 private readonly ITopmanClient _topmanClient;
 public TopmanRepository(ITopmanClient topmanClient)
 {
 _topmanClient = topmanClient;
 }
 
 public List<Store> Get(string query)
 {
 var request = _topmanClient.Request("stores");
 request.RootElement = "Stores";
 request.AddQueryParameter("q", query);
 var response = _topmanClient.Execute<List<Store>>(request);
 return response.Data;
 }
}
added 6 characters in body; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Basic API wrapper around a Restful service - Refactoredfollow-up

This is a follow up from my previous post: Basic API wrapper around a Restful service

I'm writing a basic wrapper around a restful service that returns a list of Stores. Naturally Naturally, I want to make it completely testable (that's a major requirement!).

I have split out my TopmanClientTopmanClient class so that just deals with the rest client bits (using RestSharp).

I then inject the TopmanClientTopmanClient class into my TopmanRepository.TopmanRepository:

public class TopmanClient : ITopmanClient
{
 private readonly IRestClient _restClient;
 private const string BaseUrl = "https://public.Topman.com/";
 private const string AcceptTenant = "uk";
 private const string AcceptLanguage = "en-GB";
 public TopmanClient()
 {
 _restClient = new RestClient(BaseUrl);
 
 _restClient.AddDefaultHeader("Accept-Tenant", AcceptTenant);
 _restClient.AddDefaultHeader("Accept-Language", AcceptLanguage);
 }
 public IRestRequest Request(string url)
 {
 return new RestRequest(url);
 }
 public IRestResponse<T> Execute<T>(IRestRequest request) where T : new()
 {
 return _restClient.Execute<T>(request);
 }
}
public class TopmanRepository : ITopmanRepository<Store>
{
 private readonly ITopmanClient _topmanClient;
 public TopmanRepository(ITopmanClient topmanClient)
 {
 _topmanClient = topmanClient;
 }
 
 public List<Store> Get(string query)
 {
 var request = _topmanClient.Request("stores");
 request.RootElement = "Stores";
 request.AddQueryParameter("q", query);
 var response = _topmanClient.Execute<List<Store>>(request);
 return response.Data;
 }
}

Basic API wrapper around a Restful service - Refactored

This is a follow up from my previous post Basic API wrapper around a Restful service

I'm writing a basic wrapper around a restful service that returns a list of Stores. Naturally, I want to make it completely testable (that's a major requirement!).

I have split out my TopmanClient class so that just deals with the rest client bits (using RestSharp).

I then inject the TopmanClient class into my TopmanRepository.

public class TopmanClient : ITopmanClient
{
 private readonly IRestClient _restClient;
 private const string BaseUrl = "https://public.Topman.com/";
 private const string AcceptTenant = "uk";
 private const string AcceptLanguage = "en-GB";
 public TopmanClient()
 {
 _restClient = new RestClient(BaseUrl);
 
 _restClient.AddDefaultHeader("Accept-Tenant", AcceptTenant);
 _restClient.AddDefaultHeader("Accept-Language", AcceptLanguage);
 }
 public IRestRequest Request(string url)
 {
 return new RestRequest(url);
 }
 public IRestResponse<T> Execute<T>(IRestRequest request) where T : new()
 {
 return _restClient.Execute<T>(request);
 }
}
public class TopmanRepository : ITopmanRepository<Store>
{
 private readonly ITopmanClient _topmanClient;
 public TopmanRepository(ITopmanClient topmanClient)
 {
 _topmanClient = topmanClient;
 }
 
 public List<Store> Get(string query)
 {
 var request = _topmanClient.Request("stores");
 request.RootElement = "Stores";
 request.AddQueryParameter("q", query);
 var response = _topmanClient.Execute<List<Store>>(request);
 return response.Data;
 }
}

Basic API wrapper around a Restful service - follow-up

This is a follow up from my previous post: Basic API wrapper around a Restful service

I'm writing a basic wrapper around a restful service that returns a list of Stores. Naturally, I want to make it completely testable (that's a major requirement!).

I have split out my TopmanClient class so that just deals with the rest client bits (using RestSharp).

I then inject the TopmanClient class into my TopmanRepository:

public class TopmanClient : ITopmanClient
{
 private readonly IRestClient _restClient;
 private const string BaseUrl = "https://public.Topman.com/";
 private const string AcceptTenant = "uk";
 private const string AcceptLanguage = "en-GB";
 public TopmanClient()
 {
 _restClient = new RestClient(BaseUrl);
 
 _restClient.AddDefaultHeader("Accept-Tenant", AcceptTenant);
 _restClient.AddDefaultHeader("Accept-Language", AcceptLanguage);
 }
 public IRestRequest Request(string url)
 {
 return new RestRequest(url);
 }
 public IRestResponse<T> Execute<T>(IRestRequest request) where T : new()
 {
 return _restClient.Execute<T>(request);
 }
}
public class TopmanRepository : ITopmanRepository<Store>
{
 private readonly ITopmanClient _topmanClient;
 public TopmanRepository(ITopmanClient topmanClient)
 {
 _topmanClient = topmanClient;
 }
 
 public List<Store> Get(string query)
 {
 var request = _topmanClient.Request("stores");
 request.RootElement = "Stores";
 request.AddQueryParameter("q", query);
 var response = _topmanClient.Execute<List<Store>>(request);
 return response.Data;
 }
}
Source Link

Basic API wrapper around a Restful service - Refactored

This is a follow up from my previous post Basic API wrapper around a Restful service

I'm writing a basic wrapper around a restful service that returns a list of Stores. Naturally, I want to make it completely testable (that's a major requirement!).

I have split out my TopmanClient class so that just deals with the rest client bits (using RestSharp).

I then inject the TopmanClient class into my TopmanRepository.

public class TopmanClient : ITopmanClient
{
 private readonly IRestClient _restClient;
 private const string BaseUrl = "https://public.Topman.com/";
 private const string AcceptTenant = "uk";
 private const string AcceptLanguage = "en-GB";
 public TopmanClient()
 {
 _restClient = new RestClient(BaseUrl);
 
 _restClient.AddDefaultHeader("Accept-Tenant", AcceptTenant);
 _restClient.AddDefaultHeader("Accept-Language", AcceptLanguage);
 }
 public IRestRequest Request(string url)
 {
 return new RestRequest(url);
 }
 public IRestResponse<T> Execute<T>(IRestRequest request) where T : new()
 {
 return _restClient.Execute<T>(request);
 }
}
public class TopmanRepository : ITopmanRepository<Store>
{
 private readonly ITopmanClient _topmanClient;
 public TopmanRepository(ITopmanClient topmanClient)
 {
 _topmanClient = topmanClient;
 }
 
 public List<Store> Get(string query)
 {
 var request = _topmanClient.Request("stores");
 request.RootElement = "Stores";
 request.AddQueryParameter("q", query);
 var response = _topmanClient.Execute<List<Store>>(request);
 return response.Data;
 }
}
lang-cs

AltStyle によって変換されたページ (->オリジナル) /