Class: Postmark::Mitt
- Inherits:
-
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
#raw ⇒ Object
Returns the value of attribute raw.
8
9
10
|
# File 'lib/postmark/mitt.rb', line 8
def raw
@raw
end
|
#source ⇒ Object
Returns the value of attribute source.
8
9
10
|
# File 'lib/postmark/mitt.rb', line 8
def source
@source
end
|
Instance Method Details
#attachments ⇒ Object
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
|
#bcc ⇒ Object
47
48
49
|
# File 'lib/postmark/mitt.rb', line 47
def bcc
source["Bcc"]
end
|
#bcc_email ⇒ Object
51
52
53
|
# File 'lib/postmark/mitt.rb', line 51
def bcc_email
source["BccFull"]["Email"] || bcc
end
|
#bcc_name ⇒ Object
55
56
57
|
# File 'lib/postmark/mitt.rb', line 55
def bcc_name
source["BccFull"]["Name"] || bcc
end
|
#cc ⇒ Object
59
60
61
|
# File 'lib/postmark/mitt.rb', line 59
def cc
source["Cc"]
end
|
#cc_email ⇒ Object
63
64
65
|
# File 'lib/postmark/mitt.rb', line 63
def cc_email
source["CcFull"]["Email"] || cc
end
|
#cc_name ⇒ Object
67
68
69
|
# File 'lib/postmark/mitt.rb', line 67
def cc_name
source["CcFull"]["Name"] || cc
end
|
#from ⇒ Object
18
19
20
|
# File 'lib/postmark/mitt.rb', line 18
def from
source["From"].gsub('"', '')
end
|
#from_email ⇒ Object
22
23
24
|
# File 'lib/postmark/mitt.rb', line 22
def from_email
source["FromFull"]["Email"] || from
end
|
#from_name ⇒ Object
26
27
28
|
# File 'lib/postmark/mitt.rb', line 26
def from_name
source["FromFull"]["Name"] || from
end
|
#has_attachments? ⇒ Boolean
106
107
108
|
# File 'lib/postmark/mitt.rb', line 106
def has_attachments?
!attachments.empty?
end
|
91
92
93
|
# File 'lib/postmark/mitt.rb', line 91
def
@headers ||= source["Headers"].inject({}){|hash,obj| hash[obj["Name"]] = obj["Value"]; hash}
end
|
#html_body ⇒ Object
75
76
77
|
# File 'lib/postmark/mitt.rb', line 75
def html_body
source["HtmlBody"]
end
|
#inspect ⇒ Object
10
11
12
|
# File 'lib/postmark/mitt.rb', line 10
def inspect
"<Postmark::Mitt: #{message_id}>"
end
|
#mailbox_hash ⇒ Object
83
84
85
|
# File 'lib/postmark/mitt.rb', line 83
def mailbox_hash
source["MailboxHash"]
end
|
#message_id ⇒ Object
95
96
97
|
# File 'lib/postmark/mitt.rb', line 95
def message_id
source["MessageID"]
end
|
#reply_to ⇒ Object
71
72
73
|
# File 'lib/postmark/mitt.rb', line 71
def reply_to
source["ReplyTo"]
end
|
#subject ⇒ Object
14
15
16
|
# File 'lib/postmark/mitt.rb', line 14
def subject
source["Subject"]
end
|
#tag ⇒ Object
87
88
89
|
# File 'lib/postmark/mitt.rb', line 87
def tag
source["Tag"]
end
|
#text_body ⇒ Object
79
80
81
|
# File 'lib/postmark/mitt.rb', line 79
def text_body
source["TextBody"]
end
|
#to ⇒ Object
30
31
32
|
# File 'lib/postmark/mitt.rb', line 30
def to
source["To"].gsub('"', '')
end
|
#to_email ⇒ Object
38
39
40
|
# File 'lib/postmark/mitt.rb', line 38
def to_email
to_full.any? ? to_full.first["Email"] : to
end
|
#to_full ⇒ Object
34
35
36
|
# File 'lib/postmark/mitt.rb', line 34
def to_full
source["ToFull"] || []
end
|
#to_name ⇒ Object
42
43
44
|
# File 'lib/postmark/mitt.rb', line 42
def to_name
to_full.any? ? to_full.first["Name"] : to
end
|