Class: Inky::File
- Inherits:
-
Object
- Object
- Inky::File
- Defined in:
- lib/inky/file.rb
Constant Summary collapse
- METADATA_FIELDS =
:md5, :mimetype, :uploaded, :container, :writeable, :filename, :location, :key, :path, :size, :width, :height
- MF_ARGS =
METADATA_FIELDS.each_with_object({}) { |f, h| h[f] = true }
Instance Attribute Summary collapse
-
#local_file ⇒ Object
Returns the value of attribute local_file.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#remote_url ⇒ Object
Returns the value of attribute remote_url.
-
#uid ⇒ Object
Returns the value of attribute uid.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(value = nil) ⇒ File
constructor
A new instance of File.
- #save!(opts = {}) ⇒ Object
- #uploaded_at ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(value = nil) ⇒ File
Returns a new instance of File.
14 15 16 17 18 |
# File 'lib/inky/file.rb', line 14 def initialize(value = nil) return unless value self.uid = value end |
Instance Attribute Details
#local_file ⇒ Object
Returns the value of attribute local_file.
12 13 14 |
# File 'lib/inky/file.rb', line 12 def local_file @local_file end |
#metadata ⇒ Object
Returns the value of attribute metadata.
12 13 14 |
# File 'lib/inky/file.rb', line 12 def @metadata end |
#remote_url ⇒ Object
Returns the value of attribute remote_url.
12 13 14 |
# File 'lib/inky/file.rb', line 12 def remote_url @remote_url end |
#uid ⇒ Object
Returns the value of attribute uid.
12 13 14 |
# File 'lib/inky/file.rb', line 12 def uid @uid end |
Class Method Details
.from_file(local_file) ⇒ Object
20 21 22 23 24 |
# File 'lib/inky/file.rb', line 20 def self.from_file(local_file) file = new file.local_file = local_file file end |
.from_url(url) ⇒ Object
26 27 28 29 30 |
# File 'lib/inky/file.rb', line 26 def self.from_url(url) file = new file.remote_url = url file end |
Instance Method Details
#save!(opts = {}) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/inky/file.rb', line 40 def save!(opts = {}) opts = { location: 's3', key: Inky.api_key }.merge(opts) opts.merge filename: ::File.basename(local_file) if local_file handle_post_response RestClient.post(post_url(opts), post_opts) self end |
#uploaded_at ⇒ Object
32 33 34 |
# File 'lib/inky/file.rb', line 32 def uploaded_at Time.at(uploaded / 1000.0) end |
#url ⇒ Object
36 37 38 |
# File 'lib/inky/file.rb', line 36 def url "#{BASE_URL}/file/#{uid}" end |