Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CakeMailRestClient"/> class.
        /// </summary>
        /// <param name="apiKey">The API Key received from CakeMail</param>
        /// <param name="host">The host where the API is hosted. The default is api.wbsrvc.com</param>
        /// <param name="httpClient">Allows you to inject your own HttpClient. This is useful, for example, to setup the HtppClient with a proxy</param>
        public CakeMailRestClient(string apiKey, string host = DEFAULT_HOST, HttpClient httpClient = null)
        {
            _mustDisposeHttpClient = httpClient == null;
            _httpClient            = httpClient;

            ApiKey    = apiKey;
            BaseUrl   = new Uri($"https://{host.TrimEnd('/')}/");
            Version   = typeof(CakeMailRestClient).GetTypeInfo().Assembly.GetName().Version.ToString();
            UserAgent = $"CakeMail .NET REST Client/{Version} (+https://github.com/Jericho/CakeMail.RestClient)";

            _fluentClient = new FluentClient(this.BaseUrl, httpClient)
                            .SetUserAgent(this.UserAgent);

            _fluentClient.BaseClient.DefaultRequestHeaders.Add("apikey", this.ApiKey);

            _fluentClient.Filters.Remove <DefaultErrorFilter>();
            _fluentClient.Filters.Add(new DiagnosticHandler());
            _fluentClient.Filters.Add(new CakeMailErrorHandler());

            Campaigns        = new Campaigns(_fluentClient);
            Clients          = new Clients(_fluentClient);
            Countries        = new Countries(_fluentClient);
            Permissions      = new Permissions(_fluentClient);
            Lists            = new Lists(_fluentClient);
            Timezones        = new Timezones(_fluentClient);
            Mailings         = new Mailings(_fluentClient);
            Relays           = new Relays(_fluentClient);
            Segments         = new Segments(_fluentClient);
            Users            = new Users(_fluentClient);
            SuppressionLists = new SuppressionLists(_fluentClient);
            Templates        = new Templates(_fluentClient);
            Triggers         = new Triggers(_fluentClient);
        }
Ejemplo n.º 2
0
 public void AddMail(string m)
 {
     Mailings.Add(m);
 }