report() public method

public report ( Hashtable transactions ) : void
transactions System.Collections.Hashtable
return void
Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            try {
                string provider_key = "YOUR_PROVIDER_KEY";
                string app_id = "APP_ID_OF_THE_USER";

                Api _3ScaleAPI = new Api("http://su1.3scale.net", provider_key);

                AuthorizeResponse resp = _3ScaleAPI.authorize(app_id);

                print(resp);

                Console.WriteLine("Done authorize...");

                System.Collections.Hashtable transactions = new System.Collections.Hashtable();
                System.Collections.Hashtable transaction = null;
                System.Collections.Hashtable usage = null;

                transaction = new System.Collections.Hashtable();
                transaction.Add("app_id",app_id);
                transaction.Add("timestamp", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss K"));
                usage = new System.Collections.Hashtable();
                usage.Add("hits", 10);
                transaction.Add("usage",usage);
                transactions.Add("0", transaction);

                transaction = new System.Collections.Hashtable();
                transaction.Add("app_id", app_id);
                transaction.Add("timestamp", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss K"));
                usage = new System.Collections.Hashtable();
                usage.Add("hits", 1);
                transaction.Add("usage", usage);
                transactions.Add("1", transaction);
                _3ScaleAPI.report(transactions);

                Console.WriteLine("Done report...");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            string s = Console.ReadLine();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            try
            {
                string provider_key = "YOUR_PROVIDER_KEY";

                // If needed, add your service_id
                //string service_id = "YOUR_SERVICE_ID";

                // Authorise using app_id (and app_key if necessary)
                string app_id = "YOUR_APP_ID";
                string app_key = "YOUR_APP_KEY";

                // Or alternatively you can authorise using user_key
                // string user_key = "YOUR_USER_KEY";

                Api _3ScaleAPI = new Api(provider_key);

                // Try authorize
                Hashtable parameters = new Hashtable();
                // Add service_id if needed
                //parameters.Add("service_id", service_id);

                // Add app_id (and app_key if necessary) to list of parameters to send
                parameters.Add("app_id", app_id);
                parameters.Add("app_key", app_key);

                // Alternatively, add user_key to list of parameters to send
                //parameters.Add("user_key", user_key);

                System.Collections.Hashtable usage = new Hashtable();
                usage.Add("hits", "1");
                parameters.Add("usage", usage);


                AuthorizeResponse resp = _3ScaleAPI.authorize(parameters);

                print(resp);
                Console.WriteLine("Done authorize...");

                // Try authrep

                AuthorizeResponse authRepResp = _3ScaleAPI.authrep(parameters);

                print(authRepResp);
                Console.WriteLine("Done authrep");

                // Try report
                System.Collections.Hashtable transactions = new System.Collections.Hashtable();
                System.Collections.Hashtable transaction = null;
                transaction = new System.Collections.Hashtable();
                transaction.Add("app_id", app_id);
                //transaction.Add("user_key", user_key);
                usage = new System.Collections.Hashtable();
                usage.Add("hits", 10);
                transaction.Add("usage", usage);
                transactions.Add("0", transaction);

                transaction = new System.Collections.Hashtable();
                transaction.Add("app_id", app_id);
                //transaction.Add("user_key", user_key);
                usage = new System.Collections.Hashtable();
                usage.Add("hits", 1);
                transaction.Add("usage", usage);
                transactions.Add("1", transaction);
                
                _3ScaleAPI.report(transactions);

                Console.WriteLine("Done report...");

                // Try oauth_authorize and report
                AuthorizeResponse oAuthResp = _3ScaleAPI.oauth_authorize(parameters);
                print(oAuthResp);

                if(oAuthResp.authorized)
                {
                    _3ScaleAPI.report(transactions);
                    Console.WriteLine("Done OAuth authorize and report");
                }
                else
                {
                    Console.WriteLine("OAuth authorize called, report not done as not authorized");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }