lib/groupdocs/document.rb in groupdocs-1.5.5 vs lib/groupdocs/document.rb in groupdocs-1.5.6

- old
+ new

@@ -104,43 +104,39 @@ end documents_to_sign = [] documents.map(&:file).each do |file| document = { :name => file.name } - contents = File.read(file.local_path) + contents = File.open(file.local_path, 'rb').read contents = Base64.strict_encode64(contents) document.merge!(:data => "data:#{mime_type(file.local_path)};base64,#{contents}") documents_to_sign << document + end signers = [] signatures.each do |signature| - contents = File.read(signature.image_path) + contents = File.open(signature.image_path, 'rb').read contents = Base64.strict_encode64(contents) signer = { :name => signature.name, :data => "data:#{mime_type(signature.image_path)};base64,#{contents}" } signer.merge!(signature.position) # place signature on is not implemented yet signer.merge!(:placeSignatureOn => nil) signers << signer + end json = Api::Request.new do |request| request[:access] = access request[:method] = :POST request[:path] = '/signature/{{client_id}}/sign' request[:request_body] = { :documents => documents_to_sign, :signers => signers } end.execute! + json[:jobId] - signed_documents = [] - json[:documents].each_with_index do |document, i| - file = Storage::File.new(:guid => document[:documentId], :name => "#{documents[i].file.name}_signed.pdf") - signed_documents << Document.new(:file => file) - end - - signed_documents end # # Get sign documents status # @@ -180,11 +176,11 @@ metadata.guid = json[:guid] metadata.page_count = json[:page_count] metadata.views_count = json[:views_count] if json[:last_view] metadata.last_view = json[:last_view] - metadata.last_view.document = new(:file => Storage::File.new(json)) + end end end # @attr [GroupDocs::Storage::File] file @@ -299,11 +295,14 @@ end # # Returns a stream of bytes representing a particular document page image. # - # + # @param [String] path Document path + # @param [String] name Name document (format - jpg) + # @example path = "#{File.dirname(__FILE__)}" + # name = "test.jpg" # @param [Integer] page_number Document page number to get image for # @param [Integer] dimension Image dimension "<width>x<height>"(500x600) # @param [Hash] options # @option options [Integer] :quality Image quality in range 1-100. # @option options [Boolean] :use_pdf A flag indicating whether a document should be converted to PDF format before generating the image. @@ -429,11 +428,11 @@ # Returns array of URLs to html representing document pages. # # @example # file = GroupDocs::Storage::Folder.list!.last # document = file.to_document - # document.page_html_urls! 1024, 768, first_page: 0, page_count: 1 + # document.page_html_urls! first_page: 0, page_count: 1 # # @param [Hash] options # @option options [Integer] :first_page Start page to return image for (starting with 0) # @option options [Integer] :page_count Number of pages to return image for # @param [Hash] access Access credentials @@ -459,17 +458,15 @@ # @param [Hash] access Access credentials # @option access [String] :client_id # @option access [String] :private_key # def editlock!(access = {}) - json = Api::Request.new do |request| + Api::Request.new do |request| request[:access] = access request[:method] = :GET request[:path] = "/doc/{{client_id}}/files/#{file.guid}/editlock" end.execute! - - json[:edit_url] end # # Removes edit lock for a document and replaces the document with its edited copy # @@ -485,11 +482,10 @@ request[:access] = access request[:method] = :DELETE request[:path] = "/doc/{{client_id}}/files/#{file.guid}/editlock" end api.add_params(options).execute! - end # # Returns tags assigned to the document # @@ -502,11 +498,10 @@ Api::Request.new do |request| request[:access] = access request[:method] = :GET request[:path] = "/doc/{{client_id}}/files/#{file.guid}/tags" end.execute! - end # # Assign tags to the document. # @@ -514,17 +509,15 @@ # @option access [String] :client_id # @option access [String] :private_key # @return [String] # def tags_set!(access = {}) - json = Api::Request.new do |request| + Api::Request.new do |request| request[:access] = access request[:method] = :PUT request[:path] = "/doc/{{client_id}}/files/#{file.guid}/tags" end.execute! - - json[:document_id] end # # Removes tags assigned to the document # @@ -532,17 +525,15 @@ # @option access [String] :client_id # @option access [String] :private_key # @return [String] # def tags_clear!(access = {}) - json = Api::Request.new do |request| + Api::Request.new do |request| request[:access] = access request[:method] = :DELETE request[:path] = "/doc/{{client_id}}/files/#{file.guid}/tags" end.execute! - - json[:document_id] end # # Returns document content # @@ -704,11 +695,10 @@ metadata.guid = json[:guid] metadata.page_count = json[:page_count] metadata.views_count = json[:views_count] if json[:last_view] metadata.last_view = json[:last_view] - metadata.last_view.document = self end end end # @@ -938,19 +928,19 @@ # @option access [String] :private_key # @return [GroupDocs::Job] # # @raise [ArgumentError] if datasource is not GroupDocs::DataSource object # - def datasource_fields!(datasource, datasourceFields, options = {}, access = {}) + def datasource_fields!(datasource, options = {}, access = {}) datasource.is_a?(GroupDocs::DataSource) or raise ArgumentError, "Datasource should be GroupDocs::DataSource object, received: #{datasource.inspect}" api = Api::Request.new do |request| request[:access] = access request[:method] = :POST - request[:path] = "/merge/{{client_id}}/files/#{file.guid}/datasources/" - request[:request_body] = datasourceFields + request[:path] = "/merge/{{client_id}}/files/#{file.guid}/datasources" + request[:request_body] = datasource.fields end api.add_params(options) json = api.execute! Job.new(:id => json[:job_id]) @@ -1097,20 +1087,20 @@ # @option access [String] :private_key # @return [GroupDocs::Job] # # @raise [ArgumentError] if document is not GroupDocs::Document object # - def compare!(document, access = {}) + def compare!(document, callback, access = {}) document.is_a?(GroupDocs::Document) or raise ArgumentError, "Document should be GroupDocs::Document object, received: #{document.inspect}" api = Api::Request.new do |request| request[:access] = access request[:method] = :GET request[:path] = "/comparison/{{client_id}}/comparison/compare" end - api.add_params(:source => file.guid, :target => document.file.guid) + api.add_params(:source => file.guid, :target => document.file.guid, :callback => callback) json = api.execute! Job.new(:id => json[:job_id]) end @@ -1183,19 +1173,19 @@ # @param [Hash] access Access credentials # @option access [String] :client_id # @option access [String] :private_key # # - def download!( path, name, options = {}, access = {}) + def download!( path, options = {}, access = {}) api = Api::Request.new do |request| request[:access] = access request[:method] = :DOWNLOAD request[:path] = "/comparison/{{client_id}}/comparison/download" end api.add_params(options) response = api.execute! - filepath = "#{path}/#{name}" + filepath = "#{path}/#{file.name}" Object::File.open(filepath, 'wb') do |file| file.write(response) end end