/// <summary> /// Create a new schedule for a campaign. /// </summary> /// <param name="accessToken">Constant Contact OAuth2 access token.</param> /// <param name="apiKey">The API key for the application</param> /// <param name="campaignId">Campaign id to be scheduled.</param> /// <param name="schedule">Schedule to be created.</param> /// <returns>Returns the schedule added.</returns> public Schedule AddSchedule(string accessToken, string apiKey, string campaignId, Schedule schedule) { Schedule sch = null; string url = String.Concat(Config.Endpoints.BaseUrl, String.Format(Config.Endpoints.CampaignSchedules, campaignId)); string json = schedule.ToJSON(); CUrlResponse response = RestClient.Post(url, accessToken, apiKey, json); if (response.HasData) { sch = Component.FromJSON<Schedule>(response.Body); } else if (response.IsError) { throw new CtctException(response.GetErrorMessage()); } return sch; }
/// <summary> /// Create a new schedule for a campaign. /// </summary> /// <param name="campaignId">Campaign id to be scheduled.</param> /// <param name="schedule">Schedule to be created.</param> /// <returns>Returns the schedule added.</returns> public Schedule AddSchedule(string campaignId, Schedule schedule) { if (string.IsNullOrEmpty(campaignId) || schedule == null) { throw new IllegalArgumentException(CTCT.Resources.Errors.ScheduleOrId); } string url = String.Concat(Settings.Endpoints.Default.BaseUrl, String.Format(Settings.Endpoints.Default.CampaignSchedules, campaignId)); string json = schedule.ToJSON(); RawApiResponse response = RestClient.Post(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey, json); try { var sch = response.Get<Schedule>(); return sch; } catch (Exception ex) { throw new CtctException(ex.Message, ex); } }
private void btnSave_Click(object sender, EventArgs e) { btnSave.Enabled = false; try { EmailCampaign campaign = CreateCampaignFromInputs(); EmailCampaign savedCampaign = _constantContact.AddCampaign(campaign); if (savedCampaign != null) { //campaign was saved, but need to schedule it, if the case Schedule schedule = null; if (rbnSendNow.Checked || rbnScheduled.Checked) { if (rbnSendNow.Checked) { schedule = new Schedule() { ScheduledDate = DateTime.Now }; } else { schedule = new Schedule() { ScheduledDate = Convert.ToDateTime(txtScheduleDate.Text.Trim()) }; } Schedule savedSchedule = _constantContact.AddSchedule(savedCampaign.Id, schedule); if (savedSchedule != null) { MessageBox.Show("Campaign successfully saved and scheduled!", "Success"); } else { MessageBox.Show("Campaign was saved, but failed to schedule it!", "Failure"); } } else { MessageBox.Show("Campaign successfully saved!", "Success"); } } else { MessageBox.Show("Failed to save campaign!", "Failure"); } } catch (IllegalArgumentException illegalEx) { MessageBox.Show(GetExceptionsDetails(illegalEx, "IllegalArgumentException"), "Exception"); } catch (CtctException ctcEx) { MessageBox.Show(GetExceptionsDetails(ctcEx, "CtctException"), "Exception"); } catch (OAuth2Exception oauthEx) { MessageBox.Show(GetExceptionsDetails(oauthEx, "OAuth2Exception"), "Exception"); } catch (Exception ex) { MessageBox.Show(GetExceptionsDetails(ex, "Exception"), "Exception"); } btnSave.Enabled = true; }
/// <summary> /// Update a specific schedule for a campaign. /// </summary> /// <param name="campaignId">Campaign id to be scheduled.</param> /// <param name="schedule">Schedule to retrieve.</param> /// <returns>Returns the updated schedule object.</returns> /// <exception cref="IllegalArgumentException">IllegalArgumentException</exception> public Schedule UpdateSchedule(string campaignId, Schedule schedule) { if (string.IsNullOrEmpty(campaignId) || schedule == null) { throw new IllegalArgumentException(Config.Errors.ScheduleOrId); } return CampaignScheduleService.AddSchedule(AccessToken, APIKey, campaignId, schedule); }
/// <summary> /// Update a specific schedule for a campaign. /// </summary> /// <param name="campaignId">Campaign id to be scheduled.</param> /// <param name="schedule">Schedule to retrieve.</param> /// <returns>Returns the updated schedule object.</returns> public Schedule UpdateSchedule(string campaignId, Schedule schedule) { string url = String.Concat(Settings.Endpoints.Default.BaseUrl, String.Format(Settings.Endpoints.Default.CampaignSchedule, campaignId, schedule.Id)); string json = schedule.ToJSON(); RawApiResponse response = RestClient.Put(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey, json); try { var upd = response.Get<Schedule>(); return upd; } catch (Exception ex) { throw new CtctException(ex.Message, ex); } }