diff --git a/src/Android/MainApplication.cs b/src/Android/MainApplication.cs index 7a7c3e82e..4eb52160e 100644 --- a/src/Android/MainApplication.cs +++ b/src/Android/MainApplication.cs @@ -222,6 +222,7 @@ namespace Bit.Android .RegisterType(new ContainerControlledLifetimeManager()) .RegisterType(new ContainerControlledLifetimeManager()) .RegisterType(new ContainerControlledLifetimeManager()) + .RegisterType(new ContainerControlledLifetimeManager()) // Other .RegisterInstance(CrossSettings.Current, new ContainerControlledLifetimeManager()) .RegisterInstance(CrossConnectivity.Current, new ContainerControlledLifetimeManager()) diff --git a/src/App/Abstractions/Repositories/ISettingsApiRepository.cs b/src/App/Abstractions/Repositories/ISettingsApiRepository.cs new file mode 100644 index 000000000..b106d9ad8 --- /dev/null +++ b/src/App/Abstractions/Repositories/ISettingsApiRepository.cs @@ -0,0 +1,11 @@ +using System.Threading.Tasks; +using Bit.App.Models.Api; +using Bit.App.Models.Api.Response; + +namespace Bit.App.Abstractions +{ + public interface ISettingsApiRepository + { + Task> GetDomains(bool excluded = false); + } +} \ No newline at end of file diff --git a/src/App/App.csproj b/src/App/App.csproj index d4634d884..4c7028627 100644 --- a/src/App/App.csproj +++ b/src/App/App.csproj @@ -35,6 +35,7 @@ 4 + @@ -93,6 +94,7 @@ + @@ -141,6 +143,7 @@ + diff --git a/src/App/Models/Api/Response/DomainsReponse.cs b/src/App/Models/Api/Response/DomainsReponse.cs new file mode 100644 index 000000000..61e77881b --- /dev/null +++ b/src/App/Models/Api/Response/DomainsReponse.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; + +namespace Bit.App.Models.Api.Response +{ + public class DomainsReponse + { + public IEnumerable> EquivalentDomains { get; set; } + public IEnumerable GlobalEquivalentDomains { get; set; } + + public class GlobalDomains + { + public byte Type { get; set; } + public IEnumerable Domains { get; set; } + public bool Excluded { get; set; } + } + } +} diff --git a/src/App/Repositories/SettingsApiRepository.cs b/src/App/Repositories/SettingsApiRepository.cs new file mode 100644 index 000000000..3e2636d13 --- /dev/null +++ b/src/App/Repositories/SettingsApiRepository.cs @@ -0,0 +1,64 @@ +using System; +using System.Net.Http; +using System.Threading.Tasks; +using Bit.App.Abstractions; +using Bit.App.Models.Api; +using Plugin.Connectivity.Abstractions; +using Bit.App.Models.Api.Response; +using Newtonsoft.Json; + +namespace Bit.App.Repositories +{ + public class SettingsApiRepository : BaseApiRepository, ISettingsApiRepository + { + public SettingsApiRepository( + IConnectivity connectivity, + IHttpService httpService, + ITokenService tokenService) + : base(connectivity, httpService, tokenService) + { } + + protected override string ApiRoute => "settings"; + + public virtual async Task> GetDomains(bool excluded = false) + { + if(!Connectivity.IsConnected) + { + return HandledNotConnected(); + } + + var tokenStateResponse = await HandleTokenStateAsync(); + if(!tokenStateResponse.Succeeded) + { + return tokenStateResponse; + } + + using(var client = HttpService.Client) + { + var requestMessage = new TokenHttpRequestMessage() + { + Method = HttpMethod.Get, + RequestUri = new Uri(client.BaseAddress, + string.Concat(ApiRoute, "/domains?excluded=", excluded.ToString().ToLowerInvariant())), + }; + + try + { + var response = await client.SendAsync(requestMessage).ConfigureAwait(false); + if(!response.IsSuccessStatusCode) + { + return await HandleErrorAsync(response).ConfigureAwait(false); + } + + var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var responseObj = JsonConvert.DeserializeObject(responseContent); + return ApiResult.Success(responseObj, response.StatusCode); + } + catch + { + return HandledWebException(); + } + } + } + } +} diff --git a/src/iOS/AppDelegate.cs b/src/iOS/AppDelegate.cs index c6108600a..1c9fd7fa8 100644 --- a/src/iOS/AppDelegate.cs +++ b/src/iOS/AppDelegate.cs @@ -277,6 +277,7 @@ namespace Bit.iOS .RegisterType(new ContainerControlledLifetimeManager()) .RegisterType(new ContainerControlledLifetimeManager()) .RegisterType(new ContainerControlledLifetimeManager()) + .RegisterType(new ContainerControlledLifetimeManager()) // Other .RegisterInstance(CrossConnectivity.Current, new ContainerControlledLifetimeManager()) .RegisterInstance(UserDialogs.Instance, new ContainerControlledLifetimeManager())