Module: Millionsend

Defined in:
lib/millionsend.rb,
lib/millionsend/util.rb,
lib/millionsend/batch.rb,
lib/millionsend/error.rb,
lib/millionsend/usage.rb,
lib/millionsend/emails.rb,
lib/millionsend/topics.rb,
lib/millionsend/domains.rb,
lib/millionsend/request.rb,
lib/millionsend/version.rb,
lib/millionsend/api_keys.rb,
lib/millionsend/contacts.rb,
lib/millionsend/segments.rb,
lib/millionsend/webhooks.rb,
lib/millionsend/templates.rb,
lib/millionsend/broadcasts.rb,
lib/millionsend/suppressions.rb,
lib/millionsend/deliverability.rb,
lib/millionsend/contact_properties.rb

Overview

Ruby client for the MillionSend HTTP API. Configure once, then call the resource modules:

Millionsend.api_key  = "ms_..."
Millionsend.base_url = "https://mail.acme.dev"
Millionsend::Emails.send(from: "[email protected]", to: "[email protected]",
                       subject: "Hi", html: "<strong>it works</strong>")

api_key falls back to the MILLIONSEND_API_KEY env var; base_url to MILLIONSEND_BASE_URL and then MillionSend Cloud, so a self-hosted instance sets its own origin. Plain http is only accepted for loopback hosts unless allow_insecure_http is set, since the API key travels as a bearer header. Every call returns a symbol-keyed Hash on success and raises a Millionsend::Error on any non-2xx response.

Defined Under Namespace

Modules: ApiKeys, Batch, Broadcasts, ContactProperties, Contacts, Deliverability, Domains, Emails, Segments, Suppressions, Templates, Topics, Usage, Util, Webhooks Classes: AllRecipientsSuppressedError, ApplicationError, BroadcastsPausedError, ConcurrentIdempotentRequestsError, DailyQuotaExceededError, Error, InternalServerError, InvalidApiKeyError, InvalidIdempotentRequestError, MissingApiKeyError, NotFoundError, RateLimitExceededError, Request, RestrictedApiKeyError, SendingPausedError, ValidationError

Constant Summary collapse

DEFAULT_BASE_URL =
"https://api.millionsend.com"
USER_AGENT =
"millionsend-ruby/#{VERSION}"
ERROR_TYPES =
{
  "validation_error" => ValidationError,
  "all_recipients_suppressed" => AllRecipientsSuppressedError,
  "not_found" => NotFoundError,
  "missing_api_key" => MissingApiKeyError,
  "invalid_api_key" => InvalidApiKeyError,
  "restricted_api_key" => RestrictedApiKeyError,
  "sending_paused" => SendingPausedError,
  "broadcasts_paused" => BroadcastsPausedError,
  "rate_limit_exceeded" => RateLimitExceededError,
  "daily_quota_exceeded" => DailyQuotaExceededError,
  "invalid_idempotent_request" => InvalidIdempotentRequestError,
  "concurrent_idempotent_requests" => ConcurrentIdempotentRequestsError,
  "internal_server_error" => InternalServerError,
  "application_error" => ApplicationError,
}.freeze
VERSION =
"0.8.0"

Class Attribute Summary collapse

Class Attribute Details

.allow_insecure_http ⇒ Object

Returns the value of attribute allow_insecure_http.



42
43
44
# File 'lib/millionsend.rb', line 42

def allow_insecure_http
  @allow_insecure_http
end

.api_key ⇒ Object



44
45
46
# File 'lib/millionsend.rb', line 44

def api_key
  @api_key || ENV["MILLIONSEND_API_KEY"]
end

.base_url ⇒ Object



48
49
50
# File 'lib/millionsend.rb', line 48

def base_url
  @base_url || ENV["MILLIONSEND_BASE_URL"] || DEFAULT_BASE_URL
end