/* * protected override async Task DeleteFromServer() * { * var client = WebApiClientFactory.CreateElmahUserApiClient(); * var item = Item; * * var result = await client.DeleteEntityAsync(item); * this.StatusOfResult = result.BusinessLogicLayerResponseStatus; * this.StatusMessageOfResult = result.GetStatusMessage(); * } */ protected override async Task <Elmah.ViewModelData.ElmahUser.ItemVM> GetFromServer(Elmah.EntityContracts.IElmahUserIdentifier identifier) { var client = WebApiClientFactory.CreateElmahUserApiClient(); var result = await client.GetItemVMAsync(identifier.User); return(result); }
// 2 ways to check an object. One from json printed, the other an object from the api // the first way is more modular and works for any json, the second more adjusted for SWAPI public static async Task <IEnumerable <Starships> > GetStarShipItemsAsync(bool forceRefresh = false) { IWebApiClient <IStarwarsApi> _webApiClient = WebApiClientFactory.Get <IStarwarsApi>("https://swapi.co/api", true); var jsonresult = await _webApiClient.Call( (service) => service.GetTask(), Priority.UserInitiated, 2, (ex) => true, 60); var result = await _webApiClient.Call( (service) => service.GetStarships(), Priority.UserInitiated, 2, (ex) => true, 60); // checking the get call with a quick timeout try { var timeoutresult = await _webApiClient.Call( (service) => service.GetTask(), Priority.UserInitiated, 2, (ex) => true, 3); } catch (Exception e) { Console.WriteLine("This call is longer then 3 seconds, but will display anyway of working correctly"); } ConvertJson(jsonresult); return(result.Results); }
// test post call public static async Task <string> PostRawPostmanEcho(bool forceRefresh = false) { IWebApiClient <IPostmanEcho> webApiClient = WebApiClientFactory.Get <IPostmanEcho>("https://postman-echo.com/", false); PostObject postObject = new PostObject(); postObject.testName = "hello world"; postObject.testDate = DateTime.Now.ToString(); var postObjectResult = await webApiClient.Call( (service) => service.PostObject(postObject), Priority.UserInitiated, 2, (ex) => true, 60); var postResult = await webApiClient.Call( (service) => service.Post("test"), Priority.UserInitiated, 2, (ex) => true, 60); Console.WriteLine("\t Post string: "); ConvertJson(postResult); Console.WriteLine("\t Post object: "); ConvertJson(postObjectResult); return(postResult); }
public MockDataStore() { _webApiClient = WebApiClientFactory.Get <IStarwarsApi>("https://swapi.co/api", false, () => new SampleHttpClientHandler()); items = new List <Starships>(); var mockItems = new List <Starships> { new Starships { Id = Guid.NewGuid().ToString(), name = "First starship", model = "This is an item description." }, new Starships { Id = Guid.NewGuid().ToString(), name = "Second starship", model = "This is an item description." }, new Starships { Id = Guid.NewGuid().ToString(), name = "Third starship", model = "This is an item description." }, new Starships { Id = Guid.NewGuid().ToString(), name = "Fourth starship", model = "This is an item description." }, new Starships { Id = Guid.NewGuid().ToString(), name = "Fifth starship", model = "This is an item description." }, new Starships { Id = Guid.NewGuid().ToString(), name = "Sixth starship", model = "This is an item description." } }; foreach (var item in mockItems) { items.Add(item); } }
public async Task GetDropDownContentsOfElmahUser() { try { var client = WebApiClientFactory.CreateListsApiClient(); var result = await client.ElmahUserList(currentIndex : -1, pageSize : -1, queryOrderByExpression : null); var originalDropDownContentsOfElmahUserSelectedItem = this.m_DropDownContentsOfElmahUserSelectedItem; var dropDownContentsOfElmahUser = new List <Framework.Models.NameValuePair <string> >(); if (result != null) { foreach (var item in result) { if (item != null) { string value = item.ParseToSystemString(null); dropDownContentsOfElmahUser.Add(new Framework.Models.NameValuePair <string>(value, item.Name)); } } this.DropDownContentsOfElmahUser = new ObservableCollection <Framework.Models.NameValuePair <string> >(dropDownContentsOfElmahUser); DropDownContentsOfElmahUserSelectedItem = originalDropDownContentsOfElmahUserSelectedItem; } } catch //(Exception ex) { } }
public async Task <UserResponseModel> GraphqlAsync() { var defaultHeaders = new Dictionary <string, string> { ["User-Agent"] = "LukasThijs", ["Authorization"] = "bearer insertbearer" }; var webApiClient = WebApiClientFactory.Get <IGitHubApi>("https://api.github.com/", false, default, defaultHeaders);
protected override async Task <Elmah.CommonBLLEntities.ElmahUserResponseMessageBuiltIn> UpsertToServer() { var client = WebApiClientFactory.CreateElmahUserApiClient(); var item = Item; var result = await client.UpsertEntityAsync(item); return(result); }
protected override async Task <Elmah.CommonBLLEntities.ELMAH_ErrorResponseMessageBuiltIn.Default> UpsertToServer() { var client = WebApiClientFactory.CreateELMAH_ErrorApiClient(); var item = new Elmah.DataSourceEntities.ELMAH_Error(); item.CopyFrom <Elmah.EntityContracts.IELMAH_Error>(Item); var result = await client.UpsertEntityAsync(item); return(result); }
public static async Task <string> GraphQLQueryAsync() { var first = "411eecb9b8fc9f5ac0a"; var second = "ff63e8135cb68b4f10116"; var combinedB = first + second; var defaultHeaders = new Dictionary <string, string> { ["User-Agent"] = "xabluexampleuser", ["Authorization"] = $"Bearer {combinedB}" }; var webApiClient = WebApiClientFactory.Get <IGitHubApi>("https://api.github.com", false, default, defaultHeaders);
// test login and authorization methods public static async Task <string> AuthenticatePostmanEcho(bool forceRefresh = false) { // this is how you do a basic auth, todo: how to convert to dictionary headers, i would use value? //var authData = string.Format("{0}:{1}", "postman", "password"); //var authHeaderValue = Convert.ToBase64String(Encoding.UTF8.GetBytes(authData)); //AuthenticationHeaderValue value = new AuthenticationHeaderValue(authHeaderValue, authData); // this basic auth way is working now but less clear imo IDictionary <string, string> authValues = new Dictionary <string, string> { { "postman", "password" } }; // OAuth isn't working, how do you add the headers for these //IDictionary<string, string> oAuthValues = new Dictionary<string, string> //{ // {"oauth_consumer_key", "D+EdQ-RKCGzna7bv9YD57c-%@2Nu7" }, // {"oauth_signature_method", "HMAC-SHA1" }, // {"oauth_timestamp", "1472121261"}, // {"oauth_nonce", "oauth_nonce" }, // {"oauth_version", "1.0" }, // {"oauth_signature", "s0rK92Myxx7ceUBVzlMaxiiXU00"} //}; IWebApiClient <IPostmanEcho> basicAuthWebApiClient = WebApiClientFactory.Get <IPostmanEcho>("https://postman-echo.com/", false, defaultHeaders: authValues); //IWebApiClient<IPostmanEcho> oAuthWebApiClient = WebApiClientFactory.Get<IPostmanEcho>("https://postman-echo.com/", false, () => new SampleHttpClientHandler(), oAuthValues); var basicAuthResult = await basicAuthWebApiClient.Call( (service) => service.BasicAuth(), Xablu.WebApiClient.Enums.Priority.UserInitiated, 2, (ex) => true, 60); //var oAuthResult = await oAuthWebApiClient.Call( // (service) => service.OAuth(), // Xablu.WebApiClient.Enums.Priority.UserInitiated, // 2, // (ex) => true, // 60); Console.WriteLine("\t basic auth: "); ConvertJson(basicAuthResult); //Console.WriteLine("\t oauth: "); //ConvertJson(oAuthResult); return(basicAuthResult); }
protected override async Task <Elmah.ViewModelData.ELMAH_Error.IndexVM> GetFromServer() { var vmData = new Elmah.ViewModelData.ELMAH_Error.IndexVM { Criteria = this.Criteria, QueryPagingSetting = CachingOption == Framework.Xaml.CachingOptions.NoCaching ? this.QueryPagingSetting : new Framework.Queries.QueryPagingSetting(1, 10000), QueryOrderBySettingCollection = new Framework.Queries.QueryOrderBySettingCollection(QueryOrderBySettingCollection.Where(t => t.IsSelected)), }; vmData.Criteria.CanQueryWhenNoQuery = true; /* * // Add extra QueryOrderBySetting, eg CategoryName -> Name of this class. * if (QueryOrderBySettingCollection.Any(t => t.IsSelected && t.PropertyName == nameof(Elmah.DataSourceEntities.ELMAH_Error.Default.??))) * { * vmData.QueryOrderBySettingCollection.Add(new Framework.Queries.QueryOrderBySetting { PropertyName = nameof(Elmah.DataSourceEntities.ELMAH_Error.Default.??), Direction = QueryOrderBySettingCollection.First(t => t.IsSelected && t.PropertyName == nameof(Elmah.DataSourceEntities.ELMAH_Error.Default.??)).Direction } ); * } */ var client = WebApiClientFactory.CreateELMAH_ErrorApiClient(); var result = await client.GetIndexVMAsync(vmData); return(result); }
public BooksService() { _webApiClient = WebApiClientFactory.Get <IBooksApi>(GetEndPoint()); }
public BooksService() { _webApiClient = WebApiClientFactory.Get <IBooksApi>("http://localhost:5000"); }
public async Task<JsonResult> CallOut(string number, string conferenceId) { try { var factory = new WebApiClientFactory().CreateClient<ICalloutApiEndpoints>("https://api.sinch.com", new ApplicationSigningFilter(appKey, Convert.FromBase64String(appSecret)), new RestReplyFilter()); number = number.StartsWith("+") ? number.Trim() : "+" + number.Trim(); var result = await factory.AddParticipant(new CalloutRequest { method = "conferenceCallout", conferenceCallout = new ConferenceCallout { cli = "+17864088194", destination = new Destination {endpoint = number, type = "number"}, domain = "pstn", conferenceId = conferenceId, greeting ="Welcome to the conference", enableDice = true, enableAce=true, } }); Debug.WriteLine(result.callId); return Json(null, JsonRequestBehavior.AllowGet); } catch (Exception e) { Debug.WriteLine(e.Message); } return Json(null, JsonRequestBehavior.AllowGet); }
public void SetUp() { WebApiClientFactory = new WebApiClientFactory(); }