예제 #1
1
    /// <summary> 
    /// This function is used to find an instance of a single song
    /// </summary>
    /// <param name="query">Query submitted by the user to retrieve information</param>
    /// <param name="key">Api Key</param>
    /// <param name="fileFormat">the format of the Output i.e either JSON or XML</param>
    /// <returns> return the String format of the custom JSON or XML object created</returns> 
    public string singleSongSearch(string query, string key, string fileFormat)
    {
        String apiCall = "http://tinysong.com/a/" + query + "?format=json&key=" + key;
        String outputString = "";
        SingleSong singleSong = null;
        using (WebClient wc = new WebClient())
        {

            string json = wc.DownloadString(apiCall);
            singleSong = new SingleSong();
            singleSong.url = json;
        }
        String oupForm = fileFormat;
        oupForm = oupForm.ToUpper();
        if (oupForm.Equals("JSON"))
        {
            outputString = JsonConvert.SerializeObject(singleSong);
        }
        else if (oupForm.Equals("XML"))
        {
            outputString = JsonConvert.SerializeObject(singleSong);
            XmlDocument doc = (XmlDocument)JsonConvert.DeserializeXmlNode(outputString);
            StringWriter strWriter = new StringWriter();
            XmlTextWriter xmlWriter = new XmlTextWriter(strWriter);
            doc.WriteTo(xmlWriter);
            outputString = strWriter.ToString();
        }
        else
        {
            outputString = "Invalid File format requested";
        }
        return outputString;
    }
예제 #2
0
 public BBResponse(SongParameters song)
 {
     responseType = new SingleSong(song);
 }