Ejemplo n.º 1
0
        static async Task Main(string[] args)
        {
            /**
             * Objective: Write a controller to pull data from an API. Data must be stored in a model.
             * I don't want to see too much work done within this main class. You should encapsulate anything you can in a
             * controller.
             *
             * Endpoint: https://ccm.cps.golf/RegressionSRCCM/Transactions.svc/GetTerminalIdentifiers
             * Result type: List of Strings
             * User: Regression
             * User Token: f8cd3f4554f74a89bdb625bc
             *
             * To authenticate against this API, you need to send an HTTP header called Authorization and provide the username
             * and user token in the format of user:token as a Base64 encoded string.
             *
             * Helpers:
             * EncodingHelper class in the Helpers folder will allow you to encode/decode a base64 string for doing API autentication.
             * The use case is EncodingHelper.Encode(string).
             *
             * NuGet Packages:
             * Newtonsoft.Json allows you to convert JSON replies from API requests to a usable object or vice versa.
             *
             * Advice - The HttpClient class will allow you to send/receive responses from an API. API requests are done asynchronously
             * so you'll have to use an await.
             * */
            CreditCardAPIController creditCardAPIController = new CreditCardAPIController();

            creditCardAPIController.user  = "******";
            creditCardAPIController.token = "f8cd3f4554f74a89bdb625bc";

            string[] resultList = await creditCardAPIController.GetTerminalIdentifiers();

            foreach (string s in resultList)
            {
                System.Console.WriteLine(s);
            }
            System.Console.ReadLine();
        }
Ejemplo n.º 2
0
        static async Task Main(string[] args)
        {
            CreditCardAPIController creditCardCtl = new CreditCardAPIController();

            creditCardCtl.User  = "******";
            creditCardCtl.Token = "f8cd3f4554f74a89bdb625bc";
            TerminalIdentifiersModel terminalIdentifiersMdl = new TerminalIdentifiersModel();

            terminalIdentifiersMdl.TerminalNames = await creditCardCtl.GetTerminalIdentifiers();


            System.Console.WriteLine(terminalIdentifiersMdl.ToString());
            System.Console.WriteLine("Press enter to continue.");
            System.Console.ReadLine();

            /**
             * Objective: Write a controller to pull data from an API. Data must be stored in a model.
             * I don't want to see too much work done within this main class. You should encapsulate anything you can in a
             * controller.
             *
             * Endpoint: https://ccm.cps.golf/RegressionSRCCM/Transactions.svc/GetTerminalIdentifiers
             * Result type: List of Strings
             * User: Regression
             * User Token: f8cd3f4554f74a89bdb625bc
             *
             * To authenticate against this API, you need to send an HTTP header called Authorization and provide the username
             * and user token in the format of user:token as a Base64 encoded string.
             *
             *
             *
             */
            // var userName = "******";
            // var passwd = "f8cd3f4554f74a89bdb625bc";
            // var url ="https://ccm.cps.golf/RegressionSRCCM/Transactions.svc/GetTerminalIdentifiers";// "https://httpbin.org/basic-auth/user7/passwd";
            // url = "https://ccm.cps.golf";
            // url = "https://ccm.cps.golf/RegressionSRCCM";
            // //url = "Transactions.svc/GetTerminalIdentifiers";
            // //url = "RegressionSRCCM/Transactions.svc/GetTerminalIdentifiers";
            // var client = new HttpClient();

            // var authToken = Encoding.ASCII.GetBytes($"{userName}:{passwd}");
            // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
            //         Convert.ToBase64String(authToken));
            //// client.BaseAddress = new Uri("https://ccm.cps.golf");
            //// client.DefaultRequestHeaders.Accept.Add(
            ////        new MediaTypeWithQualityHeaderValue("application/json"));
            // var result = await client.GetAsync(url);

            // var content = await result.Content.ReadAsStringAsync();
            // Console.WriteLine(content);



            /*
             * Helpers:
             * EncodingHelper class in the Helpers folder will allow you to encode/decode a base64 string for doing API autentication.
             * The use case is EncodingHelper.Encode(string).
             *
             * NuGet Packages:
             * Newtonsoft.Json allows you to convert JSON replies from API requests to a usable object or vice versa.
             *
             * Advice - The HttpClient class will allow you to send/receive responses from an API. API requests are done asynchronously
             * so you'll have to use an await.
             * */

            //               var userName = "******";
            //    var passwd = "f8cd3f4554f74a89bdb625bc";
            //    var url = "https://ccm.cps.golf/RegressionSRCCM/Transactions.svc/GetTerminalIdentifiers";// "https://httpbin.org/basic-auth/user7/passwd";
            //    url = "https://ccm.cps.golf";
            //    url = "https://ccm.cps.golf/RegressionSRCCM";
            //    //url = "Transactions.svc/GetTerminalIdentifiers";
            //    //url = "RegressionSRCCM/Transactions.svc/GetTerminalIdentifiers";
            //    url = "https://ccm.cps.golf/RegressionSRCCM/Transactions.svc/GetTerminalIdentifiers";
            //    var client = new HttpClient();
            //     var authToken = Encoding.ASCII.GetBytes($"{userName}:{passwd}");
            //    //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer",
            //    //        Convert.ToBase64String(authToken));
            //   // client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", Convert.ToBase64String(authToken));
            //    //client.DefaultRequestHeaders.Add("Authorization", Convert.ToBase64String(authToken));
            //    client.DefaultRequestHeaders.Add("Authorization", $"TOKEN id=\"{Convert.ToBase64String(authToken)}\"");
            //    // client.BaseAddress = new Uri("https://ccm.cps.golf");
            //    // client.DefaultRequestHeaders.Accept.Add(
            //    //        new MediaTypeWithQualityHeaderValue("application/json"));
            //    var result = await client.GetAsync(url); //PostAsync(url.ToString(), default(string),Convert.ToBase64String(authToken), null, null); //GetAsync(url);
            //    var response = await client.PostAsync(url.ToString(), null);

            //   var content = await result.Content.ReadAsStringAsync();
            //    Console.WriteLine(content);

            //   await PostAsync1(client,Convert.ToBase64String(authToken),url,"test" );

            //    //host = host.EndsWith("/") ? host : $"{host}/";
            //    //var url = new Uri($"{host}Transactions.svc/GetTerminalIdentifiers");
            //    //var authorizeToken = CPSEncryption.EncryptBaseString64($"{username}:{token}");

            //    //var response = await _apiClient.PostAsync(url.ToString(), default(string), authorizeToken, null, null);
            //    //response.EnsureSuccessStatusCode();
            //    //var jsonResponse = await response.Content.ReadAsStringAsync();

            //    //return !string.IsNullOrEmpty(jsonResponse) ?
            //    //    JsonConvert.DeserializeObject<string[]>(jsonResponse) :
            //    //    throw new ReferencesNotFoundDomainException();
        }