File: datafeedsample.cs

package info (click to toggle)
gdata-sharp 2.2.0.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 12,092 kB
  • sloc: cs: 67,781; xml: 38,234; python: 163; makefile: 149; sh: 27
file content (86 lines) | stat: -rw-r--r-- 3,479 bytes parent folder | download | duplicates (2)
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
using System;
using System.Collections.Generic;
using Google.GData.ContentForShopping;
using Google.GData.ContentForShopping.Elements;
using Google.GData.Client;

namespace DatafeedSample {
    class DatafeedDemo {
        private static string username;
        private static string password;
        private static string accountId;

        /// <summary>
        /// This console application demonstrates all the Google
        /// Content for Shopping datafeeds 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: DatafeedDemo admin@example.com my_password 123456</param>
        public static void Main(string[] args) {
            if (args.Length != 3) {
                Console.WriteLine("Syntax: DatafeedDemo <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("Datafeed-Sample", accountId);
            service.setUserCredentials(username, password);

            // Retrieve the list of all existing accounts
            DatafeedFeed feed = service.QueryDatafeeds();

            // Display title and filename for each datafeed
            Console.WriteLine("Listing all datafeeds returned");
            foreach (DatafeedEntry m in feed.Entries) {
                Console.WriteLine("Datafeed: " + m.Title.Text + " (" + m.FeedFileName + ")");
            }

            // Create a new datafeed entry
            DatafeedEntry entry = new DatafeedEntry();
            entry.Title.Text = "ABC Store Electronics products feed";
            entry.AttributeLanguage = "en";
            entry.ContentLanguage = "en";
            entry.FeedFileName = "electronics.txt";
            entry.TargetCountry = "US";

            FileFormat format = new FileFormat();
            format.Format = "dsv";
            format.Delimiter = "pipe";
            format.Encoding = "utf8";
            format.UseQuotedFields = "no";

            entry.FileFormat = format;

            // Add the datafeed
            Console.WriteLine("Inserting datafeed");
            DatafeedEntry inserted = service.InsertDatafeed(entry);

            // Update the datafeed we just inserted
            Console.WriteLine("Updating datafeed");
            inserted.Title.Text = "DEF Store Electronics products feed";
            DatafeedEntry updated = service.UpdateDatafeed(inserted);

            // Retrieve the new list of datafeeds
            feed = service.QueryDatafeeds();

            // Display title and filename for each datafeed
            Console.WriteLine("Listing all datafeed returned");
            foreach (DatafeedEntry m in feed.Entries) {
                Console.WriteLine("Datafeed: " + m.Title.Text + " (" + m.FeedFileName + ")");
            }

            // Delete the datafeed we inserted and updated
            Console.WriteLine("Deleting datafeed");
            service.DeleteDatafeed(updated);
        }
    }
}