public async Task Register() { var del = (AppDelegate)UIApplication.SharedApplication.Delegate; if (string.IsNullOrEmpty(del.DeviceToken)) { throw new InvalidOperationException("Push notifications has not been enabled for this app!"); } var user = _applicationService.Account; if (user.IsEnterprise) { throw new InvalidOperationException("Push notifications are for GitHub.com accounts only!"); } var client = _httpClientService.Create(); var content = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>("token", del.DeviceToken), new KeyValuePair <string, string>("user", user.Username), new KeyValuePair <string, string>("domain", "https://api.github.com"), new KeyValuePair <string, string>("oauth", user.OAuth) }); client.Timeout = new TimeSpan(0, 0, 30); var response = await client.PostAsync(RegisterUri, content); if (response.StatusCode != System.Net.HttpStatusCode.OK && response.StatusCode != System.Net.HttpStatusCode.Conflict) { throw new InvalidOperationException("Unable to register! Server returned a " + response.StatusCode + " status code"); } System.Diagnostics.Debug.WriteLine("Push notifications registered for: " + user.Username + " (" + user.OAuth + ") on device <" + del.DeviceToken + ">"); }
private HttpClient CreateApiClient() { var apiClient = httpClientService.Create(); apiClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); apiClient.DefaultRequestHeaders.Add("x-functions-key", AppSettings.Instance.ApiSecret); apiClient.DefaultRequestHeaders.Add("x-api-key", AppSettings.Instance.ApiKey); return(apiClient); }
private async Task GetExposureNotificationConfig() { loggerService.StartMethod(); try { string container = AppSettings.Instance.BlobStorageContainerName; string url = AppSettings.Instance.CdnUrlBase + $"{container}/Configration.json"; HttpClient httpClient = httpClientService.Create(); Task <HttpResponseMessage> response = httpClient.GetAsync(url); HttpResponseMessage result = await response; if (result.StatusCode == System.Net.HttpStatusCode.OK) { loggerService.Info("Success to download configuration"); var content = await result.Content.ReadAsStringAsync(); preferencesService.SetValue(PreferenceKey.ExposureNotificationConfiguration, content); } else { loggerService.Error("Fail to download configuration"); } } catch (Exception ex) { loggerService.Exception("Failed download of exposure notification configuration.", ex); } finally { loggerService.EndMethod(); } }
public ErrorService(IHttpClientService httpClient, IJsonSerializationService jsonSerialization, IEnvironmentalService environmentService) { _jsonSerialization = jsonSerialization; _environmentService = environmentService; _httpClient = httpClient.Create(); _httpClient.Timeout = new TimeSpan(0, 0, 10); _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); }
public DiagnosisKeyRepository( IHttpClientService httpClientService, ILoggerService loggerService ) { _httpClient = httpClientService.Create(); _loggerService = loggerService; }
public ErrorService(IHttpClientService httpClient, IJsonSerializationService jsonSerialization, IEnvironmentService environmentService, IAccountsService accountsService) { _jsonSerialization = jsonSerialization; _environmentService = environmentService; _accountsService = accountsService; _httpClient = httpClient.Create(); _httpClient.Timeout = new TimeSpan(0, 0, 10); _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); }
public DebugExposureDataCollectServer( ILoggerService loggerService, IServerConfigurationRepository serverConfigurationRepository, IHttpClientService httpClientService ) { _loggerService = loggerService; _serverConfigurationRepository = serverConfigurationRepository; _httpClient = httpClientService.Create(); }
public CheckVersionService( IHttpClientService httpClientService, IEssentialsService essentialsService, ILoggerService loggerService ) { _httpClient = httpClientService.Create(); _essentialsService = essentialsService; _loggerService = loggerService; }
public async Task <TMessage> Get <TMessage>(string url) { var client = _httpClientService.Create(); client.Timeout = new TimeSpan(0, 0, 30); var response = await client.GetAsync(url); var data = await response.Content.ReadAsStringAsync(); return(_jsonSerializationService.Deserialize <TMessage>(data)); }
public DiagnosisKeyRepository( IHttpClientService httpClientService, ILoggerService loggerService ) { _httpClient = httpClientService.Create(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }); _loggerService = loggerService; }
public async Task <IEnumerable <string> > GetAvailableFeatureIds() { var client = _httpClientService.Create(); client.Timeout = new TimeSpan(0, 0, 15); var response = await client.GetAsync("http://push.codehub-app.com/in-app"); var data = await response.Content.ReadAsStringAsync(); return(_jsonSerializationService.Deserialize <List <string> >(data).ToArray()); }
public TermsUpdateService( ILoggerService loggerService, IHttpClientService httpClientService, IUserDataRepository userDataRepository ) { this.loggerService = loggerService; this.userDataRepository = userDataRepository; _httpClient = httpClientService.Create(); _httpClient.Timeout = TimeSpan.FromSeconds(TimeoutSeconds); }
public HttpDataService(ILoggerService loggerService, IHttpClientService httpClientService, ISecureStorageService secureStorageService, IApplicationPropertyService applicationPropertyService) { this.loggerService = loggerService; this.secureStorageService = secureStorageService; this.applicationPropertyService = applicationPropertyService; // Create API key based client. apiClient = httpClientService.Create(); apiClient.BaseAddress = new Uri(AppSettings.Instance.ApiUrlBase); apiClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); apiClient.DefaultRequestHeaders.Add("x-functions-key", AppSettings.Instance.ApiSecret); apiClient.DefaultRequestHeaders.Add("x-api-key", AppSettings.Instance.ApiKey); // Create client. httpClient = httpClientService.Create(); httpClient.BaseAddress = new Uri(AppSettings.Instance.ApiUrlBase); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); httpClient.DefaultRequestHeaders.Add("x-functions-key", AppSettings.Instance.ApiSecret); // Create download client. downloadClient = httpClientService.Create(); }
public ExposureRiskCalculationConfigurationRepository( IHttpClientService httpClientService, ILocalPathService localPathService, IServerConfigurationRepository serverConfigurationRepository, ILoggerService loggerService ) { _localPathService = localPathService; _serverConfigurationRepository = serverConfigurationRepository; _loggerService = loggerService; _httpClient = httpClientService.Create(); _httpClient.Timeout = TimeSpan.FromSeconds(TIMEOUT_SECONDS); _configDir = PrepareConfigDir(); _currentPath = localPathService.CurrentExposureRiskCalculationConfigurationPath; }
public async Task <ImgurModel> SendImage(byte[] data) { var client = _httpClientService.Create(); client.Timeout = new TimeSpan(0, 0, 30); client.DefaultRequestHeaders.Add("Authorization", "Client-ID " + AuthorizationClientId); var body = _jsonSerializationService.Serialize(new { image = Convert.ToBase64String(data) }); var content = new StringContent(body, System.Text.Encoding.UTF8, "application/json"); var response = await client.PostAsync(ImgurPostUrl, content).ConfigureAwait(false); if (!response.IsSuccessStatusCode) { throw new InvalidOperationException("Unable to post to Imgur! " + response.ReasonPhrase); } var responseBody = await response.Content.ReadAsStringAsync().ConfigureAwait(false); return(_jsonSerializationService.Deserialize <ImgurModel>(responseBody)); }
public async Task <TMessage> Get <TMessage>(string url, Dictionary <string, string> headers = null) { var client = _httpClientService.Create(); client.Timeout = new TimeSpan(0, 0, 30); if (headers != null) { foreach (var kv in headers) { client.DefaultRequestHeaders.Add(kv.Key, kv.Value); } } var response = await client.GetAsync(url); var data = await response.Content.ReadAsStringAsync(); return(_jsonSerializationService.Deserialize <TMessage>(data)); }
public EventLogService( IUserDataRepository userDataRepository, IServerConfigurationRepository serverConfigurationRepository, IEssentialsService essentialsService, IDeviceVerifier deviceVerifier, IDateTimeUtility dateTimeUtility, IHttpClientService httpClientService, ILoggerService loggerService ) { _userDataRepository = userDataRepository; _serverConfigurationRepository = serverConfigurationRepository; _essentialsService = essentialsService; _deviceVerifier = deviceVerifier; _dateTimeUtility = dateTimeUtility; _loggerService = loggerService; _httpClient = httpClientService.Create(); }
public ExposureConfigurationRepository( IHttpClientService httpClientService, ILocalPathService localPathService, IPreferencesService preferencesService, IServerConfigurationRepository serverConfigurationRepository, IDateTimeUtility dateTimeUtility, ILoggerService loggerService ) { _localPathService = localPathService; _preferencesService = preferencesService; _serverConfigurationRepository = serverConfigurationRepository; _dateTimeUtility = dateTimeUtility; _loggerService = loggerService; _httpClient = httpClientService.Create(); _httpClient.Timeout = TimeSpan.FromSeconds(TIMEOUT_SECONDS); _configDir = PrepareConfigDir(); _currentExposureConfigurationPath = localPathService.CurrentExposureConfigurationPath; }
public async Task GetExposureNotificationConfig() { loggerService.StartMethod(); string container = AppSettings.Instance.BlobStorageContainerName; string url = AppSettings.Instance.CdnUrlBase + $"{container}/Configration.json"; HttpClient httpClient = httpClientService.Create(); Task <HttpResponseMessage> response = httpClient.GetAsync(url); HttpResponseMessage result = await response; if (result.StatusCode == System.Net.HttpStatusCode.OK) { loggerService.Info("Success to download configuration"); Application.Current.Properties["ExposureNotificationConfigration"] = await result.Content.ReadAsStringAsync(); await Application.Current.SavePropertiesAsync(); } else { loggerService.Error("Fail to download configuration"); } loggerService.EndMethod(); }
public HttpDataServiceMock(IHttpClientService httpClientService) { downloadClient = httpClientService.Create(); }