<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Yak Shavings</title>
	<atom:link href="http://webm0nk3y.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://webm0nk3y.wordpress.com</link>
	<description>What&#039;s left when I have some spare time</description>
	<lastBuildDate>Wed, 07 Dec 2011 17:30:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='webm0nk3y.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Yak Shavings</title>
		<link>http://webm0nk3y.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://webm0nk3y.wordpress.com/osd.xml" title="Yak Shavings" />
	<atom:link rel='hub' href='http://webm0nk3y.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Introducing Magic Uploads via Ubuntu One Rest API.</title>
		<link>http://webm0nk3y.wordpress.com/2011/12/02/introducing-magic-uploads-via-ubuntu-one-rest-api/</link>
		<comments>http://webm0nk3y.wordpress.com/2011/12/02/introducing-magic-uploads-via-ubuntu-one-rest-api/#comments</comments>
		<pubDate>Fri, 02 Dec 2011 04:52:52 +0000</pubDate>
		<dc:creator>webm0nk3y</dc:creator>
				<category><![CDATA[ubuntu one]]></category>

		<guid isPermaLink="false">http://webm0nk3y.wordpress.com/?p=25</guid>
		<description><![CDATA[One of the features recently introduced in Ubuntu One and hidden beneath the covers is what we refer to as Magic Uploads. Recently this feature was also enabled in the REST API so I would like to demonstrate how this works. But first What is a MAGIC Upload? a magic upload is the ability to save time [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webm0nk3y.wordpress.com&#038;blog=23286462&#038;post=25&#038;subd=webm0nk3y&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>One of the features recently introduced in Ubuntu One and hidden beneath the covers is what we refer to as Magic Uploads. Recently this feature was also enabled in the REST API so I would like to demonstrate how this works.</p>
<p>But first <strong>What is a MAGIC Upload?</strong> a magic upload is the ability to save time when uploading a file you have uploaded in the past. This is done by including the hash of the file in the upload, if Ubuntu One detects you have previously uploaded that hash, it will not require an upload and just create the file. Magic hashing is an additional way to do this for files uploaded to Ubuntu One by anyone. This is done by including the hash of the file along with a magic hash which is calculated on the hash of the file. This may sound sophisticated, but it&#8217;s not, here&#8217;s a function that returns the hash of the file along with the so-called magic hash:</p>
<blockquote>
<pre>def get_u1_hashes(filename):
    """Calculate the file hashes used to update a file."""
    hash_object = sha1()
    magic_hash_object = sha1('Ubuntu One')
    with open(filename, 'rb') as f:
    content = f.read()
    hash_object.update(content)
    magic_hash_object.update(content)
    hash = 'sha1:' + hash_object.hexdigest()
    magic_hash = 'magic_hash:' + magic_hash_object.hexdigest()
    return hash, magic_hash</pre>
</blockquote>
<p>As you can see, there&#8217;s no real magic. But in order to calculate the hash, you will need the content of the file. Note this is no trade secret I&#8217;m revealing here, it&#8217;s right there in the source for the Ubuntu One Storage Protocol used by the client. So how can you use this in the REST API?</p>
<p>Recently hash and magic_hash parameters were added to the PUT file API although as of this writing they are not documented in the <a title="public documentation" href="https://one.ubuntu.com/developer/files/store_files/cloud/#put_apifile_storagev1pathtovolumepathtonode" target="_blank">public documentation</a>. Note that this is different than the Content URI to put file content and upload a file. Here&#8217;s how the documentation should eventually include:</p>
<blockquote>
<h2 id="put_apifile_storagev1pathtovolumepathtonode">PUT /api/file_storage/v1/~/path/to/volume/path/to/node</h2>
<p>Create, or change a file with existing content that was already uploaded.</p>
<pre> {
    "kind": "file",
    "hash": "&lt;sha1 hash of file&gt;",
    "magic_hash": "&lt;magic hash&gt;", 
 }</pre>
</blockquote>
<p>And that&#8217;s it. Note that this feature has already been added to my <a title="Restful Ubuntu One Client" href="https://launchpad.net/restful-u1" target="_blank">Restful Ubuntu One client</a>. So how can you take advantage of this? See my next post.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/webm0nk3y.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/webm0nk3y.wordpress.com/25/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webm0nk3y.wordpress.com&#038;blog=23286462&#038;post=25&#038;subd=webm0nk3y&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://webm0nk3y.wordpress.com/2011/12/02/introducing-magic-uploads-via-ubuntu-one-rest-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/743e679d94c6301d66f79ebbc8b057af?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">webm0nk3y</media:title>
		</media:content>
	</item>
		<item>
		<title>Upload a directory using restful-u1 library</title>
		<link>http://webm0nk3y.wordpress.com/2011/05/31/upload-a-directory-using-restful-u1-library/</link>
		<comments>http://webm0nk3y.wordpress.com/2011/05/31/upload-a-directory-using-restful-u1-library/#comments</comments>
		<pubDate>Tue, 31 May 2011 21:36:48 +0000</pubDate>
		<dc:creator>webm0nk3y</dc:creator>
				<category><![CDATA[ubuntu one]]></category>

		<guid isPermaLink="false">http://webm0nk3y.wordpress.com/?p=22</guid>
		<description><![CDATA[Ever wonder how to upload an entire directory tree and files to Ubuntu One? Here&#8217;s 7 lines that will do it: import os from u1rest import get_files_user user = get_files_user() for p, d, files in os.walk('/home/john/Pictures'): for n in files: path = os.path.join(p,n) user.upload_file(path, '~/Ubuntu One' + path)<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webm0nk3y.wordpress.com&#038;blog=23286462&#038;post=22&#038;subd=webm0nk3y&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Ever wonder how to upload an entire directory tree and files to Ubuntu One? Here&#8217;s 7 lines that will do it:</p>
<blockquote>
<pre>import os
from u1rest import get_files_user
user = get_files_user()
for p, d, files in os.walk('/home/john/Pictures'):
    for n in files:
        path = os.path.join(p,n)
        user.upload_file(path, '~/Ubuntu One' + path)</pre>
</blockquote>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/webm0nk3y.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/webm0nk3y.wordpress.com/22/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webm0nk3y.wordpress.com&#038;blog=23286462&#038;post=22&#038;subd=webm0nk3y&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://webm0nk3y.wordpress.com/2011/05/31/upload-a-directory-using-restful-u1-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/743e679d94c6301d66f79ebbc8b057af?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">webm0nk3y</media:title>
		</media:content>
	</item>
		<item>
		<title>Using the restful-u1 library with Ubuntu One</title>
		<link>http://webm0nk3y.wordpress.com/2011/05/19/using-the-restful-u1-library-with-ubuntu-one/</link>
		<comments>http://webm0nk3y.wordpress.com/2011/05/19/using-the-restful-u1-library-with-ubuntu-one/#comments</comments>
		<pubDate>Thu, 19 May 2011 23:11:58 +0000</pubDate>
		<dc:creator>webm0nk3y</dc:creator>
				<category><![CDATA[ubuntu one]]></category>

		<guid isPermaLink="false">http://webm0nk3y.wordpress.com/?p=14</guid>
		<description><![CDATA[This post will demonstrate how the restful-u1 library wraps all of the details of making the REST API calls into a simple-to-use interface. Please read my previous post about how to get the restful-u1 python library. I&#8217;m going to use an ipython console to demonstrate: In [1]: from u1rest import get_files_user In [2]: user = [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webm0nk3y.wordpress.com&#038;blog=23286462&#038;post=14&#038;subd=webm0nk3y&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>This post will demonstrate how the restful-u1 library wraps all of the details of making the REST API calls into a simple-to-use interface. Please read my <a title="A python library for Ubuntu One’s REST API." href="http://webm0nk3y.wordpress.com/2011/05/19/a-python-library-for-ubuntu-ones-rest-api/">previous pos</a>t about how to get the restful-u1 python library.</p>
<p>I&#8217;m going to use an ipython console to demonstrate:</p>
<blockquote>
<pre>In [1]: from u1rest import get_files_user
In [2]: user = get_files_user(use_file_keystore=True)</pre>
</blockquote>
<p style="padding-left:30px;"><em>Note that I am using the flag use_file_keystore=True in get_files_user to use the file created earlier when we authorize the code to access our Ubuntu One account. If I didn&#8217;t use this flag, it would default to use an OAuth token from your keyring.</em></p>
<p>The primary way to us the u1rest library is to get a user and then make all the calls using this object. The User object is itself a resource (in Restful terms) and has attributes. Most of them are obvious, but I want to focus on 2 of them for now.</p>
<blockquote>
<pre>In [3]: user.root_node_path
Out[3]: u'/~/Ubuntu One'

In [4]: user.user_node_paths
Out[4]: [u'/~/SyncMusic/Music', u'/~/.ubuntuone/Purchased from Ubuntu One']</pre>
</blockquote>
<p>The<strong> root_node_path </strong>is the path of your default root directory, this is always going to be &#8216;~/Ubuntu One&#8217;.</p>
<blockquote>
<pre>In [5]: root = user.get_node(user.root_node_path)
In [8]: root.kind, root.path, root.resource_path, root.when_created
Out[8]: (u'directory', u'/', u'/~/Ubuntu One', u'2009-01-06T22:40:59Z')</pre>
</blockquote>
<p>Additionally, <strong>user_node_paths</strong> is a list of root directories for User Defined Folders. As you can see I have two of these. One is the special folder where music I purchase in the Ubuntu One music store is placed the other one is a UDF I created on one of my clients. Like the <strong>root_node_path </strong>these are root directories where all of your files exist. I could describe it, but I would rather demonstrate.</p>
<blockquote>
<pre>In [11]: d1 = user.make_directory("~/Ubuntu One/a/b/c/d")
In [12]: d1.resource_path
Out[12]: u'/~/Ubuntu One/a/b/c/d'
In [13]: d1.path
Out[13]: u'/a/b/c/d'</pre>
</blockquote>
<p>Here we use a method right off the user object to create a directory. Notice that we included the path &#8220;~/Ubuntu One&#8221; this tells Ubuntu One that you&#8217;re creating this in your default root directory. In this example, the directory created has the <strong>resource_path</strong> of ~/Ubuntu One/a/b/c/d all resources in the Ubuntu One Rest api have a  <strong>resource_path</strong> this is the unique path of the resource within the API. Note also that the directory has a <strong>path </strong>attribute. This is the path of the node under the root.</p>
<p>Of course Ubuntu One isn&#8217;t really about directories, it&#8217;s about files. The most common thing to do is upload files. So here&#8217;s how it&#8217;s done with the u1rest library.</p>
<blockquote>
<pre>In [15]: f1 = user.upload_file('/home/john/Screenshot-1.png', "~/Ubuntu One/I/uploaded/this/Screenshot.png")
In [16]: f1.resource_path
Out[16]: u'/~/Ubuntu One/I/uploaded/this/Screenshot.png'
In [17]: f1.content_path
Out[17]: u'/content/~/Ubuntu One/I/uploaded/this/Screenshot.png'
In [18]: f1.path
Out[18]: u'/I/uploaded/this/Screenshot.png'</pre>
</blockquote>
<p>As you can see, uploading a file is very simple. What&#8217;s really nice is that this created the folder structure needed under Ubuntu One along with the upload. So now the path &#8216;/I/uploaded/this&#8217; was created without an extra step. So now I have a file uploaded to Ubuntu One, what else can I do? How about making the file public?</p>
<blockquote>
<pre>In [19]: f1.set_public()
In [20]: f1.public_url
Out[20]: u'http://ubuntuone.com/p/uRK/'</pre>
</blockquote>
<p>There! now we have a <a href="http://ubuntuone.com/p/uRK" target="_blank">public file</a>.</p>
<p>That&#8217;s all for now, If you want to see more, checkout the example.txt doctest in the source. In the next post I&#8217;ll talk about volumes.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/webm0nk3y.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/webm0nk3y.wordpress.com/14/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webm0nk3y.wordpress.com&#038;blog=23286462&#038;post=14&#038;subd=webm0nk3y&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://webm0nk3y.wordpress.com/2011/05/19/using-the-restful-u1-library-with-ubuntu-one/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/743e679d94c6301d66f79ebbc8b057af?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">webm0nk3y</media:title>
		</media:content>
	</item>
		<item>
		<title>A python library for Ubuntu One&#8217;s REST API.</title>
		<link>http://webm0nk3y.wordpress.com/2011/05/19/a-python-library-for-ubuntu-ones-rest-api/</link>
		<comments>http://webm0nk3y.wordpress.com/2011/05/19/a-python-library-for-ubuntu-ones-rest-api/#comments</comments>
		<pubDate>Thu, 19 May 2011 20:31:25 +0000</pubDate>
		<dc:creator>webm0nk3y</dc:creator>
				<category><![CDATA[ubuntu one]]></category>

		<guid isPermaLink="false">http://webm0nk3y.wordpress.com/?p=5</guid>
		<description><![CDATA[During UDS in Budapest a few weeks ago a new feature of Ubuntu One was quietly announced on Wednesday. A set of pages documenting REST APIs was made available here including a new Rest API for accessing files and directories synchronized with Ubuntu One. As we developed the API, I also threw developed a simple library for [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webm0nk3y.wordpress.com&#038;blog=23286462&#038;post=5&#038;subd=webm0nk3y&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>During UDS in Budapest a few weeks ago a new feature of Ubuntu One was quietly announced on Wednesday. A set of pages documenting REST APIs was made available <a href="https://one.ubuntu.com/developer" target="_blank">here</a> including a new Rest API for accessing files and directories synchronized with Ubuntu One.</p>
<p>As we developed the API, I also threw developed a <a href="http://launchpad.net/restful-u1" target="_blank">simple library for accessing this API</a> mostly so I could test the server side to make sure we have something usable. The main goal for this client was to make it easy to use and provide a library which could be used to create much more robust U1 clients.</p>
<p>I&#8217;ll be blogging about this more, but if you want to tinker with it you&#8217;ll need to do the following:</p>
<p>In order to use the library:</p>
<ul>
<li>Sorry, this currently only works on Ubuntu until I get a generic OAuth library.</li>
<li>Install bzr (sudo apt-get install bzr)</li>
<li>Grab the branch lp:restful-u1</li>
<li>If you&#8217;re not already using Ubuntu One get a free account <a href="https://one.ubuntu.com" target="_blank">https://one.ubuntu.com</a></li>
</ul>
<p>For the examples we won&#8217;t be relying on the keyring for storing credentials. So run the following:</p>
<blockquote>
<pre>PYTHONPATH=. ./u1rest/createfilekeystore.py --email &lt;your username&gt; \
                                            --password &lt;your password&gt; \
                                            --name RESTfulClient</pre>
</blockquote>
<p>Now you should a file credentialsfile.txt. Guard this file as it contains the OAuth tokens to access Ubuntu One.<br />
Here&#8217;s a simple example of using the client in a python console session:</p>
<blockquote>
<pre>from u1rest import get_files_user
user = get_files_user(use_file_keystore=True)
f = user.upload_file(, "~/Ubuntu One/")</pre>
</blockquote>
<p>Look easy? Check out the doctest example.txt for a full demo of what it can do.<br />
I&#8217;ll be back with more on using this library.</p>
<p>Happy Hacking!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/webm0nk3y.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/webm0nk3y.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webm0nk3y.wordpress.com&#038;blog=23286462&#038;post=5&#038;subd=webm0nk3y&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://webm0nk3y.wordpress.com/2011/05/19/a-python-library-for-ubuntu-ones-rest-api/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/743e679d94c6301d66f79ebbc8b057af?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">webm0nk3y</media:title>
		</media:content>
	</item>
	</channel>
</rss>
