Sha256: e4abf3960b6734a8bb920f3a8dbce768cb0dbf85ada4057773b09a993f3ba03c

Contents?: true

Size: 1.76 KB

Versions: 7

Compression:

Stored size: 1.76 KB

Contents

# GET request
get '/sample4' do
  haml :sample4
end

# POST request
post '/sample4' do
  # set variables
  set :client_id, params[:client_id]
  set :private_key, params[:private_key]
  set :file_id, params[:file_id]
  set :source, params[:source]
  set :url, params[:url]

  begin
    # check required variables
    raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty?

    # get file GUID
    file = nil
    case settings.source
      when 'guid'
        file = GroupDocs::Storage::File.new({:guid => settings.file_id})
      when 'local'
        # construct path
        filepath = "#{Dir.tmpdir}/#{params[:file][:filename]}"
        # open file
        File.open(filepath, 'wb') { |f| f.write(params[:file][:tempfile].read) }
        # make a request to API using client_id and private_key
        file = GroupDocs::Storage::File.upload!(filepath, {}, client_id: settings.client_id, private_key: settings.private_key)
      when 'url'
        file = GroupDocs::Storage::File.upload_web!(settings.url, client_id: settings.client_id, private_key: settings.private_key)
      else
        raise 'Wrong GUID source.'
    end

    pp file
    pp file.name
    # download file
    dowloaded_file = file.download!("#{File.dirname(__FILE__)}/../public/downloads", {:client_id => settings.client_id, :private_key => settings.private_key})
    unless dowloaded_file.empty?
      massage = "<font color='green'>File was downloaded to the <font color='blue'>#{dowloaded_file}</font> folder</font> <br />"
    end

  rescue Exception => e
    err = e.message
  end

  # set variables for template
  haml :sample4, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :file_id => settings.file_id, :massage => massage, :err => err}
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
groupdocs-1.5.7 examples/api-samples/samples/sample4.rb
groupdocs-1.5.6 examples/api-samples/samples/sample4.rb
groupdocs-1.5.5 examples/api-samples/samples/sample4.rb
groupdocs-1.5.4 examples/api-samples/samples/sample4.rb
groupdocs-1.5.3 examples/api-samples/samples/sample4.rb
groupdocs-1.5.2 examples/api-samples/samples/sample4.rb
groupdocs-1.5.1 examples/api-samples/samples/sample4.rb