<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: xmlrpc code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 27 Jul 2008 08:12:57 GMT</pubDate>
    <description>DZone Snippets: xmlrpc code</description>
    <item>
      <title>MetaWeblog API in PHP</title>
      <link>http://snippets.dzone.com/posts/show/4816</link>
      <description>Implementation of the MetaWeblog API http://www.xmlrpc.com/metaWeblogApi in PHP.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;/**&lt;br /&gt; * Skeleton file for MetaWeblog API http://www.xmlrpc.com/metaWeblogApi in PHP&lt;br /&gt; * Requires Keith Deven's XML-RPC Library http://keithdevens.com/software/xmlrpc and store it as xmlrpc.php in the same folder&lt;br /&gt; * Written by Daniel Lorch, based heavily on Keith Deven's examples on the Blogger API.&lt;br /&gt; */&lt;br /&gt;&lt;br /&gt;require_once dirname(__FILE__) . '/xmlrpc.php';&lt;br /&gt;&lt;br /&gt;function metaWeblog_newPost($params) {&lt;br /&gt;  list($blogid, $username, $password, $struct, $publish) = $params;&lt;br /&gt;  $title = $struct['title'];&lt;br /&gt;  $description = $struct['description'];&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  // YOUR CODE:&lt;br /&gt;  $post_id = 0; // id of the post you just created&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  XMLRPC_response(XMLRPC_prepare((string)$post_id), WEBLOG_XMLRPC_USERAGENT);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function metaWeblog_editPost($params) {&lt;br /&gt;  list($postid, $username, $password, $struct, $publish) = $params;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  // YOUR CODE:&lt;br /&gt;  $result = false; // whether or not the action succeeded&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  XMLRPC_response(XMLRPC_prepare((boolean)$result), WEBLOG_XMLRPC_USERAGENT);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function metaWeblog_getPost($params) {&lt;br /&gt;  list($postid, $username, $password) = $params;&lt;br /&gt;  $post = array();&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  // YOUR CODE:&lt;br /&gt;  $post['userId'] = '1';&lt;br /&gt;  $post['dateCreated'] = XMLRPC_convert_timestamp_to_iso8601(time());&lt;br /&gt;  $post['title'] = 'Replace me';&lt;br /&gt;  $post['content'] = 'Replace me, too';&lt;br /&gt;  $post['postid'] = '1';&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  XMLRPC_response(XMLRPC_prepare($post), WEBLOG_XMLRPC_USERAGENT);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function XMLRPC_method_not_found($methodName) {&lt;br /&gt;  XMLRPC_error("2", "The method you requested, '$methodName', was not found.", WEBLOG_XMLRPC_USERAGENT);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;$xmlrpc_methods = array(&lt;br /&gt;  'metaWeblog.newPost'  =&gt; 'metaWeblog_newPost',&lt;br /&gt;  'metaWeblog.editPost' =&gt; 'metaWeblog_editPost',&lt;br /&gt;  'metaWeblog.getPost'  =&gt; 'metaWeblog_getPost'&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;$xmlrpc_request = XMLRPC_parse($HTTP_RAW_POST_DATA);&lt;br /&gt;$methodName = XMLRPC_getMethodName($xmlrpc_request);&lt;br /&gt;$params = XMLRPC_getParams($xmlrpc_request);&lt;br /&gt;&lt;br /&gt;if(!isset($xmlrpc_methods[$methodName])) {&lt;br /&gt;  XMLRPC_method_not_found($methodName);&lt;br /&gt;} else {&lt;br /&gt;  $xmlrpc_methods[$methodName]($params);&lt;br /&gt;}&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 25 Nov 2007 18:34:43 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4816</guid>
      <author>danielsanII (Daniel Lorch)</author>
    </item>
    <item>
      <title>Simple XML-RPC in Ruby</title>
      <link>http://snippets.dzone.com/posts/show/2597</link>
      <description>Example lifted from the standard library docs. Illustrative!&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!c:\ruby\bin\ruby.exe&lt;br /&gt;require 'xmlrpc/client'&lt;br /&gt;require 'pp'&lt;br /&gt;&lt;br /&gt;server = XMLRPC::Client.new2("http://rpc.technorati.com/rpc/ping")&lt;br /&gt;result = server.call("weblogUpdates.ping", "Copenhagen.rb", "http://www.copenhagenrb.dk/")&lt;br /&gt;pp result&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 15 Sep 2006 18:34:07 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2597</guid>
      <author>olleolleolle (Olle Jonsson)</author>
    </item>
    <item>
      <title>Simple XML-RPC in PHP (using cURL)</title>
      <link>http://snippets.dzone.com/posts/show/2596</link>
      <description>Ping Technorati using cURL and XMLRPC extensions.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;# Using the XML-RPC extension to format the XML package&lt;br /&gt;$request = xmlrpc_encode_request("weblogUpdates.ping", array("Copenhagen Ruby Brigade", "http://copenhagenrb.dk/") );&lt;br /&gt;&lt;br /&gt;# Using the cURL extension to send it off, &lt;br /&gt;# first creating a custom header block&lt;br /&gt;$header[] = "Host: rpc.technorati.com";&lt;br /&gt;$header[] = "Content-type: text/xml";&lt;br /&gt;$header[] = "Content-length: ".strlen($request) . "\r\n";&lt;br /&gt;$header[] = $request;&lt;br /&gt;&lt;br /&gt;$ch = curl_init();&lt;br /&gt;curl_setopt( $ch, CURLOPT_URL, "http://rpc.technorati.com/rpc/ping"); # URL to post to&lt;br /&gt;curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); # return into a variable&lt;br /&gt;curl_setopt( $ch, CURLOPT_HTTPHEADER, $header ); # custom headers, see above&lt;br /&gt;curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'POST' ); # This POST is special, and uses its specified Content-type&lt;br /&gt;$result = curl_exec( $ch ); # run!&lt;br /&gt;curl_close($ch); &lt;br /&gt;&lt;br /&gt;echo $result;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 15 Sep 2006 18:32:54 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2596</guid>
      <author>olleolleolle (Olle Jonsson)</author>
    </item>
    <item>
      <title>simple xmlrpc with python</title>
      <link>http://snippets.dzone.com/posts/show/643</link>
      <description>code for the client :&lt;br /&gt;&lt;code&gt;&lt;br /&gt;from xmlrpclib import ServerProxy&lt;br /&gt;&lt;br /&gt;print ServerProxy("http://127.0.0.1:9955").get_file()&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;code for the server :&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import SimpleXMLRPCServer&lt;br /&gt;&lt;br /&gt;def get_file():&lt;br /&gt;    return "content"&lt;br /&gt;&lt;br /&gt;server = SimpleXMLRPCServer.SimpleXMLRPCServer(("127.0.0.1", 9955))&lt;br /&gt;server.register_function(get_file)&lt;br /&gt;server.serve_forever()&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;</description>
      <pubDate>Wed, 07 Sep 2005 20:48:09 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/643</guid>
      <author>manatlan (manatlan)</author>
    </item>
  </channel>
</rss>
