Class: Minfraud::Components::Email

Inherits:
Base
  • Object
show all
Defined in:
lib/minfraud/components/email.rb

Overview

Email corresponds to the email object of a minFraud request.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Email

Returns a new instance of Email.

Parameters:

  • params (Hash) (defaults to: {})

    Hash of parameters. Each key/value should correspond to one of the available attributes.



36
37
38
39
40
41
42
# File 'lib/minfraud/components/email.rb', line 36

def initialize(params = {})
  @address      = params[:address]
  @domain       = params[:domain]
  @hash_address = params[:hash_address]

  validate
end

Instance Attribute Details

#addressString?

This field must be either be a valid email address or an MD5 of the lowercased email used in the transaction. Important: if using the MD5 hash, please be sure to convert the email address to lowercase before calculating its MD5 hash. Instead of converting an address to an MD5 hash yourself, please use the hash_address attribute in this class.

Returns:

  • (String, nil)


21
22
23
# File 'lib/minfraud/components/email.rb', line 21

def address
  @address
end

#domainString?

The domain of the email address used in the transaction.

Returns:

  • (String, nil)


26
27
28
# File 'lib/minfraud/components/email.rb', line 26

def domain
  @domain
end

#hash_addressBoolean?

By default, the address will be sent in plain text. If this is set true, the address will instead be sent as an MD5 hash.

Returns:

  • (Boolean, nil)


32
33
34
# File 'lib/minfraud/components/email.rb', line 32

def hash_address
  @hash_address
end

Instance Method Details

#to_json(*_args) ⇒ Hash

A JSON representation of Minfraud::Components::Email.

Returns:

  • (Hash)


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/minfraud/components/email.rb', line 47

def to_json(*_args)
  json = super

  if json['address'] && !json['domain']
    _, domain = address.split('@', 2)
    if domain
      domain         = clean_domain(domain)
      json['domain'] = domain if domain
    end
  end

  if json.delete('hash_address') && json['address']
    hash = hash_email_address(json['address'])

    # We could consider clearing the key if !hash.
    json['address'] = hash if hash
  end

  json
end