Exemplo n.º 1
0
        // 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);
        }
Exemplo n.º 2
0
        // 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);
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
 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);
        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);
Exemplo n.º 6
0
        // 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);
        }
Exemplo n.º 7
0
 public BooksService()
 {
     _webApiClient = WebApiClientFactory.Get <IBooksApi>(GetEndPoint());
 }
Exemplo n.º 8
0
 public BooksService()
 {
     _webApiClient = WebApiClientFactory.Get <IBooksApi>("http://localhost:5000");
 }