Sha256: c51fcfb0aada0a8863c6267c9e33c5386fc03b1d4f2926ea17d12009eb39386f

Contents?: true

Size: 1.74 KB

Versions: 2

Compression:

Stored size: 1.74 KB

Contents

require 'sinatra'
require 'groupdocs'
require 'haml'

GroupDocs.api_version = '2.0'

get '/' do
  haml :upload
end

post '/upload' do
  set :client_id, params[:client_id]
  set :private_key, params[:private_key]
  filepath = "#{Dir.tmpdir}/#{params[:file][:filename]}"
  File.open(filepath, 'wb') { |f| f.write(params[:file][:tempfile].read) }
  @@file = GroupDocs::Storage::File.upload!(filepath, '/', client_id: options.client_id, private_key: options.private_key)

  haml :annotations
end

get '/annotations' do
  annotations = @@file.to_document.annotations!(client_id: options.client_id, private_key: options.private_key)
  annotations.map { |annotation| "Annotation Type: #{annotation.type} -- Replies: #{annotation.replies.map { |reply| "'#{reply.user_name}':'#{reply.text}'" }}" }.join "<br />"
end


__END__

@@layout
%html
  %head
    %title GroupDocs Ruby SDK Annotations Sample App
    %script{ src: "http://rightjs.org/hotlink/right.js" }
    :javascript
      "#annotations".onClick(function(event) {
        event.stop();
        $('annotations_list').load("/annotations");
      });
  %body
    = yield

@@upload
%h4 Upload file
%form{ action: '/upload', method: 'post', enctype: 'multipart/form-data' }
  %label{ for: 'client_id' } GroupDocs Client ID
  %br
  %input{ type: 'text', name: 'client_id' }
  %br
  %label{ for: 'private_key' } GroupDocs Private Key
  %br
  %input{ type: 'text', name: 'private_key' }
  %br
  %label{ for: 'file' } File
  %br
  %input{ type: 'file', name: 'file' }
  %br
  %br
  %input{ type: 'submit', value: 'Upload' }

@@annotations
%iframe{ src: "https://apps.groupdocs.com/document-annotation/Embed/#{@@file.guid}", frameborder: 0, width: 720, height: 600 }
%br
%br
%button#annotations Poll annotations
%br
%br
#annotations_list

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
groupdocs-1.1.0 examples/annotations/app.rb
groupdocs-1.0.0 examples/annotations/app.rb