Class: MailCapture::Capture

Inherits:
Object
  • Object
show all
Defined in:
lib/mailcapture/models.rb

Overview

A captured email.

email = mc.wait_for('signup')
email.otp        # => "123456"
email.subject    # => "Verify your account"
email.latency_ms # => 145

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Capture

Returns a new instance of Capture.



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/mailcapture/models.rb', line 40

def initialize(data)
  @id          = data['id']
  @tag         = data['tag']
  @subject     = data['subject']
  @otp         = data['otp']
  @body_text   = data['body_text']
  @body_html   = data['body_html']
  @latency_ms  = data['latency_ms']
  @status      = data['status']
  @received_at = data['received_at']
end

Instance Attribute Details

#body_htmlString? (readonly)

Returns HTML body, or nil if not present.

Returns:

  • (String, nil)

    HTML body, or nil if not present



28
29
30
# File 'lib/mailcapture/models.rb', line 28

def body_html
  @body_html
end

#body_textString? (readonly)

Returns plain-text body, or nil if not present.

Returns:

  • (String, nil)

    plain-text body, or nil if not present



26
27
28
# File 'lib/mailcapture/models.rb', line 26

def body_text
  @body_text
end

#idString (readonly)

Returns unique capture ID.

Returns:

  • (String)

    unique capture ID



18
19
20
# File 'lib/mailcapture/models.rb', line 18

def id
  @id
end

#latency_msInteger (readonly)

Returns send-to-capture latency in milliseconds.

Returns:

  • (Integer)

    send-to-capture latency in milliseconds



30
31
32
# File 'lib/mailcapture/models.rb', line 30

def latency_ms
  @latency_ms
end

#otpString? (readonly)

Returns extracted OTP/code, or nil if none detected.

Returns:

  • (String, nil)

    extracted OTP/code, or nil if none detected



24
25
26
# File 'lib/mailcapture/models.rb', line 24

def otp
  @otp
end

#received_atString (readonly)

Returns ISO 8601 timestamp of when the email was received.

Returns:

  • (String)

    ISO 8601 timestamp of when the email was received



34
35
36
# File 'lib/mailcapture/models.rb', line 34

def received_at
  @received_at
end

#statusString (readonly)

Returns delivery status, e.g. “captured”.

Returns:

  • (String)

    delivery status, e.g. “captured”



32
33
34
# File 'lib/mailcapture/models.rb', line 32

def status
  @status
end

#subjectString (readonly)

Returns email subject line.

Returns:

  • (String)

    email subject line



22
23
24
# File 'lib/mailcapture/models.rb', line 22

def subject
  @subject
end

#tagString (readonly)

Returns tag portion of the address, e.g. “signup”.

Returns:

  • (String)

    tag portion of the address, e.g. “signup”



20
21
22
# File 'lib/mailcapture/models.rb', line 20

def tag
  @tag
end

Class Method Details

.from_hash(data) ⇒ Object



36
37
38
# File 'lib/mailcapture/models.rb', line 36

def self.from_hash(data)
  new(data)
end

Instance Method Details

#to_sObject Also known as: inspect



52
53
54
# File 'lib/mailcapture/models.rb', line 52

def to_s
  "#<MailCapture::Capture id=#{id.inspect} tag=#{tag.inspect} subject=#{subject.inspect}>"
end