Gallery2 remote API C# wrapper

Monday, June 29th, 2009

I stumbled across the Gallery.NET Toolkit on Twitter, while I should have been doing something more useful; some great work from @rmaclean (thanks for sharing / codeplexing  it).

The API wraps up a lot of the Gallery2 remote services into some easy to use C# functions.

Actions a = new SADev.Gallery2.Protocol.Actions("http://www.blakepics.com");
string authToken = a.Login("*************", "*************").AuthToken;
a.FetchAlbums(authToken).Albums.ForEach(
    album =>
    {
        Console.WriteLine(album.Title);
        a.FetchImages(authToken, album.Name).Images.ForEach(image =>
            Console.WriteLine("\t" + image.Url)
        );
    }
    );
Console.ReadKey();

Hopefully I’ll find an excuse to use this one day.

Getting document reports from Amazon Seller Central SOAP services (C#)

Sunday, March 22nd, 2009

Developing against the Amazon API becomes a lot more straightforward with being able to get at the errors with your XML documents. Validating against the XSDs is only part of the solution, but even downloading reports can be tricky. Trouble is, the documentation from Amazon is a very closed & private sort of affair – sometimes out of date and sometimes very sparse. Perhaps they should think about a wiki :)

Getting at your reports consists of two parts, firstly – use the Document ID (long) you got from posting the XML in the first place.

public DocumentProcessingInfo DocumentStatus(long DocumentID)
    {
        //Setup the service interface, set the URL of the service
        //and add our credentials.
        merchantinterfacedime myAmazon =
            new merchantinterfacedime();
        myAmazon.Url = ConfigurationManager.AppSettings["URL"];
        myAmazon.Credentials =
            new NetworkCredential(
                ConfigurationManager.AppSettings["UserName"],
                ConfigurationManager.AppSettings["Password"]);
        //Setup our merchant details.
        Merchant myMerchant = new Merchant();
        myMerchant.merchantIdentifier =
            ConfigurationManager.AppSettings["MerchantIdentifier"];
        myMerchant.merchantName =
            ConfigurationManager.AppSettings["MerchantName"];
        //Send it all off to Amazon.
        DocumentProcessingInfo myStatus =
            myAmazon.getDocumentProcessingStatus(
            myMerchant, DocumentID);
        //Return the status of the document.
        return myStatus;
    }

This will give you the status of your upload, as well as whether it’s complete or not. It also gives you another document ID, which you can use to get at your much-needed reports.

public string GetDocument(string id) {
        StringBuilder report = new StringBuilder();
        merchantinterfacedime myAmazon =
            new merchantinterfacedime();
        myAmazon.Url = ConfigurationManager.AppSettings["URL"];
        myAmazon.Credentials =
            new NetworkCredential(
                ConfigurationManager.AppSettings["UserName"],
                ConfigurationManager.AppSettings["Password"]);
        //Setup our merchant details.
        Merchant myMerchant = new Merchant();
        myMerchant.merchantIdentifier =
            ConfigurationManager.AppSettings["MerchantIdentifier"];
        myMerchant.merchantName =
            ConfigurationManager.AppSettings["MerchantName"];
        ReferencedBinary incomingDoc = new ReferencedBinary();
        // the seven-digit string is the document ID number
        myAmazon.getDocument(myMerchant, id, out incomingDoc);
        IEnumerator enumer = myAmazon.ResponseSoapContext.Attachments.GetEnumerator();
        while (enumer.MoveNext())
        {
            // Print the document to standard out
            Attachment downloadedDoc = enumer.Current as Attachment;
            StreamReader r = new StreamReader(downloadedDoc.Stream);
            report.Append(r.ReadToEnd());
        }
        return report.ToString();
}

And tying it all together:

long amazonId = #######
string report = GetDocument(DocumentStatus(amazonId).processingReport.documentID);

Your report will be in XML, and give you any validation errors that might be preventing your feed from working properly, as well as some very helpful status on the number of items processed. How did you ever live without it?

Twitter – Conversation in the Machine

Thursday, July 31st, 2008

It’s another of those life-changing technologies which will not only improve the way you interact your fellow humans across the planet, but also shape and change the web as we know it for a brighter future beyond our current limited borders.

No it’s not.

It’s a micro-blogging tool which performs about the same function as your Facebook status, with a bit more history and more conversation potential than real speaking. It also falls into the category of “shiny web things” that the magpie’s of the Internet world run bounding towards with wings flapping, declaring their undying allegiance and overwhelming excitement about the grand new era of technology, society and communication.

I am said magpie. I just haven’t had much use for it, so whilst most people are bounding towards Pownce with their wings wide open, I’m still trying to find an excuse.

My Twitter feed is decidedly empty, having originally opened it as a way only of updating my Facebook status before I realised that was syndication for the sake of it (See integrations with BrightKite, Loopt, and Flickr integration for reference). But I do get a kick out of things like the Tower Bridge Tweets. The wonderful thing about this Web 2.0 stuff is that you don’t have to use any of it for what it was intended for (which is usually so vague and fluffy, it only really starts to take shape after the rules have been broken).

So I grabbed a copy of the Net::Twitter module for Perl and before you know it, my script that monitors if the Wifi connection on the Blakepics server had gone down was happily tweeting away with only three more lines of (my) code.

use Net::Twitter;
my $twit = Net::Twitter->new(username=>"username", password=>"password", source => "DowntimeMonitor" );
$twit->update("Internet connection ".($state ? "is now up" : "has been restarted"));