Sha256: b5957abc69b571a4249c8b929a3d8d08c54dce50a29eb4b201cc96299f825088

Contents?: true

Size: 1.74 KB

Versions: 7

Compression:

Stored size: 1.74 KB

Contents

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

# POST request
post '/sample10' do
  # set variables
  set :client_id, params[:client_id]
  set :private_key, params[:private_key]
  set :guid, params[:fileId]
  set :email, params[:email]

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

    # get document by file GUID
    file = nil
    case settings.source
      when 'guid'
        file = GroupDocs::Storage::File.new({:guid => settings.guid})
      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

    # Share document. Make a request to API using client_id and private_key
    shared = file.to_document.sharers_set!(settings.email.split(' '), {:client_id => settings.client_id, :private_key => settings.private_key})

    # result
    if shared
      shared_emails = settings.email
    end
  rescue Exception => e
    err = e.message
  end

  # set variables for template
  haml :sample10, :locals => {:client_id => settings.client_id, :private_key => settings.private_key, :guid => settings.guid, :email => settings.email, :shared => shared_emails, :err => err}
end

Version data entries

7 entries across 7 versions & 1 rubygems

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