saasposesdk 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/saaspose.rb ADDED
@@ -0,0 +1,7 @@
1
+ #this file refers all the other necessary files of the saaspose.sdk for Ruby.
2
+
3
+ require 'saaspose_common'
4
+ require 'saaspose_storage'
5
+ require 'saaspose_cells'
6
+ require 'saaspose_pdf'
7
+ require 'saaspose_slides'
@@ -0,0 +1,24 @@
1
+ require_relative 'saaspose_storage'
2
+
3
+ # This module provide wrapper classes to work with Saaspose.Cells resources
4
+ module Cells
5
+ # This class provides functionality for converting Excel Spreadsheets to other supported formats.
6
+ class Convertor
7
+ # Constructor for the Convertor Class.
8
+ # * :name represents the name of the Excel Spreadsheet on the Saaspose server
9
+ def initialize(name)
10
+ # Instance variables
11
+ @name = name
12
+ end
13
+ # Uploads file from the local path to the remote folder.
14
+ # * :localFile represents full local file path and name
15
+ # * :saveFormat represents the converted format. For a list of supported formats, please visit
16
+ # http://saaspose.com/docs/display/cells/workbook
17
+ def convert(localFile,saveFormat)
18
+ urlDoc = $productURI + '/cells/' + @name + '?format=' + saveFormat
19
+ signedURL = Common::Utils.sign(urlDoc)
20
+ response = RestClient.get(signedURL, :accept => 'application/json')
21
+ Common::Utils.saveFile(response,localFile)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,98 @@
1
+ require 'rubygems'
2
+ require 'rest_client'
3
+ require 'json'
4
+ require 'openssl'
5
+ require 'base64'
6
+ require 'uri'
7
+ require 'rexml/document'
8
+
9
+ # This module provide common classes and methods to be ued by other modules
10
+ module Common
11
+
12
+ # This class allows you to set the base host Saaspose URI
13
+ class Product
14
+ def self.setBaseProductUri(productURI)
15
+ $productURI = productURI
16
+ end
17
+ end
18
+
19
+ # This class allows you to set the AppSID and AppKey values you get upon signing up
20
+ class SaasposeApp
21
+ def initialize(appSID,appKey)
22
+ $appSID = appSID
23
+ $appKey = appKey
24
+ end
25
+ end
26
+
27
+ # This class provides common methods to be repeatedly used by other wrapper classes
28
+ class Utils
29
+ # Signs a URI with your appSID and Key.
30
+ # * :url describes the URL to sign
31
+ # * :appSID holds the appSID value
32
+ # * :key holds the key value
33
+ def self.sign(url)
34
+ url = URI.escape(url)
35
+ parsedURL = URI.parse(url)
36
+
37
+ urlToSign =''
38
+ if parsedURL.query.nil?
39
+ urlToSign = parsedURL.scheme+"://"+ parsedURL.host + parsedURL.path + "?appSID=" + $appSID
40
+ else
41
+ urlToSign = parsedURL.scheme+"://"+ parsedURL.host + parsedURL.path + '?' + parsedURL.query + "&appSID=" + $appSID
42
+ end
43
+
44
+ # create a signature using the private key and the URL
45
+ rawSignature = OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), $appKey, urlToSign)
46
+
47
+ #Convert raw to encoded string
48
+ signature = Base64.strict_encode64(rawSignature).tr('+/','-_')
49
+
50
+ #remove invalid character
51
+ signature = signature.gsub(/[=_-]/,'=' => '','_' => '%2f','-' => '%2b')
52
+
53
+ #Define expression
54
+ pat = Regexp.new("%[0-9a-f]{2}")
55
+
56
+ #Replace the portion matched to the above pattern to upper case
57
+ for i in 0..5
58
+ signature = signature.sub(pat,pat.match(signature).to_s.upcase)
59
+ end
60
+
61
+ # prepend the server and append the signature.
62
+ signedUrl = urlToSign + "&signature=#{signature}"
63
+ return signedUrl
64
+ end
65
+
66
+ # Parses JSON date value to a valid date format
67
+ # * :datestring holds the JSON Date value
68
+ def self.parse_date(datestring)
69
+ seconds_since_epoch = datestring.scan(/[0-9]+/)[0].to_i
70
+ return Time.at((seconds_since_epoch-(21600000 + 18000000))/1000)
71
+ end
72
+
73
+ # Uploads a binary file from the client system
74
+ # * :localfile holds the local file path alongwith name
75
+ # * :url holds the required url to use while uploading the file to Saaspose Storage
76
+ def self.uploadFileBinary(localfile,url)
77
+ RestClient.put( url,File.new(localfile, 'rb'))
78
+ end
79
+
80
+ # Gets the count of a particular field in the response
81
+ # * :localfile holds the local file path alongwith name
82
+ # * :url holds the required url to use while uploading the file to Saaspose Storage
83
+ def self.getFieldCount(url,fieldName)
84
+ response = RestClient.get(url, :accept => 'application/xml')
85
+ doc = REXML::Document.new(response.body)
86
+ pages = []
87
+ doc.elements.each(fieldName) do |ele|
88
+ pages << ele.text
89
+ end
90
+ return pages.size
91
+ end
92
+ def self.saveFile(responseStream,localFile)
93
+ open(localFile, "wb") do |file|
94
+ file.write(responseStream.body)
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,34 @@
1
+ require_relative 'saaspose_storage'
2
+
3
+ # This module provide wrapper classes to work with Saaspose.Pdf resources
4
+ module Pdf
5
+ # This class provides functionality for converting PDF Documents to other supported formats.
6
+ class Convertor
7
+ # Constructor for the Convertor Class.
8
+ # * :name represents the name of the PDF Document on the Saaspose server
9
+ def initialize(name)
10
+ # Instance variables
11
+ @name = name
12
+ end
13
+ # Uploads file from the local path to the remote folder.
14
+ # * :localFile represents full local file path and name
15
+ # * :saveImageFormat represents the converted image format. For a list of supported image formats, please visit
16
+ # http://saaspose.com/docs/display/pdf/page
17
+ # * :pageNumber represents the page number in the PDF document
18
+ # * :height represents height of the converted image
19
+ # * :width represents width of the converted image
20
+ def convert(localFile,saveImageFormat,pageNumber,height,width)
21
+ urlDoc = $productURI + '/pdf/' + @name + '/pages/' + pageNumber + '?format=' + saveImageFormat + '&width=' + width + '&height=' + height
22
+ signedURL = Common::Utils.sign(urlDoc)
23
+ response = RestClient.get(signedURL, :accept => 'application/json')
24
+ Common::Utils.saveFile(response,localFile)
25
+ end
26
+ # Retruns the number of pages in a PDF document
27
+ def getPageCount
28
+ urlPage = $productURI + '/pdf/' + @name + '/pages'
29
+ signedURL = Common::Utils.sign(urlPage)
30
+ count = Common::Utils.getFieldCount(signedURL,'/SaaSposeResponse/Pages/Page')
31
+ return count
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,24 @@
1
+ require_relative 'saaspose_storage'
2
+
3
+ # This module provide wrapper classes to work with Saaspose.Slides resources
4
+ module Slides
5
+ # This class provides functionality for converting PowerPoint Presentations to other supported formats.
6
+ class Convertor
7
+ # Constructor for the Convertor Class.
8
+ # * :name represents the name of the PowerPoint Presentation on the Saaspose server
9
+ def initialize(name)
10
+ # Instance variables
11
+ @name = name
12
+ end
13
+ # Uploads file from the local path to the remote folder.
14
+ # * :localFile represents full local file path and name
15
+ # * :saveFormat represents the converted format. For a list of supported formats, please visit
16
+ # http://saaspose.com/docs/display/slides/presentation+Resource
17
+ def convert(localFile,saveFormat)
18
+ urlDoc = $productURI + '/slides/' + @name + '?format=' + saveFormat
19
+ signedURL = Common::Utils.sign(urlDoc)
20
+ response = RestClient.get(signedURL, :accept => 'application/json')
21
+ Common::Utils.saveFile(response,localFile)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,59 @@
1
+ require_relative 'saaspose_common'
2
+
3
+ # This module provides wrapper classes to work with Saaspose.Storage resources
4
+ module Storage
5
+ # This class represents File Saaspose URI data
6
+ class AppFile
7
+ attr_accessor :Name, :IsFolder, :ModifiedDate, :Size
8
+ end
9
+
10
+ # This class represents IsExist Saaspose URI data
11
+ class FileExist
12
+ attr_accessor :IsExist, :IsFolder
13
+ end
14
+
15
+ # This class represents Disc Saaspose URI data
16
+ class Disc
17
+ attr_accessor :TotalSize, :UsedSize
18
+ end
19
+
20
+ # This class provides functionality to manage files in a Remote Saaspose Folder
21
+ class Folder
22
+ # Uploads file from the local path to the remote folder.
23
+ # * :localFilePath represents full local file path and name
24
+ # * :remoteFolderPath represents remote folder relative to the root. Pass empty string for the root folder.
25
+ def self.uploadFile(localFilePath,remoteFolderPath)
26
+ fileName = File.basename(localFilePath)
27
+ urlFile = $productURI + '/storage/file/' + fileName
28
+ if not remoteFolderPath.empty?
29
+ urlFile = $productURI + '/storage/file/' + remoteFolderPath + '/' + fileName
30
+ end
31
+ signedURL = Common::Utils.sign(urlFile)
32
+ Common::Utils.uploadFileBinary(localFilePath,signedURL)
33
+ end
34
+ # Retrieves Files and Folder information from a remote folder. The method returns an Array of AppFile objects.
35
+ # * :remoteFolderPath represents remote folder relative to the root. Pass empty string for the root folder.
36
+ def self.getFiles(remoteFolderPath)
37
+ urlFolder = $productURI + '/storage/folder'
38
+ urlFile = ''
39
+ urlExist = ''
40
+ urlDisc = ''
41
+ if not remoteFolderPath.empty?
42
+ urlFile = $productURI + '/storage/folder/' + remoteFolderPath
43
+ end
44
+ signedURL = Common::Utils.sign(urlFolder)
45
+ response = RestClient.get(signedURL, :accept => 'application/json')
46
+ result = JSON.parse(response.body)
47
+ apps = Array.new(result["Files"].size)
48
+
49
+ for i in 0..result["Files"].size - 1
50
+ apps[i] = AppFile.new
51
+ apps[i].Name = result["Files"][i]["Name"]
52
+ apps[i].IsFolder = result["Files"][i]["IsFolder"]
53
+ apps[i].Size = result["Files"][i]["Size"]
54
+ apps[i].ModifiedDate = Common::Utils.parse_date(result["Files"][i]["ModifiedDate"])
55
+ end
56
+ return apps
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,24 @@
1
+ require_relative 'saaspose_storage'
2
+
3
+ # This module provide wrapper classes to work with Saaspose.Words resources
4
+ module Words
5
+ # This class provides functionality for converting Word Documents to other supported formats.
6
+ class Convertor
7
+ # Constructor for the Convertor Class.
8
+ # * :name represents the name of the Word Document on the Saaspose server
9
+ def initialize(name)
10
+ # Instance variables
11
+ @name = name
12
+ end
13
+ # Uploads file from the local path to the remote folder.
14
+ # * :localFile represents full local file path and name
15
+ # * :saveFormat represents the converted format. For a list of supported formats, please visit
16
+ # http://saaspose.com/docs/display/words/document
17
+ def convert(localFile,saveFormat)
18
+ urlDoc = $productURI + '/words/' + @name + '?format=' + saveFormat
19
+ signedURL = Common::Utils.sign(urlDoc)
20
+ response = RestClient.get(signedURL, :accept => 'application/json')
21
+ Common::Utils.saveFile(response,localFile)
22
+ end
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: saasposesdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Saaspose
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-12 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Saaspose.SDK for Ruby allows you to use Saaspose API in your Ruby applications
15
+ email: contact@saaspose.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/saaspose.rb
21
+ - lib/saaspose_cells.rb
22
+ - lib/saaspose_common.rb
23
+ - lib/saaspose_pdf.rb
24
+ - lib/saaspose_slides.rb
25
+ - lib/saaspose_storage.rb
26
+ - lib/saaspose_words.rb
27
+ homepage: http://www.saaspose.com
28
+ licenses: []
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubyforge_project:
47
+ rubygems_version: 1.8.17
48
+ signing_key:
49
+ specification_version: 3
50
+ summary: Saaspose.SDK for Ruby
51
+ test_files: []