Module: LayerVault::Client::Files
- Included in:
- LayerVault::Client
- Defined in:
- lib/layervault/client/files.rb
Instance Method Summary collapse
- #create_file(organization_name, project_name, path, file_name, options = {}) ⇒ Object
- #delete_file(organization_name, project_name, path, file_name, options = {}) ⇒ Object
- #file(organization_name, project_name, path, file_name) ⇒ Object
- #move_file(organization_name, project_name, path, file_name, options = {}) ⇒ Object
- #previews(organization_name, project_name, path, file_name, options = {}) ⇒ Object
- #revisions(organization_name, project_name, path, file_name, options = {}) ⇒ Object
- #sync_check(organization_name, project_name, path, file_name, options = {}) ⇒ Object
Instance Method Details
#create_file(organization_name, project_name, path, file_name, options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/layervault/client/files.rb', line 17 def create_file(organization_name, project_name, path, file_name, ={} ) raise ClientParamsError.new("You must specify the local_file_path option to the file you want to upload.") unless .fetch(:local_file_path, nil) raise ClientParamsError.new("You must specify the content_type option to the content type of the file you are uploading.") unless .fetch(:content_type, nil) local_file_path = .fetch(:local_file_path, nil) content_type = .fetch(:content_type, nil) md5 = Digest::MD5.hexdigest(::File.read(local_file_path)) = {md5: md5} json_response = put("#{organization_name}/#{project_name}/#{path}/#{file_name}", ) s3_response = MultiJson.decode(json_response) s3_response.merge!( "Content-Type" => content_type) payload = s3_response.merge({ file: Faraday::UploadIO.new(local_file_path, content_type) }) conn = Faraday.new('https://omnivore-scratch.s3.amazonaws.com') do |f| f.request :multipart f.request :url_encoded f.adapter :net_http # This is what ended up making it work end response_from_s3 = conn.post('/', payload) redirect = response_from_s3[:location] # Add the access_token to the query uri = URI.parse(redirect) new_query_ar = URI.decode_www_form(uri.query) << ["access_token", LayerVault.client.access_token] uri.query = URI.encode_www_form(new_query_ar) re = conn.post( uri.to_s ) end |
#delete_file(organization_name, project_name, path, file_name, options = {}) ⇒ Object
12 13 14 15 |
# File 'lib/layervault/client/files.rb', line 12 def delete_file(organization_name, project_name, path, file_name, ={}) raise ClientParamsError.new("You must specify the md5 option of the file you are trying to delete.") unless .fetch(:md5, nil) delete "#{organization_name}/#{project_name}/#{path}/#{file_name}", end |
#file(organization_name, project_name, path, file_name) ⇒ Object
8 9 10 |
# File 'lib/layervault/client/files.rb', line 8 def file(organization_name, project_name, path, file_name) get "#{organization_name}/#{project_name}/#{path}/#{file_name}" end |
#move_file(organization_name, project_name, path, file_name, options = {}) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/layervault/client/files.rb', line 51 def move_file(organization_name, project_name, path, file_name, ={}) raise ClientParamsError.new("You must specify the new_folder option to specify the destination folder") unless .fetch(:new_folder, nil) raise ClientParamsError.new("You must specify the new_filename option to specify the destination folder") unless .fetch(:new_file_name, nil) post "#{organization_name}/#{project_name}/#{path}/#{file_name}/move", end |
#previews(organization_name, project_name, path, file_name, options = {}) ⇒ Object
63 64 65 66 |
# File 'lib/layervault/client/files.rb', line 63 def previews(organization_name, project_name, path, file_name, ={}) raise ClientParamsError.new("You must specify the :w (width) and :h (height) options for the previews.") unless .fetch(:w, nil) && .fetch(:h, nil) get "#{organization_name}/#{project_name}/#{path}/#{file_name}/previews", end |
#revisions(organization_name, project_name, path, file_name, options = {}) ⇒ Object
68 69 70 71 |
# File 'lib/layervault/client/files.rb', line 68 def revisions(organization_name, project_name, path, file_name, ={}) raise ClientParamsError.new("You must specify the :first_seen or :latest_seen option for the file.") if .fetch(:first_seen, nil) && .fetch(:latest_seen, nil) get "#{organization_name}/#{project_name}/#{path}/#{file_name}/revisions", end |
#sync_check(organization_name, project_name, path, file_name, options = {}) ⇒ Object
58 59 60 61 |
# File 'lib/layervault/client/files.rb', line 58 def sync_check(organization_name, project_name, path, file_name, ={}) raise ClientParamsError.new("You must specify the md5 option of the file you are trying to sync check.") unless .fetch(:md5, nil) get "#{organization_name}/#{project_name}/#{path}/#{file_name}/sync_check", end |