<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: api code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 24 Jul 2008 02:46:45 GMT</pubDate>
    <description>DZone Snippets: api code</description>
    <item>
      <title>Get a Jaiku personal_key given a username and password</title>
      <link>http://snippets.dzone.com/posts/show/5539</link>
      <description>Logs into Jaiku and then gets the personal_key for using the API.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;def GetJaikuPersonalKey(user, password):&lt;br /&gt;  """Finds the Jaiku API personal_key from a username and password.&lt;br /&gt;&lt;br /&gt;  One day I'll learn to use urllib2 properly and cookie parsing and stuff.&lt;br /&gt;  """&lt;br /&gt;&lt;br /&gt;  # login and find a cookie&lt;br /&gt;  login_url = "http://jaiku.com/login"&lt;br /&gt;  request_body = urllib.urlencode({'log': user,&lt;br /&gt;                                   'pwd': password,&lt;br /&gt;                                   'rememberme': '1'})&lt;br /&gt;  # Open a connection to the authentication server.&lt;br /&gt;  auth_connection = httplib.HTTPConnection('jaiku.com')&lt;br /&gt;  # Begin the POST request to the client login service.&lt;br /&gt;  auth_connection.putrequest('POST', '/login')&lt;br /&gt;  # Set the required headers for an Account Authentication request.&lt;br /&gt;  auth_connection.putheader('Content-type',&lt;br /&gt;                            'application/x-www-form-urlencoded')&lt;br /&gt;  auth_connection.putheader('Content-Length', str(len(request_body)))&lt;br /&gt;  auth_connection.endheaders()&lt;br /&gt;  auth_connection.send(request_body)&lt;br /&gt;  auth_response = auth_connection.getresponse()&lt;br /&gt;  if auth_response.status == 303:&lt;br /&gt;    cookie_str = auth_response.getheader("set-cookie")&lt;br /&gt;    # TODO(ark) parse this properly!&lt;br /&gt;    res = re.search("(jaikuuser_[^;]*).*(jaikupass_[^;]*)", cookie_str)&lt;br /&gt;    if res:&lt;br /&gt;      auth_cookie = "%s; %s" % (res.group(1), res.group(2))&lt;br /&gt;      apikey_url = "http://api.jaiku.com/key"&lt;br /&gt;      req = urllib2.Request(url=apikey_url)&lt;br /&gt;      req.add_header('Cookie', auth_cookie)&lt;br /&gt;      f = urllib2.urlopen(req)&lt;br /&gt;      return f.read()&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 25 May 2008 23:21:45 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5539</guid>
      <author>ark (ark)</author>
    </item>
    <item>
      <title>A simple XHTML submit form for ProjectX</title>
      <link>http://snippets.dzone.com/posts/show/5354</link>
      <description>Preparing ProjectX API requests through the browser's address bar  can get quite messy, however inputting the request through a simple form makes it much easier to read.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"&lt;br /&gt;  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;&lt;br /&gt;&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;&lt;br /&gt;  &lt;head&gt;&lt;br /&gt;    &lt;title&gt;ProjectX API&lt;/title&gt;&lt;br /&gt;    &lt;meta http-equiv="Content-Type" content="text/html;charset=utf-8"/&gt;&lt;br /&gt;  &lt;/head&gt;&lt;br /&gt;  &lt;body&gt;&lt;br /&gt;    &lt;h1&gt;ProjectX API form&lt;/h1&gt;&lt;br /&gt;    &lt;p&gt;Enter the Project API XML to send a request to the server.&lt;/p&gt;&lt;br /&gt;    &lt;form action="http://rorbuilder.info/api/projectx.cgi" method="post" id="projectx_form"&gt;&lt;br /&gt;    &lt;fieldset&gt;&lt;legend&gt;xml_project&lt;/legend&gt;&lt;textarea id="xml_project" name="xml_project" cols="104" rows="20"&gt;&lt;/textarea&gt;&lt;/fieldset&gt;&lt;br /&gt;    &lt;div&gt;&lt;button type="submit"&gt;Submit&lt;/button&gt;&lt;/div&gt;&lt;br /&gt;    &lt;/form&gt;&lt;br /&gt;  &lt;p&gt;&lt;br /&gt;    &lt;a href="http://validator.w3.org/check?uri=referer"&gt;&lt;img&lt;br /&gt;        src="http://www.w3.org/Icons/valid-xhtml10"&lt;br /&gt;        alt="Valid XHTML 1.0 Strict" height="31" width="88" style="float:right;  border:0 "/&gt;&lt;/a&gt;&lt;br /&gt;  &lt;/p&gt;&lt;br /&gt;  &lt;p style="clear:float"&gt;last updated: 13th April 2008&lt;/p&gt;&lt;br /&gt;  &lt;br /&gt;  &lt;/body&gt;&lt;br /&gt;&lt;/html&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;The web page can be seen at http://rorbuilder.info/r/projectx-api/index.html&lt;br /&gt;The following XML request value when submitted should return an XML result containing the results and the method executed.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;project name='whiteboardqueue'&gt;&lt;br /&gt;  &lt;methods&gt;&lt;br /&gt;    &lt;method name='get_user_id'&gt;&lt;br /&gt;      &lt;params/&gt;&lt;br /&gt;    &lt;/method&gt;&lt;br /&gt;  &lt;/methods&gt;&lt;br /&gt;&lt;/project&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;eg.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;result method="rtn_get_user_id"&gt;&lt;br /&gt;  &lt;get_user_id&gt;36539&lt;/get_user_id&gt;&lt;br /&gt;&lt;/result&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 13 Apr 2008 22:32:48 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5354</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Undo the last shape stored in the whiteboard message buffer</title>
      <link>http://snippets.dzone.com/posts/show/5335</link>
      <description>This ECMAScript implements an undo feature for the SVG whiteboard. When the user presses CTRL+Z the last shape in the message_buffer variable is removed.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;  function undoLast() {&lt;br /&gt;    ipos = getLastMethodPos(message_buffer,-1)&lt;br /&gt;    if (ipos &gt; 0)&lt;br /&gt;      message_buffer = message_buffer.substring(0, ipos)&lt;br /&gt;    else&lt;br /&gt;      message_buffer = ''    &lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  function getLastMethodPos(message, pos) {&lt;br /&gt;    i = message.indexOf('&lt;method', pos+1)&lt;br /&gt;    if (i &gt;= 0) &lt;br /&gt;      result = getLastMethodPos(message, i)&lt;br /&gt;    else&lt;br /&gt;      result = pos &lt;br /&gt;    return result;&lt;br /&gt;  }&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Here's an example of the messages (containing shapes) stored in the message_buffer&lt;br /&gt;&lt;code&gt;&lt;br /&gt;"&lt;method name='create'&gt;&lt;params&gt;&lt;param var='type'&gt;shape&lt;/param&gt;&lt;param var='body'&gt;&lt;br /&gt;polyline%20x%3D%27524%27%20y%3D%27198%27%20fill%3D%27none%27%20stroke%3D%27red%27%20id%3D&lt;br /&gt;%27348553%27%20stroke-width%3D%272%27%20points%3D%27524%2C198%20523%2C198%20522%2C198%20521%2C198%20&lt;br /&gt;513%2C198%20511%2C198%20503%2C198%20495%2C200%20493%2C200%20485%2C204%20483%2C205%20475%2C207%20474%&lt;br /&gt;2C208%20470%2C212%20466%2C216%20465%2C217%20464%2C219%20463%2C220%20463%2C222%20463%2C223%20463%2C22&lt;br /&gt;5%20463%2C226%20463%2C228%20464%2C230%20465%2C231%20466%2C233%20467%2C234%20471%2C238%20472%2C238%20&lt;br /&gt;478%2C242%20484%2C246%20485%2C247%20488%2C247%20489%2C248%20491%2C248%20493%2C249%20496%2C249%20497%&lt;br /&gt;2C249%20505%2C249%20515%2C249%20521%2C247%20531%2C245%20533%2C245%20539%2C243%20547%2C243%20548%2C24&lt;br /&gt;3%20550%2C242%20555%2C237%20556%2C237%20557%2C235%20558%2C234%20558%2C233%20559%2C231%20559%2C230%20&lt;br /&gt;560%2C228%20560%2C226%20560%2C222%20559%2C221%20559%2C220%20559%2C219%20559%2C217%20559%2C216%20558%&lt;br /&gt;2C215%20558%2C214%20556%2C208%20555%2C206%20555%2C205%20553%2C199%20549%2C191%20547%2C185%20546%2C18&lt;br /&gt;4%20544%2C176%20540%2C170%20539%2C168%20535%2C162%20534%2C161%20528%2C155%20528%2C154%20524%2C148%20&lt;br /&gt;518%2C144%20517%2C143%20511%2C139%20509%2C138%20501%2C134%20499%2C133%20491%2C129%20489%2C129%20479%&lt;br /&gt;2C129%20469%2C129%20467%2C129%20459%2C129%20457%2C129%20454%2C129%20452%2C129%20446%2C131%20438%2C13&lt;br /&gt;1%20437%2C132%20435%2C132%20435%2C133%20434%2C133%20434%2C134%20433%2C134%20433%2C135%27%23%3A&lt;br /&gt;&lt;/param&gt;&lt;param var='sender'&gt;34855&lt;/param&gt;&lt;/params&gt;&lt;/method&gt;&lt;method name='create'&gt;&lt;params&gt;&lt;param &lt;br /&gt;var='type'&gt;shape&lt;/param&gt;&lt;param var='body'&gt;polyline%20x%3D%27457%27%20y%3D%27175%27%20fill%3D%27none&lt;br /&gt;%27%20stroke%3D%27red%27%20id%3D&lt;br /&gt;%27348554%27%20stroke-width%3D%272%27%20points%3D%27457%2C175%20456%2C175%20455%2C176%20454%2C176%20&lt;br /&gt;453%2C177%20452%2C177%20451%2C177%20449%2C178%20448%2C179%20442%2C181%20440%2C183%20438%2C184%20438%&lt;br /&gt;2C185%20437%2C186%20436%2C187%20435%2C189%20435%2C191%20434%2C193%20434%2C194%20433%2C195%20433%2C19&lt;br /&gt;6%20431%2C200%20431%2C201%20431%2C203%20431%2C205%20431%2C206%20431%2C207%20431%2C208%20431%2C209%20&lt;br /&gt;431%2C210%20431%2C211%20431%2C212%20431%2C213%20431%2C214%20431%2C215%20431%2C216%20431%2C217%20432%&lt;br /&gt;2C223%20432%2C224%20432%2C225%20432%2C226%20433%2C226%20433%2C227%20433%2C228%20433%2C229%20434%2C22&lt;br /&gt;9%20434%2C230%20435%2C231%20435%2C233%20435%2C234%20436%2C235%20437%2C236%20437%2C237%20438%2C237%20&lt;br /&gt;438%2C238%20438%2C239%20438%2C240%20439%2C240%20439%2C241%20443%2C245%20444%2C246%20444%2C247%20445%&lt;br /&gt;2C247%20446%2C248%20447%2C248%20448%2C248%20448%2C249%20449%2C249%20450%2C250%20451%2C251%20452%2C25&lt;br /&gt;2%20454%2C253%20455%2C253%20461%2C255%20462%2C255%20464%2C256%20466%2C256%20467%2C257%20469%2C257%20&lt;br /&gt;469%2C258%20471%2C259%20472%2C259%20474%2C260%20475%2C260%20477%2C261%20478%2C261%20480%2C262%20481%&lt;br /&gt;2C262%20481%2C263%20482%2C263%20483%2C263%20484%2C263%20485%2C263%20486%2C263%20489%2C263%20491%2C26&lt;br /&gt;3%20492%2C263%20495%2C263%20496%2C263%20502%2C261%20504%2C261%20507%2C261%20509%2C261%20510%2C261%20&lt;br /&gt;511%2C261%20512%2C261%20513%2C261%20515%2C261%20517%2C261%20518%2C261%20520%2C260%20523%2C260%20524%&lt;br /&gt;2C260%20526%2C259%20528%2C259%20529%2C259%20534%2C258%20535%2C258%20536%2C257%20537%2C257%20538%2C25&lt;br /&gt;7%20540%2C257%27%23%3A&lt;/param&gt;&lt;param var='sender'&gt;34855&lt;/param&gt;&lt;/params&gt;&lt;/method&gt;"&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;In the above example there are 2 methods calls ready to be sent to the server, the 2nd method would be removed after the undoLast() function had executed.&lt;br /&gt;&lt;br /&gt;The methods are ready to be passed to the function getLatestMessages which passes the request through the ProjectX API, which then returns the results. &lt;br /&gt;&lt;br /&gt;This code only removes the shape before it's sent to the server, I still need to write the code to delete a shape which is in the server whiteboardqueue, and remove the shape element from the web browser display (SVG DOM).</description>
      <pubDate>Mon, 07 Apr 2008 23:42:40 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5335</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Instruct a shared whiteboard to save and refresh</title>
      <link>http://snippets.dzone.com/posts/show/5284</link>
      <description>The following code used with the ProjectX API informs the client web browser that the whiteboard will be refreshed in 5 seconds. It then archives the current whiteboard information, formats it, and sends a message to each web browser to refresh their view.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;project name="whiteboardqueue"&gt;&lt;br /&gt;  &lt;methods&gt;&lt;br /&gt;    &lt;method name="create"&gt;&lt;br /&gt;      &lt;params&gt;&lt;br /&gt;        &lt;param var="type"&gt;ecmascript&lt;/param&gt;&lt;br /&gt;        &lt;param var="body"&gt;startRefresh(5)&lt;/param&gt;&lt;br /&gt;        &lt;param var="sender"&gt;system&lt;/param&gt;&lt;br /&gt;      &lt;/params&gt;&lt;br /&gt;    &lt;/method&gt;&lt;br /&gt;    &lt;method name="timer"&gt;&lt;br /&gt;      &lt;params&gt;&lt;br /&gt;        &lt;param var="timer"&gt;5&lt;/param&gt;&lt;br /&gt;      &lt;/params&gt;&lt;br /&gt;    &lt;/method&gt;&lt;br /&gt;    &lt;method name="archive_and_format"&gt;&lt;br /&gt;      &lt;params/&gt;&lt;br /&gt;    &lt;/method&gt;&lt;br /&gt;    &lt;method name="create"&gt;&lt;br /&gt;      &lt;params&gt;&lt;br /&gt;        &lt;param var="type"&gt;ecmascript&lt;/param&gt;&lt;br /&gt;        &lt;param var="body"&gt;reloadDocument()&lt;/param&gt;&lt;br /&gt;        &lt;param var="sender"&gt;system&lt;/param&gt;&lt;br /&gt;      &lt;/params&gt;&lt;br /&gt;    &lt;/method&gt;&lt;br /&gt;  &lt;/methods&gt;&lt;br /&gt;&lt;/project&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;*update 1:14am*&lt;br /&gt;The &lt;a href="http://rorbuilder.info/r/whiteboardqueue/index2.svg"&gt;whiteboard demo&lt;/a&gt; [rorbuilder.info] allows the user to draw using the mouse within the web browser which renders SVG. Tested on Flock and Firefox.&lt;br /&gt;&lt;br /&gt;*update 4:42pm 28 Mar 08*&lt;br /&gt;You can also view the &lt;a href="http://rorbuilder.info/whiteboardqueue/whiteboardqueue_data.xml?passthru=1"&gt;whiteboard message queue&lt;/a&gt; [rorbuilder.info].&lt;br /&gt;&lt;br /&gt;*update 6:29pm Mar 08*&lt;br /&gt;I've created a short url (http://rubyurl.com/vxHD) (to demonstrate the cleaning of the whiteboard) which redirects to this http://rorbuilder.info/api/projectx.cgi?xml_project=&lt;project name="whiteboardqueue"&gt;&lt;methods&gt;&lt;method name="create"&gt;&lt;params&gt;&lt;param var="type"&gt;ecmascript&lt;/param&gt;&lt;param var="body"&gt;startRefresh(5)&lt;/param&gt;&lt;param var="sender"&gt;system&lt;/param&gt;&lt;/params&gt;&lt;/method&gt;&lt;method name="timer"&gt;&lt;params&gt;&lt;param var="timer"&gt;5&lt;/param&gt;&lt;/params&gt;&lt;/method&gt;&lt;method name="archive_and_format"&gt;&lt;params/&gt;&lt;/method&gt;&lt;method name="create"&gt;&lt;params&gt;&lt;param var="type"&gt;ecmascript&lt;/param&gt;&lt;param var="body"&gt;reloadDocument()&lt;/param&gt;&lt;param var="sender"&gt;system&lt;/param&gt;&lt;/params&gt;&lt;/method&gt;&lt;/methods&gt;&lt;/project&gt;&lt;br /&gt;&lt;br /&gt;I've </description>
      <pubDate>Thu, 27 Mar 2008 19:14:07 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5284</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Post to Jaiku using PHP</title>
      <link>http://snippets.dzone.com/posts/show/5259</link>
      <description>This example uses the ProjectX API to post to Jaiku.com&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;  $msg = 'this is just a test message using the ProjectX API for posting to Jaiku';&lt;br /&gt;&lt;br /&gt;  $xml_result =  simplexml_load_file('http://rorbuilder.info/api/projectx.cgi?xml_project=&lt;project name="jaiku"&gt;&lt;methods&gt;&lt;method name="post"&gt;&lt;params&gt;&lt;param var="user" val="jrobertson"/&gt;&lt;param var="msg" val="' . $msg . '"/&gt;&lt;param var="location" val="London"/&gt;&lt;param var="apikey" val="9ee6ffd165r364492"/&gt;&lt;/params&gt;&lt;/method&gt;&lt;/methods&gt;&lt;/project&gt;');&lt;br /&gt;  $method_result = $xml_result-&gt;post2jaiku;&lt;br /&gt;  echo 'result' . $method_result;&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Reference: &lt;a href="http://www.ibm.com/developerworks/library/x-simplexml.html"&gt;SimpleXML processing with PHP&lt;/a&gt; [ibm.com]</description>
      <pubDate>Wed, 19 Mar 2008 18:50:56 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5259</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Post to both Jaiku and Twitter</title>
      <link>http://snippets.dzone.com/posts/show/5247</link>
      <description>This XML code is the ProjectX API to post to both Twitter and Jaiku. This is a follow-up example from &lt;a href="http://snippets.dzone.com/posts/show/5239"&gt;Post to Jaiku using ProjectX API&lt;/a&gt; [dzone.com]&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;xml_project = &lt;&lt;PROJECT&lt;br /&gt;&lt;project name='micro_blog'&gt;&lt;br /&gt;  &lt;methods&gt;&lt;br /&gt;    &lt;method name='post2jaiku'&gt;&lt;br /&gt;      &lt;params&gt;&lt;br /&gt;        &lt;param var='user' val='YourJaikuUserName'/&gt;&lt;br /&gt;        &lt;param var='msg' val='YourMessage'/&gt;&lt;br /&gt;        &lt;param var='location' val='YourCity'/&gt;&lt;br /&gt;        &lt;param var='apikey' val='YourApiKey'/&gt;&lt;br /&gt;      &lt;/params&gt;&lt;br /&gt;    &lt;/method&gt;&lt;br /&gt;    &lt;method name='post2twitter'&gt;&lt;br /&gt;      &lt;params&gt;&lt;br /&gt;        &lt;param var='user' val='YourTwitterUserName'/&gt;&lt;br /&gt;        &lt;param var='msg' val='YourMessage'/&gt;&lt;br /&gt;        &lt;param var='password' val='YourPassword'/&gt;&lt;br /&gt;      &lt;/params&gt;&lt;br /&gt;    &lt;/method&gt;    &lt;br /&gt;  &lt;/methods&gt;&lt;br /&gt;&lt;/project&gt;"&lt;br /&gt;PROJECT&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 18 Mar 2008 15:36:06 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5247</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Post to Jaiku using ProjectX API</title>
      <link>http://snippets.dzone.com/posts/show/5239</link>
      <description>This Ruby code uses the ProjectX API on rorbuilder.info to send a post to Jaiku. &lt;br /&gt;&lt;br /&gt;Prerequisites:&lt;br /&gt;1) You have a Jaiku account. see http://jaiku.com/&lt;br /&gt;2) You know your Jaiku API key. see http://api.jaiku.com/&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/ruby&lt;br /&gt;# file: projectx_client.rb&lt;br /&gt;&lt;br /&gt;require 'net/http'&lt;br /&gt;require 'rexml/document'&lt;br /&gt;include REXML&lt;br /&gt;&lt;br /&gt;class ProjectXClient&lt;br /&gt;  attr :doc&lt;br /&gt;  def initialize(raw_url)&lt;br /&gt;    url = URI.escape(raw_url)&lt;br /&gt;    xml_data = Net::HTTP.get_response(URI.parse(url)).body&lt;br /&gt;    @doc = Document.new(xml_data)&lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;if __FILE__ == $0&lt;br /&gt;&lt;br /&gt;xml_project = &lt;&lt;PROJECT&lt;br /&gt;&lt;project name='jaiku'&gt;&lt;br /&gt;  &lt;methods&gt;&lt;br /&gt;    &lt;method name='post'&gt;&lt;br /&gt;      &lt;params&gt;&lt;br /&gt;        &lt;param var='user' val='YourJaikuUserName'/&gt;&lt;br /&gt;        &lt;param var='msg' val='YourMessage'/&gt;&lt;br /&gt;        &lt;param var='location' val='YourCity'/&gt;&lt;br /&gt;        &lt;param var='apikey' val='YourApiKey'/&gt;&lt;br /&gt;      &lt;/params&gt;&lt;br /&gt;    &lt;/method&gt;&lt;br /&gt;  &lt;/methods&gt;&lt;br /&gt;&lt;/project&gt;"&lt;br /&gt;PROJECT&lt;br /&gt;  &lt;br /&gt;  pxc = ProjectXClient.new("http://rorbuilder.info/api/projectx.cgi?xml_project=" + xml_project)&lt;br /&gt;  doc = pxc.doc&lt;br /&gt;  puts doc&lt;br /&gt;    &lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;You can also pass the url including xml into the address bar and it will post to Jaiku successfully.&lt;br /&gt;eg.&lt;br /&gt;http://rorbuilder.info/api/projectx.cgi?xml_project="&lt;project name='jaiku'&gt;&lt;methods&gt;&lt;method name='post'&gt;&lt;params&gt;&lt;param var='user' val='jrobertson'/&gt;&lt;param var='msg' val='testing 223'/&gt;&lt;param var='location' val='London'/&gt;&lt;param var='apikey' val='5ugr6ttr754y214445'/&gt;&lt;/params&gt;&lt;/method&gt;&lt;/methods&gt;&lt;/project&gt;"&lt;br /&gt;&lt;br /&gt;Note: &lt;br /&gt;Your api key is not in any way stored by the website rorbuilder.info.&lt;br /&gt;Rorbuilder.info is a 3rd party developer website which is not part of Jaiku.com.&lt;br /&gt;</description>
      <pubDate>Sun, 16 Mar 2008 21:33:51 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5239</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <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>tw.py</title>
      <link>http://snippets.dzone.com/posts/show/4150</link>
      <description>// Sets and views Twitter status&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/env python&lt;br /&gt;&lt;br /&gt;__author__="Andrew Pennebaker (andrew.pennebaker@gmail.com)"&lt;br /&gt;__date__="17 Jun 2007 - 28 Jun 2007"&lt;br /&gt;__copyright__="Copyright 2007 Andrew Pennebaker"&lt;br /&gt;__license__="GPL"&lt;br /&gt;__version__="0.0.1"&lt;br /&gt;__credits__="Based on tweetyPy (http://muffinresearch.co.uk/archives/2007/03/24/tweetypy-python-based-cli-client-for-twitter/)"&lt;br /&gt;__URL__="http://snippets.dzone.com/posts/show/4150"&lt;br /&gt;&lt;br /&gt;import sys, getopt, getpass, urllib, urllib2&lt;br /&gt;&lt;br /&gt;import configreader&lt;br /&gt;&lt;br /&gt;STATUS_MODE="STATUS"&lt;br /&gt;VIEW_MODE="VIEW"&lt;br /&gt;COMMAND_MODE="COMMAND"&lt;br /&gt;&lt;br /&gt;COMMANDS="""Command\t\tMeaning&lt;br /&gt;&lt;br /&gt;d username\tDirect Text&lt;br /&gt;@username\tReply&lt;br /&gt;follow username\tReceive updates via phone or IM&lt;br /&gt;leave username\tStop following username&lt;br /&gt;leave all\tStop following all friends&lt;br /&gt;remove username\tRemove username from friends list&lt;br /&gt;delete username\tDelete username from friends list&lt;br /&gt;get username\tGet the last update from username&lt;br /&gt;get\tGet the most recent updates from all friends&lt;br /&gt;nudge username\tTwitter aks what the person is currently up to&lt;br /&gt;whois username\tGet username's bio&lt;br /&gt;add phonenumber\tSend text invite. If already a member, invite will turn into a friend request.&lt;br /&gt;accept username\tAccept username as a friend&lt;br /&gt;deny username\tDeny username as friend"""&lt;br /&gt;&lt;br /&gt;def usage():&lt;br /&gt;	print "Usage: %s [options]" % (sys.argv[0])&lt;br /&gt;	print "\nWithout any options, uses status mode. Leftover args are concatenated to form message."&lt;br /&gt;	print "\n-u|--username &lt;username&gt; specified in tw.conf"&lt;br /&gt;	print "-s|--status mode"&lt;br /&gt;	print "-v|--view status"&lt;br /&gt;	print "-l|--list-commands List Twitter commands"&lt;br /&gt;	print "-c|--config &lt;configfile&gt;"&lt;br /&gt;	print "-h|--help"&lt;br /&gt;&lt;br /&gt;	sys.exit()&lt;br /&gt;&lt;br /&gt;def set_status(settings, status):&lt;br /&gt;	auth=urllib2.HTTPPasswordMgrWithDefaultRealm()&lt;br /&gt;	auth.add_password(None, settings["rootauthurl"], settings["username"], settings["password"])&lt;br /&gt;	authHandler=urllib2.HTTPBasicAuthHandler(auth)&lt;br /&gt;	opener=urllib2.build_opener(authHandler)&lt;br /&gt;&lt;br /&gt;	url="http://twitter.com/statuses/update.xml"&lt;br /&gt;	post=urllib.urlencode({"status":status})&lt;br /&gt;&lt;br /&gt;	request=urllib2.Request(url, post)&lt;br /&gt;	request.add_header("User-Agent", settings["useragent"])&lt;br /&gt;&lt;br /&gt;	try:&lt;br /&gt;		response=opener.open(request)&lt;br /&gt;	except IOError, e:&lt;br /&gt;		raise "Could not connect."&lt;br /&gt;&lt;br /&gt;def view_status(settings):&lt;br /&gt;	url="http://twitter.com/"+settings["username"]&lt;br /&gt;	message=""&lt;br /&gt;&lt;br /&gt;	statusdelimeter1=settings["statusdelimeter1"]&lt;br /&gt;	statusdelimeter2=settings["statusdelimeter2"]&lt;br /&gt;&lt;br /&gt;	try:&lt;br /&gt;		instream=urllib.urlopen(url)&lt;br /&gt;		for line in instream:&lt;br /&gt;			if statusdelimeter1 in line:&lt;br /&gt;				message=line[&lt;br /&gt;					line.index(statusdelimeter1)+len(statusdelimeter1):line.index(statusdelimeter2)&lt;br /&gt;				]&lt;br /&gt;				break&lt;br /&gt;		instream.close()&lt;br /&gt;&lt;br /&gt;		return message&lt;br /&gt;				&lt;br /&gt;	except IOError, e:&lt;br /&gt;		raise "Could not connect."&lt;br /&gt;&lt;br /&gt;def main():&lt;br /&gt;	global STATUS_MODE&lt;br /&gt;	global VIEW_MODE&lt;br /&gt;	global COMMAND_MODE&lt;br /&gt;	global COMMANDS&lt;br /&gt;&lt;br /&gt;	sysArgs=sys.argv[1:]&lt;br /&gt;&lt;br /&gt;	mode=STATUS_MODE&lt;br /&gt;&lt;br /&gt;	settings={&lt;br /&gt;		"config":"tw.conf",&lt;br /&gt;		"username":"mcandre",&lt;br /&gt;		"rootauthurl":"http://twitter.com/statuses/",&lt;br /&gt;		"useragent":sys.argv[0]+" "+__version__,&lt;br /&gt;		"statusdelimeter1":"&lt;p class=\"entry-title entry-content\"&gt;",&lt;br /&gt;		"statusdelimeter2":"&lt;/p&gt;"&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	optlist, args=[], []&lt;br /&gt;	try:&lt;br /&gt;		optlist, args=getopt.getopt(sysArgs, "u:svlc:h", ["username=", "status", "view", "list-commands", "config=", "help"])&lt;br /&gt;	except:&lt;br /&gt;		usage()&lt;br /&gt;&lt;br /&gt;	for option, value in optlist:&lt;br /&gt;		if option=="-c" or option=="--config":&lt;br /&gt;			settings["config"]=value&lt;br /&gt;&lt;br /&gt;	try:&lt;br /&gt;		configreader.load(open(settings["config"], "r"), settings)&lt;br /&gt;	except IOError, e:&lt;br /&gt;		pass&lt;br /&gt;&lt;br /&gt;	for option, value in optlist:&lt;br /&gt;		if option=="-h" or option=="--help":&lt;br /&gt;			usage()&lt;br /&gt;&lt;br /&gt;		elif option=="-u" or option=="--username":&lt;br /&gt;			settings["username"]=value&lt;br /&gt;		elif option=="-s" or option=="--status":&lt;br /&gt;			mode=STATUS_MODE&lt;br /&gt;		elif option=="-v" or option=="--view":&lt;br /&gt;			mode=VIEW_MODE&lt;br /&gt;		elif option=="-l" or option=="--list=commands":&lt;br /&gt;			mode=COMMAND_MODE&lt;br /&gt;&lt;br /&gt;	if mode==STATUS_MODE:&lt;br /&gt;		if len(args)&lt;1:&lt;br /&gt;			usage()&lt;br /&gt;&lt;br /&gt;		message=" ".join(args)&lt;br /&gt;&lt;br /&gt;		settings["password"]=getpass.getpass()&lt;br /&gt;&lt;br /&gt;		set_status(settings, message)&lt;br /&gt;	elif mode==VIEW_MODE:&lt;br /&gt;		print view_status(settings)&lt;br /&gt;	elif mode==COMMAND_MODE:&lt;br /&gt;		print COMMANDS&lt;br /&gt;&lt;br /&gt;if __name__=="__main__":&lt;br /&gt;	try:&lt;br /&gt;		main()&lt;br /&gt;	except KeyboardInterrupt, e:&lt;br /&gt;		pass&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 17 Jun 2007 07:07:43 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4150</guid>
      <author>mcandre (Andrew Pennebaker)</author>
    </item>
    <item>
      <title>Quick Flickr search in Ruby</title>
      <link>http://snippets.dzone.com/posts/show/3493</link>
      <description>// Examples for the three listed APIs weren't working. Instead of choosing one and debugging it, I chose to do something quick and dirty. "MY_API_KEY" and other params would need to be removed to make this more generic. A naive mapping of API method calls that take hashes, and returns an OpenStruct is an approach I'm considering, as it would likely break less often and require less code.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'net/http'&lt;br /&gt;require 'rexml/document'&lt;br /&gt;require 'ostruct'&lt;br /&gt;&lt;br /&gt;class Flickr &lt; OpenStruct&lt;br /&gt;  include REXML&lt;br /&gt;&lt;br /&gt;  def Flickr.search(text)&lt;br /&gt;    doc = Document.new(&lt;br /&gt;            Net::HTTP.get(&lt;br /&gt;              URI.parse('http://api.flickr.com/services/rest/?method=flickr.photos.search&amp;api_key=MY_API_KEY' +&lt;br /&gt;                        '&amp;extras=license,owner_name,original_format&amp;license=4,5&amp;per_page=20&amp;sort=interestingness-desc' +&lt;br /&gt;                        '&amp;text=' + text)))&lt;br /&gt;     throw "flickr error" unless doc.root.attributes['stat'] == "ok"&lt;br /&gt;     doc.root.elements['photos'].get_elements('//photo').collect {|photo| photo &lt;&lt; Flickr.new(photo) }&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;  def initialize(e)&lt;br /&gt;    super(e.attributes)&lt;br /&gt;    self.new_ostruct_member("photo_id")&lt;br /&gt;    self.photo_id = e.attributes['id']&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;  def to_url(image_type="s")&lt;br /&gt;    "http://farm#{farm}.static.flickr.com/#{server}/#{photo_id}_#{secret}_#{image_type}.jpg"&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 11 Feb 2007 20:50:32 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3493</guid>
      <author>chebuctonian (Daniel Haran)</author>
    </item>
  </channel>
</rss>
