saaspose 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.
Files changed (35) hide show
  1. data/.gitignore +0 -0
  2. data/.rspec +2 -0
  3. data/.rvmrc +1 -0
  4. data/.travis.yml +3 -0
  5. data/Gemfile +4 -0
  6. data/Gemfile.lock +44 -0
  7. data/README.md +79 -0
  8. data/lib/saaspose.rb +8 -0
  9. data/lib/saaspose/cells.rb +10 -0
  10. data/lib/saaspose/configuration.rb +39 -0
  11. data/lib/saaspose/pdf.rb +21 -0
  12. data/lib/saaspose/slides.rb +12 -0
  13. data/lib/saaspose/storage.rb +29 -0
  14. data/lib/saaspose/utils.rb +62 -0
  15. data/lib/saaspose/version.rb +3 -0
  16. data/lib/saaspose/words.rb +12 -0
  17. data/saaspose.gemspec +25 -0
  18. data/spec/fixtures/saaspose_test.doc +0 -0
  19. data/spec/fixtures/saaspose_test.pdf +0 -0
  20. data/spec/fixtures/saaspose_test.ppt +0 -0
  21. data/spec/fixtures/saaspose_test.xls +0 -0
  22. data/spec/lib/saaspose_spec.rb +105 -0
  23. data/spec/spec_helper.rb +26 -0
  24. data/spec/vcr_cassettes/ensure_remote_file_saaspose_test_doc.yml +40 -0
  25. data/spec/vcr_cassettes/ensure_remote_file_saaspose_test_pdf.yml +40 -0
  26. data/spec/vcr_cassettes/ensure_remote_file_saaspose_test_ppt.yml +40 -0
  27. data/spec/vcr_cassettes/ensure_remote_file_saaspose_test_xls.yml +40 -0
  28. data/spec/vcr_cassettes/saaspose/cells_should_generate_a_pdf_from_a_remote_xls.yml +409 -0
  29. data/spec/vcr_cassettes/saaspose/pdf_should_generate_a_png_from_a_remote_pdf.yml +905 -0
  30. data/spec/vcr_cassettes/saaspose/pdf_should_read_the_number_of_pages_from_a_remote_pdf.yml +43 -0
  31. data/spec/vcr_cassettes/saaspose/slides_should_generate_a_pdf_from_a_remote_ppt.yml +12882 -0
  32. data/spec/vcr_cassettes/saaspose/storage_should_get_a_list_of_files_from_the_root_dir.yml +40 -0
  33. data/spec/vcr_cassettes/saaspose/storage_should_upload_a_file_to_the_root_dir.yml +805 -0
  34. data/spec/vcr_cassettes/saaspose/words_should_generate_a_pdf_from_a_remote_doc.yml +767 -0
  35. metadata +150 -0
data/.gitignore ADDED
File without changes
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm 1.9.3@saaspose --create
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ script: "bundle exec rspec"
2
+ rvm:
3
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ # A sample Gemfile
2
+ source "https://rubygems.org"
3
+
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,44 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ saasposesdk (0.1.0)
5
+ rest-client (~> 1.6)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.2.7)
11
+ coderay (1.0.6)
12
+ crack (0.3.1)
13
+ diff-lcs (1.1.3)
14
+ method_source (0.7.1)
15
+ mime-types (1.18)
16
+ pry (0.9.9.4)
17
+ coderay (~> 1.0.5)
18
+ method_source (~> 0.7.1)
19
+ slop (>= 2.4.4, < 3)
20
+ rest-client (1.6.7)
21
+ mime-types (>= 1.16)
22
+ rspec (2.9.0)
23
+ rspec-core (~> 2.9.0)
24
+ rspec-expectations (~> 2.9.0)
25
+ rspec-mocks (~> 2.9.0)
26
+ rspec-core (2.9.0)
27
+ rspec-expectations (2.9.1)
28
+ diff-lcs (~> 1.1.3)
29
+ rspec-mocks (2.9.0)
30
+ slop (2.4.4)
31
+ vcr (2.1.1)
32
+ webmock (1.8.6)
33
+ addressable (>= 2.2.7)
34
+ crack (>= 0.1.7)
35
+
36
+ PLATFORMS
37
+ ruby
38
+
39
+ DEPENDENCIES
40
+ pry (~> 0.9)
41
+ rspec (~> 2.9)
42
+ saasposesdk!
43
+ vcr (~> 2.1)
44
+ webmock (~> 1.8)
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ #Saaspose.SDK for Ruby Repository
2
+
3
+ This repository contains Saaspose.SDK for Ruby source code. This SDK allows you to work with Saaspose REST API in your Ruby applications quickly and easily.
4
+
5
+
6
+ ##What's included in this SDK repository?
7
+
8
+ ###Code
9
+
10
+ <table>
11
+ <tr>
12
+ <th>Module</th>
13
+ <th>Description</th>
14
+ </tr>
15
+
16
+ <tr>
17
+ <td>Common</td>
18
+ <td>This module provides the features commonly used by other sections of the SDK.</td>
19
+ </tr>
20
+
21
+ <tr>
22
+ <td>Storage</td>
23
+ <td>This module provides the features to work with Saaspose storage.</td>
24
+ </tr>
25
+
26
+ <tr>
27
+ <td>Pdf</td>
28
+ <td>This module provides the features to manipulate PDF files using Saaspose.Pdf.</td>
29
+ </tr>
30
+
31
+ <tr>
32
+ <td>Words</td>
33
+ <td>This module provides the features to manipulate Word files using Saaspose.Words.</td>
34
+ </tr>
35
+
36
+ <tr>
37
+ <td>Cells</td>
38
+ <td>This module provides the features to manipulate Excel files using Saaspose.Cells.</td>
39
+ </tr>
40
+
41
+ <tr>
42
+ <td>Slides</td>
43
+ <td>This module provides the features to manipulate Powerpoint files using Saaspose.Slides.</td>
44
+ </tr>
45
+
46
+ <tr>
47
+ <td>BarCode</td>
48
+ <td>This module provides the features to manipulate bar codes using Saaspose.BarCode.</td>
49
+ </tr>
50
+
51
+
52
+ </table>
53
+
54
+
55
+
56
+ ###Data
57
+
58
+ In order to manipulate any files, you first need to upload them to the Saaspose storage using Storage module.
59
+
60
+ ###Output
61
+
62
+ The Saaspose.SDK for Ruby allows you to save the output files at your specified location.
63
+
64
+
65
+ ###Help Material
66
+
67
+ You may get help regarding Saaspose API or Saaspose.SDK for Ruby on [www.saaspose.com](http://www.saaspose.com).
68
+
69
+ ##How to use Saaspose.SDK for Ruby?
70
+
71
+ Please see the Saaaspose.SDK for Ruby Examples sections in the [Documentation](http://www.saaspose.com/docs).
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
data/lib/saaspose.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "saaspose/version"
2
+ require "saaspose/configuration"
3
+ require "saaspose/utils"
4
+ require "saaspose/pdf"
5
+ require "saaspose/slides"
6
+ require "saaspose/words"
7
+ require "saaspose/cells"
8
+ require "saaspose/storage"
@@ -0,0 +1,10 @@
1
+ module Saaspose
2
+ class Cells
3
+ class << self
4
+ def convert(name, file, options={:format=>:pdf})
5
+ url = "/cells/#{name}"
6
+ Utils.call(url, options, file)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,39 @@
1
+ require "logger"
2
+
3
+ module Saaspose
4
+ class Configuration
5
+ class << self
6
+ attr_accessor :product_uri
7
+ attr_accessor :app_sid, :app_key
8
+ attr_accessor :logger
9
+ attr_accessor :init
10
+
11
+ def configure(options={})
12
+ init_config
13
+ if block_given?
14
+ yield self
15
+ else
16
+ options.each do |key, value|
17
+ send(:"#{key}=", value)
18
+ end
19
+ end
20
+ self
21
+ end
22
+
23
+ def reset
24
+ init_config(true)
25
+ end
26
+
27
+ private
28
+
29
+ def init_config(force=false)
30
+ return if @init && !force
31
+ @init = true
32
+ @product_uri = ""
33
+ @app_key = ""
34
+ @app_sid = ""
35
+ @logger = Logger.new(STDERR)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,21 @@
1
+ require "rexml/document"
2
+
3
+ module Saaspose
4
+ class Pdf
5
+ class << self
6
+ def convert(name, local_file, save_image_format, page_number, height, width)
7
+ url_doc = Configuration.product_uri + '/pdf/' + name + '/pages/' + page_number + '?format=' + save_image_format + '&width=' + width + '&height=' + height
8
+ signed_url = Utils.sign(url_doc)
9
+ response = RestClient.get(signed_url, :accept => 'application/json')
10
+ Utils.save_file(response, local_file)
11
+ end
12
+
13
+ def page_count(name)
14
+ url_page = Configuration.product_uri + '/pdf/' + name + '/pages'
15
+ signed_url = Utils.sign(url_page)
16
+ response = RestClient.get(signed_url, :accept => 'application/xml')
17
+ REXML::Document.new(response.body).elements.size
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,12 @@
1
+ module Saaspose
2
+ class Slides
3
+ class << self
4
+ def convert(name, local_file, save_format)
5
+ url_doc = Configuration.product_uri + '/slides/' + name + '?format=' + save_format
6
+ signed_url = Utils.sign(url_doc)
7
+ response = RestClient.get(signed_url, :accept => 'application/json')
8
+ Utils.save_file(response, local_file)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,29 @@
1
+ require "json"
2
+
3
+ module Saaspose
4
+ class Storage
5
+ File = Struct.new(:name, :folder, :modified, :size)
6
+
7
+ class << self
8
+ def upload(local_file_path, remote_folder_path)
9
+ file_name = ::File.basename(local_file_path)
10
+ url_file = "#{Configuration.product_uri}/storage/file/#{remote_folder_path.empty? ? "" : "/#{remote_folder_path}" }#{file_name}"
11
+ signed_url = Utils.sign(url_file)
12
+ RestClient.put(signed_url, ::File.new(local_file_path, 'rb'))
13
+ end
14
+
15
+ def files(remote_folder_path="")
16
+ url_folder = "#{Configuration.product_uri}/storage/folder"
17
+ url_folder << "/#{remote_folder_path}" unless remote_folder_path.empty?
18
+
19
+ signed_url = Utils.sign(url_folder)
20
+ response = RestClient.get(signed_url, :accept => 'application/json')
21
+ result = JSON.parse(response.body)
22
+
23
+ result["Files"].map do |entry|
24
+ File.new(entry["Name"], entry["IsFolder"], Utils.parse_date(entry["ModifiedDate"]), entry["Size"])
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,62 @@
1
+ require 'cgi'
2
+ require 'rest_client'
3
+ require 'openssl'
4
+ require 'base64'
5
+ require 'uri'
6
+
7
+ module Saaspose
8
+ class Utils
9
+ class << self
10
+ # Signs a URI with your appSID and Key.
11
+ # * :url describes the URL to sign
12
+ def sign(url)
13
+ url = URI.escape(url)
14
+ parsed_url = URI.parse(url)
15
+
16
+ url_to_sign =''
17
+ if parsed_url.query.nil?
18
+ url_to_sign = parsed_url.scheme+"://"+ parsed_url.host + parsed_url.path + "?appSID=" + Configuration.app_sid
19
+ else
20
+ url_to_sign = parsed_url.scheme+"://"+ parsed_url.host + parsed_url.path + '?' + parsed_url.query + "&appSID=" + Configuration.app_sid
21
+ end
22
+
23
+ # create a signature using the private key and the URL
24
+ raw_signature = OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), Configuration.app_key, url_to_sign)
25
+
26
+ #Convert raw to encoded string
27
+ signature = Base64.strict_encode64(raw_signature).tr('+/','-_')
28
+
29
+ #remove invalid character
30
+ signature = signature.gsub(/[=_-]/,'=' => '', '_' => '%2f', '-' => '%2b')
31
+
32
+ #Define expression
33
+ pat = /%[0-9a-f]{2}/
34
+
35
+ #Replace the portion matched to the above pattern to upper case
36
+ 6.times do
37
+ signature = signature.sub(pat, pat.match(signature).to_s.upcase)
38
+ end
39
+
40
+ # prepend the server and append the signature.
41
+ url_to_sign + "&signature=#{signature}"
42
+ end
43
+
44
+ def parse_date(date_string)
45
+ seconds_since_epoch = date_string.scan(/[0-9]+/)[0].to_i
46
+ Time.at((seconds_since_epoch-(21600000 + 18000000))/1000)
47
+ end
48
+
49
+ def call(uri, options, file)
50
+ url = "#{Configuration.product_uri}#{uri}"
51
+ url << "?" << options.map{|key, value| "#{key}=#{CGI::escape(value.to_s)}"}.join("&") if options
52
+ signed_url = Utils.sign(url)
53
+ response = RestClient.get(signed_url, :accept => 'application/json')
54
+ Utils.save_file(response, file)
55
+ end
56
+
57
+ def save_file(response_stream, local_file)
58
+ File.open(local_file, "wb") { |file| file.write(response_stream.body) }
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,3 @@
1
+ module Saaspose
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,12 @@
1
+ module Saaspose
2
+ class Words
3
+ class << self
4
+ def convert(name, local_file, save_format)
5
+ urlDoc = Configuration.product_uri + '/words/' + name + '?format=' + save_format
6
+ signedURL = Utils.sign(urlDoc)
7
+ response = RestClient.get(signedURL, :accept => 'application/json')
8
+ Utils.save_file(response, local_file)
9
+ end
10
+ end
11
+ end
12
+ end
data/saaspose.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "saaspose/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'saaspose'
7
+ s.version = Saaspose::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.summary = s.description = "Ruby bindings to Saaspose REST API"
10
+ s.authors = ["Peter Schröder"]
11
+ s.email = 'phoetmail@googlemail.com'
12
+ s.homepage = 'http://nofail.de'
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ s.add_dependency 'rest-client', '~> 1.6'
20
+
21
+ s.add_development_dependency 'vcr', '~> 2.1'
22
+ s.add_development_dependency 'webmock', '~> 1.8'
23
+ s.add_development_dependency 'rspec', '~> 2.9'
24
+ s.add_development_dependency 'pry', '~> 0.9'
25
+ end
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,105 @@
1
+ require "spec_helper"
2
+
3
+ describe "saaspose" do
4
+ REMOTE_ROOT_DIR = ""
5
+
6
+ PNG_PATH = "/tmp/test.png"
7
+ PDF_PATH = "/tmp/test.pdf"
8
+
9
+ TEST_PDF_NAME = "saaspose_test.pdf"
10
+ TEST_PPT_NAME = "saaspose_test.ppt"
11
+ TEST_DOC_NAME = "saaspose_test.doc"
12
+ TEST_XLS_NAME = "saaspose_test.xls"
13
+
14
+ before(:all) do
15
+ configure_client
16
+ [TEST_PDF_NAME, TEST_PPT_NAME, TEST_DOC_NAME, TEST_XLS_NAME].each { |path| ensure_remote_file(path) }
17
+ end
18
+
19
+ before(:each) do
20
+ [PNG_PATH, PDF_PATH].each { |path| FileUtils.rm(path) if File.exists?(path) }
21
+ end
22
+
23
+ context "pdf" do
24
+ it "should generate a png from a remote pdf", :vcr => true do
25
+ Saaspose::Pdf.convert(TEST_PDF_NAME, PNG_PATH, 'png', '1', '800', '600')
26
+ File.exists?(PNG_PATH).should be_true
27
+ end
28
+
29
+ it "should read the number of pages from a remote pdf", :vcr => true do
30
+ Saaspose::Pdf.page_count(TEST_PDF_NAME).should eql(1)
31
+ end
32
+ end
33
+
34
+ context "slides" do
35
+ it "should generate a pdf from a remote ppt", :vcr => true do
36
+ Saaspose::Slides.convert(TEST_PPT_NAME, PDF_PATH, 'pdf')
37
+ File.exists?(PDF_PATH).should be_true
38
+ end
39
+ end
40
+
41
+ context "words" do
42
+ it "should generate a pdf from a remote doc", :vcr => true do
43
+ Saaspose::Words.convert(TEST_DOC_NAME, PDF_PATH, 'pdf')
44
+ File.exists?(PDF_PATH).should be_true
45
+ end
46
+ end
47
+
48
+ context "cells" do
49
+ it "should generate a pdf from a remote xls", :vcr => true do
50
+ Saaspose::Cells.convert(TEST_XLS_NAME, PDF_PATH)
51
+ File.exists?(PDF_PATH).should be_true
52
+ end
53
+ end
54
+
55
+ context "storage" do
56
+ let(:folder) { Saaspose::Storage::File.new("test", true, Time.at(1334562314), 0) }
57
+
58
+ it "should upload a file to the root dir", :vcr => true do
59
+ resp = Saaspose::Storage.upload(fixture_path(TEST_PDF_NAME), REMOTE_ROOT_DIR)
60
+ resp.should match("<Status>OK</Status>")
61
+ end
62
+
63
+ it "should get a list of files from the root dir", :vcr => true do
64
+ files = Saaspose::Storage.files(REMOTE_ROOT_DIR)
65
+ files.first.should be_an_instance_of(Saaspose::Storage::File)
66
+ files.map(&:name).should include(TEST_PDF_NAME)
67
+ files.first.should eql(folder)
68
+ end
69
+ end
70
+
71
+ context "utils" do
72
+ before(:each) do
73
+ Saaspose::Configuration.configure do |config|
74
+ config.app_sid = "SAASPOSE_APPSID"
75
+ config.app_key = "SAASPOSE_APPKEY"
76
+ end
77
+ end
78
+
79
+ let(:url) { "http://example.com/path?uschi=true&a_param=yes" }
80
+ it "should sign a uri" do
81
+ Saaspose::Utils.sign(url).should eql("http://example.com/path?uschi=true&a_param=yes&appSID=SAASPOSE_APPSID&signature=zl%2BjolbjggyKZ31QgflGVILu%2F0I")
82
+ end
83
+ end
84
+ end
85
+
86
+ def configure_client
87
+ Saaspose::Configuration.configure do |config|
88
+ config.product_uri = "http://api.saaspose.com/v1.0"
89
+ config.app_sid = ENV["SAASPOSE_APPSID"]
90
+ config.app_key = ENV["SAASPOSE_APPKEY"]
91
+ end
92
+ end
93
+
94
+ def ensure_remote_file(test_file)
95
+ VCR.use_cassette("ensure_remote_file #{test_file}", :record => :new_episodes, :match_requests_on => [:host, :path]) do
96
+ unless Saaspose::Storage.files.map(&:name).include?(test_file)
97
+ puts "uploading #{test_file} for testing purposes"
98
+ Saaspose::Storage.upload(fixture_path(test_file), REMOTE_ROOT_DIR)
99
+ end
100
+ end
101
+ end
102
+
103
+ def fixture_path(name)
104
+ File.expand_path("../fixtures/#{name}", File.dirname(__FILE__))
105
+ end