Class: ContextIO::File
Overview
A file found as an email attachment
Instance Attribute Summary collapse
-
#addresses ⇒ Hash
readonly
Information on the different addresses attached to this file’s message.
- #body_section ⇒ Integer readonly
-
#date ⇒ Time
readonly
When this file was sent.
-
#date_indexed ⇒ Time
readonly
When Context.IO indexed the file (not the same as when it was sent).
-
#email_message_id ⇒ String
readonly
The email message ID (The Message-ID header).
-
#file_name ⇒ String
readonly
The full filename.
-
#file_name_structure ⇒ Array
readonly
The file name split up into parts.
-
#id ⇒ String
readonly
The ID of the file.
-
#message_id ⇒ String
readonly
The (Context.IO) ID of the message this file was attached to.
-
#person_info ⇒ Hash
readonly
Information about the people involved with the message.
-
#size ⇒ Integer
readonly
The size of the file, in bytes.
-
#subject ⇒ String
readonly
The subject of the message this file was attached to.
-
#supports_preview ⇒ true, false
readonly
Whether the file supports preview.
-
#type ⇒ String
readonly
The MIME type of the file.
Class Method Summary collapse
-
.all(account, query = {}) ⇒ Array<File>, Array<Hash>
Get all files for a given account, optionally filtered with a query.
-
.from_json(account_id, json) ⇒ File
private
Create a File with the JSON from Context.IO.
Instance Method Summary collapse
-
#content ⇒ String
Fetch the content of the message.
Methods included from Request
#delete, #get, #post, #put, #request
Instance Attribute Details
#addresses ⇒ Hash (readonly)
Returns Information on the different addresses attached to this file’s message.
31 32 33 |
# File 'lib/context-io/file.rb', line 31 def addresses @addresses end |
#body_section ⇒ Integer (readonly)
39 40 41 |
# File 'lib/context-io/file.rb', line 39 def body_section @body_section end |
#date ⇒ Time (readonly)
Returns When this file was sent.
26 27 28 |
# File 'lib/context-io/file.rb', line 26 def date @date end |
#date_indexed ⇒ Time (readonly)
Returns When Context.IO indexed the file (not the same as when it was sent).
52 53 54 |
# File 'lib/context-io/file.rb', line 52 def date_indexed @date_indexed end |
#email_message_id ⇒ String (readonly)
Returns The email message ID (The Message-ID header).
56 57 58 |
# File 'lib/context-io/file.rb', line 56 def @email_message_id end |
#file_name ⇒ String (readonly)
Returns The full filename.
35 36 37 |
# File 'lib/context-io/file.rb', line 35 def file_name @file_name end |
#file_name_structure ⇒ Array (readonly)
Returns The file name split up into parts.
64 65 66 |
# File 'lib/context-io/file.rb', line 64 def file_name_structure @file_name_structure end |
#id ⇒ String (readonly)
Returns The ID of the file.
10 11 12 |
# File 'lib/context-io/file.rb', line 10 def id @id end |
#message_id ⇒ String (readonly)
Returns The (Context.IO) ID of the message this file was attached to.
47 48 49 |
# File 'lib/context-io/file.rb', line 47 def @message_id end |
#person_info ⇒ Hash (readonly)
Returns Information about the people involved with the message.
60 61 62 |
# File 'lib/context-io/file.rb', line 60 def person_info @person_info end |
#size ⇒ Integer (readonly)
Returns The size of the file, in bytes.
14 15 16 |
# File 'lib/context-io/file.rb', line 14 def size @size end |
#subject ⇒ String (readonly)
Returns The subject of the message this file was attached to.
22 23 24 |
# File 'lib/context-io/file.rb', line 22 def subject @subject end |
#supports_preview ⇒ true, false (readonly)
Returns Whether the file supports preview.
43 44 45 |
# File 'lib/context-io/file.rb', line 43 def supports_preview @supports_preview end |
#type ⇒ String (readonly)
Returns The MIME type of the file.
18 19 20 |
# File 'lib/context-io/file.rb', line 18 def type @type end |
Class Method Details
.all(account, query = {}) ⇒ Array<File>, Array<Hash>
Get all files for a given account, optionally filtered with a query
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/context-io/file.rb', line 131 def self.all(account, query={}) if query[:file_name] && query[:file_name].is_a?(Regexp) query[:file_name] = "/#{query[:file_name].source}/" end [:date_before, :date_after, :indexed, :indexed_after].each do |field| if query[field] && query[field].respond_to?(:to_i) query[field] = query[field].to_i end end if query[:group_by_revisions] query[:group_by_revisions] = query[:group_by_revisions] ? '1' : '0' end account_id = account.is_a?(Account) ? account.id : account.to_s get("/2.0/accounts/#{account_id}/files", query).map do |file| if query[:group_by_revisions] occurences = file['occurences'].map do |file| File.from_json(account_id, file) end { :occurences => occurences, :file_name => file['file_name'], :latest_date => Time.at(file['latest_date'].to_i) } else File.from_json(account_id, file) end end end |
.from_json(account_id, json) ⇒ File
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a File with the JSON from Context.IO.
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/context-io/file.rb', line 186 def self.from_json(account_id, json) file = new file.instance_eval do @id = json['file_id'] @account_id = account_id @size = json['size'] @type = json['type'] @subject = json['subject'] @date = Time.at(json['date']) @addresses = {} json['addresses'].each do |type, info| @addresses[type.to_sym] = {} if info.is_a?(Hash) info.each do |key, value| @addresses[type.to_sym][key.to_sym] = value end elsif info.is_a?(Array) @addresses[type.to_sym] = [] info.each do |email_info| @addresses[type.to_sym] << {} email_info.each do |key, value| @addresses[type.to_sym].last[key.to_sym] = value end end end end @file_name = json['file_name'] @body_section = json['body_section'] @supports_preview = json['supports_preview'] @message_id = json['message_id'] @date_indexed = Time.at(json['date_indexed']) @email_message_id = json['email_message_id'] @person_info = {} json['person_info'].each do |email, info| @person_info[email] = {} info.each do |key, value| @person_info[email][key.to_sym] = value end end @file_name_structure = [] json['file_name_structure'].each do |part| @file_name_structure << [part.first, part.last.to_sym] end end file end |
Instance Method Details
#content ⇒ String
Data transfer for this call is metered and charged at the end of the month. See [Context.IO’s pricing page](context.io/pricing) for more info.
Fetch the content of the message.
173 174 175 |
# File 'lib/context-io/file.rb', line 173 def content get("/2.0/accounts/#@account_id/files/#@id/content", :raw => true) end |