This C# .NET DayPI client is contributed by Tikiri, co-founder and star developer at Chillx.com.
Replace your Accesskey and SharedSecret in the attached code and you are ready to make the DayPI calls from your C# .NET app.
Below is sample code that demonstrates how you can use this library.
DayLifeAPI.Data.Topic objTopic;
DayLifeAPI.Data.Article objArticle;
DayLifeAPI.Data.Quote objQuote;
DayLifeAPI.Data.SearchResult DayLifeSearchResult;
DayLifeAPI.DayRequest RequestAPI;
List SearchTopicTypes;
DateTime StartDate;
DateTime EndDate;
int Offset;
int Limit;
string Query;
// Create new daylife request api object
RequestAPI = new DayLifeAPI.DayRequest();
// Note your access key and shared secred need to be set in the DayRequest constructor
#region "Get Specific Topic Example"
//Example get specific topic
objTopic = RequestAPI.GetTopicByID("03yu9dZ7aa6lP");
//Or
objTopic = RequestAPI.GetTopicByName("Amitabh Bachchan");
//All done
//Check response data packet is valid
if (objTopic.prop_IsValid)
{
//The Topic object defines all the data as properties
//objTopic.prop_TopicID;
//objTopic.prop_TopicName;
if (objTopic.prop_TopicType == DayLifeAPI.Data.Topic.enum_TopicType.person) { /* do something */ };
if (objTopic.prop_TopicType == DayLifeAPI.Data.Topic.enum_TopicType.place) { /* do something */ };
if (objTopic.prop_TopicType == DayLifeAPI.Data.Topic.enum_TopicType.organization) { /* do something */ };
if (objTopic.prop_TopicType == DayLifeAPI.Data.Topic.enum_TopicType.Unknown) { /* something is wrong */ };
//objTopic.prop_DaylifeUrl;
if (objTopic.prop_HasWikipediaInfo)
{
//objTopic.prop_WikipediaURL;
//objTopic.prop_WikipediaAbstract;
}
}
else
{
// Something is wrong no data recieved - Usually topic ID or topic name is invalid, or possibly http error (501 bad gateway)
}
#endregion
#region "Get specific article example"
//Example get specific article
objArticle = RequestAPI.GetArticle("06px1XH1su3mv");
//All done
//Check response data packet is valid
if (objArticle.prop_IsValid)
{
//The Article object defines all the data as properties
//objArticle.prop_ArticleID;
//objArticle.prop_ArticleDate;
//objArticle.prop_URL;
//objArticle.prop_DaylifeURL;
//objArticle.prop_Headline;
//objArticle.prop_Excerpt;
//objArticle.prop_TimeStamp;
if (objArticle.prop_Source.prop_IsValid)
{
//objArticle.prop_Source.prop_SourceID;
//objArticle.prop_Source.prop_Name;
//objArticle.prop_Source.prop_URL;
//objArticle.prop_Source.prop_DaylifeURL;
//objArticle.prop_Source.prop_Rank;
//objArticle.prop_Source.prop_SourceType;
}
}
else
{
// Something is wrong no data recieved - Usually article ID is invalid, or possibly http error (501 bad gateway)
}
#endregion
#region "Get specific quote example"
//Example get specific quote
objQuote = RequestAPI.GetQuote("09XH5Db7uO7sq");
//All done
//Check response data packet is valid
if (objQuote.prop_IsValid)
{
//The Quote object defines all the data as properties
//objQuote.prop_QuoteID;
//objQuote.prop_QuoteText;
//objQuote.prop_QuoteDate;
//objQuote.prop_DaylifeURL;
//objQuote.prop_ArticleID;
if (objQuote.prop_Source.prop_IsValid)
{
//objQuote.prop_Source.prop_SourceID;
//objQuote.prop_Source.prop_Name;
//objQuote.prop_Source.prop_URL;
//objQuote.prop_Source.prop_DaylifeURL;
//objQuote.prop_Source.prop_Rank;
//objQuote.prop_Source.prop_SourceType;
}
//This is a special one
//The following property will make a request and get the article the first time it is accessed
//objQuote.prop_Article;
//objQuote.prop_Article.prop_Headline
//etc...
}
else
{
// Something is wrong no data recieved - Usually quote ID is invalid, or possibly http error (501 bad gateway)
}
#endregion
//---------Searching---------
// Search Types Implemented
//
// SearchRelatedTopics
// SearchMatchingTopics
// SearchRelatedArticles
// SearchRelatedQuotes
// SearchQuotesAbout
// SearchQuotesBy
// TopicGetRelatedTopicsByID
// TopicGetRelatedQuotesByID
// TopicGetRelatedArticlesByID
// TopicGetRelatedTopicsByName
// TopicGetRelatedQuotesByName
// TopicGetRelatedArticlesByName
// QuoteGetRelatedTopics
// QuoteGetRelatedQuotes
// QuoteGetRelatedArticles
// ArticleGetTopics
// ArticleGetRelatedTopics
// ArticleGetRelatedQuotes
// ArticleGetRelatedArticles
// ArticleGetQuotes
// Search Types NOT Implemented - I felt lazy
// TopicGetTimeLineByID
// TopicGetTimeLineByName
// Common parameter set that we will use in all the example calls that follow;
StartDate = ((DateTime)DateTime.Now.Subtract(TimeSpan.FromDays(30))).Date;
EndDate = DateTime.Now.AddDays(1);
Offset = 0;
Limit = 10;
#region "Example Search Call - Topic Get Related Topics By Topic Name"
Query = "Amitabh Bachchan";
SearchTopicTypes = new List();
SearchTopicTypes.Add(DayLifeAPI.Data.Topic.enum_TopicType.person);
SearchTopicTypes.Add(DayLifeAPI.Data.Topic.enum_TopicType.place);
DayLifeSearchResult = RequestAPI.Search(DayRequest.enum_DayRequestSearchType.TopicGetRelatedTopicsByName, Query, DayRequest.enum_SortOrder.relevance, SearchTopicTypes, StartDate, EndDate, Offset, Limit);
if (DayLifeSearchResult.prop_Success)
{
MessageBox.Show(string.Concat("Success, Topics found = ", DayLifeSearchResult.prop_SearchTopicsList.Count.ToString()));
foreach (DayLifeAPI.Data.Topic RelatedTopic in DayLifeSearchResult.prop_SearchTopicsList)
{
MessageBox.Show(string.Concat("Topic Name: ", RelatedTopic.prop_TopicName));
MessageBox.Show(string.Concat("Topic ID: ", RelatedTopic.prop_TopicID));
//And so on RelatedTopic.prop_TopicType, RelatedTopic.prop_DaylifeUrl etc....
}
}
else
{
MessageBox.Show(string.Concat("Failed, Error Code = ", DayLifeSearchResult.prop_ResultCode));
MessageBox.Show(string.Concat("Failed, Error Message = ", DayLifeSearchResult.prop_ResultMessage));
}
#endregion
#region "Example Search Call - Topic Get TimeLine By Topic ID"
Query = "03yu9dZ7aa6lP";
DayLifeSearchResult = RequestAPI.Search(DayRequest.enum_DayRequestSearchType.TopicGetRelatedArticlesByID, Query, DayRequest.enum_SortOrder.date, null, StartDate, EndDate, Offset, Limit);
if (DayLifeSearchResult.prop_Success)
{
MessageBox.Show(string.Concat("Success, Articles found = ", DayLifeSearchResult.prop_SearchArticlesList.Count.ToString()));
foreach (DayLifeAPI.Data.Article RelatedArticle in DayLifeSearchResult.prop_SearchArticlesList)
{
//Do stuff with
//RelatedArticle.prop_ArticleDate;
//RelatedArticle.prop_ArticleID;
//RelatedArticle.prop_Headline;
//RelatedArticle.prop_Excerpt;
//etc....
}
}
else
{
MessageBox.Show(string.Concat("Failed, Error Code = ", DayLifeSearchResult.prop_ResultCode));
MessageBox.Show(string.Concat("Failed, Error Message = ", DayLifeSearchResult.prop_ResultMessage));
}
#endregion
#region "Example Search Call - Topic Get Related Articles By Topic ID"
Query = "Amitabh Bachchan";
DayLifeSearchResult = RequestAPI.Search(DayRequest.enum_DayRequestSearchType.TopicGetRelatedQuotesByName, Query, DayRequest.enum_SortOrder.relevance, null, StartDate, EndDate, Offset, Limit);
if (DayLifeSearchResult.prop_Success)
{
MessageBox.Show(string.Concat("Success, Quotes found = ", DayLifeSearchResult.prop_SearchQuotesList.Count.ToString()));
foreach (DayLifeAPI.Data.Quote RelatedQuote in DayLifeSearchResult.prop_SearchQuotesList)
{
// Do stuff with
//RelatedQuote.prop_QuoteID;
//RelatedQuote.prop_QuoteText;
//RelatedQuote.prop_Source.prop_Name;
//RelatedQuote.prop_Source.prop_SourceID;
//RelatedQuote.prop_ArticleID;
//RelatedQuote.prop_Article.prop_ArticleDate;
//RelatedQuote.prop_Article.prop_Headline;
//etc...
}
}
else
{
MessageBox.Show(string.Concat("Failed, Error Code = ", DayLifeSearchResult.prop_ResultCode));
MessageBox.Show(string.Concat("Failed, Error Message = ", DayLifeSearchResult.prop_ResultMessage));
}
#endregion