docraptor 2.0.0 → 3.1.0

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 (83) hide show
  1. checksums.yaml +4 -4
  2. data/.docker_env.list +5 -0
  3. data/.docker_mounts.list +4 -0
  4. data/.generator-language-identifier +1 -0
  5. data/.generator-revision +1 -0
  6. data/.github/pull_request_template.txt +17 -0
  7. data/.gitignore +20 -14
  8. data/.gitlab-ci.yml +26 -0
  9. data/.openapi-generator/FILES +32 -0
  10. data/.openapi-generator/VERSION +1 -0
  11. data/{.swagger-codegen-ignore → .openapi-generator-ignore} +13 -7
  12. data/.review/README.md +16 -0
  13. data/.review/generated_files/.gitignore +39 -0
  14. data/.review/generated_files/README.md +108 -0
  15. data/.review/generated_files/docs/AsyncDoc.md +18 -0
  16. data/.review/generated_files/docs/Doc.md +50 -0
  17. data/.review/generated_files/docs/DocApi.md +503 -0
  18. data/.review/generated_files/docs/DocStatus.md +28 -0
  19. data/.review/generated_files/docs/PrinceOptions.md +82 -0
  20. data/.review/generated_files/spec/api/doc_api_spec.rb +112 -0
  21. data/{spec → .review/generated_files/spec}/api_client_spec.rb +6 -21
  22. data/{spec → .review/generated_files/spec}/configuration_spec.rb +6 -6
  23. data/.review/generated_files/spec/models/async_doc_spec.rb +34 -0
  24. data/.review/generated_files/spec/models/doc_spec.rb +138 -0
  25. data/.review/generated_files/spec/models/doc_status_spec.rb +64 -0
  26. data/.review/generated_files/spec/models/prince_options_spec.rb +234 -0
  27. data/{spec → .review/generated_files/spec}/spec_helper.rb +3 -3
  28. data/.rubocop.yml +148 -0
  29. data/.runtime-environments +13 -0
  30. data/.travis.yml +9 -7
  31. data/CHANGELOG.md +8 -0
  32. data/Gemfile +3 -1
  33. data/README.md +8 -8
  34. data/Rakefile +1 -2
  35. data/docraptor.gemspec +5 -19
  36. data/docraptor.yaml +283 -284
  37. data/examples/async.rb +24 -30
  38. data/examples/hosted_async.rb +21 -33
  39. data/examples/hosted_sync.rb +19 -32
  40. data/examples/sync.rb +20 -26
  41. data/gemfiles/Gemfile.2.5.lock +70 -0
  42. data/gemfiles/Gemfile.2.6.lock +70 -0
  43. data/gemfiles/Gemfile.2.7.lock +70 -0
  44. data/gemfiles/Gemfile.3.0.lock +70 -0
  45. data/gemfiles/Gemfile.3.1.lock +72 -0
  46. data/gemfiles/Gemfile.3.2.lock +72 -0
  47. data/gemfiles/Gemfile.3.3.lock +72 -0
  48. data/{swagger-config.json → generator-config.json} +3 -2
  49. data/lib/docraptor/api/doc_api.rb +180 -85
  50. data/lib/docraptor/api_client.rb +91 -90
  51. data/lib/docraptor/api_error.rb +23 -3
  52. data/lib/docraptor/configuration.rb +101 -15
  53. data/lib/docraptor/models/async_doc.rb +53 -18
  54. data/lib/docraptor/models/doc.rb +80 -50
  55. data/lib/docraptor/models/doc_status.rb +58 -23
  56. data/lib/docraptor/models/prince_options.rb +149 -75
  57. data/lib/docraptor/version.rb +4 -4
  58. data/lib/docraptor.rb +3 -3
  59. data/script/clean +2 -2
  60. data/script/console +5 -0
  61. data/script/docker +56 -0
  62. data/script/fix_gemspec.rb +3 -18
  63. data/script/generate_language +43 -4
  64. data/script/inside_container/README.md +6 -0
  65. data/script/inside_container/test +87 -0
  66. data/script/post_generate_language +8 -2
  67. data/script/release +13 -0
  68. data/script/setup +25 -14
  69. data/script/swagger +6 -33
  70. data/script/test +30 -27
  71. data/test/async.rb +2 -2
  72. data/test/expire_hosted.rb +2 -2
  73. data/test/hosted_async.rb +7 -1
  74. data/test/hosted_sync.rb +2 -2
  75. data/test/iframes_default.rb +40 -0
  76. data/test/iframes_false.rb +40 -0
  77. data/test/iframes_true.rb +40 -0
  78. data/test/prince_options.rb +45 -0
  79. data/test/sync.rb +2 -2
  80. data/test/xlsx.rb +10 -3
  81. metadata +52 -214
  82. data/.swagger-codegen/VERSION +0 -1
  83. data/.swagger-revision +0 -1
@@ -0,0 +1,87 @@
1
+ #!/bin/bash
2
+ set -e
3
+ cd "$(dirname "$0")/../.."
4
+
5
+ apt update
6
+ apt install poppler-utils -y
7
+
8
+ # check dependencies
9
+ ruby -v > /dev/null || (echo "ruby must be installed"; exit 1)
10
+
11
+ major_minor_version="$(ruby -e 'puts RUBY_VERSION.split(".")[0, 2].join(".")')"
12
+ gemfile_lock="gemfiles/Gemfile.${major_minor_version}.lock"
13
+ if [ -f "$gemfile_lock" ]; then
14
+ cp -v "$gemfile_lock" Gemfile.lock
15
+ else
16
+ rm -vf Gemfile.lock
17
+ fi
18
+
19
+ bundle -v > /dev/null || (echo "bundler must be installed"; exit 1)
20
+
21
+ # TODO: update to test against updates dependencies as well
22
+ bundle install
23
+
24
+ if [ ! -f "$gemfile_lock" ]; then
25
+ cp -v Gemfile.lock "$gemfile_lock"
26
+ fi
27
+
28
+ cd test
29
+
30
+
31
+ green() {
32
+ tput bold # bold text
33
+ tput setaf 2 # green text
34
+ echo -n "$@"
35
+ tput sgr0 # reset to default text
36
+ }
37
+ red() {
38
+ tput bold # bold text
39
+ tput setaf 1 # red text
40
+ echo -n "$@"
41
+ tput sgr0 # reset to default text
42
+ }
43
+
44
+
45
+ key_relative_path="tmp/.docraptor_key"
46
+ key_path="../$key_relative_path"
47
+
48
+ # runs a test file with PASS/FAIL message
49
+ run_test() {
50
+ test_success="true"
51
+ test_name="$1 ${2:-(without $key_relative_path)}"
52
+ if [[ "$DOCRAPTOR_KEY" == "" ]] && [ -f "$key_path" ]; then
53
+ (
54
+ export DOCRAPTOR_KEY="$(cat "$key_path")"
55
+ run_test $1 "(with $key_relative_path)"
56
+ ) || test_success="false"
57
+ fi
58
+
59
+ if ruby $1; then
60
+ echo "$(green PASS) $test_name"
61
+ else
62
+ test_success="false"
63
+ echo "$(red FAIL) $test_name"
64
+ fi
65
+
66
+ if [ $test_success == "true" ]; then
67
+ return 0
68
+ else
69
+ return 1
70
+ fi
71
+ }
72
+
73
+ success="true"
74
+
75
+ if [ "$1" == "" ]; then
76
+ for test in $(ls *.rb); do
77
+ run_test $test || success="false"
78
+ done
79
+ else
80
+ run_test $1.rb || success="false"
81
+ fi
82
+
83
+ if [ $success == "true" ]; then
84
+ exit 0
85
+ else
86
+ exit 1
87
+ fi
@@ -1,9 +1,15 @@
1
- #!/bin/sh
1
+ #!/bin/bash
2
2
  set -e
3
- cd "`dirname \"$0\"`/.."
3
+ [[ "$TRACE" == "true" ]] && set -x
4
+ cd "$(dirname "$0")/.."
4
5
 
5
6
  echo "Removing trailing whitespace..."
6
7
  find lib -name "*.rb" -type f -exec sed -E -i '' 's/[[:space:]]+$//g' {} +
7
8
 
8
9
  echo "Fixing gemspec to work around swagger..."
9
10
  ruby script/fix_gemspec.rb
11
+
12
+ if compgen -G "patches/*.patch" > /dev/null; then
13
+ echo "Apply patches to generated code"
14
+ git apply --verbose patches/*.patch
15
+ fi
data/script/release ADDED
@@ -0,0 +1,13 @@
1
+ #!/bin/bash
2
+ set -e
3
+ [[ "$TRACE" == "true" ]] && set -x
4
+ cd "$(dirname "$0")/.."
5
+
6
+
7
+ if [[ "$INSIDE_DOCKER" != "true" ]]; then
8
+ git config --local user.email "$(git config --get user.email)"
9
+ exec script/docker "/app/script/$(basename "$0")"
10
+ fi
11
+
12
+ public_remote="$(git remote -v | grep -i 'git@github.com:DocRaptor/docraptor-ruby.git' | head -n 1 | cut -f1)"
13
+ rake "release[${public_remote}]"
data/script/setup CHANGED
@@ -2,24 +2,35 @@
2
2
  set -e
3
3
  cd "$(dirname "$0")/.."
4
4
 
5
- rbenv which ruby || (brew upgrade ruby-build || true; rbenv install)
5
+ setup_echo() {
6
+ echo "[script/setup] $1"
7
+ }
6
8
 
7
- # Setup rbenv so we can switch rubies below
8
- eval "$(rbenv init - --no-rehash)"
9
+ setup_error() {
10
+ echo "[script/setup][ERROR] $1"
11
+ }
9
12
 
10
- for ruby_version in `ruby -ryaml -e 'puts YAML.load(File.read(".travis.yml"))["rvm"].join(" ")'`; do
11
- rbenv versions --bare | grep "^${ruby_version}$" || rbenv install $ruby_version
12
- rbenv shell $ruby_version
13
- gem list -i bundler --version 2.2.15 >/dev/null || gem install bundler:2.2.15
13
+ brew_install() {
14
+ setup_echo "Installing $1..."
15
+ brew list --formula "$1" > /dev/null || brew install --formula "$1"
16
+ }
14
17
 
15
- bundle install
16
- done
18
+ brew_cask_install() {
19
+ setup_echo "Installing cask $1..."
20
+ brew list --cask "$1" &> /dev/null || brew install --cask "$1"
21
+ }
22
+
23
+ brew_cask_install docker
24
+ brew_install docker
25
+
26
+ # Avoid a warning message (vs. --overwrite)
27
+ brew unlink docker && brew link docker
17
28
 
18
29
  tput bold # bold text
19
30
  tput setaf 2 # green text
20
- echo "****************************************************************"
21
- echo "* *"
22
- echo "* Good to go! *"
23
- echo "* *"
24
- echo "****************************************************************"
31
+ setup_echo "****************************************************************"
32
+ setup_echo "* *"
33
+ setup_echo "* Good to go! *"
34
+ setup_echo "* *"
35
+ setup_echo "****************************************************************"
25
36
  tput sgr0 # reset to default text
data/script/swagger CHANGED
@@ -2,39 +2,12 @@
2
2
  set -e
3
3
  cd "$(dirname "$0")/.."
4
4
 
5
- SWAGGER_CODGEN_REVISION=$(cat .swagger-revision 2> /dev/null || true)
6
- if [ "$SWAGGER_CODGEN_REVISION" = "" ]; then
7
- echo "Set a revision of swagger-codegen to use in .swagger-revision"
8
- exit 1
9
- fi
5
+ set -x
10
6
 
11
- if ! [ -x "$(command -v mvn)" ]; then
12
- echo 'Error: mvn not installed, using homebrew to install' >&2
13
- brew install maven
14
- fi
15
-
16
- if [ ! -d "swagger-codegen" ]; then
17
- git clone https://github.com/swagger-api/swagger-codegen
18
- fi
19
-
20
- (
21
- cd swagger-codegen
22
- if [[ "${#SWAGGER_CODGEN_REVISION}" -lt 40 ]]; then
23
- # resolve git tags / branch names
24
- SWAGGER_CODGEN_REVISION=$(git show "$SWAGGER_CODGEN_REVISION" --format="%H")
25
- fi
26
- if [[ $(cat .git/HEAD) != "$SWAGGER_CODGEN_REVISION" ]]; then
27
- git fetch
28
- git checkout "$SWAGGER_CODGEN_REVISION"
29
- mvn clean package
30
- fi
31
- )
32
-
33
- executable="./swagger-codegen/modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"
34
-
35
- if [ ! -f "$executable" ]; then
36
- mvn clean package
7
+ GENERATOR_REVISION=$(cat .generator-revision 2> /dev/null || true)
8
+ if [ "$GENERATOR_REVISION" = "" ]; then
9
+ echo "Set a revision of openapi-generator to use in .generator-revision"
10
+ exit 1
37
11
  fi
38
12
 
39
- export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties -DapiTests=false -DapiDocs=false -DmodelTests=false -DmodelDocs=false"
40
- java $JAVA_OPTS -jar $executable $*
13
+ docker run -it -w "/local" --rm -v "${PWD}:/local" openapitools/openapi-generator-cli:"${GENERATOR_REVISION}" "$@"
data/script/test CHANGED
@@ -1,46 +1,49 @@
1
- #!/bin/sh
1
+ #!/bin/bash
2
2
  set -e
3
- cd "`dirname \"$0\"`/.."
3
+ [[ "$TRACE" == "true" ]] && set -x
4
+ cd "$(dirname "$0")/.."
4
5
 
5
- # check dependencies
6
- ruby -v > /dev/null || (echo "ruby must be installed"; exit 1)
7
- bundler -v > /dev/null || (echo "bundler must be installed"; exit 1)
6
+ echo "Clearing test output directory"
7
+ rm -rf tmp/test_output/
8
+ mkdir -p tmp/test_output
8
9
 
9
- bundle install
10
-
11
- # runs a test file with PASS/FAIL message
12
- run_test() {
13
- ruby $1 && echo "PASS $1" || (echo "FAIL $1"; exit 1)
14
- }
10
+ [ -f script/build ] && script/build
15
11
 
16
12
  run_tests() {
17
- if [ "$1" == "" ]; then
18
- for test in $(ls *.rb); do
19
- run_test $test
20
- done
13
+ runtime_env="$1"
14
+ if time script/docker -i "$runtime_env" /app/script/inside_container/test; then
15
+ tput bold # bold text
16
+ tput setaf 2 # green text
17
+ echo "======================================"
18
+ echo "$runtime_env Passed"
19
+ echo "======================================"
20
+ tput sgr0 # reset to default text
21
+ return 0
21
22
  else
22
- run_test $1.rb
23
+ tput bold # bold text
24
+ tput setaf 1 # red text
25
+ echo "======================================"
26
+ echo "$runtime_env FAILED"
27
+ echo "======================================"
28
+ tput sgr0 # reset to default text
29
+ return 1
23
30
  fi
24
31
  }
25
32
 
26
33
  success="true"
27
34
 
28
- # Setup rbenv so we can switch rubies below
29
- eval "$(rbenv init - --no-rehash)"
30
-
31
- for ruby_version in `ruby -ryaml -e 'puts YAML.load(File.read(".travis.yml"))["rvm"].join(" ")'`; do
32
- {
33
- echo "testing ruby version $ruby_version" &&
34
- rbenv shell $ruby_version &&
35
- ( cd test && run_tests )
36
- } || success="false"
35
+ for runtime_env in $(cat .runtime-environments | grep -v '^#'); do
36
+ echo
37
+ echo
38
+ echo "Testing runtime env $runtime_env"
39
+ run_tests "$runtime_env" || success="false"
37
40
  done
38
41
 
39
42
  if [ $success == "true" ]; then
40
43
  tput bold # bold text
41
44
  tput setaf 2 # green text
42
45
  echo "======================================"
43
- echo "= Passed ="
46
+ echo "= Full Test Suite Passed ="
44
47
  echo "======================================"
45
48
  tput sgr0 # reset to default text
46
49
  exit 0
@@ -48,7 +51,7 @@ else
48
51
  tput bold # bold text
49
52
  tput setaf 1 # red text
50
53
  echo "======================================"
51
- echo "= FAILED ="
54
+ echo "= Full Test Suite FAILED ="
52
55
  echo "======================================"
53
56
  tput sgr0 # reset to default text
54
57
  exit 1
data/test/async.rb CHANGED
@@ -8,7 +8,8 @@ end
8
8
 
9
9
  $docraptor = DocRaptor::DocApi.new
10
10
 
11
- output_file = "ruby-async.pdf"
11
+ test_output_dir = File.join(File.dirname(File.expand_path(__FILE__)), "..", "tmp", "test_output")
12
+ output_file = File.join(test_output_dir, "#{File.basename(__FILE__, ".rb")}_ruby_#{RUBY_VERSION}.pdf")
12
13
 
13
14
  create_response = $docraptor.create_async_doc(
14
15
  test: true,
@@ -28,7 +29,6 @@ output_payload = $docraptor.get_async_doc(status_response.download_id)
28
29
 
29
30
  File.write(output_file, output_payload)
30
31
  output_type = `file -b #{output_file}`
31
- File.delete output_file
32
32
 
33
33
  raise "Output was not a PDF" unless output_type.start_with?("PDF")
34
34
 
@@ -9,7 +9,8 @@ end
9
9
 
10
10
  $docraptor = DocRaptor::DocApi.new
11
11
 
12
- output_file = "expire-hosted-ruby-sync.pdf"
12
+ test_output_dir = File.join(File.dirname(File.expand_path(__FILE__)), "..", "tmp", "test_output")
13
+ output_file = File.join(test_output_dir, "#{File.basename(__FILE__, ".rb")}_ruby_#{RUBY_VERSION}.pdf")
13
14
 
14
15
  output_payload = $docraptor.create_hosted_async_doc(
15
16
  test: true,
@@ -30,7 +31,6 @@ actual_document = URI.parse(status_response.download_url).open
30
31
  IO.copy_stream(actual_document, output_file)
31
32
 
32
33
  output_type = `file -b #{output_file}`
33
- File.delete output_file
34
34
 
35
35
  raise "Output was not a PDF" unless output_type.start_with?("PDF")
36
36
 
data/test/hosted_async.rb CHANGED
@@ -9,7 +9,8 @@ end
9
9
 
10
10
  $docraptor = DocRaptor::DocApi.new
11
11
 
12
- output_file = "hosted-ruby-sync.pdf"
12
+ test_output_dir = File.join(File.dirname(File.expand_path(__FILE__)), "..", "tmp", "test_output")
13
+ output_file = File.join(test_output_dir, "#{File.basename(__FILE__, ".rb")}_ruby_#{RUBY_VERSION}.pdf")
13
14
 
14
15
  output_payload = $docraptor.create_hosted_async_doc(
15
16
  test: true,
@@ -26,4 +27,9 @@ status_response = nil
26
27
  sleep 1
27
28
  end
28
29
 
30
+ output_payload = $docraptor.get_async_doc(status_response.download_id)
29
31
 
32
+ File.write(output_file, output_payload)
33
+ output_type = `file -b #{output_file}`
34
+
35
+ raise "Output was not a PDF" unless output_type.start_with?("PDF")
data/test/hosted_sync.rb CHANGED
@@ -9,7 +9,8 @@ end
9
9
 
10
10
  $docraptor = DocRaptor::DocApi.new
11
11
 
12
- output_file = "hosted-ruby-sync.pdf"
12
+ test_output_dir = File.join(File.dirname(File.expand_path(__FILE__)), "..", "tmp", "test_output")
13
+ output_file = File.join(test_output_dir, "#{File.basename(__FILE__, ".rb")}_ruby_#{RUBY_VERSION}.pdf")
13
14
 
14
15
  output_payload = $docraptor.create_hosted_doc(
15
16
  test: true,
@@ -23,6 +24,5 @@ actual_document = URI.parse(output_payload.download_url).open
23
24
  IO.copy_stream(actual_document, output_file)
24
25
 
25
26
  output_type = `file -b #{output_file}`
26
- File.delete output_file
27
27
 
28
28
  raise "Output was not a PDF" unless output_type.start_with?("PDF")
@@ -0,0 +1,40 @@
1
+ require "bundler/setup"
2
+ Bundler.require
3
+
4
+ DocRaptor.configure do |dr|
5
+ dr.username = ENV["DOCRAPTOR_KEY"] || "YOUR_API_KEY_HERE"
6
+ # dr.debugging = true
7
+ end
8
+
9
+ # TODO: Remove once pipeline 10 is public. At that point the try it out user
10
+ # will be able to use the iframes option, so this test will pass.
11
+ unless ENV["DOCRAPTOR_KEY"]
12
+ puts "Skipping #{$0} because DOCRAPTOR_KEY is not set."
13
+ exit(0)
14
+ end
15
+
16
+ $docraptor = DocRaptor::DocApi.new
17
+
18
+ test_output_dir = File.join(File.dirname(File.expand_path(__FILE__)), "..", "tmp", "test_output")
19
+ output_file = File.join(test_output_dir, "#{File.basename(__FILE__, ".rb")}_ruby_#{RUBY_VERSION}.pdf")
20
+ output_payload = $docraptor.create_doc(
21
+ test: true,
22
+ document_content: <<~HTML,
23
+ <html><body>
24
+ <p>Baseline text</p>
25
+ <iframe src="https://docraptor-test-harness.herokuapp.com/public/index.html"></iframe>
26
+ </body></html>
27
+ HTML
28
+ name: output_file,
29
+ document_type: "pdf",
30
+ pipeline: "10",
31
+ # prince_options: { iframes: true },
32
+ )
33
+
34
+ File.write(output_file, output_payload)
35
+ output_type = `file -b #{output_file}`
36
+
37
+ raise "Output was not a PDF" unless output_type.start_with?("PDF")
38
+
39
+ text = `pdftotext #{output_file} -`
40
+ raise "Output shouldn't load iframe" if text !~ /Test/
@@ -0,0 +1,40 @@
1
+ require "bundler/setup"
2
+ Bundler.require
3
+
4
+ DocRaptor.configure do |dr|
5
+ dr.username = ENV["DOCRAPTOR_KEY"] || "YOUR_API_KEY_HERE"
6
+ # dr.debugging = true
7
+ end
8
+
9
+ # TODO: Remove once pipeline 10 is public. At that point the try it out user
10
+ # will be able to use the iframes option, so this test will pass.
11
+ unless ENV["DOCRAPTOR_KEY"]
12
+ puts "Skipping #{$0} because DOCRAPTOR_KEY is not set."
13
+ exit(0)
14
+ end
15
+
16
+ $docraptor = DocRaptor::DocApi.new
17
+
18
+ test_output_dir = File.join(File.dirname(File.expand_path(__FILE__)), "..", "tmp", "test_output")
19
+ output_file = File.join(test_output_dir, "#{File.basename(__FILE__, ".rb")}_ruby_#{RUBY_VERSION}.pdf")
20
+ output_payload = $docraptor.create_doc(
21
+ test: true,
22
+ document_content: <<~HTML,
23
+ <html><body>
24
+ <p>Baseline text</p>
25
+ <iframe src="https://docraptor-test-harness.herokuapp.com/public/index.html"></iframe>
26
+ </body></html>
27
+ HTML
28
+ name: output_file,
29
+ document_type: "pdf",
30
+ pipeline: "10",
31
+ prince_options: { iframes: false },
32
+ )
33
+
34
+ File.write(output_file, output_payload)
35
+ output_type = `file -b #{output_file}`
36
+
37
+ raise "Output was not a PDF" unless output_type.start_with?("PDF")
38
+
39
+ text = `pdftotext #{output_file} -`
40
+ raise "Output shouldn't load iframe" if text =~ /Test/
@@ -0,0 +1,40 @@
1
+ require "bundler/setup"
2
+ Bundler.require
3
+
4
+ DocRaptor.configure do |dr|
5
+ dr.username = ENV["DOCRAPTOR_KEY"] || "YOUR_API_KEY_HERE"
6
+ # dr.debugging = true
7
+ end
8
+
9
+ # TODO: Remove once pipeline 10 is public. At that point the try it out user
10
+ # will be able to use the iframes option, so this test will pass.
11
+ unless ENV["DOCRAPTOR_KEY"]
12
+ puts "Skipping #{$0} because DOCRAPTOR_KEY is not set."
13
+ exit(0)
14
+ end
15
+
16
+ $docraptor = DocRaptor::DocApi.new
17
+
18
+ test_output_dir = File.join(File.dirname(File.expand_path(__FILE__)), "..", "tmp", "test_output")
19
+ output_file = File.join(test_output_dir, "#{File.basename(__FILE__, ".rb")}_ruby_#{RUBY_VERSION}.pdf")
20
+ output_payload = $docraptor.create_doc(
21
+ test: true,
22
+ document_content: <<~HTML,
23
+ <html><body>
24
+ <p>Baseline text</p>
25
+ <iframe src="https://docraptor-test-harness.herokuapp.com/public/index.html"></iframe>
26
+ </body></html>
27
+ HTML
28
+ name: output_file,
29
+ document_type: "pdf",
30
+ pipeline: "10",
31
+ prince_options: { iframes: true },
32
+ )
33
+
34
+ File.write(output_file, output_payload)
35
+ output_type = `file -b #{output_file}`
36
+
37
+ raise "Output was not a PDF" unless output_type.start_with?("PDF")
38
+
39
+ text = `pdftotext #{output_file} -`
40
+ raise "Output shouldn't load iframe" if text !~ /Test/
@@ -0,0 +1,45 @@
1
+ require "bundler/setup"
2
+ Bundler.require
3
+
4
+ DocRaptor.configure do |dr|
5
+ dr.username = "YOUR_API_KEY_HERE"
6
+ # dr.debugging = true
7
+ end
8
+
9
+ $docraptor = DocRaptor::DocApi.new
10
+
11
+ test_output_dir = File.join(File.dirname(File.expand_path(__FILE__)), "..", "tmp", "test_output")
12
+ output_file = File.join(test_output_dir, "#{File.basename(__FILE__, ".rb")}_ruby_#{RUBY_VERSION}.pdf")
13
+
14
+ # Verify the test works as expected by confirming that this url will fail
15
+ # without prince_options[insecure]=true.
16
+ begin
17
+ $docraptor.create_doc(
18
+ test: true,
19
+ document_url: "https://expired.badssl.com/",
20
+ name: output_file,
21
+ document_type: "pdf",
22
+ )
23
+ rescue DocRaptor::ApiError => ex
24
+ expected_message = "SSL Error downloading document content from supplied url.";
25
+ if ex.message !~ /#{expected_message}/
26
+ raise "Wrong exception, expected: #{expected_message}, got: #{ex.message}"
27
+ end
28
+ end
29
+
30
+ # Verify prince_options works by testing a url that will fail without
31
+ # prince_options[insecure]=true.
32
+ output_payload = $docraptor.create_doc(
33
+ test: true,
34
+ document_url: "https://expired.badssl.com/",
35
+ name: output_file,
36
+ document_type: "pdf",
37
+ prince_options: {
38
+ insecure: true,
39
+ }
40
+ )
41
+
42
+ File.write(output_file, output_payload)
43
+ output_type = `file -b #{output_file}`
44
+
45
+ raise "Output was not a PDF" unless output_type.start_with?("PDF")
data/test/sync.rb CHANGED
@@ -8,7 +8,8 @@ end
8
8
 
9
9
  $docraptor = DocRaptor::DocApi.new
10
10
 
11
- output_file = "ruby-sync.pdf"
11
+ test_output_dir = File.join(File.dirname(File.expand_path(__FILE__)), "..", "tmp", "test_output")
12
+ output_file = File.join(test_output_dir, "#{File.basename(__FILE__, ".rb")}_ruby_#{RUBY_VERSION}.pdf")
12
13
 
13
14
  output_payload = $docraptor.create_doc(
14
15
  test: true,
@@ -19,6 +20,5 @@ output_payload = $docraptor.create_doc(
19
20
 
20
21
  File.write(output_file, output_payload)
21
22
  output_type = `file -b #{output_file}`
22
- File.delete output_file
23
23
 
24
24
  raise "Output was not a PDF" unless output_type.start_with?("PDF")
data/test/xlsx.rb CHANGED
@@ -8,7 +8,8 @@ end
8
8
 
9
9
  $docraptor = DocRaptor::DocApi.new
10
10
 
11
- output_file = "ruby-xlsx.xlsx"
11
+ test_output_dir = File.join(File.dirname(File.expand_path(__FILE__)), "..", "tmp", "test_output")
12
+ output_file = File.join(test_output_dir, "#{File.basename(__FILE__, ".rb")}_ruby_#{RUBY_VERSION}.xlsx")
12
13
 
13
14
  output_payload = $docraptor.create_doc(
14
15
  test: true,
@@ -19,6 +20,12 @@ output_payload = $docraptor.create_doc(
19
20
 
20
21
  File.write(output_file, output_payload)
21
22
  output_type = `file -b #{output_file}`
22
- File.delete output_file
23
23
 
24
- raise "Output was not an XLSX (zip)" unless output_type.start_with?("Zip")
24
+ acceptable_output_types = [
25
+ "Microsoft Excel 2007+", # Newest versions of `file`
26
+ "Microsoft OOXML", # Older versions of `file`
27
+ "Zip archive data, at least v2.0 to extract", # Even older versions of `file`
28
+ ]
29
+ if !acceptable_output_types.include?(output_type.strip)
30
+ raise "Output was not an XLSX: #{output_type.inspect}"
31
+ end