2016-05-06 07:17:38 +03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Bit.App.Abstractions;
|
|
|
|
|
using Bit.App.Models.Api;
|
|
|
|
|
using Newtonsoft.Json;
|
2016-07-02 01:54:00 +03:00
|
|
|
|
using Plugin.Connectivity.Abstractions;
|
2016-05-06 07:17:38 +03:00
|
|
|
|
|
|
|
|
|
namespace Bit.App.Repositories
|
|
|
|
|
{
|
|
|
|
|
public class FolderApiRepository : ApiRepository<FolderRequest, FolderResponse, string>, IFolderApiRepository
|
|
|
|
|
{
|
2016-07-02 01:54:00 +03:00
|
|
|
|
public FolderApiRepository(IConnectivity connectivity)
|
|
|
|
|
: base(connectivity)
|
|
|
|
|
{ }
|
|
|
|
|
|
2016-05-06 07:17:38 +03:00
|
|
|
|
protected override string ApiRoute => "folders";
|
|
|
|
|
|
|
|
|
|
public virtual async Task<ApiResult<ListResponse<FolderResponse>>> GetByRevisionDateAsync(DateTime since)
|
|
|
|
|
{
|
2016-07-02 01:54:00 +03:00
|
|
|
|
if(!Connectivity.IsConnected)
|
2016-05-06 07:17:38 +03:00
|
|
|
|
{
|
2016-07-02 01:54:00 +03:00
|
|
|
|
return HandledNotConnected<ListResponse<FolderResponse>>();
|
|
|
|
|
}
|
2016-05-06 07:17:38 +03:00
|
|
|
|
|
2016-07-02 01:54:00 +03:00
|
|
|
|
using(var client = new ApiHttpClient())
|
2016-05-06 07:17:38 +03:00
|
|
|
|
{
|
2016-07-02 01:54:00 +03:00
|
|
|
|
var requestMessage = new TokenHttpRequestMessage()
|
|
|
|
|
{
|
|
|
|
|
Method = HttpMethod.Get,
|
|
|
|
|
RequestUri = new Uri(client.BaseAddress, string.Concat(ApiRoute, "?since=", since)),
|
|
|
|
|
};
|
2016-05-06 07:17:38 +03:00
|
|
|
|
|
2016-07-02 01:54:00 +03:00
|
|
|
|
var response = await client.SendAsync(requestMessage);
|
|
|
|
|
if(!response.IsSuccessStatusCode)
|
|
|
|
|
{
|
|
|
|
|
return await HandleErrorAsync<ListResponse<FolderResponse>>(response);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var responseContent = await response.Content.ReadAsStringAsync();
|
|
|
|
|
var responseObj = JsonConvert.DeserializeObject<ListResponse<FolderResponse>>(responseContent);
|
|
|
|
|
return ApiResult<ListResponse<FolderResponse>>.Success(responseObj, response.StatusCode);
|
|
|
|
|
}
|
2016-05-06 07:17:38 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|