Class: ContextIO::File
Overview
A file found as an email attachment
Instance Attribute Summary (collapse)
-
- (Hash) addresses
readonly
Information on the different addresses attached to this file's message.
- - (Integer) body_section readonly
-
- (Time) date
readonly
When this file was sent.
-
- (Time) date_indexed
readonly
When Context.IO indexed the file (not the same as when it was sent).
-
- (String) email_message_id
readonly
The email message ID (The Message-ID header).
-
- (String) file_name
readonly
The full filename.
-
- (Array) file_name_structure
readonly
The file name split up into parts.
-
- (String) id
readonly
The ID of the file.
-
- (String) message_id
readonly
The (Context.IO) ID of the message this file was attached to.
-
- (Hash) person_info
readonly
Information about the people involved with the message.
-
- (Integer) size
readonly
The size of the file, in bytes.
-
- (String) subject
readonly
The subject of the message this file was attached to.
-
- (true, false) supports_preview
readonly
Whether the file supports preview.
-
- (String) type
readonly
The MIME type of the file.
Class Method Summary (collapse)
-
+ (Array<File>) all(account, query = {})
Get all files for a given account, optionally filtered with a query.
-
+ (File) from_json(account_id, json)
private
Create a File with the JSON from Context.IO.
Instance Method Summary (collapse)
-
- (String) content
Fetch the content of the message.
Methods included from Request
#delete, #get, #post, #put, #request
Instance Attribute Details
- (Hash) addresses (readonly)
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 |
- (Integer) body_section (readonly)
39 40 41 |
# File 'lib/context-io/file.rb', line 39 def body_section @body_section end |
- (Time) date (readonly)
When this file was sent
26 27 28 |
# File 'lib/context-io/file.rb', line 26 def date @date end |
- (Time) date_indexed (readonly)
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 |
- (String) email_message_id (readonly)
The email message ID (The Message-ID header)
56 57 58 |
# File 'lib/context-io/file.rb', line 56 def @email_message_id end |
- (String) file_name (readonly)
The full filename
35 36 37 |
# File 'lib/context-io/file.rb', line 35 def file_name @file_name end |
- (Array) file_name_structure (readonly)
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 |
- (String) id (readonly)
The ID of the file
10 11 12 |
# File 'lib/context-io/file.rb', line 10 def id @id end |
- (String) message_id (readonly)
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 |
- (Hash) person_info (readonly)
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 |
- (Integer) size (readonly)
The size of the file, in bytes.
14 15 16 |
# File 'lib/context-io/file.rb', line 14 def size @size end |
- (String) subject (readonly)
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 |
- (true, false) supports_preview (readonly)
Whether the file supports preview
43 44 45 |
# File 'lib/context-io/file.rb', line 43 def supports_preview @supports_preview end |
- (String) type (readonly)
The MIME type of the file.
18 19 20 |
# File 'lib/context-io/file.rb', line 18 def type @type end |
Class Method Details
+ (Array<File>) all(account, query = {})
Get all files for a given account, optionally filtered with a query
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/context-io/file.rb', line 122 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 account_id = account.is_a?(Account) ? account.id : account.to_s get("/2.0/accounts/#{account_id}/files", query).map do |file| File.from_json(account_id, file) end end |
+ (File) from_json(account_id, json)
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.
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/context-io/file.rb', line 161 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
- (String) content
Data transfer for this call is metered and charged at the end of the month. See Context.IO's pricing page for more info.
Fetch the content of the message.
148 149 150 |
# File 'lib/context-io/file.rb', line 148 def content get("/2.0/accounts/#@account_id/files/#@id/content", :raw => true) end |