// Tasteometer.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.Collections.Generic; using System.Xml; namespace Lastfm.Services { /// /// Compare Last.fm users and others. /// public class Tasteometer : Base { private string firstType {get; set;} private string firstValue {get; set;} private string secondType {get; set;} private string secondValue {get; set;} internal override RequestParameters getParams () { RequestParameters p = new Lastfm.RequestParameters(); p["type1"] = firstType; p["type2"] = secondType; p["value1"] = firstValue; p["value2"] = secondValue; return p; } /// /// Compare a user with another user. /// /// /// A /// /// /// A /// /// /// A /// public Tasteometer(User firstUser, User secondUser, Session session) :base(session) { firstType = "user"; secondType = "user"; firstValue = firstUser.Name; secondValue = secondUser.Name; } /// /// Compare a list of artists with another list of artists. /// /// /// A /// /// /// A /// /// /// A /// public Tasteometer(IEnumerable firstArtists, IEnumerable secondArtists, Session session) :base(session) { firstType = "artists"; secondType = "artists"; foreach(Artist artist in firstArtists) firstValue += "," + artist.Name; foreach(Artist artist in secondArtists) secondValue += "," + artist.Name; } /// /// Compare a myspace profile with another. /// /// /// A /// /// /// A /// /// /// A /// public Tasteometer(string firstMyspaceURL, string secondMyspaceURL, Session session) :base(session) { firstType = "myspace"; secondType = "myspace"; firstValue = firstMyspaceURL; secondValue = secondMyspaceURL; } /// /// Compare a user with a list of artists. /// /// /// A /// /// /// A /// /// /// A /// public Tasteometer(User user, IEnumerable artists, Session session) :base(session) { firstType = "user"; secondType = "artists"; firstValue = user.Name; foreach(Artist artist in artists) secondValue += "," + artist.Name; } /// /// Compare a user with a myspace profile. /// /// /// A /// /// /// A /// /// /// A /// public Tasteometer(User user, string myspaceURL, Session session) :base(session) { firstType = "user"; secondType = "myspace"; firstValue = user.Name; secondValue = myspaceURL; } /// /// Compare a list of artists with a myspace profile. /// /// /// A /// /// /// A /// /// /// A /// public Tasteometer(IEnumerable artists, string myspaceURL, Session session) :base(session) { firstType = "artists"; secondType = "myspace"; foreach(Artist artist in artists) firstValue += "," + artist.Name; secondValue = myspaceURL; } /// /// Returns the comparison percentage. /// /// /// A /// public float GetScore() { XmlDocument doc = request("tasteometer.compare"); return float.Parse(extract(doc, "score")); } /// /// Returns the shared artits. /// /// /// A /// public Artist[] GetSharedArtists() { // default limit value return GetSharedArtists(5); } /// /// Returns the shared artists. /// /// /// A /// /// /// A /// public Artist[] GetSharedArtists(int limit) { RequestParameters p = getParams(); p["limit"] = limit.ToString(); XmlDocument doc = request("tasteometer.compare", p); List list = new List(); foreach(XmlNode node in doc.GetElementsByTagName("artist")) list.Add(new Artist(node, base.Session)); return list.ToArray(); } } }