Class: Mailgun::Address

Inherits:
Object
  • Object
show all
Defined in:
lib/mailgun/address.rb

Overview

Mailgun::Address is a simple interface to the Email Validation API.

Instance Method Summary collapse

Constructor Details

#initialize(api_key = "") ⇒ Address

Returns a new instance of Address

Parameters:

  • api_key (String) (defaults to: "")

    Mailgun API - public key


9
10
11
12
13
14
15
16
# File 'lib/mailgun/address.rb', line 9

def initialize(api_key = "")
  if api_key == "" then
    fail ParameterError.new('Public API key is required for Mailgun::Address.initialize()', nil)
  end

  @api_key = api_key
  @client = Mailgun::Client.new(api_key = api_key)
end

Instance Method Details

#parse(addresses, syntax_only = true) ⇒ Object

Parses a delimiter separated list of email addresses into two lists: parsed addresses and unparsable portions. The parsed addresses are a list of addresses that are syntactically valid (and optionally have DNS and ESP specific grammar checks) the unparsable list is a list of characters sequences that the parser was not able to understand. These often align with invalid email addresses, but not always. Delimiter characters are comma (,) and semicolon (;).

Parameters:

  • addresses (Array)

    Addresses to parse

  • syntax_only (TrueClass|FalseClass) (defaults to: true)

    Perform only syntax checks


36
37
38
39
40
41
42
# File 'lib/mailgun/address.rb', line 36

def parse(addresses, syntax_only = true)
  validate_addrs = addresses.join(";")

  res = @client.get "address/parse", {:addresses => validate_addrs,
                                      :syntax_only => syntax_only.to_s}
  return res.to_h!
end

#validate(address) ⇒ Object

Given an arbitrary address, validates it based on defined checks.

Parameters:

  • address (String)

    Email address to validate (max 512 chars.)


21
22
23
24
# File 'lib/mailgun/address.rb', line 21

def validate(address)
  res = @client.get "address/validate", {:address => address}
  return res.to_h!
end