Skip to content

listing keys with S3Ajax

In a previous post (learning how to use S3Ajax to access Amazon S3), I show how to use Chickenfoot and S3Ajax to list S3 buckets. Here is a slight elaboration of the code to list the keys within buckets (in addition to the buckets):

include("D:\\document\\JavaScriptLib\\sha1.js");
include("D:\\document\\JavaScriptLib\\S3Ajax.js");

var AWSAccessKeyId = "[AWSAccessKeyId]";
var AWSSecretAccessKey = "[AWSSecretAccessKey]";

S3Ajax.DEBUG = true;
S3Ajax.KEY_ID = AWSAccessKeyId;
S3Ajax.SECRET_KEY = AWSSecretAccessKey;

function s3_listKeys(bucket) {
  S3Ajax.listKeys(bucket,null,
    function(req, obj) {
        var contents = obj.ListBucketResult.Contents;
        for (var i=0, item; item=contents[i]; i++) {
           output("key: " + bucket + ": " + item.Key +
            " [" + item.LastModified + '] ' + 
             " (" + item.Size + ")");
        }
    },
     function(req,obj) {
        output("s3_listKeys failed at " + (new Date()));
     }
  )
} // s3_listKeys

S3Ajax.listBuckets(
    function(req, obj) {
        if (obj.ListAllMyBucketsResult) {
            var buckets = obj.ListAllMyBucketsResult.Buckets.Bucket;
            for (var i=0, bucket; bucket=buckets[i]; i++) {
              output (
                    "bucket: " + bucket.Name + ' ['+ 
                      bucket.CreationDate+']'
              );
              s3_listKeys(bucket.Name);
            }
        }
    },
    function(req) {
        output ("Buckets list failed at "+(new Date()));
    }
);
Tagged

learning how to use S3Ajax to access Amazon S3

In a previous post ( Amazon S3 signature calculation in JavaScript), I show how to calculate using JavaScript a "signature" need to access Amazon S3. In this post, I show a code snippet for using Leslie Michael Orchard's S3Ajax, which I'm evaluating for using to connect Zotero with Amazon S3. (Like the code from my previous calculation, it too depends on the sha1.js library.). Here's a Chickenfoot script (which is a slight rewriting of a L. M. Orchard's listbuckets function in play.js) to list your S3 buckets (you need to substitute the appropriate key/secret and download S3Ajax.js and sha1.js and substitute the correct path for these libraries):

include("D:\\document\\JavaScriptLib\\sha1.js");
include("D:\\document\\JavaScriptLib\\S3Ajax.js");

var AWSAccessKeyId = "[AWSAccessKeyId]";
var AWSSecretAccessKey = "[AWSSecretAccessKey]";

S3Ajax.DEBUG = true;
S3Ajax.KEY_ID = AWSAccessKeyId;
S3Ajax.SECRET_KEY = AWSSecretAccessKey;

S3Ajax.listBuckets(
    function(req, obj) {
        if (obj.ListAllMyBucketsResult) {
            var buckets = obj.ListAllMyBucketsResult.Buckets.Bucket;
            for (var i=0, bucket; bucket=buckets[i]; i++) {
                output (
                    bucket.Name + ' ['+bucket.CreationDate+']'
                );
            }
        }
    },
    function(req) {
        output ("Buckets list failed at "+(new Date()));
    }
);

I will have to try some more sophisticated actions — but the simple listing of buckets worked for me.

Amazon S3 signature calculation in JavaScript

On pp. 478-479 of Chapter 16 of my mashup book on online storage APIs, I show how to how to reproduce the calculation of an API signature in Amazon S3 in Python and PHP. Recently, because I now want to access S3 from within the browser, I have figured out how to do the same example using JavaScript. Specifically, the following is a Chickenfoot script that generates the correct signature.   (Note that the code depends on Paul Johnson's sha1.js library. (See his instructions on how to use the library. I had to consult the page to learn about the b64pad variable).):

// reproduce results on pp. 478-479 of
// Pro Web 2.0 Mashups

// http://docs.amazonwebservices.com/AmazonS3/2006-03-01/RESTAuthentication.html
// http://pajhome.org.uk/crypt/md5/instructions.html

include("D:\\Document\\JavaScriptLib\\sha1.js");

var AWSAccessKeyId = "0PN5J17HBGZHT7JJ3X82";
var AWSSecretAccessKey = "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o";
var Expires = '1175139620';
var HTTPVerb = "GET"
var ContentMD5 = ""
var ContentType = ""
var CanonicalizedAmzHeaders = ""
var CanonicalizedResource = "/johnsmith/photos/puppy.jpg"
var string_to_sign = HTTPVerb + "\n" + ContentMD5 + "\n" + ContentType + "\n" + 
  Expires + "\n" + CanonicalizedAmzHeaders + CanonicalizedResource
output(string_to_sign);

b64pad = "="; // needed for "strict RFC compliance"
var sig = b64_hmac_sha1(AWSSecretAccessKey , string_to_sign);
output ("|"+sig+"|");
Tagged , ,

Learning about JavaScript libraries using the Google Ajax Libraries API

In Chapter 8 of my mashup book, I wrote

    Ideally there would be one obvious choice for an excellent JavaScript library, and everyone would use it. The current situation is that there are many JavaScript libraries, and it is not at all obvious how they compare.

I was hoping that in the course of writing my book, I would have had an opportunity to do my in-depth study of various JavaScript libraries (of which there are many, judging from the table in the Wikipedia entry Comparison of JavaScript frameworks). I raised the question of how to choose a JavaScript library during a panel on OpenAjax as a way of studying the implications of such initiatives as OpenAjax — that is, does OpenAjax make it easier to figure out what JavaScript library to choose — or does it allow one to pick and choose the best parts from a whole range of libraries? These are questions I plan to raise in my spring 2009 Mixing and Remixing Information course.

At any rate, I recently had a chance to take a closer look at AJAX Libraries API – Google Code, which is "a content distribution network and loading architecture for the most popular, open source JavaScript libraries", which at present, include:

  • jQuery
  • jQuery UI
  • Prototype
  • script.aculo.us
  • MooTools
  • Dojo
  • SWFObject
  • Yahoo! User Interface Library (YUI)

From a pedagogical point of view, the Google AJAX Libraries API, by providing a single common library call (google.load) simplifies getting set up with each of the libraries, which otherwise, would require a different setup. Of course, there are reasons that you might not want to depend on Google to host JavaScript libraries you use — but not having to take care of hosting these files yourself helps beginners jump right in.

I'm pleased to see that The Yahoo! User Interface Library (YUI) recently became part of the Google API. I use that library in my course and in my book. The post on Google AJAX Search API Blog announcing this inclusion gave a short code example on how to use YUI with the Google AJAX Libraries API — it did not actually show any visible in the user interface. Here I show to elaborate the example slightly to actually show something visible in the UI.

To do so, you should take look at the YUI docs for the calendar widget and understand a bit about what the YUILoader (Yahoo! UI Library: YUI Loader Utility does. One thing to note is that google.load('yui', '2.6.0'); creates an instance of a global YAHOO object. Secondly, YUILoader takes care of loading the pieces of YUI required to use the widget that you want to use — see Getting Started for more details. You will also want to load in the default CSS to get started (through the line <body class="yui-skin-sam">). The modified code I came up with is:

<head>
  <script src="http://www.google.com/jsapi" type="text/javascript" charset="utf-8"></script>
  <script type="text/javascript" charset="utf-8">
  google.load('yui', '2.6.0');
  function init() {
    var loader = new YAHOO.util.YUILoader({
      require: ["button", "calendar"],
      base: "http://ajax.googleapis.com/ajax/libs/yui/2.6.0/build/",
      onSuccess: function() {
        // start playing with buttons and calendars!
        var cal = new YAHOO.widget.Calendar("calContainer");
        cal.render();
      }
    });
    loader.insert();
  }
  google.setOnLoadCallback(init);
  </script>
</head>
<body class="yui-skin-sam">
  <div id="calContainer"></div>
</body>

which you can run at http://labs.mashupguide.net/doc/2008/11/google.ajaxlib.yui.eg.html

In case you were trying to login using OpenID, it should work now

See Data Unbound » Fixing the OpenID setup my WordPress blogs.  Thanks for your patience while I was fixing this problem — and let me know if you continue to have problems with logging in and with commenting.

Tagged ,

Two reviews of my book

Yesterday, I was very pleased to read Ralph LeVan's review in Ariadne (Issue 57):

I can’t imagine a more comprehensive book on mashups. This book would make a great textbook for a class on the topic. If you are a developer of mashups, this book must be in your reference library. However, if you’re looking for a gentle introduction to the topic, it may be more than you want.

(Thanks to Lorcan Dempsey for pointing out the review to me.)

A little while ago, I also learned about a review on a German blogger: Pro Web 2.0 Mashups: Remixing Data and Web Services. Buchrezension. Since I can't read German, I turned to Google Translate (Pro Web 2.0 mashups: Remixing Data and Web Services. Book reviews). From what I can glean, the review seems very positive.

Tagged

Preparing for a panel on OpenAjax

I've started preparing for the first panel at next week's Mashup Camp on OpenAjax Alliance: Why Ajax Standards Matter. Some things I'm reading and synthesizing:

A big question for me: what hands-on stuff is there to try? How hard is it to download code from Open source projects and take the projects "out for a spin"? Is there a screencast showing OpenAjax in action so that we can quickly see its purported benefits rather than just read about them?

It's also a good time to study Google's AJAX Libraries API ("a content distribution network and loading architecture for the most popular open source JavaScript libraries") as a way of comparing various leading JavaScript libraries. I plan to use it in the next "Mixing and Remixing Information" course I teach in Spring 2009.

Tagged ,

What'd I'd like to have discussed at Mashup Camp

Later this month (from Nov 17-18), I'll be attending the latest Mashup Camp. I've been mulling over various sessions that I like to propose. This afternoon I finally wrote up one of them: "Learning and Teaching How to Create Mashups":

    In this session we will share our experiences about how we teach others to create mashups, as well as how we ourselves learn about mashups. What approaches do you use? What has worked and what hasn't?

I hope to write up a few more proposals, including ones focused on mashups in research and and mashups for personal information integration.

Tagged

delicious: the name changed, but has the API?

I'm looking forward to having the chance to teach my "Mixing and Remixing information" course for the fourth time In January 2009.  Since I plan to use my book on mashups as one of the primary texts, I'm going to have to update it.  Even though the book was published in February, a fair amount has changed in the world of mashups.   As a consequence,  I plan, over the next three months before class starts,  is to document some of those changes.

Let me start with something that should be straightforward. I wrote about delicious in Chapter 14 of my mashup  book,   a chapter about social bookmarking.    Since the book was published, delicious underwent a change of name — from http://del.icio.us to http://delicious.com.

In updating my book, I will have to make note this name change and any consequences.   My hope is that all the old URLs would continue to work.  Indeed, that is my experience during some casual testing.  For instance, the URL

http://del.icio.us/url/53113b15b14c90292a02c24b55c316e5

is redirected to

http://delicious.com/url/53113b15b14c90292a02c24b55c316e5

as one would expect.

Curiously though, the URLs involved in the delicious API are still based on the old domain name — according to the current documentation.    Hence, all the URLs that look like

curl -u USER:PASSWORD https://api.del.icio.us/v1/tags/get

in my book are still correct.

After not had an opportunity to look at whether there are  changes in the API  that don't result from the name change — that examination will have to come later.

Tagged ,

My talk at the Library of Congress

The talk I gave recently at the Library of Congress on web 2.0 mashups might be of interest to you all. The recording of the talk is available now from the LC site:

http://www.loc.gov/today/cyberlc/feature_wdesc.php?rec=4346

I tried not to be to be too technical while working in some technical details on the side for those in audience who want to know more.

Tagged ,