1
0
mirror of https://github.com/bitwarden/mobile synced 2026-01-04 17:43:17 +00:00

change syncing to use new sync api

This commit is contained in:
Kyle Spearrin
2017-09-20 13:17:05 -04:00
parent 45d171e0e3
commit a426d98e92
10 changed files with 114 additions and 60 deletions

View File

@@ -172,45 +172,5 @@ namespace Bit.App.Repositories
}
}
}
public virtual async Task<ApiResult<KeysResponse>> GetKeys()
{
if(!Connectivity.IsConnected)
{
return HandledNotConnected<KeysResponse>();
}
var tokenStateResponse = await HandleTokenStateAsync<KeysResponse>();
if(!tokenStateResponse.Succeeded)
{
return tokenStateResponse;
}
using(var client = HttpService.ApiClient)
{
var requestMessage = new TokenHttpRequestMessage()
{
Method = HttpMethod.Get,
RequestUri = new Uri(string.Concat(client.BaseAddress, ApiRoute, "/keys")),
};
try
{
var response = await client.SendAsync(requestMessage).ConfigureAwait(false);
if(!response.IsSuccessStatusCode)
{
return await HandleErrorAsync<KeysResponse>(response).ConfigureAwait(false);
}
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
var responseObj = JsonConvert.DeserializeObject<KeysResponse>(responseContent);
return ApiResult<KeysResponse>.Success(responseObj, response.StatusCode);
}
catch
{
return HandledWebException<KeysResponse>();
}
}
}
}
}

View File

@@ -0,0 +1,63 @@
using System;
using System.Net.Http;
using System.Threading.Tasks;
using Bit.App.Abstractions;
using Bit.App.Models.Api;
using Plugin.Connectivity.Abstractions;
using Newtonsoft.Json;
namespace Bit.App.Repositories
{
public class SyncApiRepository : BaseApiRepository, ISyncApiRepository
{
public SyncApiRepository(
IConnectivity connectivity,
IHttpService httpService,
ITokenService tokenService)
: base(connectivity, httpService, tokenService)
{ }
protected override string ApiRoute => "sync";
public virtual async Task<ApiResult<SyncResponse>> Get()
{
if(!Connectivity.IsConnected)
{
return HandledNotConnected<SyncResponse>();
}
var tokenStateResponse = await HandleTokenStateAsync<SyncResponse>();
if(!tokenStateResponse.Succeeded)
{
return tokenStateResponse;
}
using(var client = HttpService.ApiClient)
{
var requestMessage = new TokenHttpRequestMessage()
{
Method = HttpMethod.Get,
RequestUri = new Uri(
string.Concat(client.BaseAddress, ApiRoute)),
};
try
{
var response = await client.SendAsync(requestMessage).ConfigureAwait(false);
if(!response.IsSuccessStatusCode)
{
return await HandleErrorAsync<SyncResponse>(response).ConfigureAwait(false);
}
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
var responseObj = JsonConvert.DeserializeObject<SyncResponse>(responseContent);
return ApiResult<SyncResponse>.Success(responseObj, response.StatusCode);
}
catch
{
return HandledWebException<SyncResponse>();
}
}
}
}
}