Uri INabaztagMessage.GenerateUrl(Nabaztag nab) { string url = NabaztagApiUrl; string queryString = this.GenerateQueryString(nab); if (!string.IsNullOrEmpty(queryString)) { url += "?" + queryString; } return new Uri(url); }
private string GenerateQueryString(Nabaztag nab) { string queryString = string.Empty; queryString += "sn=" + nab.SerialNumber; queryString += "&token=" + nab.Token; if (this.Speech != null) { queryString += "&voice=" + this.Speech.Voice; queryString += "&tts=" + this.Speech.Text; } if (this.RightEar.HasValue) { queryString += "&rightear=" + (int)this.RightEar.Value; } if (this.LeftEar.HasValue) { queryString += "&leftear=" + (int)this.LeftEar.Value; } if (this.RequestEarPosition) { queryString += "&ears=ok"; } string chor = string.Empty; foreach (Choreography choreography in this.Choreography) { chor += choreography + ","; } chor = chor.TrimEnd(','); if (!string.IsNullOrEmpty(chor)) { queryString += "&chor=" + chor; } return queryString; }
Uri INabaztagMessage.GenerateUrl(Nabaztag nab) { string url = NabaztagPodcastApiUrl; if (this.Podcasts.Count > 0) { string queryString = "sn=" + nab.SerialNumber; queryString += "&token=" + nab.Token; queryString += "&urlList="; foreach (Uri uri in this.Podcasts) { queryString += uri + "|"; } url += "?" + queryString.TrimEnd('|'); } return new Uri(url); }
/// <summary> /// Gets a <see cref="Nabaztag"/> object configured from the nabaztagSection in the config file. /// </summary> /// <param name="name">Name of the rabbit in the config file.</param> /// <returns></returns> /// <exception cref="ConfigurationErrorsException"></exception> public static Nabaztag GetRabbit(string name) { if (string.IsNullOrEmpty("name")) { throw new ArgumentNullException("name"); } Rabbit rabbit = Config.Rabbits[name]; if (rabbit == null) { throw new ConfigurationErrorsException("Configuration for rabbit " + name + " does not exist."); } Nabaztag nab = new Nabaztag(rabbit.Name, rabbit.Key, rabbit.SerialNumber, rabbit.Token); nab.Enabled = rabbit.Enabled; return nab; }