public void Should_ReturnNewClientInstance_WhenNewClientIsCalled() { // act var client1 = factory.CreateClient(); var client2 = factory.CreateClient(); // assert client1.Should().NotBeNull(); client2.Should().NotBeNull(); client1.Should().NotBeSameAs(client2); }
private static UserInfoModel GetUserInfo(string accessToken) { var client = GetClient(); RequestFactory factory = new RequestFactory(); OAuth2.Client.Endpoint baseEndpoint = new OAuth2.Client.Endpoint() { BaseUri = "https://start.exactonline.nl", }; OAuth2.Client.Endpoint endpoint = new OAuth2.Client.Endpoint() { BaseUri = "https://start.exactonline.nl", Resource = "/api/v1/current/Me" }; var restClient = factory.CreateClient(baseEndpoint); restClient.Authenticator = new OAuth2AuthorizationRequestHeaderAuthenticator(accessToken, "Bearer"); IRestRequest request = factory.CreateRequest(endpoint); IRestResponse response = restClient.ExecuteAndVerify(request); return(JObject.Parse(response.Content)["d"]["results"][0].ToObject <UserInfoModel>()); }
public void Initialize(string appToken) { RequestFactory _factory = new RequestFactory(); _client = _factory.CreateClient(new AuthenticationHeaderValue("Bearer", appToken)); _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", appToken); }
/// <summary> /// Gets Access Token and makes Request against Endpoint passed in /// </summary> /// <param name="endpoint">Uri of Api to Query</param> /// <param name="AccessToken">Items on QS/Form Data used to fulfill Api Call</param> /// <returns></returns> internal static async Task <XDocument> GetResponseData(EndPoint endpoint, string AccessToken) { return(await await ResilientCall(async() => { RequestFactory _factory = new RequestFactory(); var client = _factory.CreateClient(endpoint, new AuthenticationHeaderValue("Bearer", AccessToken)); var request = _factory.CreateRequest(endpoint); var response = await client.GetAsync(request.RequestUri).ConfigureAwait(false); var result = await response.Content.ReadAsStringAsync(); if (string.IsNullOrEmpty(result)) { throw new Exception("Combination of Resource and SubResources Not Allowed, Please try altering"); } return XDocument.Parse(result); })); }