bitwarden-android/src/App/Repositories/DeviceApiRepository.cs

34 lines
1.2 KiB
C#
Raw Normal View History

2016-06-18 23:10:09 +03:00
using System;
2016-06-22 05:29:29 +03:00
using System.Net.Http;
using System.Threading.Tasks;
2016-06-18 23:10:09 +03:00
using Bit.App.Abstractions;
using Bit.App.Models.Api;
2016-06-22 05:29:29 +03:00
using Newtonsoft.Json;
2016-06-18 23:10:09 +03:00
namespace Bit.App.Repositories
{
public class DeviceApiRepository : ApiRepository<DeviceRequest, DeviceResponse, string>, IDeviceApiRepository
{
protected override string ApiRoute => "devices";
2016-06-22 05:29:29 +03:00
public virtual async Task<ApiResult<DeviceResponse>> PutTokenAsync(string identifier, DeviceTokenRequest request)
{
var requestMessage = new TokenHttpRequestMessage(request)
{
Method = HttpMethod.Put,
RequestUri = new Uri(Client.BaseAddress, string.Concat(ApiRoute, "/identifier/", identifier, "/token")),
};
var response = await Client.SendAsync(requestMessage);
if(!response.IsSuccessStatusCode)
{
return await HandleErrorAsync<DeviceResponse>(response);
}
var responseContent = await response.Content.ReadAsStringAsync();
var responseObj = JsonConvert.DeserializeObject<DeviceResponse>(responseContent);
return ApiResult<DeviceResponse>.Success(responseObj, response.StatusCode);
}
2016-06-18 23:10:09 +03:00
}
}