Пример #1
0
        public Dictionary <string, string> save()
        {
            string     uri        = CallCenter.GetAPIurl();
            string     parameters = ConvertToForm(Parameters);
            WebRequest request    = WebRequest.Create(uri);

            request.ContentType = "application/x-www-form-urlencoded";
            request.Method      = "POST";
            request.Credentials = new NetworkCredential(CallCenter.APIUsername, CallCenter.APIPassword);
            byte[] bytes = Encoding.UTF8.GetBytes(parameters);
            request.ContentLength = bytes.Length;
            using (Stream os = request.GetRequestStream())
            {
                os.Write(bytes, 0, bytes.Length);
            }
            HttpWebResponse response = null;

            try
            {
                try
                {
                    response = (HttpWebResponse)request.GetResponse();
                }
                catch (WebException ex)
                {
                    response = (HttpWebResponse)ex.Response;
                }
                using (Stream os = response.GetResponseStream())
                {
                    using (StreamReader reader = new StreamReader(os))
                    {
                        HttpStatusCode code = response.StatusCode;
                        string         body = reader.ReadToEnd();

                        Dictionary <string, string> result = new Dictionary <string, string>();
                        result.Add("status_code", code.ToString());
                        result.Add("response_body", body);
                        return(result);
                    }
                }
            }
            finally
            {
                if (response != null)
                {
                    response.Close();
                }
            }
        }
Пример #2
0
        static void Main()
        {
            Dictionary <string, string> dict = new Dictionary <string, string>();

            dict.Add("CallCenterID", "1");
            dict.Add("APIVersion", "2010-04-22");
            dict.Add("APIUsername", "*****@*****.**");
            dict.Add("APIPassword", "firefox");
            CallCenter.config(dict);

            // create a list of parameters
            List <Dictionary <string, object> > parameters = new List <Dictionary <string, object> >();

            Dictionary <string, object> c1params = new Dictionary <string, object>();

            c1params.Add("start_time_t", 1339289018);
            c1params.Add("call_center_call_id", 91234567);
            c1params.Add("duration_in_seconds", 200);
            c1params.Add("reason_code", "Terms&Conditions");
            c1params.Add("sale_currency", "USD");
            c1params.Add("sale_amount", 1.01);
            parameters.Add(c1params);

            String[] a = { "DVD", "cleaner" };
            String[] b = { "2", "1" };

            Dictionary <string, object> c2params = new Dictionary <string, object>();

            c2params.Add("start_time_t", 1339721018);
            c2params.Add("call_center_call_id", 91234568);
            c2params.Add("duration_in_seconds", 200);
            c2params.Add("reason_code", "S");
            c2params.Add("sale_currency", "USD");
            c2params.Add("sale_amount", 1.12);
            c2params.Add("email_address", "*****@*****.**");
            c2params.Add("sku_list", a);
            c2params.Add("quantity_list", b);
            parameters.Add(c2params);

            Dictionary <string, object> c3params = new Dictionary <string, object>();

            c3params.Add("start_time_t", 1340153017);
            c3params.Add("call_center_call_id", 91234569);
            c3params.Add("duration_in_seconds", 200);
            c3params.Add("reason_code", "S");
            c3params.Add("sale_currency", "USD");
            c3params.Add("sale_amount", 2.02);
            c3params.Add("called_phone_number", "+1 8888665440");
            c3params.Add("calling_phone_number", "+1 8056801218");
            parameters.Add(c3params);

            foreach (var options in parameters)
            {
                try
                {
                    Call call = new Call(options);
                    Dictionary <string, string> response = call.save();
                    Console.WriteLine("status_code: {0}\nresponse_body: {1}", response["status_code"], response["response_body"]);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Alternative exception caught.");
                    Console.WriteLine(e.Message);
                }
            }
            Thread.Sleep(15000);
        }