1
0
mirror of https://github.com/bitwarden/mobile synced 2026-01-03 00:53:27 +00:00

HttpService abstraction with CustomAndroidClientHandler to handle xamarin android bug with error response body

This commit is contained in:
Kyle Spearrin
2016-12-24 10:54:18 -05:00
parent 62cef0d141
commit 9682abdded
19 changed files with 871 additions and 31 deletions

View File

@@ -10,8 +10,10 @@ namespace Bit.App.Repositories
{
public class AccountsApiRepository : BaseApiRepository, IAccountsApiRepository
{
public AccountsApiRepository(IConnectivity connectivity)
: base(connectivity)
public AccountsApiRepository(
IConnectivity connectivity,
IHttpService httpService)
: base(connectivity, httpService)
{ }
protected override string ApiRoute => "accounts";
@@ -23,7 +25,7 @@ namespace Bit.App.Repositories
return HandledNotConnected();
}
using(var client = new ApiHttpClient())
using(var client = HttpService.Client)
{
var requestMessage = new TokenHttpRequestMessage(requestObj)
{
@@ -55,7 +57,7 @@ namespace Bit.App.Repositories
return HandledNotConnected();
}
using(var client = new ApiHttpClient())
using(var client = HttpService.Client)
{
var requestMessage = new TokenHttpRequestMessage(requestObj)
{

View File

@@ -15,8 +15,10 @@ namespace Bit.App.Repositories
where TRequest : class
where TResponse : class
{
public ApiRepository(IConnectivity connectivity)
: base(connectivity)
public ApiRepository(
IConnectivity connectivity,
IHttpService httpService)
: base(connectivity, httpService)
{ }
public virtual async Task<ApiResult<TResponse>> GetByIdAsync(TId id)
@@ -26,7 +28,7 @@ namespace Bit.App.Repositories
return HandledNotConnected<TResponse>();
}
using(var client = new ApiHttpClient())
using(var client = HttpService.Client)
{
var requestMessage = new TokenHttpRequestMessage()
{
@@ -60,7 +62,7 @@ namespace Bit.App.Repositories
return HandledNotConnected<ListResponse<TResponse>>();
}
using(var client = new ApiHttpClient())
using(var client = HttpService.Client)
{
var requestMessage = new TokenHttpRequestMessage()
{
@@ -94,7 +96,7 @@ namespace Bit.App.Repositories
return HandledNotConnected<TResponse>();
}
using(var client = new ApiHttpClient())
using(var client = HttpService.Client)
{
var requestMessage = new TokenHttpRequestMessage(requestObj)
{
@@ -128,7 +130,7 @@ namespace Bit.App.Repositories
return HandledNotConnected<TResponse>();
}
using(var client = new ApiHttpClient())
using(var client = HttpService.Client)
{
var requestMessage = new TokenHttpRequestMessage(requestObj)
{
@@ -162,7 +164,7 @@ namespace Bit.App.Repositories
return HandledNotConnected();
}
using(var client = new ApiHttpClient())
using(var client = HttpService.Client)
{
var requestMessage = new TokenHttpRequestMessage()
{

View File

@@ -11,8 +11,10 @@ namespace Bit.App.Repositories
{
public class AuthApiRepository : BaseApiRepository, IAuthApiRepository
{
public AuthApiRepository(IConnectivity connectivity)
: base(connectivity)
public AuthApiRepository(
IConnectivity connectivity,
IHttpService httpService)
: base(connectivity, httpService)
{ }
protected override string ApiRoute => "auth";
@@ -24,7 +26,7 @@ namespace Bit.App.Repositories
return HandledNotConnected<TokenResponse>();
}
using(var client = new ApiHttpClient())
using(var client = HttpService.Client)
{
var requestMessage = new TokenHttpRequestMessage(requestObj)
{
@@ -44,7 +46,7 @@ namespace Bit.App.Repositories
var responseObj = JsonConvert.DeserializeObject<TokenResponse>(responseContent);
return ApiResult<TokenResponse>.Success(responseObj, response.StatusCode);
}
catch(WebException)
catch(WebException e)
{
return HandledWebException<TokenResponse>();
}
@@ -58,7 +60,7 @@ namespace Bit.App.Repositories
return HandledNotConnected<TokenResponse>();
}
using(var client = new ApiHttpClient())
using(var client = HttpService.Client)
{
var requestMessage = new TokenHttpRequestMessage(requestObj)
{

View File

@@ -5,17 +5,20 @@ using System.Threading.Tasks;
using Bit.App.Models.Api;
using Newtonsoft.Json;
using Plugin.Connectivity.Abstractions;
using Bit.App.Abstractions;
namespace Bit.App.Repositories
{
public abstract class BaseApiRepository
{
public BaseApiRepository(IConnectivity connectivity)
public BaseApiRepository(IConnectivity connectivity, IHttpService httpService)
{
Connectivity = connectivity;
HttpService = httpService;
}
protected IConnectivity Connectivity { get; private set; }
protected IHttpService HttpService { get; private set; }
protected abstract string ApiRoute { get; }
protected ApiResult HandledNotConnected()

View File

@@ -12,8 +12,10 @@ namespace Bit.App.Repositories
{
public class CipherApiRepository : BaseApiRepository, ICipherApiRepository
{
public CipherApiRepository(IConnectivity connectivity)
: base(connectivity)
public CipherApiRepository(
IConnectivity connectivity,
IHttpService httpService)
: base(connectivity, httpService)
{ }
protected override string ApiRoute => "ciphers";
@@ -25,7 +27,7 @@ namespace Bit.App.Repositories
return HandledNotConnected<CipherResponse>();
}
using(var client = new ApiHttpClient())
using(var client = HttpService.Client)
{
var requestMessage = new TokenHttpRequestMessage()
{
@@ -59,7 +61,7 @@ namespace Bit.App.Repositories
return HandledNotConnected<ListResponse<CipherResponse>>();
}
using(var client = new ApiHttpClient())
using(var client = HttpService.Client)
{
var requestMessage = new TokenHttpRequestMessage()
{
@@ -93,7 +95,7 @@ namespace Bit.App.Repositories
return HandledNotConnected<CipherHistoryResponse>();
}
using(var client = new ApiHttpClient())
using(var client = HttpService.Client)
{
var requestMessage = new TokenHttpRequestMessage()
{

View File

@@ -11,8 +11,10 @@ namespace Bit.App.Repositories
{
public class DeviceApiRepository : ApiRepository<DeviceRequest, DeviceResponse, string>, IDeviceApiRepository
{
public DeviceApiRepository(IConnectivity connectivity)
: base(connectivity)
public DeviceApiRepository(
IConnectivity connectivity,
IHttpService httpService)
: base(connectivity, httpService)
{ }
protected override string ApiRoute => "devices";
@@ -24,7 +26,7 @@ namespace Bit.App.Repositories
return HandledNotConnected();
}
using(var client = new ApiHttpClient())
using(var client = HttpService.Client)
{
var requestMessage = new TokenHttpRequestMessage(request)
{
@@ -56,7 +58,7 @@ namespace Bit.App.Repositories
return HandledNotConnected();
}
using(var client = new ApiHttpClient())
using(var client = HttpService.Client)
{
var requestMessage = new TokenHttpRequestMessage
{

View File

@@ -12,8 +12,10 @@ namespace Bit.App.Repositories
{
public class FolderApiRepository : ApiRepository<FolderRequest, FolderResponse, string>, IFolderApiRepository
{
public FolderApiRepository(IConnectivity connectivity)
: base(connectivity)
public FolderApiRepository(
IConnectivity connectivity,
IHttpService httpService)
: base(connectivity, httpService)
{ }
protected override string ApiRoute => "folders";
@@ -25,7 +27,7 @@ namespace Bit.App.Repositories
return HandledNotConnected<ListResponse<FolderResponse>>();
}
using(var client = new ApiHttpClient())
using(var client = HttpService.Client)
{
var requestMessage = new TokenHttpRequestMessage()
{

View File

@@ -11,8 +11,10 @@ namespace Bit.App.Repositories
{
public class SiteApiRepository : ApiRepository<SiteRequest, SiteResponse, string>, ISiteApiRepository
{
public SiteApiRepository(IConnectivity connectivity)
: base(connectivity)
public SiteApiRepository(
IConnectivity connectivity,
IHttpService httpService)
: base(connectivity, httpService)
{ }
protected override string ApiRoute => "sites";