예제 #1
0
파일: Client.cs 프로젝트: jnus/nPlivo
        private IRestResponse<T> _request<T>(string http_method, string resource, Dictionary<string,string> data)
         where T : new()
        {
            var request = new RestRequest() { Resource = resource, RequestFormat = DataFormat.Json };

            // add the parameters to the request
            foreach (KeyValuePair<string, string> kvp in data)
                request.AddParameter(kvp.Key, HtmlEntity.Convert(kvp.Value));

            //set the HTTP method for this request
            switch (http_method.ToUpper())
            {
                case "GET": request.Method = Method.GET;
                    break;
                case "POST": request.Method = Method.POST;
                    request.Parameters.Clear();
                    request.AddParameter("application/json", request.JsonSerializer.Serialize(data), ParameterType.RequestBody);
                    break;
                case "DELETE": request.Method = Method.DELETE;
                    break;
                default: request.Method = Method.GET;
                    break;
            };
            restClient.AddHandler("application/json", new JsonDeserializer());
            IRestResponse<T> response = restClient.Execute<T>(request);
            return response;
        }
예제 #2
0
        private IRestResponse <T> _request <T>(string http_method, string resource, dict data)
            where T : new()
        {
            var request = new RestRequest()
            {
                Resource = resource, RequestFormat = DataFormat.Json
            };

            // add the parameters to the request
            foreach (KeyValuePair <string, string> kvp in data)
            {
                request.AddParameter(kvp.Key, HtmlEntity.Convert(kvp.Value), ParameterType.QueryString);
            }

            //set the HTTP method for this request
            switch (http_method.ToUpper())
            {
            case "GET": request.Method = Method.GET;
                break;

            case "POST": request.Method = Method.POST;
                request.Parameters.Clear();
                request.AddParameter("application/json", request.JsonSerializer.Serialize(data), ParameterType.RequestBody);
                break;

            case "DELETE": request.Method = Method.DELETE;
                break;

            default: request.Method = Method.GET;
                break;
            }

            IRestResponse <T> test = new RestResponse <T>();

            client.ExecuteAsync <T>(request, response =>
            {
                test = response.Data as IRestResponse <T>;
            });

            return(test);
        }
예제 #3
0
 public PlivoElement(string body)
 {
     Element = new XElement(GetType().Name, HtmlEntity.Convert(body));
 }
예제 #4
0
 public PlivoElement(string body, dict attributes)
 {
     Element    = new XElement(GetType().Name, HtmlEntity.Convert(body));
     Attributes = attributes;
 }