Beispiel #1
0
        public static void Test(AwsKeyHelper keyHelper)
        {
            var helper = new SignedRequestHelper(keyHelper.GetAwsAccessKeyId(), keyHelper.GetAwsSecretKey(), DESTINATION);

            String requestUrl;
            String title;

            //TODO: AHT - Add AssociateId
            // Add Request week for caching key?

            /*
             * Here is an ItemLookup example where the request is stored as a dictionary.
             */
            IDictionary <string, string> r1 = new Dictionary <string, String>();

            r1["Service"] = "AWSECommerceService";
            r1["Version"] = "2009-03-31";
            //r1["Operation"] = "ItemLookup";
            r1["Operation"] = "ItemLookup";
            //r1["ItemId"] = ITEM_ID;
            r1["ItemId"]      = isbn;
            r1["IdType"]      = "ISBN";
            r1["SearchIndex"] = "Books";
            //r1["ResponseGroup"] = "Small";
            r1["ResponseGroup"] = "Tags,Reviews,EditorialReview";
            r1["TagsPerPage"]   = "20";

            /* Random params for testing */
            //r1["AnUrl"] = "http://www.amazon.com/books";
            //r1["AnEmailAddress"] = "*****@*****.**";
            //r1["AUnicodeString"] = "αβγδεٵٶٷٸٹٺチャーハン叉焼";
            //r1["Latin1Chars"] = "ĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıIJij";

            requestUrl = helper.Sign(r1);
            var response = new HtmlLoader().LoadUrl(requestUrl);

            var xDoc = XDocument.Parse(response);
            var x    = xDoc.Descendants().Where(node => node.Name.LocalName == "Item").Select(item => Item.Create(item));

            x.Count();
        }
Beispiel #2
0
        public static void Test2(AwsKeyHelper keyHelper)
        {
            SignedRequestHelper helper = new SignedRequestHelper(keyHelper.GetAwsAccessKeyId(), keyHelper.GetAwsSecretKey(), DESTINATION);

            /*
             * The helper supports two forms of requests - dictionary form and query string form.
             */
            String requestUrl;
            String title;

            /*
             * Here is an ItemLookup example where the request is stored as a dictionary.
             */
            IDictionary <string, string> r1 = new Dictionary <string, String>();

            r1["Service"]   = "AWSECommerceService";
            r1["Version"]   = "2009-03-31";
            r1["Operation"] = "ItemLookup";
            //r1["ItemId"] = ITEM_ID;
            r1["ItemId"]      = isbn;
            r1["IdType"]      = "ISBN";
            r1["SearchIndex"] = "Books";
            //r1["ResponseGroup"] = "Small";
            r1["ResponseGroup"] = "Tags";

            /* Random params for testing */
            r1["AnUrl"]          = "http://www.amazon.com/books";
            r1["AnEmailAddress"] = "*****@*****.**";
            r1["AUnicodeString"] = "αβγδεٵٶٷٸٹٺチャーハン叉焼";
            r1["Latin1Chars"]    = "ĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıIJij";

            requestUrl = helper.Sign(r1);
            title      = FetchTitle(requestUrl);

            System.Console.WriteLine("Method 1: ItemLookup Dictionary form.");
            System.Console.WriteLine("Title is \"" + title + "\"");
            System.Console.WriteLine();

            /*
             * Here is a CartCreate example where the request is stored as a dictionary.
             */
            IDictionary <string, string> r2 = new Dictionary <string, String>();

            r2["Service"]               = "AWSECommerceService";
            r2["Version"]               = "2009-03-31";
            r2["Operation"]             = "CartCreate";
            r2["Item.1.OfferListingId"] = "Ho46Hryi78b4j6Qa4HdSDD0Jhan4MILFeRSa9mK+6ZTpeCBiw0mqMjOG7ZsrzvjqUdVqvwVp237ZWaoLqzY11w==";
            r2["Item.1.Quantity"]       = "1";

            requestUrl = helper.Sign(r2);
            title      = FetchTitle(requestUrl);

            System.Console.WriteLine("Method 1: CartCreate Dictionary form.");
            System.Console.WriteLine("Cart Item Title is \"" + title + "\"");
            System.Console.WriteLine();

            /*
             * Here is an example where the request is stored as a query-string:
             */

            /*
             * string requestString = "Service=AWSECommerceService&Version=2009-03-31&Operation=ItemLookup&ResponseGroup=Small&ItemId=" + ITEM_ID;
             */
            System.Console.WriteLine("Method 2: Query String form.");

            String[] Keywords = new String[] {
                "surprise!",
                "café",
                "black~berry",
                "James (Jim) Collins",
                "münchen",
                "harry potter (paperback)",
                "black*berry",
                "finger lickin' good",
                "!\"#$%'()*+,-./:;<=>?@[\\]^_`{|}~",
                "αβγδε",
                "ٵٶٷٸٹٺ",
                "チャーハン",
                "叉焼",
            };

            foreach (String keyword in Keywords)
            {
                String requestString = "Service=AWSECommerceService"
                                       + "&Version=2009-03-31"
                                       + "&Operation=ItemSearch"
                                       + "&SearchIndex=Books"
                                       + "&ResponseGroup=Small"
                                       + "&Keywords=" + keyword
                ;
                requestUrl = helper.Sign(requestString);
                title      = FetchTitle(requestUrl);

                System.Console.WriteLine("Keyword=\"" + keyword + "\"; Title=\"" + title + "\"");
                System.Console.WriteLine();
            }

            String cartCreateRequestString =
                "Service=AWSECommerceService"
                + "&Version=2009-03-31"
                + "&Operation=CartCreate"
                + "&Item.1.OfferListingId=Ho46Hryi78b4j6Qa4HdSDD0Jhan4MILFeRSa9mK%2B6ZTpeCBiw0mqMjOG7ZsrzvjqUdVqvwVp237ZWaoLqzY11w%3D%3D"
                + "&Item.1.Quantity=1"
            ;

            requestUrl = helper.Sign(cartCreateRequestString);
            title      = FetchTitle(requestUrl);

            System.Console.WriteLine("Cart Item Title=\"" + title + "\"");
            System.Console.WriteLine();


            System.Console.WriteLine("Hit Enter to end");
            System.Console.ReadLine();
        }