Exemple #1
0
        public UploadFileResponse SendUploadFileRequest(UploadFileRequest request)
        {
            UploadFileResponse response = new UploadFileResponse();

            var rpcClient  = new XmlRpcRestClient(config.RequestUrl);
            var rpcRequest = new XmlRpcRestRequest(request.RequestUrl)
            {
                Method = Method.POST
            };

            // Add request parameters
            //rpcRequest.XmlSerializer = new XmlRpcSerializer("",false);
            rpcRequest.AddXmlRpcBody(config.BlogID, config.Username, config.Password, request.FileRequestStruct, "true", "false");

            try
            {
                // Get response
                var rpcResponse = rpcClient.Execute <RpcResponseValue <string> >(rpcRequest);

                // Find and fill members in
                XmlMemberSearcher searcher = new XmlMemberSearcher(rpcResponse.Content);
                response.FileResponseStruct.Id       = Convert.ToInt32(searcher.GetValueOfMember("id"));
                response.FileResponseStruct.Url      = searcher.GetValueOfMember("url");
                response.FileResponseStruct.File     = searcher.GetValueOfMember("file");
                response.FileResponseStruct.FileType = searcher.GetValueOfMember("type");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(null);
            }

            return(response);
        }
Exemple #2
0
        public DeletePostResponse SendDeletePostRequest(DeletePostRequest request)
        {
            DeletePostResponse response = new DeletePostResponse();

            var rpcClient  = new XmlRpcRestClient(config.RequestUrl);
            var rpcRequest = new XmlRpcRestRequest(request.RequestUrl)
            {
                Method = Method.POST
            };

            // Add request parameters
            rpcRequest.AddXmlRpcBody(config.BlogID, config.Username, config.Password, request.PostId);

            try
            {
                // Get response
                var rpcResponse = rpcClient.Execute <RpcResponseValue <string> >(rpcRequest);

                // Find and fill members in
                response.Success = rpcResponse.Data.Value != "false";
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(null);
            }

            return(response);
        }
Exemple #3
0
        public GetMediaItemResponse SendMediaItemRequest(GetMediaItemRequest request)
        {
            GetMediaItemResponse response = new GetMediaItemResponse();

            var rpcClient  = new XmlRpcRestClient(config.RequestUrl);
            var rpcRequest = new XmlRpcRestRequest(request.RequestUrl)
            {
                Method = Method.POST
            };

            // Add request parameters
            rpcRequest.AddXmlRpcBody(config.BlogID, config.Username, config.Password, request.Id);

            try
            {
                // Get response
                var rpcResponse = rpcClient.Execute <RpcResponseValue <string> >(rpcRequest);

                // Find and fill members in
                XmlMemberSearcher searcher = new XmlMemberSearcher(rpcResponse.Content);
                response.Link = searcher.GetValueOfMember("link");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(null);
            }

            return(response);
        }
Exemple #4
0
            public void WordPressHelloWorld()
            {
                var rpcClient = new XmlRpcRestClient("https://wordpress.com/xmlrpc.php");

                var sayHelloRequest = new XmlRpcRestRequest("demo.sayHello");

                sayHelloRequest.AddXmlRpcBody();
                var helloResponse = rpcClient.Execute <RpcResponseValue <string> >(sayHelloRequest);

                Assert.AreEqual("Hello!", helloResponse.Data.Value);
            }
Exemple #5
0
            public void WordPressFault()
            {
                var rpcClient = new XmlRpcRestClient("https://wordpress.com/xmlrpc.php");

                var faultRequest = new XmlRpcRestRequest("demo.fault ");

                faultRequest.AddXmlRpcBody( );

                var response = rpcClient.Execute <RpcResponseValue <string> >(faultRequest);

                Assert.IsInstanceOf(typeof(XmlRpcFaultException), response.ErrorException);
                Assert.AreEqual(-32601, (( XmlRpcFaultException )response.ErrorException).FaultCode);
            }
Exemple #6
0
            public void WordPressAddTwoNumbers()
            {
                var rpcClient = new XmlRpcRestClient("https://wordpress.com/xmlrpc.php");

                var addTwoNumbersRequest = new XmlRpcRestRequest("demo.addTwoNumbers ");

                addTwoNumbersRequest.AddXmlRpcBody(100, 88);
                var addTwoNumbersResponse = rpcClient.Execute <RpcResponseValue <int> >(addTwoNumbersRequest);

                var sum = addTwoNumbersResponse.Data.Value;

                Assert.AreEqual(188, addTwoNumbersResponse.Data.Value);
            }
Exemple #7
0
        public GetProfileResponse SendGetProfileRequest(GetProfileRequest request)
        {
            GetProfileResponse response = new GetProfileResponse();

            var rpcClient  = new XmlRpcRestClient(config.RequestUrl);
            var rpcRequest = new XmlRpcRestRequest(request.RequestUrl)
            {
                Method = Method.POST
            };

            // Add request parameters
            rpcRequest.AddXmlRpcBody(config.BlogID, config.Username, config.Password);

            try
            {
                // Get response
                var rpcResponse = rpcClient.Execute <RpcResponseValue <string> >(rpcRequest);

                Console.WriteLine("RESPONSE:");
                Console.WriteLine(rpcResponse.Content);

                // Find and fill members in
                XmlMemberSearcher searcher = new XmlMemberSearcher(rpcResponse.Content);
                response.Bio         = searcher.GetValueOfMember("bio");
                response.DisplayName = searcher.GetValueOfMember("display_name");
                response.Email       = searcher.GetValueOfMember("email");
                response.FirstName   = searcher.GetValueOfMember("first_name");
                response.LastName    = searcher.GetValueOfMember("last_name");
                response.NiceName    = searcher.GetValueOfMember("nicename");
                response.Nickname    = searcher.GetValueOfMember("nickname");
                response.Url         = searcher.GetValueOfMember("url");
                response.UserId      = searcher.GetValueOfMember("user_id");
                response.Username    = searcher.GetValueOfMember("username");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(null);
            }

            return(response);
        }