lib/groupdocs/document.rb in groupdocs-1.2.11 vs lib/groupdocs/document.rb in groupdocs-1.3.0
- old
+ new
@@ -7,14 +7,14 @@
require 'groupdocs/document/metadata'
require 'groupdocs/document/rectangle'
require 'groupdocs/document/view'
ACCESS_MODES = {
- private: 0,
- restricted: 1,
- inherited: 2,
- public: 3,
+ :private => 0,
+ :restricted => 1,
+ :inherited => 2,
+ :public => 3,
}
include Api::Helpers::AccessMode
include Api::Helpers::AccessRights
include Api::Helpers::Status
@@ -59,11 +59,11 @@
request[:method] = :GET
request[:path] = '/merge/{{client_id}}/templates'
end.execute!
json[:templates].map do |template|
- template.merge!(file: Storage::File.new(template))
+ template.merge!(:file => Storage::File.new(template))
Document.new(template)
end
end
#
@@ -102,41 +102,41 @@
signature.position or raise ArgumentError, "Each signature should have position, received: #{signature.position.inspect}"
end
documents_to_sign = []
documents.map(&:file).each do |file|
- document = { name: file.name }
+ document = { :name => file.name }
contents = File.read(file.local_path)
contents = Base64.strict_encode64(contents)
- document.merge!(data: "data:#{mime_type(file.local_path)};base64,#{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 = Base64.strict_encode64(contents)
- signer = { name: signature.name, data: "data:#{mime_type(signature.image_path)};base64,#{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)
+ 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 }
+ request[:request_body] = { :documents => documents_to_sign, :signers => signers }
end.execute!
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)
+ file = Storage::File.new(:guid => document[:documentId], :name => "#{documents[i].file.name}_signed.pdf")
+ signed_documents << Document.new(:file => file)
end
signed_documents
end
@@ -161,11 +161,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))
+ metadata.last_view.document = new(:file => Storage::File.new(json))
end
end
end
# @attr [GroupDocs::Storage::File] file
@@ -200,11 +200,11 @@
# Returns output formats in human-readable format.
#
# @return [Array<Symbol>]
#
def output_formats
- @output_formats.split(?,).map(&:to_sym)
+ @output_formats.split(',').map(&:to_sym)
end
#
# Converts status to human-readable format.
#
@@ -272,10 +272,41 @@
json[:url]
end
#
+ # Returns array of URLs to images representing document pages thumbnails.
+ #
+ # @example
+ # file = GroupDocs::Storage::Folder.list!.last
+ # document = file.to_document
+ # document.thumbnails! first_page: 0, page_count: 1, width: 1024
+ #
+ # @param [Hash] options
+ # @option options [Integer] :page_number Start page to return image for (starting with 0)
+ # @option options [Integer] :page_count Number of pages to return image for
+ # @option options [Integer] :width
+ # @option options [Integer] :quality
+ # @option options [Boolean] :use_pdf
+ # @param [Hash] access Access credentials
+ # @option access [String] :client_id
+ # @option access [String] :private_key
+ # @return [Array<String>]
+ #
+ def thumbnails!(options = {}, access = {})
+ api = Api::Request.new do |request|
+ request[:access] = access
+ request[:method] = :POST
+ request[:path] = "/doc/{{client_id}}/files/#{file.guid}/thumbnails"
+ end
+ api.add_params(options)
+ json = api.execute!
+
+ json[:image_urls]
+ end
+
+ #
# Returns access mode of document.
#
# @param [Hash] access Access credentials
# @option access [String] :client_id
# @option access [String] :private_key
@@ -304,11 +335,11 @@
api = Api::Request.new do |request|
request[:access] = access
request[:method] = :PUT
request[:path] = "/doc/{{client_id}}/files/#{file.id}/accessinfo"
end
- api.add_params(mode: ACCESS_MODES[mode])
+ api.add_params(:mode => ACCESS_MODES[mode])
json = api.execute!
parse_access_mode(json[:access])
end
# note that aliased version cannot accept access credentials hash
@@ -373,11 +404,11 @@
api = Api::Request.new do |request|
request[:access] = access
request[:method] = :GET
request[:path] = "/doc/{{client_id}}/files/#{file.guid}/fields"
end
- api.add_params(include_geometry: true)
+ api.add_params(:include_geometry => true)
json = api.execute!
json[:fields].map do |field|
Document::Field.new(field)
end
@@ -465,21 +496,21 @@
# @option access [String] :client_id
# @option access [String] :private_key
# @return [GroupDocs::Job] Created job
#
def convert!(format, options = {}, access = {})
- options.merge!(new_type: format)
+ options.merge!(:new_type => format)
api = Api::Request.new do |request|
request[:access] = access
request[:method] = :POST
request[:path] = "/async/{{client_id}}/files/#{file.guid}"
end
api.add_params(options)
json = api.execute!
- Job.new(id: json[:job_id])
+ Job.new(:id => json[:job_id])
end
#
# Creates new job to merge datasource into document.
#
@@ -504,11 +535,11 @@
request[:path] = "/merge/{{client_id}}/files/#{file.guid}/datasources/#{datasource.id}"
end
api.add_params(options)
json = api.execute!
- Job.new(id: json[:job_id])
+ Job.new(:id => json[:job_id])
end
#
# Returns an array of questionnaires.
#
@@ -612,11 +643,11 @@
request[:path] = "/ant/{{client_id}}/files/#{file.guid}/annotations"
end.execute!
if json[:annotations]
json[:annotations].map do |annotation|
- annotation.merge!(document: self)
+ annotation.merge!(:document => self)
Document::Annotation.new(annotation)
end
else
[]
end
@@ -634,11 +665,11 @@
api = Api::Request.new do |request|
request[:access] = access
request[:method] = :GET
request[:path] = "/comparison/{{client_id}}/comparison/document"
end
- api.add_params(guid: file.guid)
+ api.add_params(:guid => file.guid)
api.execute!
end
#
# Schedules a job for comparing document with given.
@@ -658,14 +689,14 @@
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)
json = api.execute!
- Job.new(id: json[:job_id])
+ Job.new(:id => json[:job_id])
end
#
# Returns an array of changes in document.
#
@@ -685,10 +716,10 @@
api = Api::Request.new do |request|
request[:access] = access
request[:method] = :GET
request[:path] = "/comparison/{{client_id}}/comparison/changes"
end
- api.add_params(resultFileId: file.guid)
+ api.add_params(:resultFileId => file.guid)
json = api.execute!
json[:changes].map do |change|
Document::Change.new(change)
end