module Paperclip::Storage::Elvfs

Public Class Methods

extended(base) click to toggle source
# File lib/paperclip/storage/elvfs.rb, line 6
def self.extended base
end

Public Instance Methods

exists?(style_name = default_style) click to toggle source
# File lib/paperclip/storage/elvfs.rb, line 9
def exists?(style_name = default_style)
  if original_filename
    !!file_json(path(style_name))
  else
    false
  end
end

Private Instance Methods

delete_entry(path) click to toggle source
# File lib/paperclip/storage/elvfs.rb, line 50
def delete_entry(path)
  if file_hash = file_json(path)
    open(storage_url("#{File.dirname(path)}?cmd=rm&targets[]=#{file_hash['hash']}"))
  end
end
directory_json(path) click to toggle source
# File lib/paperclip/storage/elvfs.rb, line 38
def directory_json(path)
  JSON.parse(open(storage_url("#{File.dirname(path)}?cmd=open&init=true")).read)
end
directory_target(path) click to toggle source
# File lib/paperclip/storage/elvfs.rb, line 46
def directory_target(path)
  directory_json(path)['cwd']['hash']
end
file_json(path) click to toggle source
# File lib/paperclip/storage/elvfs.rb, line 42
def file_json(path)
  directory_json(path)['files'].select{|file| file['name'] == File.basename(path).gsub(/\+/, ' ')}.first
end
storage_url(path='') click to toggle source
# File lib/paperclip/storage/elvfs.rb, line 65
def storage_url(path='')
  "#{options[:elvfs_url]}/api/el_finder/v2/#{path}"
end
upload_file(path, file) click to toggle source
# File lib/paperclip/storage/elvfs.rb, line 56
def upload_file(path, file)
  curl = Curl::Easy.new(storage_url("#{File.dirname(path)}?cmd=upload&target=#{directory_target(path)}")) do |curl|
    curl.multipart_form_post = true
    curl.on_failure{|curl| raise "Cann't upload file #{File.basename(path)}"}
    curl.on_success{|response| instance.update_column "#{name}_url", JSON.parse(response.body_str)['added'].first['url'] }
  end
  curl.http_post(Curl::PostField.file('upload[]', file.path, File.basename(path)))
end