public async Task <ActionResult> Index() { var options = new CampaignRequest { ListId = "f809a0eba9", Status = CampaignStatus.Save, SortOrder = CampaignSortOrder.DESC, Limit = 10 }; ViewBag.ListId = "f809a0eba9"; try { var model = await Manager.Campaigns.GetAllAsync(options); return(View(model)); } catch (MailChimpException mce) { return(new HttpStatusCodeResult(HttpStatusCode.BadGateway, mce.Message)); } catch (Exception ex) { return(new HttpStatusCodeResult(HttpStatusCode.ServiceUnavailable, ex.Message)); } }
public CampaignRetrieveResult GetCampaign(int campaignId) { var url = $"{this._baseUrl}/campaigns/viewCampaign/"; var request = new CampaignRequest { ApiKey = this._apiKey, CampaignId = campaignId }; var xmlRequest = this._parser.Serialize(request); var httpResponse = this._httpClient.Request(url, xmlRequest); if (httpResponse.Status != HttpStatus.Successful) { return(new CampaignRetrieveResult { Status = Status.Error, Message = "Http error" }); } var campaignResult = this._parser.Deserialize <CampaignRetrieveResult>(httpResponse.Result); return(campaignResult); }
private static AimeRequest DecodeCampaignRequest(ref ReadOnlySpan <byte> packet) { var request = new CampaignRequest(); DecodeMetadata(request, ref packet); return(request); }
public static CampaignResponse CreateCampaign(string apiUrl, CampaignRequest content) { ApiRequest request = new ApiRequest("Campaign/Create"); request.Content = content; ApiProxy proxy = new ApiProxy(apiUrl); return(proxy.PostRequest <CampaignResponse>(request)); }
public async Task <ActionResult> Drafts(string id = null) { var options = new CampaignRequest { ListId = id, Status = CampaignStatus.Save, SortOrder = CampaignSortOrder.DESC, Limit = 10, }; ViewBag.Lists = await Manager.Lists.GetAllAsync(); //ViewBag.Clicks = GetOpens().Result; //14d2abf97d //var model = await Manager.Campaigns.GetAllAsync(options); //return View(model); var sortedList = await Manager.Campaigns.GetAllAsync(options); var newCampaignList = new List <CCampaign>(); foreach (var Campaign in sortedList) { var newCampaign = new CCampaign { CampaignName = Campaign.Settings.Title, //newCampaign.ClickRate = Clicks(Campaign.Id).Result; OpenRate = await Manager.Reports.GetCampaignOpenReportCountAsync(Campaign.Id), Id = Campaign.Id, //newCampaign.UnsubRate = await Manager.Reports.GetUnsubscribesCountAsync(id); ListName = Campaign.Recipients.ListName, DateCreated = Campaign.CreateTime.ToString("dd MMMM yyyy"), URL = Campaign.ArchiveUrl, EmailsSent = Campaign.EmailsSent, ListId = Campaign.Recipients.ListId }; newCampaignList.Add(newCampaign); } newCampaignList.OrderBy(camp => camp.DateCreated); Audience audience = new Audience { CampaignList = newCampaignList }; ViewBag.Lists = await Manager.Lists.GetAllAsync(); return(View(audience)); }
/// <summary> /// The get all. /// </summary> /// <param name="request"> /// The request. /// </param> /// <exception cref="ArgumentNullException"> /// The <paramref> /// <name>requestUri</name> /// </paramref> /// was null. /// </exception> /// <returns> /// The <see cref="Task"/>. /// </returns> /// <exception cref="UriFormatException">In the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, <see cref="T:System.FormatException" />, instead.<paramref name="uriString" /> is empty.-or- The scheme specified in <paramref name="uriString" /> is not correctly formed. See <see cref="M:System.Uri.CheckSchemeName(System.String)" />.-or- <paramref name="uriString" /> contains too many slashes.-or- The password specified in <paramref name="uriString" /> is not valid.-or- The host name specified in <paramref name="uriString" /> is not valid.-or- The file name specified in <paramref name="uriString" /> is not valid. -or- The user name specified in <paramref name="uriString" /> is not valid.-or- The host or authority name specified in <paramref name="uriString" /> cannot be terminated by backslashes.-or- The port number specified in <paramref name="uriString" /> is not valid or cannot be parsed.-or- The length of <paramref name="uriString" /> exceeds 65519 characters.-or- The length of the scheme specified in <paramref name="uriString" /> exceeds 1023 characters.-or- There is an invalid character sequence in <paramref name="uriString" />.-or- The MS-DOS path specified in <paramref name="uriString" /> must start with c:\\.</exception> /// <exception cref="ArgumentOutOfRangeException">Enlarging the value of this instance would exceed <see cref="P:System.Text.StringBuilder.MaxCapacity" />. </exception> /// <exception cref="MailChimpException"> /// Custom Mail Chimp Exception /// </exception> /// <exception cref="NotSupportedException"><paramref name="element" /> is not a constructor, method, property, event, type, or field. </exception> /// <exception cref="TypeLoadException">A custom attribute type cannot be loaded. </exception> public async Task <CampaignResponse> GetResponseAsync(CampaignRequest request = null) { using (var client = this.CreateMailClient("campaigns")) { var response = await client.GetAsync(request?.ToQueryString()).ConfigureAwait(false); await response.EnsureSuccessMailChimpAsync().ConfigureAwait(false); var campaignResponse = await response.Content.ReadAsAsync <CampaignResponse>().ConfigureAwait(false); return(campaignResponse); } }
public async Task <IEnumerable <Campaign> > GetAll(CampaignRequest request = null) { using (var client = CreateMailClient("campaigns")) { var response = await client.GetAsync(request?.ToQueryString()); await response.EnsureSuccessMailChimpAsync(); var campaignResponse = await response.Content.ReadAsAsync <CampaignResponse>(); return(campaignResponse.Campaigns); } }
public CampaignSubscriberResult GetBounces(int campaignId, DateFilter filter) { if (filter == null) { return(new CampaignSubscriberResult { Status = Status.Error, Message = "Filter is null" }); } var url = $"{this._baseUrl}/campaigns/listBounces/"; var request = new CampaignRequest { ApiKey = this._apiKey, CampaignId = campaignId, }; if (filter.FromDate.HasValue) { request.FromDate = filter.FromDate.Value; } if (filter.ToDate.HasValue) { request.ToDate = filter.ToDate.Value; } var xmlRequest = this._parser.Serialize(request); var httpResponse = this._httpClient.Request(url, xmlRequest); if (httpResponse.Status != HttpStatus.Successful) { return(new CampaignSubscriberResult { Status = Status.Error, Message = "Http error" }); } var subscriberResult = this._parser.Deserialize <CampaignSubscriberResult>(httpResponse.Result); return(subscriberResult); }
public void SerializeCampaignsRequest() { // Serialize request test for following api methods: // -GetOpenedEmails // -GetUnsubscribers // -GetBounces IXmlParser xmlParser = new DefaultXmlParser(); var request = new CampaignRequest { ApiKey = "44-121312131223", CampaignId = 4124 }; var requestXml = xmlParser.Serialize(request); var xml = File.ReadAllText("CampaignsRequest.xml"); Assert.AreEqual(xml, requestXml); }
public async Task <IEnumerable <Campaign> > GetAll(CampaignRequest request = null) { try { using (var client = CreateMailClient("campaigns")) { var response = await client.GetAsync(request?.ToQueryString()); response.EnsureSuccessStatusCode(); var campaignResponse = await response.Content.ReadAsAsync <CampaignResponse>(); return(campaignResponse.Campaigns); } } catch (Exception ex) { } return(null); }
public ActionResult Create(Campaign newCampaign) { string message = string.Empty; // Setup our new campaign newCampaign.UserId = Convert.ToInt32(Request.Cookies[Constants._COOKIE_NAME_].Values.Get(Constants._COOKIE_USER_ID_)); newCampaign.CreateDate = DateTime.Now; // Create our campaign request CampaignRequest request = new CampaignRequest(); request.UserToken = User.Identity.Name; request.Campaign = newCampaign; try { // Send response to create the new campaign CampaignResponse response = CampaignApiProxy.CreateCampaign(SSConfiguration.WebApiUrl, request); if (response.Success) { return(RedirectToAction("Profile", "User", new { id = response.Campaign.UserId })); } else { return(View(response.Message)); } } catch (System.Web.Http.HttpResponseException) { // Should be - HttpResponseException return(RedirectToAction("Logout", "Account")); } catch (Exception e) { message = e.Message; } return(View(message)); }
/// <summary> /// The get all. /// </summary> /// <param name="request"> /// The request. /// </param> /// <exception cref="ArgumentNullException"> /// The <paramref> /// <name>requestUri</name> /// </paramref> /// was null. /// </exception> /// <returns> /// The <see cref="Task"/>. /// </returns> /// <exception cref="UriFormatException">In the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, <see cref="T:System.FormatException" />, instead.<paramref name="uriString" /> is empty.-or- The scheme specified in <paramref name="uriString" /> is not correctly formed. See <see cref="M:System.Uri.CheckSchemeName(System.String)" />.-or- <paramref name="uriString" /> contains too many slashes.-or- The password specified in <paramref name="uriString" /> is not valid.-or- The host name specified in <paramref name="uriString" /> is not valid.-or- The file name specified in <paramref name="uriString" /> is not valid. -or- The user name specified in <paramref name="uriString" /> is not valid.-or- The host or authority name specified in <paramref name="uriString" /> cannot be terminated by backslashes.-or- The port number specified in <paramref name="uriString" /> is not valid or cannot be parsed.-or- The length of <paramref name="uriString" /> exceeds 65519 characters.-or- The length of the scheme specified in <paramref name="uriString" /> exceeds 1023 characters.-or- There is an invalid character sequence in <paramref name="uriString" />.-or- The MS-DOS path specified in <paramref name="uriString" /> must start with c:\\.</exception> /// <exception cref="ArgumentOutOfRangeException">Enlarging the value of this instance would exceed <see cref="P:System.Text.StringBuilder.MaxCapacity" />. </exception> /// <exception cref="MailChimpException"> /// Custom Mail Chimp Exception /// </exception> /// <exception cref="NotSupportedException"><paramref name="element" /> is not a constructor, method, property, event, type, or field. </exception> /// <exception cref="TypeLoadException">A custom attribute type cannot be loaded. </exception> public async Task <IEnumerable <Campaign> > GetAllAsync(CampaignRequest request = null) { return((await this.GetResponseAsync(request).ConfigureAwait(false))?.Campaigns); }
private CampaignResponse Campaign(CampaignRequest request) { return(Ok(new CampaignResponse())); }
public CampaignServiceResponse <Campaign> GetCampaigns(CampaignRequest req, List <ServiceLogRecord> logRecords = null) { var response = new CampaignServiceResponse <Campaign>(); var campaigns = new List <Campaign>(); #region [ Envelope settings ] // Create the including fields according to the envelope var includes = new List <string>(); includes.Add("CampaignProperties"); #endregion #region [ Filters ] // Check for filters Expression <Func <Campaign, bool> > filterPredicate = PredicateBuilder.New <Campaign>(true); // Add the filters if (req.CampaignIds.Any()) { filterPredicate = filterPredicate.And(r => req.CampaignIds.Contains(r.CampaignID)); } if (req.CampaignTypes.Any()) { filterPredicate = filterPredicate.And(m => req.CampaignTypes.Contains(m.DiscountType)); } if (req.RelatedDataEntityIds.Any()) { filterPredicate = filterPredicate.And(m => req.RelatedDataEntityIds.Contains(m.RelatedDataEntityID)); } if (req.RelatedDataEntityTypes.Any()) { filterPredicate = filterPredicate.And(m => req.RelatedDataEntityTypes.Contains(m.RelatedDataEntityName)); } if (req.CampaignProperties.Any()) { var propertyFilter = req.CampaignProperties.Select(p => p.Key + "|" + p.Value).ToList(); filterPredicate = filterPredicate.And(d => d.CampaignProperties.Select(dp => dp.Key + "|" + dp.Value).Intersect(propertyFilter).Any()); } #endregion // Make the query if (filterPredicate.Parameters.Count > 0) { campaigns = _CampaignServiceBase.GetIncluding(filterPredicate, includes.ToArray()).Result; } else { campaigns = _CampaignServiceBase.GetAllIncluding(includes.ToArray()).Result; } response.Type = Headstone.Common.ServiceResponseTypes.Success; response.Result = campaigns; return(response); }
public CampaignResponse Create(CampaignRequest request) { AuthenticateUserToken(request.UserToken); return(MyCampaignService.Create(request.Campaign)); }