/// <summary> /// Gets a com.esendex.sdk.optouts.OptOut instance containing an opt out. /// </summary> /// <param name="id">A System.Guid instance that contains the Id of an opt out.</param> /// <returns>A com.esendex.sdk.optouts.OptOut instance containing an opt out.</returns> /// <exception cref="System.Net.WebException"></exception> public OptOut GetById(Guid optOutId) { var requestUrl = new Uri(_baseUrl, string.Format("v1.0/optouts/{0}", optOutId)); var request = Request.Create("GET", requestUrl) .WithHeader("Authorization", "Basic " + _credentials.EncodedValue()) .WithAcceptHeader(Constants.JSON_MEDIA_TYPE) .If(_credentials.UseProxy, r => r.WithProxy(_credentials.WebProxy)); var response = request.GetResponse(); return(response.DeserialiseJson <OptOut>()); }
public SurveyResult Send(Guid surveyId, string recipient, Dictionary <string, string> templateFields = null, Dictionary <string, string> metaData = null) { var requestData = new SurveysAddRecipientsRequest { Recipients = new[] { new SurveysAddRecipientRequest { PhoneNumber = recipient, TemplateFields = templateFields, MetaData = metaData } } }; var requestUrl = new Uri(_baseUrl, string.Format("v1.0/surveys/{0}/send", surveyId)); var request = Request.Create("POST", requestUrl) .WithHeader("Authorization", "Basic " + _credentials.EncodedValue()) .WithAcceptHeader(Constants.JSON_MEDIA_TYPE) .If(_credentials.UseProxy, r => r.WithProxy(_credentials.WebProxy)) .WriteBody(Constants.JSON_MEDIA_TYPE, streamWriter => JsonSerializer.Create().Serialize(streamWriter, requestData)); HttpWebResponse response; try { response = request.GetResponse(); } catch (WebException ex) { response = (HttpWebResponse)ex.Response; if (response.StatusCode != HttpStatusCode.BadRequest) { throw; } } return(response.DeserialiseJson <SurveyResult>()); }