public void Post(MailchimpConfigurationRequest request) { try { MailchimpConnectorConfig mailchimpConnectorConfig = new MailchimpConnectorConfig(); mailchimpConnectorConfig.MailchimpApiKey = request.ApiKey; using (var testConnectionClient = new MailchimpListClient(mailchimpConnectorConfig, new HttpClient())) { testConnectionClient.GetLists(); } } catch (Exception ex) { Log.Write(ex, TraceEventType.Error); throw new Exception(Res.Get <Labels>().UnableToConnectCheckYourCredentials); } var configManager = ConfigManager.GetManager(); var config = configManager.GetSection <MailchimpConnectorConfig>(); config.Enabled = true; config.MailchimpApiKey = request.ApiKey; configManager.SaveSection(config, true); }
/// <summary> /// Checks whether the Mailchimp config has the required settings for the connector to work. /// </summary> /// <param name="mailchimpConnectorConfig">The Mailchimp config object.</param> /// <returns>Returns true if the config has the required settings for the connector. Otherwise, false.</returns> private bool MailchimpConfigHasRequiredSettings(MailchimpConnectorConfig mailchimpConnectorConfig) { if (string.IsNullOrWhiteSpace(mailchimpConnectorConfig.MailchimpApiKey)) { return(false); } if (!mailchimpConnectorConfig.Enabled) { return(false); } return(true); }
/// <summary> /// Initializes a new instance of the <see cref="MailchimpListClient"/> class. /// </summary> /// <param name="mailchimpConnectorConfig">The Mailchimp connector configuration</param> /// <param name="httpClient">The http client used</param> /// <param name="formUrlBuilder">The form URL builder</param> internal MailchimpListClient(MailchimpConnectorConfig mailchimpConnectorConfig, HttpClient httpClient) { if (mailchimpConnectorConfig == null) { throw new ArgumentNullException("mailchimpConnectorConfig"); } if (httpClient == null) { throw new ArgumentNullException("httpClient"); } this.apiKey = mailchimpConnectorConfig.MailchimpApiKey; string apiUrl = this.GetApiUrl(this.apiKey); this.httpClient = httpClient; this.httpClient.BaseAddress = new Uri(apiUrl, UriKind.Absolute); string authorizationHeaderValue = this.GetAuthorizationHeaderValue(this.apiKey); this.DecorateHeaders(this.httpClient, MailchimpListClient.ApplicationJsonContentType, authorizationHeaderValue); }
/// <summary> /// Checks whether the Mailchimp config has the required settings for the connector to work. /// </summary> /// <returns>Returns true if the config has the required settings for the connector. Otherwise, false.</returns> private bool MailchimpConfigHasRequiredSettings() { MailchimpConnectorConfig mailchimpConnectorConfig = Config.Get <MailchimpConnectorConfig>(); return(this.MailchimpConfigHasRequiredSettings(mailchimpConnectorConfig)); }
/// <summary> /// Initializes a new instance of the <see cref="MailchimpConnectorDataMappingExtender"/> class. /// </summary> /// <param name="mailchimpFormsProvider">The <see cref="IMailchimpListProvider"/> instance that will be used in the class.</param> /// <param name="mailchimpConnectorConfig">The <see cref="MailchimpConnectorConfig"/> instance that will be used in the class.</param> internal MailchimpConnectorDataMappingExtender(IMailchimpListProvider mailchimpListProvider, MailchimpConnectorConfig mailchimpConnectorConfig) { this.mailchimpListProvider = mailchimpListProvider; this.mailchimpConnectorConfig = mailchimpConnectorConfig; }