1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
using System;
using System.Collections.Generic;
using Google.GData.ContentForShopping;
using Google.GData.ContentForShopping.Elements;
using Google.GData.Client;
namespace ContentForShoppingSample {
class ContentForShoppingDemo {
private static string username;
private static string password;
private static string accountId;
/// <summary>
/// This console application demonstrates all the Google
/// Content for Shopping API calls.
/// </summary>
/// <param name="args">Command-line arguments: args[0] is
/// the username, args[1] is the password, args[2] is the account ID.
///
/// Example: ContentForShoppingDemo admin@example.com my_password 123456</param>
public static void Main(string[] args) {
if (args.Length != 3) {
Console.WriteLine("Syntax: ContentForShoppingDemo <username> <password> <account_id>");
} else {
username = args[0];
password = args[1];
accountId = args[2];
RunSample(username, password, accountId);
}
}
private static void RunSample(string username, string password, string accountId) {
// Connect to the service
ContentForShoppingService service = new ContentForShoppingService("ContentForShopping-Sample");
service.setUserCredentials(username, password);
// Retrieve the list of all existing products
string projection = "schema";
ProductQuery query = new ProductQuery(projection, accountId);
ProductFeed feed = service.Query(query);
// Display title and id for each product
Console.WriteLine("Listing all products");
foreach (ProductEntry p in feed.Entries) {
Console.WriteLine("Product: " + p.Title.Text + " (" + p.ProductId + ")");
}
// Create a new product
ProductEntry entry = new ProductEntry();
entry.Title.Text = "Wool sweater";
AtomContent c = new AtomContent();
c.Content = "Comfortable and soft, this sweater will keep you warm on those cold winter nights. Red and blue stripes.";
entry.Content = c;
entry.ProductId = "123457";
entry.Language = "it";
entry.TargetCountry = "US";
entry.ContentLanguage = "en";
entry.Brand = "ACME";
entry.Condition = "new";
entry.Price = new Price("usd", "25");
entry.ProductType = "Clothing & Accessories > Clothing > Outerwear > Sweaters";
entry.Quantity = 3;
entry.ShippingWeight = new ShippingWeight("lb", "0.1");
entry.ImageLink = new ImageLink("http://www.example.com/image.jpg");
entry.Availability = "available for order";
entry.Channel = "online";
entry.Gender = "female";
entry.Material = "wool";
entry.Pattern = "Red and blue stripes";
entry.Color = "red";
AtomLink link = new AtomLink();
link.HRef = "http://www.example.com";
link.Rel = "alternate";
link.Type = "text/html";
entry.Links.Add(link);
// Shipping rules
Shipping s1 = new Shipping();
s1.Country = "US";
s1.Region = "MA";
s1.Service = "Speedy Shipping - Ground";
s1.Price = new ShippingPrice("usd", "5.95");
Shipping s2 = new Shipping();
s2.Country = "US";
s2.Region = "024*";
s2.Service = "Speedy Shipping - Air";
s2.Price = new ShippingPrice("usd", "7.95");
entry.ShippingRules.Add(s1);
entry.ShippingRules.Add(s2);
// Tax rules
Tax t1 = new Tax();
t1.Country = "US";
t1.Region = "CA";
t1.Rate = "8.25";
t1.Ship = true;
Tax t2 = new Tax();
t2.Country = "US";
t2.Region = "926*";
t2.Rate = "8.75";
t2.Ship = false;
entry.TaxRules.Add(t1);
entry.TaxRules.Add(t2);
// Additional Image Links
AdditionalImageLink il1 = new AdditionalImageLink("http://www.example.com/1.jpg");
entry.AdditionalImageLinks.Add(il1);
AdditionalImageLink il2 = new AdditionalImageLink("http://www.example.com/2.jpg");
entry.AdditionalImageLinks.Add(il2);
// Add the product to the server feed
Console.WriteLine("Inserting product");
ProductEntry inserted = service.Insert(feed, entry);
// Update the product we just inserted
inserted.Title.Text = "2011 Wool sweater";
Console.WriteLine("Updating product");
ProductEntry updated = service.Update(inserted);
// Retrieve the new list of products
feed = service.Query(query);
// Display title and id for each product
Console.WriteLine("Listing all products again");
foreach (ProductEntry p in feed.Entries) {
Console.WriteLine("Product: " + p.Title.Text + " (" + p.ProductId + ")");
}
// Delete the item we inserted and updated
Console.WriteLine("Deleting product");
service.Delete(updated);
}
}
}
|