public void SetUp() { var appSettingsCredentials = new StubbedConsumerCreds(); var apiUri = new ApiUri(); _requestBuilder = new RequestBuilder(apiUri, appSettingsCredentials); }
public RequestAuthorization(HttpClient httpClient, ApiUri apiUri, string userLogin, string userHash) { RequestType = RequestType.Authorization; RequestUri = apiUri.Private.GetUrl(RequestType); HttpClient = httpClient; _userLogin = userLogin; _userHash = userHash; }
/// <summary> /// Edits existing device defined in OneSignal App. /// </summary> /// <param name="id"> Id of the device </param> /// <param name="options"> Options used to modify attributes of the device. </param> /// <exception cref="Exception"></exception> public async Task EditAsync(string id, DeviceEditOptions options) { var result = await ApiUri.AppendPathSegment($"players/{id}") .WithHeader("Authorization", $"Basic {ApiKey}") .PutJsonAsync(options) .ConfigureAwait(true); }
public override bool Equals(object obj) { if (ReferenceEquals(this, obj)) { return(true); } var other = obj as HostAddress; return(other != null && WebUri.IsSameHost(other.WebUri) && ApiUri.IsSameHost(other.ApiUri)); }
/// <summary> /// Adds new device into OneSignal App. /// </summary> /// <param name="options"> Here you can specify options used to add new device. </param> /// <returns> Result of device add operation. </returns> public async Task <DeviceAddResult> AddAsync(DeviceAddOptions options) { var result = await ApiUri.AppendPathSegment("players") .WithHeader("Authorization", $"Basic {ApiKey}") .PostJsonAsync(options) .ReceiveJson <DeviceAddResult>() .ConfigureAwait(true); return(result); }
/// <summary> /// Cancel a notification scheduled by the OneSignal system /// </summary> /// <param name="options"> Options used for notification cancel operation. </param> /// <returns></returns> public async Task <NotificationCancelResult> CancelAsync(NotificationCancelOptions options) { var result = await ApiUri.AppendPathSegment($"notifications/{options.Id}?app_id={options.AppId}") .WithHeader("Authorization", $"Basic {ApiKey}") .DeleteAsync() .ReceiveJson <NotificationCancelResult>() .ConfigureAwait(true); return(result); }
/// <inheritdoc /> /// <summary> /// Creates new notification to be sent by OneSignal system. /// </summary> /// <param name="options"> Options used for notification create operation. </param> /// <returns></returns> public async Task <NotificationCreateResult> CreateAsync(NotificationCreateOptions options) { var result = await ApiUri.AppendPathSegment("notifications") .WithHeader("Authorization", $"Basic {ApiKey}") .PostJsonAsync(options) .ReceiveJson <NotificationCreateResult>() .ConfigureAwait(true); return(result); }
public static Client BuildClient(string subDomain) { var apiUri = new ApiUri(subDomain); IHttpSettings settings = new HttpSettings() { BaseUrl = apiUri.BaseUrl, UserAgent = $"({GetASPNetVersion()}; {GetOsVersion()}; {GetArchitecture()})" }; var client = new Client(apiUri) { HttpClient = HttpClientFactory.Instance.GetClient(settings) }; return(client); }
public IActionResult Index() { var googleState = SetNewSessionState(_googleSessionSettings.StateKey); var redirectUri = ApiUri.GetGoogleRedirectUri(HttpContext); var googleLoginUrl = _googleService.GetLoginUrl(googleState, redirectUri); var githubState = SetNewSessionState(_githubSessionSettings.StateKey); var githubOAuthUrl = _githubService.GetOAuthCodeUrl(githubState); var viewModel = new IndexViewModel { GoogleLoginUrl = googleLoginUrl, GithubOAuthUrl = githubOAuthUrl }; return(View(viewModel)); }
public async Task <DeviceInfo> GetAsync(string playerId, string appId) { try { var result = await ApiUri .AppendPathSegment($"players/{playerId}") .SetQueryParam("app_id", appId) .WithHeader("Authorization", $"Basic {ApiKey}") .GetJsonAsync <DeviceInfo>() .ConfigureAwait(true); return(result); } catch (Exception) { return(null); } }
public async Task <IActionResult> AuthReturn( [FromQuery] string code, [FromQuery] string state) { var stateFromCookie = HttpContext.Session.GetString(_googleSessionSettings.StateKey); if (stateFromCookie != state) { return(RedirectToAction("Index", "Home")); } var redirectUri = ApiUri.GetGoogleRedirectUri(HttpContext); var tokens = await _googleService.GetTokensFromApi(code, redirectUri); HttpContext.Session.SetString(_googleSessionSettings.AccessTokenKey, tokens.AccessToken); HttpContext.Session.SetString(_googleSessionSettings.IdTokenKey, tokens.IdToken); return(RedirectToAction("Profile")); }
public void EtagWorksOnGet() { HttpClient client = new HttpClient(); HttpRequestMessage request; HttpResponseMessage response; // Retrieving an object for the first time. Observe that the ETag is NOT in the response headers and // the returned payload contains the annotation @odata.etag indicating the ETag associated with that customer. request = new HttpRequestMessage(HttpMethod.Get, ApiUri.ToString() + "/Houses('" + house1guid.ToString("D") + "')"); response = client.SendAsync(request).Result; response.EnsureSuccessStatusCode(); dynamic house = JObject.Parse(response.Content.ReadAsStringAsync().Result); string odataEtag = house["@odata.etag"]; // Retrieving the same object as in the previous request but only if the ETag doesn't match the one // specified in the If-None-Match header. We are sending the ETag value that we obtained from the previous // request, so we expect to see a 304 (Not Modified) response. request = new HttpRequestMessage(HttpMethod.Get, ApiUri.ToString() + "/Houses('" + house1guid.ToString("D") + "')"); request.Headers.IfNoneMatch.Add(EntityTagHeaderValue.Parse(odataEtag)); response = client.SendAsync(request).Result; Assert.AreEqual(HttpStatusCode.NotModified, response.StatusCode); }
/// <summary> /// Gets a reference to an HttpClient object to communicate with /// </summary> /// <param name="url">Base url for the hosted services</param> /// <returns>HttpClient object pointing to the given url</returns> private HttpClient GetClient() { if (m_Clients == null) { m_Clients = new Dictionary <string, HttpClient>(); } string url = ApiUri.ToString(); HttpClient client = null; if (m_Clients.ContainsKey(url)) { client = m_Clients[url]; } else { client = new HttpClient() { BaseAddress = new Uri(url) }; m_Clients[url] = client; } return(client); }
public ApiWithCredentials() { _credentials = new AppSettingsCredentials(); _apiUrl = new ApiUri(); }
private Client(ApiUri apiUri) { _apiUri = apiUri; }
public override int GetHashCode() { return((WebUri?.GetHashCode() ?? 0) ^ (ApiUri?.GetHashCode() ?? 0)); }
private RoomsSoapClient getRoomsApi() { if (_roomsApi == null) { _roomsApi = new RoomsSoapClient(new BasicHttpBinding(), new EndpointAddress(ApiUri.ToString())); } return(_roomsApi); }
public RequestGetTasks(HttpClient httpClient, ApiUri apiUri) { RequestType = RequestType.Task; RequestUri = apiUri.Private.GetUrl(RequestType); HttpClient = httpClient; }
public static string ToUrl(this ApiUri apiUri) { return(!serviceUris.TryGetValue(apiUri, out string uriStr) ? String.Empty : "http://" + ipAddress + "/periwinkle/api" + uriStr); }
public RequestGetCompanies(HttpClient httpClient, ApiUri apiUri) { RequestType = RequestType.Company; RequestUri = apiUri.Private.GetUrl(RequestType); HttpClient = httpClient; }
public void SetUp() { var appSettingsCredentials = new StubbedConsumerCreds(); var apiUri = new ApiUri(); _requestBuilder = new RequestBuilder(new RouteParamsSubstitutor(apiUri), appSettingsCredentials); }
public RequestGetCurrentAccount(HttpClient httpClient, ApiUri apiUri) { RequestType = RequestType.CurrentAccount; RequestUri = apiUri.Private.GetUrl(RequestType); HttpClient = httpClient; }