Inheritance: IApi
コード例 #1
0
        //user_key=3scale-9f58660be36c0add4d52198c7c9ecb6e&provider_key=3scale-5fc9d398ac038e4e8f212cc1e8cf01d2
        static void Main(string[] args)
        {
        Api _3ScaleAPI = new Api("http://server.3scale.net", "3scale-5fc9d398ac038e4e8f212cc1e8cf01d2");

       

        Console.WriteLine("====>Test 1:Success<======");

        string resp = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><status><plan>Demo</plan><usage period=\"day\" metric=\"hits\"><period_start>2010-08-01 22:00:00</period_start><period_end>2010-08-02 21:59:59</period_end><current_value>0</current_value><max_value>10000</max_value></usage><usage period=\"hour\" metric=\"demoapiupload\"><period_start>2010-08-02 09:00:00</period_start><period_end>2010-08-02 09:59:59</period_end><current_value>0</current_value><max_value>1000</max_value></usage><usage period=\"hour\" metric=\"demoapiretrieve\"><period_start>2010-08-02 09:00:00</period_start><period_end>2010-08-02 09:59:59</period_end><current_value>0</current_value><max_value>1000</max_value></usage><usage period=\"hour\" metric=\"demoapisearch\"><period_start>2010-08-02 09:00:00</period_start><period_end>2010-08-02 09:59:59</period_end><current_value>0</current_value><max_value>2000</max_value></usage><usage period=\"day\" metric=\"demoapisearch\"><period_start>2010-08-01 22:00:00</period_start><period_end>2010-08-02 21:59:59</period_end><current_value>0</current_value><max_value>5000</max_value></usage></status>";

        AuthorizeResponse auth_response = new AuthorizeResponse(Encoding.UTF8.GetString(resp));
            
        }
コード例 #2
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();
        }
コード例 #3
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);
            }
        }