docraptor 2.0.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.docker_env.list +5 -0
- data/.docker_mounts.list +4 -0
- data/.generator-language-identifier +1 -0
- data/.generator-revision +1 -0
- data/.github/pull_request_template.txt +17 -0
- data/.gitignore +20 -14
- data/.gitlab-ci.yml +26 -0
- data/.openapi-generator/FILES +32 -0
- data/.openapi-generator/VERSION +1 -0
- data/{.swagger-codegen-ignore → .openapi-generator-ignore} +13 -7
- data/.review/README.md +16 -0
- data/.review/generated_files/.gitignore +39 -0
- data/.review/generated_files/README.md +108 -0
- data/.review/generated_files/docs/AsyncDoc.md +18 -0
- data/.review/generated_files/docs/Doc.md +50 -0
- data/.review/generated_files/docs/DocApi.md +503 -0
- data/.review/generated_files/docs/DocStatus.md +28 -0
- data/.review/generated_files/docs/PrinceOptions.md +82 -0
- data/.review/generated_files/spec/api/doc_api_spec.rb +112 -0
- data/{spec → .review/generated_files/spec}/api_client_spec.rb +6 -21
- data/{spec → .review/generated_files/spec}/configuration_spec.rb +6 -6
- data/.review/generated_files/spec/models/async_doc_spec.rb +34 -0
- data/.review/generated_files/spec/models/doc_spec.rb +138 -0
- data/.review/generated_files/spec/models/doc_status_spec.rb +64 -0
- data/.review/generated_files/spec/models/prince_options_spec.rb +234 -0
- data/{spec → .review/generated_files/spec}/spec_helper.rb +3 -3
- data/.rubocop.yml +148 -0
- data/.runtime-environments +13 -0
- data/.travis.yml +9 -7
- data/CHANGELOG.md +8 -0
- data/Gemfile +3 -1
- data/README.md +8 -8
- data/Rakefile +1 -2
- data/docraptor.gemspec +5 -19
- data/docraptor.yaml +283 -284
- data/examples/async.rb +24 -30
- data/examples/hosted_async.rb +21 -33
- data/examples/hosted_sync.rb +19 -32
- data/examples/sync.rb +20 -26
- data/gemfiles/Gemfile.2.5.lock +70 -0
- data/gemfiles/Gemfile.2.6.lock +70 -0
- data/gemfiles/Gemfile.2.7.lock +70 -0
- data/gemfiles/Gemfile.3.0.lock +70 -0
- data/gemfiles/Gemfile.3.1.lock +72 -0
- data/gemfiles/Gemfile.3.2.lock +72 -0
- data/gemfiles/Gemfile.3.3.lock +72 -0
- data/{swagger-config.json → generator-config.json} +3 -2
- data/lib/docraptor/api/doc_api.rb +180 -85
- data/lib/docraptor/api_client.rb +91 -90
- data/lib/docraptor/api_error.rb +23 -3
- data/lib/docraptor/configuration.rb +101 -15
- data/lib/docraptor/models/async_doc.rb +53 -18
- data/lib/docraptor/models/doc.rb +80 -50
- data/lib/docraptor/models/doc_status.rb +58 -23
- data/lib/docraptor/models/prince_options.rb +149 -75
- data/lib/docraptor/version.rb +4 -4
- data/lib/docraptor.rb +3 -3
- data/script/clean +2 -2
- data/script/console +5 -0
- data/script/docker +56 -0
- data/script/fix_gemspec.rb +3 -18
- data/script/generate_language +43 -4
- data/script/inside_container/README.md +6 -0
- data/script/inside_container/test +87 -0
- data/script/post_generate_language +8 -2
- data/script/release +13 -0
- data/script/setup +25 -14
- data/script/swagger +6 -33
- data/script/test +30 -27
- data/test/async.rb +2 -2
- data/test/expire_hosted.rb +2 -2
- data/test/hosted_async.rb +7 -1
- data/test/hosted_sync.rb +2 -2
- data/test/iframes_default.rb +40 -0
- data/test/iframes_false.rb +40 -0
- data/test/iframes_true.rb +40 -0
- data/test/prince_options.rb +45 -0
- data/test/sync.rb +2 -2
- data/test/xlsx.rb +10 -3
- metadata +52 -214
- data/.swagger-codegen/VERSION +0 -1
- 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/
|
1
|
+
#!/bin/bash
|
2
2
|
set -e
|
3
|
-
|
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
|
-
|
5
|
+
setup_echo() {
|
6
|
+
echo "[script/setup] $1"
|
7
|
+
}
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
+
setup_error() {
|
10
|
+
echo "[script/setup][ERROR] $1"
|
11
|
+
}
|
9
12
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
13
|
+
brew_install() {
|
14
|
+
setup_echo "Installing $1..."
|
15
|
+
brew list --formula "$1" > /dev/null || brew install --formula "$1"
|
16
|
+
}
|
14
17
|
|
15
|
-
|
16
|
-
|
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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
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
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
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/
|
1
|
+
#!/bin/bash
|
2
2
|
set -e
|
3
|
-
|
3
|
+
[[ "$TRACE" == "true" ]] && set -x
|
4
|
+
cd "$(dirname "$0")/.."
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
echo "Clearing test output directory"
|
7
|
+
rm -rf tmp/test_output/
|
8
|
+
mkdir -p tmp/test_output
|
8
9
|
|
9
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
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
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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 "=
|
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 "=
|
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
|
-
|
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
|
|
data/test/expire_hosted.rb
CHANGED
@@ -9,7 +9,8 @@ end
|
|
9
9
|
|
10
10
|
$docraptor = DocRaptor::DocApi.new
|
11
11
|
|
12
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|