Class: Inky::File

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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_fileObject

Returns the value of attribute local_file.



12
13
14
# File 'lib/inky/file.rb', line 12

def local_file
  @local_file
end

#metadataObject

Returns the value of attribute metadata.



12
13
14
# File 'lib/inky/file.rb', line 12

def 
  @metadata
end

#remote_urlObject

Returns the value of attribute remote_url.



12
13
14
# File 'lib/inky/file.rb', line 12

def remote_url
  @remote_url
end

#uidObject

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_atObject



32
33
34
# File 'lib/inky/file.rb', line 32

def uploaded_at
  Time.at(uploaded / 1000.0)
end

#urlObject



36
37
38
# File 'lib/inky/file.rb', line 36

def url
  "#{BASE_URL}/file/#{uid}"
end