Class: Heathrow::Message
- Inherits:
-
Object
- Object
- Heathrow::Message
- Defined in:
- lib/heathrow/message.rb
Instance Attribute Summary collapse
-
#archived ⇒ Object
Returns the value of attribute archived.
-
#attachments ⇒ Object
Returns the value of attribute attachments.
-
#bcc ⇒ Object
Returns the value of attribute bcc.
-
#cc ⇒ Object
Returns the value of attribute cc.
-
#content ⇒ Object
Returns the value of attribute content.
-
#external_id ⇒ Object
Returns the value of attribute external_id.
-
#html_content ⇒ Object
Returns the value of attribute html_content.
-
#id ⇒ Object
Returns the value of attribute id.
-
#labels ⇒ Object
Returns the value of attribute labels.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#parent_id ⇒ Object
Returns the value of attribute parent_id.
-
#read ⇒ Object
(also: #is_read)
Returns the value of attribute read.
-
#received_at ⇒ Object
Returns the value of attribute received_at.
-
#recipients ⇒ Object
Returns the value of attribute recipients.
-
#sender ⇒ Object
Returns the value of attribute sender.
-
#sender_name ⇒ Object
Returns the value of attribute sender_name.
-
#source_id ⇒ Object
Returns the value of attribute source_id.
-
#starred ⇒ Object
(also: #is_starred)
Returns the value of attribute starred.
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#thread_id ⇒ Object
Returns the value of attribute thread_id.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
Instance Method Summary collapse
- #add_label(label) ⇒ Object
- #age_in_days ⇒ Object
- #archive! ⇒ Object
- #archived? ⇒ Boolean
- #display_sender ⇒ Object
- #has_attachments? ⇒ Boolean
- #has_label?(label) ⇒ Boolean
- #has_thread? ⇒ Boolean
-
#initialize(attrs = {}) ⇒ Message
constructor
A new instance of Message.
- #is_reply? ⇒ Boolean
-
#mark_as_read! ⇒ Object
Message state methods.
- #mark_as_unread! ⇒ Object
-
#read? ⇒ Boolean
Query methods.
- #remove_label(label) ⇒ Object
- #short_content(length = 100) ⇒ Object
-
#short_subject(length = 50) ⇒ Object
Display helpers.
- #starred? ⇒ Boolean
- #timestamp_formatted(format = '%Y-%m-%d %H:%M:%S') ⇒ Object
- #to_h ⇒ Object
- #toggle_star! ⇒ Object
- #unarchive! ⇒ Object
- #unread? ⇒ Boolean
Constructor Details
#initialize(attrs = {}) ⇒ Message
Returns a new instance of Message.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/heathrow/message.rb', line 20 def initialize(attrs = {}) # Set defaults @timestamp = Time.now.to_i @received_at = Time.now.to_i @read = false @starred = false @archived = false @recipients = [] @cc = [] @bcc = [] @labels = [] @attachments = [] @metadata = {} # Set attributes from hash attrs.each do |key, value| # Handle both string and symbol keys key = key.to_s if key.is_a?(Symbol) # Parse JSON strings for array/hash fields if ['recipients', 'cc', 'bcc', 'labels', 'attachments', 'metadata'].include?(key) value = parse_json_field(value) end # Handle backward compatibility key = 'read' if key == 'is_read' key = 'starred' if key == 'is_starred' send("#{key}=", value) if respond_to?("#{key}=") end end |
Instance Attribute Details
#archived ⇒ Object
Returns the value of attribute archived.
6 7 8 |
# File 'lib/heathrow/message.rb', line 6 def archived @archived end |
#attachments ⇒ Object
Returns the value of attribute attachments.
6 7 8 |
# File 'lib/heathrow/message.rb', line 6 def @attachments end |
#bcc ⇒ Object
Returns the value of attribute bcc.
6 7 8 |
# File 'lib/heathrow/message.rb', line 6 def bcc @bcc end |
#cc ⇒ Object
Returns the value of attribute cc.
6 7 8 |
# File 'lib/heathrow/message.rb', line 6 def cc @cc end |
#content ⇒ Object
Returns the value of attribute content.
6 7 8 |
# File 'lib/heathrow/message.rb', line 6 def content @content end |
#external_id ⇒ Object
Returns the value of attribute external_id.
6 7 8 |
# File 'lib/heathrow/message.rb', line 6 def external_id @external_id end |
#html_content ⇒ Object
Returns the value of attribute html_content.
6 7 8 |
# File 'lib/heathrow/message.rb', line 6 def html_content @html_content end |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/heathrow/message.rb', line 6 def id @id end |
#labels ⇒ Object
Returns the value of attribute labels.
6 7 8 |
# File 'lib/heathrow/message.rb', line 6 def labels @labels end |
#metadata ⇒ Object
Returns the value of attribute metadata.
6 7 8 |
# File 'lib/heathrow/message.rb', line 6 def @metadata end |
#parent_id ⇒ Object
Returns the value of attribute parent_id.
6 7 8 |
# File 'lib/heathrow/message.rb', line 6 def parent_id @parent_id end |
#read ⇒ Object Also known as: is_read
Returns the value of attribute read.
6 7 8 |
# File 'lib/heathrow/message.rb', line 6 def read @read end |
#received_at ⇒ Object
Returns the value of attribute received_at.
6 7 8 |
# File 'lib/heathrow/message.rb', line 6 def received_at @received_at end |
#recipients ⇒ Object
Returns the value of attribute recipients.
6 7 8 |
# File 'lib/heathrow/message.rb', line 6 def recipients @recipients end |
#sender ⇒ Object
Returns the value of attribute sender.
6 7 8 |
# File 'lib/heathrow/message.rb', line 6 def sender @sender end |
#sender_name ⇒ Object
Returns the value of attribute sender_name.
6 7 8 |
# File 'lib/heathrow/message.rb', line 6 def sender_name @sender_name end |
#source_id ⇒ Object
Returns the value of attribute source_id.
6 7 8 |
# File 'lib/heathrow/message.rb', line 6 def source_id @source_id end |
#starred ⇒ Object Also known as: is_starred
Returns the value of attribute starred.
6 7 8 |
# File 'lib/heathrow/message.rb', line 6 def starred @starred end |
#subject ⇒ Object
Returns the value of attribute subject.
6 7 8 |
# File 'lib/heathrow/message.rb', line 6 def subject @subject end |
#thread_id ⇒ Object
Returns the value of attribute thread_id.
6 7 8 |
# File 'lib/heathrow/message.rb', line 6 def thread_id @thread_id end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
6 7 8 |
# File 'lib/heathrow/message.rb', line 6 def @timestamp end |
Instance Method Details
#add_label(label) ⇒ Object
99 100 101 |
# File 'lib/heathrow/message.rb', line 99 def add_label(label) @labels << label unless @labels.include?(label) end |
#age_in_days ⇒ Object
159 160 161 |
# File 'lib/heathrow/message.rb', line 159 def age_in_days ((Time.now.to_i - @timestamp) / 86400.0).round(1) end |
#archive! ⇒ Object
91 92 93 |
# File 'lib/heathrow/message.rb', line 91 def archive! @archived = true end |
#archived? ⇒ Boolean
124 125 126 |
# File 'lib/heathrow/message.rb', line 124 def archived? @archived end |
#display_sender ⇒ Object
151 152 153 |
# File 'lib/heathrow/message.rb', line 151 def display_sender @sender_name || @sender || 'Unknown' end |
#has_attachments? ⇒ Boolean
128 129 130 |
# File 'lib/heathrow/message.rb', line 128 def @attachments && !@attachments.empty? end |
#has_label?(label) ⇒ Boolean
107 108 109 |
# File 'lib/heathrow/message.rb', line 107 def has_label?(label) @labels.include?(label) end |
#has_thread? ⇒ Boolean
132 133 134 |
# File 'lib/heathrow/message.rb', line 132 def has_thread? !@thread_id.nil? end |
#is_reply? ⇒ Boolean
136 137 138 |
# File 'lib/heathrow/message.rb', line 136 def is_reply? !@parent_id.nil? end |
#mark_as_read! ⇒ Object
Message state methods
79 80 81 |
# File 'lib/heathrow/message.rb', line 79 def mark_as_read! @read = true end |
#mark_as_unread! ⇒ Object
83 84 85 |
# File 'lib/heathrow/message.rb', line 83 def mark_as_unread! @read = false end |
#read? ⇒ Boolean
Query methods
112 113 114 |
# File 'lib/heathrow/message.rb', line 112 def read? @read end |
#remove_label(label) ⇒ Object
103 104 105 |
# File 'lib/heathrow/message.rb', line 103 def remove_label(label) @labels.delete(label) end |
#short_content(length = 100) ⇒ Object
146 147 148 149 |
# File 'lib/heathrow/message.rb', line 146 def short_content(length = 100) return '' unless @content @content.length > length ? "#{@content[0...length]}..." : @content end |
#short_subject(length = 50) ⇒ Object
Display helpers
141 142 143 144 |
# File 'lib/heathrow/message.rb', line 141 def short_subject(length = 50) return '' unless @subject @subject.length > length ? "#{@subject[0...length]}..." : @subject end |
#starred? ⇒ Boolean
120 121 122 |
# File 'lib/heathrow/message.rb', line 120 def starred? @starred end |
#timestamp_formatted(format = '%Y-%m-%d %H:%M:%S') ⇒ Object
155 156 157 |
# File 'lib/heathrow/message.rb', line 155 def (format = '%Y-%m-%d %H:%M:%S') Time.at(@timestamp).strftime(format) end |
#to_h ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/heathrow/message.rb', line 52 def to_h { id: @id, source_id: @source_id, external_id: @external_id, thread_id: @thread_id, parent_id: @parent_id, sender: @sender, sender_name: @sender_name, recipients: @recipients, cc: @cc, bcc: @bcc, subject: @subject, content: @content, html_content: @html_content, timestamp: @timestamp, received_at: @received_at, read: @read, starred: @starred, archived: @archived, labels: @labels, attachments: @attachments, metadata: @metadata } end |
#toggle_star! ⇒ Object
87 88 89 |
# File 'lib/heathrow/message.rb', line 87 def toggle_star! @starred = !@starred end |
#unarchive! ⇒ Object
95 96 97 |
# File 'lib/heathrow/message.rb', line 95 def unarchive! @archived = false end |
#unread? ⇒ Boolean
116 117 118 |
# File 'lib/heathrow/message.rb', line 116 def unread? !@read end |