// Event.cs
//
// Copyright (C) 2008 Amr Hassan
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
//
using System;
using System.Xml;
using System.Collections.Generic;
namespace Lastfm.Services
{
///
/// A Last.fm event.
///
public class Event : Base, IEquatable, IShareable, IHasImage, IHasURL
{
///
/// The event ID.
///
public int ID {get; private set;}
public Event(int id, Session session)
:base(session)
{
ID = id;
}
internal override RequestParameters getParams ()
{
RequestParameters p = new Lastfm.RequestParameters();
p["event"] = ID.ToString();
return p;
}
///
/// Set the authenticated user's status for this event.
///
///
/// A
///
public void SetAttendance(EventAttendance attendance)
{
requireAuthentication();
RequestParameters p = getParams();
int i = (int)attendance;
p["status"] = i.ToString();
request("event.attend", p);
}
///
/// Returns the title of the event.
///
///
/// A
///
public string GetTitle()
{
XmlDocument doc = request("event.getInfo");
return extract(doc, "title");
}
///
/// Returns the participating artists in this event.
///
///
/// A
///
public Artist[] GetArtists()
{
XmlDocument doc = request("event.getInfo");
List list = new List();
foreach(string name in extractAll(doc, "artist"))
list.Add(new Artist(name, Session));
return list.ToArray();
}
///
/// Returns the headliner artist.
///
///
/// A
///
public Artist GetHeadliner()
{
XmlDocument doc = request("event.getInfo");
return new Artist(extract(doc, "headliner"), Session);
}
///
/// Returns the start time of the event.
///
///
/// A
///
public DateTime GetStartDate()
{
XmlDocument doc = request("event.getInfo");
return DateTime.Parse(extract(doc, "startDate"));
}
///
/// Returns the description of the evnet.
///
///
/// A
///
public string GetDescription()
{
XmlDocument doc = request("event.getInfo");
return extract(doc, "description");
}
///
/// Returns the url to the image of this event.
///
///
/// A
///
///
/// A
///
public string GetImageURL(ImageSize size)
{
XmlDocument doc = request("event.getInfo");
return extractAll(doc, "image")[(int)size];
}
///
/// Returns the url to the image of this event.
///
///
/// A
///
public string GetImageURL()
{
return GetImageURL(ImageSize.Large);
}
///
/// Returns the number of attendees.
///
///
/// A
///
public int GetAttendantCount()
{
XmlDocument doc = request("event.getInfo");
return Int32.Parse(extract(doc, "attendance"));
}
///
/// Returns the number of reviews for this event.
///
///
/// A
///
public int GetReviewCount()
{
XmlDocument doc = request("event.getInfo");
return Int32.Parse(extract(doc, "reviews"));
}
///
/// Returns the flickr tag.
///
///
/// You can tag your image on flickr with this tag and they would be imported into
/// the last.fm page for this event.
///
///
/// A
///
public string GetFlickrTag()
{
XmlDocument doc = request("event.getInfo");
return extract(doc, "tag");
}
///
/// Check to see if this object equals another.
///
///
/// A
///
///
/// A
///
public bool Equals(Event eventObject)
{
if(eventObject.ToString() == this.ToString())
return true;
else
return false;
}
///
/// Share this event with others.
///
///
/// A
///
///
/// A
///
public void Share(Recipients recipients, string message)
{
if (recipients.Count > 1)
{
foreach(string recipient in recipients)
{
Recipients r = new Recipients();
r.Add(recipient);
Share(r, message);
}
return;
}
requireAuthentication();
RequestParameters p = getParams();
p["recipient"] = recipients[0];
p["message"] = message;
request("event.Share", p);
}
///
/// Share this event with others.
///
///
/// A
///
public void Share(Recipients recipients)
{
if (recipients.Count > 1)
{
foreach(string recipient in recipients)
{
Recipients r = new Recipients();
r.Add(recipient);
Share(r);
}
return;
}
requireAuthentication();
RequestParameters p = getParams();
p["recipient"] = recipients[0];
request("event.Share", p);
}
///
/// Returns the Last.fm page of this object.
///
///
/// A
///
///
/// A
///
public string GetURL(SiteLanguage language)
{
string domain = getSiteDomain(language);
return "http://" + domain + "/event/" + ID.ToString();
}
///
/// The object's Last.fm page url.
///
public string URL
{ get { return GetURL(SiteLanguage.English); } }
///
/// The venue where the event is being held.
///
public Venue Venue
{
get
{
XmlDocument doc = request("event.getInfo");
string url = ((XmlElement)doc.GetElementsByTagName("venue")[0]).GetElementsByTagName("url")[0].InnerText;
int id = int.Parse(url.Substring(url.LastIndexOf('/') + 1));
return new Venue(id, Session);
}
}
}
}