Class: Replyr::BounceAddress

Inherits:
Object
  • Object
show all
Includes:
AddressBuilder
Defined in:
lib/replyr/bounce_address.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AddressBuilder

class_from_normalized_model_name, #create_token, #ensure_valid_token!, get_parsed_address, #id_from_model, #normalized_model_name, #token_valid?

Constructor Details

#initialize(model) ⇒ BounceAddress

Create a new reply address from a given user and model



11
12
13
# File 'lib/replyr/bounce_address.rb', line 11

def initialize(model)
  @model = model
end

Instance Attribute Details

#modelObject

Returns the value of attribute model.



7
8
9
# File 'lib/replyr/bounce_address.rb', line 7

def model
  @model
end

Class Method Details

.new_from_address(address) ⇒ Object

Create a reply address from a given address string Checks for validity of address and raises an ArgumentError if it’s invalid.



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/replyr/bounce_address.rb', line 19

def self.new_from_address(address)
  parts = AddressBuilder.get_parsed_address(address)

  model_class = AddressBuilder.class_from_normalized_model_name(parts[:model_name])
  model = model_class.find(parts[:model_id])

  address = new(model)
  address.ensure_valid_token!(parts[:token])
  address
rescue
  Replyr.logger.warn "Bounce email address invalid."
  nil
end

Instance Method Details

#addressObject Also known as: to_s

Returns the address string (e.g bounce-newsletter-12-01ce26dc69094af9246ea7e7ce9970aff2b81cc9@bounce.example.com)



42
43
44
45
46
47
48
# File 'lib/replyr/bounce_address.rb', line 42

def address
  model_id = id_from_model(@model)
  model_name = normalized_model_name(@model)

  local_part = [Replyr.config.bounce_prefix, model_name, model_id, token].join("-")
  "#{local_part}@#{Replyr.config.bounce_host}"
end

#tokenObject

Returs the token from this address



35
36
37
# File 'lib/replyr/bounce_address.rb', line 35

def token
  create_token(@model)
end