Class: Postmark::Mitt

Inherits:
Object
  • Object
show all
Defined in:
lib/postmark/mitt.rb

Defined Under Namespace

Classes: Attachment, AttachmentsArray

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Mitt

Returns a new instance of Mitt.



3
4
5
6
# File 'lib/postmark/mitt.rb', line 3

def initialize(json)
  @raw = json
  @source = MultiJson.decode(json)
end

Instance Attribute Details

#rawObject (readonly)

Returns the value of attribute raw.



8
9
10
# File 'lib/postmark/mitt.rb', line 8

def raw
  @raw
end

#sourceObject (readonly)

Returns the value of attribute source.



8
9
10
# File 'lib/postmark/mitt.rb', line 8

def source
  @source
end

Instance Method Details

#attachmentsObject



99
100
101
102
103
104
# File 'lib/postmark/mitt.rb', line 99

def attachments
  @attachments ||= begin
    raw_attachments = source["Attachments"] || []
    AttachmentsArray.new(raw_attachments.map{|a| Attachment.new(a)})
  end
end

#bccObject



47
48
49
# File 'lib/postmark/mitt.rb', line 47

def bcc
  source["Bcc"]
end

#bcc_emailObject



51
52
53
# File 'lib/postmark/mitt.rb', line 51

def bcc_email
  source["BccFull"]["Email"] || bcc
end

#bcc_nameObject



55
56
57
# File 'lib/postmark/mitt.rb', line 55

def bcc_name
  source["BccFull"]["Name"] || bcc
end

#ccObject



59
60
61
# File 'lib/postmark/mitt.rb', line 59

def cc
  source["Cc"]
end

#cc_emailObject



63
64
65
# File 'lib/postmark/mitt.rb', line 63

def cc_email
  source["CcFull"]["Email"] || cc
end

#cc_nameObject



67
68
69
# File 'lib/postmark/mitt.rb', line 67

def cc_name
  source["CcFull"]["Name"] || cc
end

#fromObject



18
19
20
# File 'lib/postmark/mitt.rb', line 18

def from
  source["From"].gsub('"', '')
end

#from_emailObject



22
23
24
# File 'lib/postmark/mitt.rb', line 22

def from_email
  source["FromFull"]["Email"] || from
end

#from_nameObject



26
27
28
# File 'lib/postmark/mitt.rb', line 26

def from_name
  source["FromFull"]["Name"] || from
end

#has_attachments?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/postmark/mitt.rb', line 106

def has_attachments?
  !attachments.empty?
end

#headersObject



91
92
93
# File 'lib/postmark/mitt.rb', line 91

def headers
  @headers ||= source["Headers"].inject({}){|hash,obj| hash[obj["Name"]] = obj["Value"]; hash}
end

#html_bodyObject



75
76
77
# File 'lib/postmark/mitt.rb', line 75

def html_body
  source["HtmlBody"]
end

#inspectObject



10
11
12
# File 'lib/postmark/mitt.rb', line 10

def inspect
  "<Postmark::Mitt: #{message_id}>"
end

#mailbox_hashObject



83
84
85
# File 'lib/postmark/mitt.rb', line 83

def mailbox_hash
  source["MailboxHash"]
end

#message_idObject



95
96
97
# File 'lib/postmark/mitt.rb', line 95

def message_id
  source["MessageID"]
end

#reply_toObject



71
72
73
# File 'lib/postmark/mitt.rb', line 71

def reply_to
  source["ReplyTo"]
end

#subjectObject



14
15
16
# File 'lib/postmark/mitt.rb', line 14

def subject
  source["Subject"]
end

#tagObject



87
88
89
# File 'lib/postmark/mitt.rb', line 87

def tag
  source["Tag"]
end

#text_bodyObject



79
80
81
# File 'lib/postmark/mitt.rb', line 79

def text_body
  source["TextBody"]
end

#toObject



30
31
32
# File 'lib/postmark/mitt.rb', line 30

def to
  source["To"].gsub('"', '')
end

#to_emailObject



38
39
40
# File 'lib/postmark/mitt.rb', line 38

def to_email
  to_full.any? ? to_full.first["Email"] : to
end

#to_fullObject



34
35
36
# File 'lib/postmark/mitt.rb', line 34

def to_full
  source["ToFull"] || []
end

#to_nameObject



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

def to_name
  to_full.any? ? to_full.first["Name"] : to
end