Skip to content

Instantly share code, notes, and snippets.

@sandrinodimattia
Created July 23, 2012 06:21
Show Gist options
  • Save sandrinodimattia/3162260 to your computer and use it in GitHub Desktop.
Save sandrinodimattia/3162260 to your computer and use it in GitHub Desktop.
GoogleReader subscription
public abstract class GoogleSyndicationItem
{
/// <summary>
/// Initialize the item.
/// </summary>
/// <param name="item"></param>
internal GoogleSyndicationItem(SyndicationItem item)
{
if (item != null)
{
LoadItem(item);
}
}
/// <summary>
/// Load the item (to be implemented by inheriting classes).
/// </summary>
/// <param name="item"></param>
protected abstract void LoadItem(SyndicationItem item);
/// <summary>
/// Get the text from a TextSyndicationContent.
/// </summary>
/// <param name="content"></param>
/// <returns></returns>
public string GetTextSyndicationContent(SyndicationContent content)
{
TextSyndicationContent txt = content as TextSyndicationContent;
if (txt != null)
return txt.Text;
else
return "";
}
}
public abstract class GoogleXmlItem : SyndicationItem
{
/// <summary>
/// Initialize the item.
/// </summary>
/// <param name="item"></param>
internal GoogleXmlItem(XElement item)
{
if (item != null)
{
LoadItem(item);
}
}
/// <summary>
/// Load the item (to be implemented by inheriting classes).
/// </summary>
/// <param name="item"></param>
protected abstract void LoadItem(XElement item);
/// <summary>
/// Get a list of descendants.
/// </summary>
/// <param name="item"></param>
/// <param name="descendant"></param>
/// <param name="attribute"></param>
/// <param name="attributeValue"></param>
/// <returns></returns>
protected IEnumerable<XElement> GetDescendants(XElement item, string descendant,
string attribute, string attributeValue)
{
return item.Descendants(descendant).Where(o => o.Attribute(attribute) != null
&& o.Attribute(attribute).Value == attributeValue);
}
/// <summary>
/// Get a descendant.
/// </summary>
/// <param name="item"></param>
/// <param name="descendant"></param>
/// <param name="attribute"></param>
/// <param name="attributeValue"></param>
/// <returns></returns>
protected XElement GetDescendant(XElement item, string descendant,
string attribute, string attributeValue)
{
return GetDescendants(item, descendant, attribute, attributeValue).First();
}
/// <summary>
/// Get the value of a descendant.
/// </summary>
/// <param name="item"></param>
/// <param name="descendant"></param>
/// <param name="attribute"></param>
/// <param name="attributeValue"></param>
/// <returns></returns>
protected string GetDescendantValue(XElement item, string descendant,
string attribute, string attributeValue)
{
var desc = GetDescendant(item, descendant, attribute, attributeValue);
if (desc != null)
return desc.Value;
else
return "";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment