Example #1
0
 static void PrintTrackingSource(Source s)
 {
     Console.WriteLine();
       if (s.error == null){
     Console.WriteLine("Tracking Source: " + s.id);
     Console.WriteLine("       Name: " + s.name);
     Console.WriteLine("     Online: " + (s.online ? "Yes" : "No"));
     Console.WriteLine("Ref pattern: " + s.referring_url);
     Console.WriteLine("Ref exclude: " + s.not_referrer_url);
     Console.WriteLine("URL pattern: " + s.landing_url);
     Console.WriteLine("URL exclude: " + s.not_landing_url);
     Console.WriteLine("   Position: " + s.position);
       }
 }
Example #2
0
        static void UpdateSource(Source src)
        {
            if (src.error != null){
            Console.WriteLine("Source has error: " + src.error);
            return;
              }

              PrintTrackingSource(src);

              string oldname     = src.name;
              int?   oldposition = src.position;
              bool   oldonline   = src.online;

              string oldref_pattern = src.referring_url;
              string oldref_exclude = src.not_referrer_url;
              string oldurl_pattern = src.landing_url;
              string oldurl_exclude = src.not_landing_url;

              src.name     = "Changed the name!";
              src.position = 23;
              src.online   = false;

              src.referring_url    = "Referring URL Regex";
              src.not_referrer_url = "Referring URL Exclude";
              src.landing_url      = "Landing URL Regex";
              src.not_landing_url  = "Landing URL Exclude";

              if (!src.save()){
            Console.WriteLine("Error saving source: " + src.error);
            src.reload();
            return;
              }else{
            src.reload();
              }

              PrintTrackingSource(src);

              src.name     = oldname;
              src.position = oldposition;
              src.online   = oldonline;

              src.referring_url    = oldref_pattern;
              src.not_referrer_url = oldref_exclude;
              src.landing_url      = oldurl_pattern;
              src.not_landing_url  = oldurl_exclude;

              if (!src.save()){
            Console.WriteLine("Error saving source: " + src.error);
            src.reload();
            return;
              }else{
            src.reload();
              }

              PrintTrackingSource(src);
        }
Example #3
0
        /*
         * List sources in the current account
         */
        public static Page<Source> list(CTM.AuthToken token, int page=0)
        {
            string url = CTM.Config.Endpoint() + "/accounts/" + token.account_id + "/sources.json";

              Hashtable parameters = new Hashtable();
              parameters["page"]   = page.ToString();

              CTM.Response res = new CTM.Request(url, token).get(parameters);

              if (res.error != null){
            return new Page<Source>(res.error);

              } else {
            int index = 0;
            Source[] sources = new Source[res.data.sources.Count];

            foreach (JObject item in res.data.sources.Children<JToken>()) {
              sources[index++] = new Source(item, token);
            }
            return new Page<Source>(sources, page, (int)res.data.total_entries, (int)res.data.total_pages);
              }
        }