Archive for the ‘JavaScript’ Category
Signing Amazon Product Advertising API calls in Ruby
I have a simple site that generates covers for CDs I burn from iTunes purchases and so on (it pre-dates widespread use of JS libraries, and is in much need of prettifying). The site uses Amazon Product Advertising API calls to search and retrieve album cover art and track listings. Since earlier this month, such API calls have to be cryptographically signed.
This is somewhat annoying — the site’s original design has it communicating independently with Amazon (using Amazon’s XSLT API feature to transform their XML data into JSON), and that’s no longer possible with the use of a private key. But it’s not unfixable. The site now sends its API call first to my server, which returns a signed version, and then forwards the signed call on to Amazon.
I found most of what I needed for this on Chris Roos’ blog, but his version still wasn’t quite working for me (the two problems I recall are that Ruby’s CGI.escape doesn’t quite follow Amazon’s requirements, and that times need converting to GMT).
Getting a Firefox extension’s directory from within the extension
When creating a Firefox extension recently, I was surprised how much pain is involved simply in finding out, from within an extension, where that extension’s files are installed.
You have to create a ‘component’, which entails a fair chunk of unintelligible boilerplate code (well, unintelligible unless you’re much better acquainted with Firefox’s innards than developing a basic extension generally requires you to be).
Plenty of places will tell you roughly how to do it. But, after some experimentation, let me show you exactly how.
- Copy this JavaScript file into your extension’s /components directory (if that directory doesn’t exist yet, create it).
- Use it from elsewhere in your extension like so:
own_path = Components.classes["@mackerron.com/get_ext_dir;1"] .createInstance().wrappedJSObject.get_ext_dir();
And that’s it. Let me know if it helps you out.