Skip to content

Instantly share code, notes, and snippets.

@groupdocscloud
Last active January 12, 2020 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save groupdocscloud/ba011159eee59cd5a1f696ae6fadb2e4 to your computer and use it in GitHub Desktop.
Save groupdocscloud/ba011159eee59cd5a1f696ae6fadb2e4 to your computer and use it in GitHub Desktop.
# Load the gem
require 'groupdocs_signature_cloud'
require 'common_utilities/Utils.rb'
class Working_With_Files
def self.Editor_Ruby_Copy_File()
# Getting instance of the API
$api = Common_Utilities.Get_FileApi_Instance()
$request = GroupDocsEditorCloud::CopyFileRequest.new("Editor/one-page.docx", "Editor/one-page-copied.docx", $myStorage, $myStorage)
$response = $api.copy_file($request)
puts("Expected response type is Void: 'Editor/one-page.docx' file copied as 'Editor/one-page-copied.docx'.")
end
end
# Load the gem
require 'groupdocs_signature_cloud'
require 'common_utilities/Utils.rb'
class Working_With_Folder
def self.Editor_Ruby_Copy_Folder()
# Getting instance of the API
$api = Common_Utilities.Get_FolderApi_Instance()
$request = GroupDocsEditorCloud::CopyFolderRequest.new("Editordocs", "Editordocs1", $myStorage, $myStorage)
$response = $api.copy_folder($request)
puts("Expected response type is Void: 'Editordocs' folder copied as 'Editordocs1'.")
end
end
# Load the gem
require 'groupdocs_signature_cloud'
require 'common_utilities/Utils.rb'
class Working_With_Folder
def self.Editor_Ruby_Create_Folder()
# Getting instance of the API
$api = Common_Utilities.Get_FolderApi_Instance()
$request = GroupDocsEditorCloud::CreateFolderRequest.new("Editordocs", $myStorage)
$response = $api.create_folder($request)
puts("Expected response type is Void: 'Editordocs' folder created.")
end
end
# Load the gem
require 'groupdocs_signature_cloud'
require 'common_utilities/Utils.rb'
class Working_With_Files
def self.Editor_Ruby_Delete_File()
# Getting instance of the API
$api = Common_Utilities.Get_FileApi_Instance()
$request = GroupDocsEditorCloud::DeleteFileRequest.new("Editordocs1/one-page.docx", $myStorage)
$response = $api.delete_file($request)
puts("Expected response type is Void: 'Editordocs1/one-page.docx' deleted.")
end
end
# Load the gem
require 'groupdocs_signature_cloud'
require 'common_utilities/Utils.rb'
class Working_With_Folder
def self.Editor_Ruby_Delete_Folder()
# Getting instance of the API
$api = Common_Utilities.Get_FolderApi_Instance()
$request = GroupDocsEditorCloud::DeleteFolderRequest.new("Editordocs1", $myStorage, true)
$response = $api.delete_folder($request)
puts("Expected response type is Void: 'Editordocs/Editordocs1' folder deleted recursively.")
end
end
# Load the gem
require 'groupdocs_signature_cloud'
require 'common_utilities/Utils.rb'
class Working_With_Files
def self.Editor_Ruby_Download_File()
# Getting instance of the API
$api = Common_Utilities.Get_FileApi_Instance()
$request = GroupDocsEditorCloud::DownloadFileRequest.new("Editordocs/one-page.docx", $myStorage)
$response = $api.download_file($request)
puts("Expected response type is Stream: " + ($response).to_s)
end
end
# Load the gem
require 'groupdocs_signature_cloud'
require 'common_utilities/Utils.rb'
class Working_With_Storage
def self.Editor_Ruby_Get_Disc_Usage()
# Getting instance of the API
$api = Common_Utilities.Get_StorageApi_Instance()
$request = GroupDocsEditorCloud::GetDiscUsageRequest.new($myStorage)
$response = $api.get_disc_usage($request)
puts("Expected response type is DiscUsage: " + ($response).to_s)
end
end
# For complete examples and data files, please go to https://github.com/groupdocs-editor-cloud/groupdocs-editor-cloud-ruby-samples
require 'groupdocs_editor_cloud'
$app_sid = "XXXX-XXXX-XXXX-XXXX" # Get AppKey and AppSID from https://dashboard.groupdocs.cloud
$app_key = "XXXXXXXXXXXXXXXX" # Get AppKey and AppSID from https://dashboard.groupdocs.cloud
infoApi = GroupDocsEditorCloud::InfoApi.from_keys($app_sid, $app_key)
result = infoApi.get_supported_file_formats()
# For complete examples and data files, please go to https://github.com/groupdocs-editor-cloud/groupdocs-editor-cloud-ruby-samples
require 'groupdocs_editor_cloud'
$app_sid = "XXXX-XXXX-XXXX-XXXX" # Get AppKey and AppSID from https://dashboard.groupdocs.cloud
$app_key = "XXXXXXXXXXXXXXXX" # Get AppKey and AppSID from https://dashboard.groupdocs.cloud
infoApi = GroupDocsEditorCloud::InfoApi.from_keys($app_sid, $app_key)
fileInfo = GroupDocsEditorCloud::FileInfo.new
fileInfo.file_path = 'WordProcessing/password-protected.docx'
fileInfo.password = 'password'
request = GroupDocsEditorCloud::GetInfoRequest.new(fileInfo)
response = infoApi.get_info(request)
puts("Pages count = " + response.page_count.to_s)
# Load the gem
require 'groupdocs_signature_cloud'
require 'common_utilities/Utils.rb'
class Working_With_Storage
def self.Editor_Ruby_Get_File_Versions()
# Getting instance of the API
$api = Common_Utilities.Get_StorageApi_Instance()
$request = GroupDocsEditorCloud::GetFileVersionsRequest.new("Editordocs/one-page.docx", $myStorage)
$response = $api.get_file_versions($request)
puts("Expected response type is FileVersions: " + ($response).to_s)
end
end
# Load the gem
require 'groupdocs_signature_cloud'
require 'common_utilities/Utils.rb'
class Working_With_Folder
def self.Editor_Ruby_Get_Files_List()
# Getting instance of the API
$api = Common_Utilities.Get_FolderApi_Instance()
$request = GroupDocsEditorCloud::GetFilesListRequest.new("Editordocs/sample.docx", $myStorage)
$response = $api.get_files_list($request)
puts("Expected response type is FilesList: " + ($response).to_s)
end
end
# Load the gem
require 'groupdocs_signature_cloud'
require 'common_utilities/Utils.rb'
class Working_With_Files
def self.Editor_Ruby_Move_File()
# Getting instance of the API
$api = Common_Utilities.Get_FileApi_Instance()
$request = GroupDocsEditorCloud::MoveFileRequest.new("Editordocs/one-page.docx", "Editordocs1/one-page.docx", $myStorage, $myStorage)
$response = $api.move_file($request)
puts("Expected response type is Void: 'Editordocs/one-page.docx' file moved to 'Editordocs1/one-page.docx'.")
end
end
# Load the gem
require 'groupdocs_signature_cloud'
require 'common_utilities/Utils.rb'
class Working_With_Folder
def self.Editor_Ruby_Move_Folder()
# Getting instance of the API
$api = Common_Utilities.Get_FolderApi_Instance()
$request = GroupDocsEditorCloud::MoveFolderRequest.new("Editordocs1", "Editordocs/Editordocs1", $myStorage, $myStorage)
$response = $api.move_folder($request)
puts("Expected response type is Void: 'Editordocs1' folder moved to 'Editordocs/Editordocs1'.")
end
end
# Load the gem
require 'groupdocs_signature_cloud'
require 'common_utilities/Utils.rb'
class Working_With_Storage
def self.Editor_Ruby_Object_Exists()
# Getting instance of the API
$api = Common_Utilities.Get_StorageApi_Instance()
$request = GroupDocsEditorCloud::ObjectExistsRequest.new("Editordocs/one-page.docx", $myStorage)
$response = $api.object_exists($request)
puts("Expected response type is ObjectExist: " + ($response).to_s)
end
end
# Load the gem
require 'groupdocs_signature_cloud'
require 'common_utilities/Utils.rb'
class Working_With_Storage
def self.Editor_Ruby_Storage_Exist()
# Getting instance of the API
$api = Common_Utilities.Get_StorageApi_Instance()
$request = GroupDocsEditorCloud::StorageExistsRequest.new($myStorage)
$response = $api.storage_exists($request)
puts("Expected response type is StorageExist: " + ($response).to_s)
end
end
# Load the gem
require 'groupdocs_signature_cloud'
require 'common_utilities/Utils.rb'
class Working_With_Files
def self.Editor_Ruby_Upload_File()
# Getting instance of the API
$api = Common_Utilities.Get_FileApi_Instance()
$fileStream = File.new("..\\Resources\\Editordocs\\one-page.docx", "r")
$request = GroupDocsEditorCloud::UploadFileRequest.new("Editordocs/one-page1.docx", $fileStream, $myStorage)
$response = $api.upload_file($request)
$fileStream.close()
puts("Expected response type is FilesUploadResult: " + ($response).to_s)
end
end
# For complete examples and data files, please go to https://github.com/groupdocs-editor-cloud/groupdocs-editor-cloud-ruby-samples
require 'groupdocs_editor_cloud'
$app_sid = "XXXX-XXXX-XXXX-XXXX" # Get AppKey and AppSID from https://dashboard.groupdocs.cloud
$app_key = "XXXXXXXXXXXXXXXX" # Get AppKey and AppSID from https://dashboard.groupdocs.cloud
# Create necessary API instances
fileApi = GroupDocsEditorCloud::FileApi.from_keys($app_sid, $app_key)
editApi = GroupDocsEditorCloud::EditApi.from_keys($app_sid, $app_key)
# The document already uploaded into the storage.
# Load it into editable state
fileInfo = GroupDocsEditorCloud::FileInfo.new
fileInfo.file_path = 'Spreadsheet/sample.tsv'
loadOptions = GroupDocsEditorCloud::DelimitedTextLoadOptions.new
loadOptions.file_info = fileInfo
loadOptions.output_path = "output"
loadRequest = GroupDocsEditorCloud::LoadRequest.new(loadOptions)
loadResult = editApi.load(loadRequest)
# Download html document
htmlFile = fileApi.download_file(GroupDocsEditorCloud::DownloadFileRequest.new loadResult.html_path)
htmlFile.open
html = htmlFile.read
htmlFile.close
# Edit something...
html = html.gsub("32", "66")
# Upload html back to storage
htmlFile = File.open(htmlFile.path, "w")
htmlFile.write(html)
htmlFile.close
uploadRequest = GroupDocsEditorCloud::UploadFileRequest.new loadResult.html_path, File.open(htmlFile.path, "r")
fileApi.upload_file(uploadRequest)
# Save html back to tsv
saveOptions = GroupDocsEditorCloud::DelimitedTextSaveOptions.new
saveOptions.file_info = fileInfo
saveOptions.output_path = "output/edited.tsv"
saveOptions.html_path = loadResult.html_path
saveOptions.resources_path = loadResult.resources_path
saveRequest = GroupDocsEditorCloud::SaveRequest.new(saveOptions)
saveResult = editApi.save(saveRequest)
puts("Document edited: " + saveResult.path)
# For complete examples and data files, please go to https://github.com/groupdocs-editor-cloud/groupdocs-editor-cloud-ruby-samples
require 'groupdocs_editor_cloud'
$app_sid = "XXXX-XXXX-XXXX-XXXX" # Get AppKey and AppSID from https://dashboard.groupdocs.cloud
$app_key = "XXXXXXXXXXXXXXXX" # Get AppKey and AppSID from https://dashboard.groupdocs.cloud
# Create necessary API instances
fileApi = GroupDocsEditorCloud::FileApi.from_keys($app_sid, $app_key)
editApi = GroupDocsEditorCloud::EditApi.from_keys($app_sid, $app_key)
# The document already uploaded into the storage.
# Load it into editable state
fileInfo = GroupDocsEditorCloud::FileInfo.new
fileInfo.file_path = 'Presentation/with-notes.pptx'
loadOptions = GroupDocsEditorCloud::PresentationLoadOptions.new
loadOptions.file_info = fileInfo
loadOptions.output_path = "output"
loadOptions.slide_number = 0
loadRequest = GroupDocsEditorCloud::LoadRequest.new(loadOptions)
loadResult = editApi.load(loadRequest)
# Download html document
htmlFile = fileApi.download_file(GroupDocsEditorCloud::DownloadFileRequest.new loadResult.html_path)
htmlFile.open
html = htmlFile.read
htmlFile.close
# Edit something...
html = html.gsub("Slide sub-heading", "Hello world!")
# Upload html back to storage
htmlFile = File.open(htmlFile.path, "w")
htmlFile.write(html)
htmlFile.close
uploadRequest = GroupDocsEditorCloud::UploadFileRequest.new loadResult.html_path, File.open(htmlFile.path, "r")
fileApi.upload_file(uploadRequest)
# Save html back to pptx
saveOptions = GroupDocsEditorCloud::PresentationSaveOptions.new
saveOptions.file_info = fileInfo
saveOptions.output_path = "output/edited.pptx"
saveOptions.html_path = loadResult.html_path
saveOptions.resources_path = loadResult.resources_path
saveRequest = GroupDocsEditorCloud::SaveRequest.new(saveOptions)
saveResult = editApi.save(saveRequest)
puts("Document edited: " + saveResult.path)
# For complete examples and data files, please go to https://github.com/groupdocs-editor-cloud/groupdocs-editor-cloud-ruby-samples
require 'groupdocs_editor_cloud'
$app_sid = "XXXX-XXXX-XXXX-XXXX" # Get AppKey and AppSID from https://dashboard.groupdocs.cloud
$app_key = "XXXXXXXXXXXXXXXX" # Get AppKey and AppSID from https://dashboard.groupdocs.cloud
# Create necessary API instances
fileApi = GroupDocsEditorCloud::FileApi.from_keys($app_sid, $app_key)
editApi = GroupDocsEditorCloud::EditApi.from_keys($app_sid, $app_key)
# The document already uploaded into the storage.
# Load it into editable state
fileInfo = GroupDocsEditorCloud::FileInfo.new
fileInfo.file_path = 'Spreadsheet/four-sheets.xlsx'
loadOptions = GroupDocsEditorCloud::SpreadsheetLoadOptions.new
loadOptions.file_info = fileInfo
loadOptions.output_path = "output"
loadOptions.worksheet_index = 0
loadRequest = GroupDocsEditorCloud::LoadRequest.new(loadOptions)
loadResult = editApi.load(loadRequest)
# Download html document
htmlFile = fileApi.download_file(GroupDocsEditorCloud::DownloadFileRequest.new loadResult.html_path)
htmlFile.open
html = htmlFile.read
htmlFile.close
# Edit something...
html = html.gsub("This is sample sheet", "This is sample sheep")
# Upload html back to storage
htmlFile = File.open(htmlFile.path, "w")
htmlFile.write(html)
htmlFile.close
uploadRequest = GroupDocsEditorCloud::UploadFileRequest.new loadResult.html_path, File.open(htmlFile.path, "r")
fileApi.upload_file(uploadRequest)
# Save html back to xlsx
saveOptions = GroupDocsEditorCloud::SpreadsheetSaveOptions.new
saveOptions.file_info = fileInfo
saveOptions.output_path = "output/edited.xlsx"
saveOptions.html_path = loadResult.html_path
saveOptions.resources_path = loadResult.resources_path
saveRequest = GroupDocsEditorCloud::SaveRequest.new(saveOptions)
saveResult = editApi.save(saveRequest)
puts("Document edited: " + saveResult.path)
# For complete examples and data files, please go to https://github.com/groupdocs-editor-cloud/groupdocs-editor-cloud-ruby-samples
require 'groupdocs_editor_cloud'
$app_sid = "XXXX-XXXX-XXXX-XXXX" # Get AppKey and AppSID from https://dashboard.groupdocs.cloud
$app_key = "XXXXXXXXXXXXXXXX" # Get AppKey and AppSID from https://dashboard.groupdocs.cloud
# Create necessary API instances
fileApi = GroupDocsEditorCloud::FileApi.from_keys($app_sid, $app_key)
editApi = GroupDocsEditorCloud::EditApi.from_keys($app_sid, $app_key)
# The document already uploaded into the storage.
# Load it into editable state
fileInfo = GroupDocsEditorCloud::FileInfo.new
fileInfo.file_path = 'Text/document.txt'
loadOptions = GroupDocsEditorCloud::TextLoadOptions.new
loadOptions.file_info = fileInfo
loadOptions.output_path = "output"
loadRequest = GroupDocsEditorCloud::LoadRequest.new(loadOptions)
loadResult = editApi.load(loadRequest)
# Download html document
htmlFile = fileApi.download_file(GroupDocsEditorCloud::DownloadFileRequest.new loadResult.html_path)
htmlFile.open
html = htmlFile.read
htmlFile.close
# Edit something...
html = html.gsub("Page Text", "New Text")
# Upload html back to storage
htmlFile = File.open(htmlFile.path, "w")
htmlFile.write(html)
htmlFile.close
uploadRequest = GroupDocsEditorCloud::UploadFileRequest.new loadResult.html_path, File.open(htmlFile.path, "r")
fileApi.upload_file(uploadRequest)
# Save html back to txt
saveOptions = GroupDocsEditorCloud::TextSaveOptions.new
saveOptions.file_info = fileInfo
saveOptions.output_path = "output/edited.txt"
saveOptions.html_path = loadResult.html_path
saveOptions.resources_path = loadResult.resources_path
saveRequest = GroupDocsEditorCloud::SaveRequest.new(saveOptions)
saveResult = editApi.save(saveRequest)
puts("Document edited: " + saveResult.path)
# For complete examples and data files, please go to https://github.com/groupdocs-editor-cloud/groupdocs-editor-cloud-ruby-samples
require 'groupdocs_editor_cloud'
$app_sid = "XXXX-XXXX-XXXX-XXXX" # Get AppKey and AppSID from https://dashboard.groupdocs.cloud
$app_key = "XXXXXXXXXXXXXXXX" # Get AppKey and AppSID from https://dashboard.groupdocs.cloud
# Create necessary API instances
fileApi = GroupDocsEditorCloud::FileApi.from_keys($app_sid, $app_key)
editApi = GroupDocsEditorCloud::EditApi.from_keys($app_sid, $app_key)
# The document already uploaded into the storage.
# Load it into editable state
fileInfo = GroupDocsEditorCloud::FileInfo.new
fileInfo.file_path = 'WordProcessing/password-protected.docx'
fileInfo.password = 'password'
loadOptions = GroupDocsEditorCloud::WordProcessingLoadOptions.new
loadOptions.file_info = fileInfo
loadOptions.output_path = "output"
loadRequest = GroupDocsEditorCloud::LoadRequest.new(loadOptions)
loadResult = editApi.load(loadRequest)
# Download html document
htmlFile = fileApi.download_file(GroupDocsEditorCloud::DownloadFileRequest.new loadResult.html_path)
htmlFile.open
html = htmlFile.read
htmlFile.close
# Edit something...
html = html.gsub("Sample test text", "Hello world")
# Upload html back to storage
htmlFile = File.open(htmlFile.path, "w")
htmlFile.write(html)
htmlFile.close
uploadRequest = GroupDocsEditorCloud::UploadFileRequest.new loadResult.html_path, File.open(htmlFile.path, "r")
fileApi.upload_file(uploadRequest)
# Save html back to docx
saveOptions = GroupDocsEditorCloud::WordProcessingSaveOptions.new
saveOptions.file_info = fileInfo
saveOptions.output_path = "output/edited.docx"
saveOptions.html_path = loadResult.html_path
saveOptions.resources_path = loadResult.resources_path
saveRequest = GroupDocsEditorCloud::SaveRequest.new(saveOptions)
saveResult = editApi.save(saveRequest)
puts("Document edited: " + saveResult.path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment