public void AccountFeedConstructorTest() { AccountFeed target = new AccountFeed(null, null); Assert.IsNotNull(target, "better have an object"); Assert.IsNull(target.Service, "better have no service yet"); }
public void Construction() { var f = new AccountFeed(Data.account, Data.items); Assert.AreEqual(Data.account, f.account); Assert.AreEqual(Data.items.Count(), f.items.Count()); Assert.AreEqual(Data.expectedMentions, f.mentionTotal); }
public void CreateAccountFeedTest() { AccountFeed target = new AccountFeed(null, null); AccountEntry entry = target.CreateFeedEntry() as AccountEntry; Assert.IsNotNull(entry, "better have a AccountEntry here"); }
public int Syndicate(ManagedSecurityContext sec) { GetACL().Check(sec, DataOperation.Update); AccountFeed feed = GetSyndicatedFeed(); if (feed == null) { feed = new AccountFeed(); feed.Account = mInstance.Account; feed.Created = feed.Updated = DateTime.UtcNow; feed.UpdateFrequency = 12; feed.PublishImgs = true; feed.Publish = true; feed.Hidden = true; feed.FeedUrl = FeedUrl; feed.LinkUrl = LinkUrl; feed.FeedType = ManagedFeedType.GetDefaultFeedType(Session); } else { feed.Updated = DateTime.UtcNow; } feed.Name = mInstance.Name; feed.Description = mInstance.Description; Session.Save(feed); return(feed.Id); }
private static AccountFeed Parse(string xml) { byte[] bytes = new UTF8Encoding().GetBytes(xml); AccountFeed feed = new AccountFeed(new Uri(AccountFeedUrl), new AnalyticsService("Test")); feed.Parse(new MemoryStream(bytes), AlternativeFormat.Atom); return(feed); }
public void AccountCheck() { var badItem = new FeedItem(Data.account + "me", 1234, "MEGABYTE!", DateTime.Now, 0); //make sure if theres a tweet from another user its caught //this SHOULD not be a general exception Assert.Throws<Exception>(() => { var f = new AccountFeed(Data.account, Data.items.Concat(new [] {badItem })); }); }
public void AccountParseTest() { string xml = "<?xml version='1.0' encoding='UTF-8'?>\n" + "<feed xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' gd:etag='W/"D0UFR347eCp8ImA4WxVQE04."' xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/' xmlns:dxp='http://schemas.google.com/analytics/2009'>" + "<author>" + "<name>Google Analytics</name>" + "</author>" + "<generator>Google Analytics</generator>" + "<id>http://www.google.com/analytics/feeds/accounts/[email protected]</id>" + "<link href='http://www.google.com/analytics/feeds/accounts/default' rel='self' type='application/atom+xml' />" + "<title type='text'>Profile list for [email protected]</title>" + "<updated>2009-01-31T01:01:01+10:00</updated>" + "<entry gd:etag='W/"D0UAR248eCp4ImA9WxVQE04."'>" + "<dxp:tableId>ga:1234567</dxp:tableId>" + "<dxp:property name='ga:accountId' value='123456' />" + "<dxp:property name='ga:accountName' value='Test Account' />" + "<dxp:property name='ga:profileId' value='1234567' />" + "<dxp:property name='ga:webPropertyId' value='UA-111111-1' />" + "<title type='text'>www.test.com</title>" + "<id>http://www.google.com/analytics/feeds/accounts/ga:1234567</id>" + "<link href='http://www.google.com/analytics' rel='alternate' type='text/html' />" + "<content type='text'/>" + "<updated>2009-01-31T01:01:01+10:00</updated>" + "</entry>" + "</feed>"; AccountFeed feed = Parse(xml); AccountEntry entry = feed.Entries[0] as AccountEntry; Assert.IsNotNull(entry, "entry"); Assert.IsNotNull(entry.Properties); Assert.IsNotNull(entry.ProfileId); Assert.AreEqual("ga:accountId", entry.Properties[0].Name); Assert.AreEqual("123456", entry.Properties[0].Value); Assert.AreEqual("ga:accountName", entry.Properties[1].Name); Assert.AreEqual("Test Account", entry.Properties[1].Value); Assert.AreEqual("ga:profileId", entry.Properties[2].Name); Assert.AreEqual("1234567", entry.Properties[2].Value); Assert.AreEqual("ga:webPropertyId", entry.Properties[3].Name); Assert.AreEqual("UA-111111-1", entry.Properties[3].Value); Assert.AreEqual("www.test.com", entry.Title.Text); Account a = new Account(); a.AtomEntry = entry; Assert.AreEqual("123456", a.AccountId); Assert.AreEqual("Test Account", a.AccountName); Assert.AreEqual("1234567", a.ProfileId); Assert.AreEqual("UA-111111-1", a.WebPropertyId); Assert.AreEqual("www.test.com", a.Title); Assert.AreEqual("ga:1234567", a.TableId); }
public void Construction_BadArgs() { Assert.Throws<ArgumentNullException>(() => { var f = new AccountFeed(null, Data.items); }); Assert.Throws<ArgumentException>(() => { var f = new AccountFeed("", Data.items); }); Assert.Throws<ArgumentNullException>(() => { var f = new AccountFeed(Data.account, null); }); //make sure empty items doens't explode anything var empty = new AccountFeed(Data.account, new FeedItem[0]); }
private bool Validate() { /* * try * { * google.Analytics.SetAuthenticationToken(google.Settings.Current.Token); * google.Webmastertools.SetAuthenticationToken(google.Settings.Current.Token); * } * catch (Exception ex) * { * lbl_error.Text += "Token" + ex.ToString(); * } */ try { google.Analytics.setUserCredentials(tbx_Google_Account_Name.Text, tbx_Google_Account_Password.Text); google.Webmastertools.setUserCredentials(tbx_Google_Account_Name.Text, tbx_Google_Account_Password.Text); } catch (Exception ex) { lbl_error.Text += "Credentials" + ex.ToString(); } try { //DataQuery query = new DataQuery(AccountQuery.HttpsFeedUrl); AccountQuery query = new AccountQuery(); query.ExtraParameters += "key=" + google.Settings.APIkey; AccountFeed accounts = google.Analytics.Query(query); //DataFeed accountFeed = google.Analytics.Query(query); } catch (Exception ex) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data); /* * tbx_Google_Account_Name.Text = String.Empty; * tbx_Google_Account_Password.Text = String.Empty; * lbl_correct.Text = "Account validation has failed."; * lbl_correct.ForeColor = Color.Red; * lbl_error.Text = ex.Message; * return false; */ } lbl_correct.Text = "Account has been validated."; lbl_correct.ForeColor = Color.Green; SetNotice(); return(true); }
/** * Creates a new service object, attempts to authorize using the Client Login * authorization mechanism and requests data from the Google Analytics API. * @throws AuthenticationException if an error occurs with authorizing with * Google Accounts. * @throws IOException if a network error occurs. * @throws ServiceException if an error occurs with the Google Analytics API. */ public AccountFeedExample() { // Configure GA API. AnalyticsService asv = new AnalyticsService("gaExportAPI_acctSample_v2.0"); // Client Login Authorization. asv.setUserCredentials(CLIENT_USERNAME, CLIENT_PASS); // GA Account Feed query uri. AccountQuery query = new AccountQuery(); // Send our request to the Analytics API and wait for the results to // come back. accountFeed = asv.Query(query); }
public void QueryAccountIds() { AnalyticsService service = new AnalyticsService(this.ApplicationName); service.Credentials = new GDataCredentials(this.userName, this.passWord); AccountQuery feedQuery = new AccountQuery(AccountFeedUrl); AccountFeed actual = service.Query(feedQuery); foreach (AccountEntry entry in actual.Entries) { Assert.IsNotNull(entry.Id); Assert.IsNotNull(entry.ProfileId.Value); if (this.accountId == null) { this.accountId = entry.ProfileId.Value; } } }
public override void Delete(ManagedSecurityContext sec) { // orphan groups foreach (AccountGroup group in Collection <AccountGroup> .GetSafeCollection(mInstance.AccountGroups)) { group.AccountBlog = null; Session.Save(group); } // delete features ManagedFeature.Delete(Session, "AccountBlog", Id); // delete automatic feeds AccountFeed feed = GetSyndicatedFeed(); if (feed != null) { Session.Delete(feed); } base.Delete(sec); }
private void RefreshFeed() { string userName = this.Username.Text; string passWord = this.Password.Text; AccountQuery query = new AccountQuery(); AnalyticsService service = new AnalyticsService("AnalyticsSampleApp"); if (!string.IsNullOrEmpty(userName)) { service.setUserCredentials(userName, passWord); } AccountFeed accountFeed = service.Query(query); foreach (AccountEntry entry in accountFeed.Entries) { ListViewItem item = new ListViewItem(entry.Title.Text); //item.SubItems.Add(entry.Title.Text); item.SubItems.Add(entry.ProfileId.Value); this.ProfileIds.Items.Add(item); } }
public void AccountParseTest() { string xml = @"<?xml version='1.0' encoding='UTF-8'?> <feed xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' gd:etag='W/"D0UFR347eCp8ImA4WxVQE04."' xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/' xmlns:dxp='http://schemas.google.com/analytics/2009' xmlns:ga='http://schemas.google.com/ga/2009'> <author> <name>Google Analytics</name> </author> <generator>Google Analytics</generator> <id>http://www.google.com/analytics/feeds/accounts/[email protected]</id> <link href='http://www.google.com/analytics/feeds/accounts/default' rel='self' type='application/atom+xml' /> <title type='text'>Profile list for [email protected]</title> <updated>2009-01-31T01:01:01+10:00</updated> <dxp:segment id='gaid::-1' name='All Visits'> <dxp:definition> </dxp:definition> </dxp:segment> <dxp:segment id='gaid::-2' name='New Visitors'> <dxp:definition>ga:visitorType==New Visitor</dxp:definition> </dxp:segment> <entry gd:etag='W/"D0UAR248eCp4ImA9WxVQE04."'> <ga:customVariable index='1' name='My Custom Variable' scope='3'/> <ga:customVariable index='2' name='My Seconds Variable' scope='1'/> <dxp:tableId>ga:1234567</dxp:tableId> <dxp:property name='ga:accountId' value='123456' /> <dxp:property name='ga:accountName' value='Test Account' /> <dxp:property name='ga:profileId' value='1234567' /> <dxp:property name='ga:webPropertyId' value='UA-111111-1' /> <title type='text'>www.test.com</title> <id>http://www.google.com/analytics/feeds/accounts/ga:1234567</id> <link href='http://www.google.com/analytics' rel='alternate' type='text/html' /> <content type='text'/> <updated>2009-01-31T01:01:01+10:00</updated> <ga:goal active='true' name='Completing Order' number='1' value='10.0'> <ga:destination caseSensitive='false' expression='/purchaseComplete.html' matchType='regex' step1Required='false'> <ga:step name='View Product Categories' number='1' path='/Apps|Accessories'/> <ga:step name='View Product' number='2' path='/Apps|Accessories/(.*)\.axd'/> <ga:step name='View Shopping Cart' number='3' path='/shoppingcart.aspx'/> <ga:step name='Login' number='4' path='/login.html'/> <ga:step name='Place Order' number='5' path='/placeOrder.html'/> </ga:destination> </ga:goal> <ga:goal active='true' name='Browsed my site over 5 minutes' number='2' value='0.0'> <ga:engagement comparison='>' thresholdValue='300' type='timeOnSite'/> </ga:goal> <ga:goal active='true' name='Visited > 4 pages' number='3' value='0.25'> <ga:engagement comparison='>' thresholdValue='4' type='pagesVisited'/> </ga:goal> </entry> </feed>"; AccountFeed feed = Parse(xml); AccountEntry entry = feed.Entries[0] as AccountEntry; Assert.IsNotNull(entry, "entry"); Assert.IsNotNull(entry.Properties); Assert.IsNotNull(entry.ProfileId); Assert.AreEqual("ga:accountId", entry.Properties[0].Name); Assert.AreEqual("123456", entry.Properties[0].Value); Assert.AreEqual("ga:accountName", entry.Properties[1].Name); Assert.AreEqual("Test Account", entry.Properties[1].Value); Assert.AreEqual("ga:profileId", entry.Properties[2].Name); Assert.AreEqual("1234567", entry.Properties[2].Value); Assert.AreEqual("ga:webPropertyId", entry.Properties[3].Name); Assert.AreEqual("UA-111111-1", entry.Properties[3].Value); Assert.AreEqual("www.test.com", entry.Title.Text); Account a = new Account(); a.AtomEntry = entry; Assert.AreEqual("123456", a.AccountId); Assert.AreEqual("Test Account", a.AccountName); Assert.AreEqual("1234567", a.ProfileId); Assert.AreEqual("UA-111111-1", a.WebPropertyId); Assert.AreEqual("www.test.com", a.Title); Assert.AreEqual("ga:1234567", a.TableId); Assert.IsNotEmpty(feed.Segments); foreach (Segment s in feed.Segments) { Assert.IsNotNull(s.Name); Assert.IsNotNull(s.Id); } Assert.AreEqual(feed.Segments[0].Name, "All Visits"); Assert.AreEqual(feed.Segments[0].Id, "gaid::-1"); Assert.AreEqual(feed.Segments[1].Name, "New Visitors"); Assert.AreEqual(feed.Segments[1].Id, "gaid::-2"); System.Collections.Generic.List <Goal> goals = entry.Goals; Assert.IsNotEmpty(goals); Assert.AreEqual(goals.Count, 3); //First goal: Test all the way down Goal firstGoal = goals[0]; Assert.AreEqual(firstGoal.Active, "true"); Assert.AreEqual(firstGoal.Name, "Completing Order"); Assert.AreEqual(firstGoal.Number, "1"); Assert.AreEqual(firstGoal.Value, "10.0"); //Destination Assert.IsNotNull(firstGoal.Destination); Destination destination = firstGoal.Destination; Assert.AreEqual(destination.CaseSensitive, "false"); Assert.AreEqual(destination.Expression, "/purchaseComplete.html"); Assert.AreEqual(destination.MatchType, "regex"); Assert.AreEqual(destination.Step1Required, "false"); //Test first step of destination //<ga:step name='View Product Categories' number='1' path='/Apps|Accessories'/> Assert.IsNotNull(destination.Steps); Assert.IsNotEmpty(destination.Steps); Step step = destination.Steps[0]; Assert.AreEqual(step.Name, "View Product Categories"); Assert.AreEqual(step.Number, "1"); Assert.AreEqual(step.Path, "/Apps|Accessories"); //Engagement //testing against node: <ga:engagement comparison='>' thresholdValue='300' type='timeOnSite'/> Assert.IsNotNull(goals[1].Engagement); Engagement engagement = goals[1].Engagement; Assert.AreEqual(engagement.Comparison, ">"); Assert.AreEqual(engagement.Threshold, "300"); Assert.AreEqual(engagement.Type, "timeOnSite"); //Custom Variables Assert.IsNotNull(entry.CustomVariables); Assert.IsNotEmpty(entry.CustomVariables); CustomVariable cv = entry.CustomVariables[0]; Assert.AreEqual(cv.Name, "My Custom Variable"); Assert.AreEqual(cv.Index, "1"); Assert.AreEqual(cv.Scope, "3"); }
public void MentionTotal() { var f = new AccountFeed(Data.account, Data.items); Assert.AreEqual(Data.expectedMentions, f.mentionTotal); }