├── .generator-revision ├── .openapi-generator ├── VERSION └── FILES ├── .generator-language-identifier ├── .rspec ├── script ├── clean ├── console ├── swagger ├── inside_container │ ├── README.md │ └── test ├── release ├── post_generate_language ├── fix_gemspec.rb ├── setup ├── update_from_upstream ├── docker ├── test └── generate_language ├── .docker_env.list ├── Gemfile ├── Rakefile ├── .docker_mounts.list ├── .travis.yml ├── lib ├── docraptor │ ├── version.rb │ ├── api_error.rb │ ├── models │ │ ├── async_doc.rb │ │ ├── doc_status.rb │ │ └── doc.rb │ ├── configuration.rb │ └── api_client.rb └── docraptor.rb ├── .review ├── generated_files │ ├── docs │ │ ├── AsyncDoc.md │ │ ├── DocStatus.md │ │ ├── Doc.md │ │ ├── PrinceOptions.md │ │ └── DocApi.md │ ├── .gitignore │ ├── spec │ │ ├── models │ │ │ ├── async_doc_spec.rb │ │ │ ├── doc_status_spec.rb │ │ │ ├── doc_spec.rb │ │ │ └── prince_options_spec.rb │ │ ├── configuration_spec.rb │ │ ├── api │ │ │ └── doc_api_spec.rb │ │ ├── spec_helper.rb │ │ └── api_client_spec.rb │ └── README.md └── README.md ├── test ├── invalid_sync.rb ├── invalid_async.rb ├── sync.rb ├── hosted_sync.rb ├── async.rb ├── xlsx.rb ├── hosted_async.rb ├── iframes_false.rb ├── iframes_true.rb ├── iframes_default.rb ├── expire_hosted.rb └── prince_options.rb ├── .github └── pull_request_template.txt ├── .runtime-environments ├── .gitlab-ci.yml ├── generator-config.json ├── LICENSE ├── docraptor.gemspec ├── .gitignore ├── examples ├── sync.rb ├── async.rb ├── hosted_sync.rb └── hosted_async.rb ├── .openapi-generator-ignore ├── gemfiles ├── Gemfile.2.5.lock ├── Gemfile.2.6.lock ├── Gemfile.2.7.lock ├── Gemfile.3.0.lock ├── Gemfile.3.1.lock ├── Gemfile.3.2.lock └── Gemfile.3.3.lock ├── CHANGELOG.md ├── README.md ├── .rubocop.yml └── docraptor.yaml /.generator-revision: -------------------------------------------------------------------------------- 1 | v6.6.0 2 | -------------------------------------------------------------------------------- /.openapi-generator/VERSION: -------------------------------------------------------------------------------- 1 | 6.6.0 -------------------------------------------------------------------------------- /.generator-language-identifier: -------------------------------------------------------------------------------- 1 | ruby 2 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --color 2 | --require spec_helper 3 | -------------------------------------------------------------------------------- /script/clean: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | cd "$(dirname "$0")/.." 4 | 5 | rm -rf lib/ 6 | -------------------------------------------------------------------------------- /script/console: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | cd "$(dirname "$0")/.." 4 | 5 | script/docker "$@" /bin/bash 6 | -------------------------------------------------------------------------------- /.docker_env.list: -------------------------------------------------------------------------------- 1 | TRACE 2 | TEST_OUTPUT_DIR=/app/tmp/test_output 3 | BUNDLE_PATH=/app/tmp/cache/bundle 4 | INSIDE_DOCKER=true 5 | SSH_AUTH_SOCK=/run/host-services/ssh-auth.sock 6 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gemspec 4 | 5 | group :development, :test do 6 | gem 'rake', '~> 13.0.1' 7 | gem 'pry-byebug' 8 | gem 'rubocop', '~> 0.66.0' 9 | end 10 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | 3 | begin 4 | require 'rspec/core/rake_task' 5 | 6 | RSpec::Core::RakeTask.new(:spec) 7 | task default: :spec 8 | rescue LoadError 9 | # no rspec available 10 | end 11 | -------------------------------------------------------------------------------- /.docker_mounts.list: -------------------------------------------------------------------------------- 1 | # Specify mounts in `docker run --volume` format (source:target). Bash 2 | # expressions will be evaluated. 3 | $(pwd)/tmp/cache_${image//:/_}:/app/tmp/cache 4 | /run/host-services/ssh-auth.sock:/run/host-services/ssh-auth.sock 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | cache: bundler 3 | rvm: 4 | - 2.7 5 | - 3.0 6 | - 3.1 7 | script: 8 | - bundle install --path vendor/bundle 9 | - bundle exec rspec 10 | - gem build docraptor.gemspec 11 | - gem install ./docraptor-3.1.0.gem 12 | -------------------------------------------------------------------------------- /lib/docraptor/version.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | #DocRaptor 3 | 4 | #A native client library for the DocRaptor HTML to PDF/XLS service. 5 | 6 | The version of the OpenAPI document: 2.0.0 7 | 8 | Generated by: https://openapi-generator.tech 9 | OpenAPI Generator version: 6.6.0 10 | 11 | =end 12 | 13 | module DocRaptor 14 | VERSION = '3.1.0' 15 | end 16 | -------------------------------------------------------------------------------- /script/swagger: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | cd "$(dirname "$0")/.." 4 | 5 | set -x 6 | 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 11 | fi 12 | 13 | docker run -it -w "/local" --rm -v "${PWD}:/local" openapitools/openapi-generator-cli:"${GENERATOR_REVISION}" "$@" 14 | -------------------------------------------------------------------------------- /script/inside_container/README.md: -------------------------------------------------------------------------------- 1 | This folder contains scripts that are only intended to be run inside 2 | of a relevant docker container. For example, `script/test` may run 3 | `script/inside_container/test` inside a container with particular 4 | versions of libraries to make it easy to test the agent in multiple 5 | settings. It's possible these scripts will work outside of any 6 | particular container, but that may or may not mean anything. 7 | -------------------------------------------------------------------------------- /script/release: -------------------------------------------------------------------------------- 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}]" 14 | -------------------------------------------------------------------------------- /.review/generated_files/docs/AsyncDoc.md: -------------------------------------------------------------------------------- 1 | # DocRaptor::AsyncDoc 2 | 3 | ## Properties 4 | 5 | | Name | Type | Description | Notes | 6 | | ---- | ---- | ----------- | ----- | 7 | | **status_id** | **String** | The identifier used to get the status of the document using the status API. | [optional] | 8 | 9 | ## Example 10 | 11 | ```ruby 12 | require 'docraptor' 13 | 14 | instance = DocRaptor::AsyncDoc.new( 15 | status_id: null 16 | ) 17 | ``` 18 | 19 | -------------------------------------------------------------------------------- /script/post_generate_language: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | [[ "$TRACE" == "true" ]] && set -x 4 | cd "$(dirname "$0")/.." 5 | 6 | echo "Removing trailing whitespace..." 7 | find lib -name "*.rb" -type f -exec sed -E -i '' 's/[[:space:]]+$//g' {} + 8 | 9 | echo "Fixing gemspec to work around swagger..." 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 16 | -------------------------------------------------------------------------------- /test/invalid_sync.rb: -------------------------------------------------------------------------------- 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 | begin 12 | $docraptor.create_doc( 13 | test: true, 14 | name: "s" * 201, # limit is 200 characters 15 | document_type: "pdf", 16 | ) 17 | rescue DocRaptor::ApiError 18 | exit 19 | end 20 | 21 | abort "Exception expected, but not raised" 22 | -------------------------------------------------------------------------------- /.github/pull_request_template.txt: -------------------------------------------------------------------------------- 1 | Why is this change needed? 2 | -------------------------- 3 | 4 | How does it address the issue? 5 | ------------------------------ 6 | 7 | Any links to any relevant tickets, articles, or other resources? 8 | --------------------------------------------------------------- 9 | 10 | Any screenshots? 11 | ---------------- 12 | 13 | Did you complete all of the following? 14 | -------------------------------------- 15 | - Run test suite? 16 | - Add new tests? 17 | - Consider security implications and practices? 18 | -------------------------------------------------------------------------------- /.runtime-environments: -------------------------------------------------------------------------------- 1 | # Versions without patch numbers will test the latest patch version. We include 2 | # specific patch versions to provide consistency. We include version numbers 3 | # without the patch version in order to automatically test the latest patch 4 | # version of each minor version. 5 | # DR gem itself requires >= 2.4, so 2.3 is out 6 | # 2.4: /app/lib/docraptor/models/async_doc.rb:111:in `build_from_hash': undefined method `transform_keys' 7 | ruby:2.5 8 | ruby:2.6 9 | ruby:2.7 10 | ruby:3.0 11 | ruby:3.1 12 | ruby:3.2 13 | ruby:3.3-rc 14 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | .ruby: &ruby 2 | variables: 3 | LANG: "C.UTF-8" 4 | before_script: 5 | - ruby -v 6 | - bundle config set --local deployment true 7 | - bundle install -j $(nproc) 8 | parallel: 9 | matrix: 10 | - RUBY_VERSION: ['2.7', '3.0', '3.1'] 11 | image: "ruby:$RUBY_VERSION" 12 | cache: 13 | paths: 14 | - vendor/ruby 15 | key: 'ruby-$RUBY_VERSION' 16 | 17 | gem: 18 | extends: .ruby 19 | script: 20 | - bundle exec rspec 21 | - bundle exec rake build 22 | - bundle exec rake install 23 | artifacts: 24 | paths: 25 | - pkg/*.gem 26 | 27 | -------------------------------------------------------------------------------- /generator-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "gemName": "docraptor", 3 | "moduleName": "DocRaptor", 4 | "gemVersion": "3.1.0", 5 | "gemAuthor": "Expected Behavior", 6 | "gemAuthorEmail": "support@docraptor.com", 7 | "gemHomepage": "https://github.com/docraptor/docraptor-ruby", 8 | "gemSummary": "A wrapper for the DocRaptor HTML to PDF/XLS service.", 9 | "gemDescription": "A native client library for the DocRaptor HTML to PDF/XLS service.", 10 | "gemLicense": "MIT", 11 | "hideGenerationTimestamp": true, 12 | "httpUserAgent": "ruby-swagger-#{VERSION}", 13 | "gemRequiredRubyVersion": ">= 2.5" 14 | } 15 | -------------------------------------------------------------------------------- /test/invalid_async.rb: -------------------------------------------------------------------------------- 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 | create_response = $docraptor.create_async_doc( 12 | test: true, 13 | document_content: "Hello from Ruby", 14 | name: "s" * 201, # limit is 200 characters 15 | document_type: "pdf", 16 | ) 17 | 18 | status_response = nil 19 | 30.times do 20 | status_response = $docraptor.get_async_doc_status(create_response.status_id) 21 | exit if status_response.status == "failed" 22 | sleep 1 23 | end 24 | 25 | abort "Did not receive failed validation within 30 seconds." 26 | -------------------------------------------------------------------------------- /.review/README.md: -------------------------------------------------------------------------------- 1 | # Review newly generated files 2 | 3 | This directory helps with review of generated files where we lagely want 4 | the content to be custom. 5 | 6 | The project `README.md` is a good example. We heavily custimize 7 | `README.md` based on our particular use case. There are also important 8 | changes to the generated `README.md` that should be reviewed when it is 9 | updated. These include things like new minimum language versions, or 10 | client API changes. 11 | 12 | If you add the `README.md` to the `.openapi-generator-ignore` list then 13 | you never see the updates, making it easy to miss things. If you don't 14 | add it to the `.openapi-generator-ignore` list then any uncommitted 15 | updates to the `README.md` are lost when running 16 | `script/generate_language`. 17 | -------------------------------------------------------------------------------- /test/sync.rb: -------------------------------------------------------------------------------- 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 | output_payload = $docraptor.create_doc( 15 | test: true, 16 | document_content: "Hello from Ruby", 17 | name: output_file, 18 | document_type: "pdf", 19 | ) 20 | 21 | File.write(output_file, output_payload) 22 | output_type = `file -b #{output_file}` 23 | 24 | raise "Output was not a PDF" unless output_type.start_with?("PDF") 25 | -------------------------------------------------------------------------------- /.openapi-generator/FILES: -------------------------------------------------------------------------------- 1 | .gitignore 2 | .gitlab-ci.yml 3 | .rspec 4 | .rubocop.yml 5 | .travis.yml 6 | Gemfile 7 | README.md 8 | Rakefile 9 | docraptor.gemspec 10 | docs/AsyncDoc.md 11 | docs/Doc.md 12 | docs/DocApi.md 13 | docs/DocStatus.md 14 | docs/PrinceOptions.md 15 | lib/docraptor.rb 16 | lib/docraptor/api/doc_api.rb 17 | lib/docraptor/api_client.rb 18 | lib/docraptor/api_error.rb 19 | lib/docraptor/configuration.rb 20 | lib/docraptor/models/async_doc.rb 21 | lib/docraptor/models/doc.rb 22 | lib/docraptor/models/doc_status.rb 23 | lib/docraptor/models/prince_options.rb 24 | lib/docraptor/version.rb 25 | spec/api/doc_api_spec.rb 26 | spec/api_client_spec.rb 27 | spec/configuration_spec.rb 28 | spec/models/async_doc_spec.rb 29 | spec/models/doc_spec.rb 30 | spec/models/doc_status_spec.rb 31 | spec/models/prince_options_spec.rb 32 | spec/spec_helper.rb 33 | -------------------------------------------------------------------------------- /.review/generated_files/.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by: https://openapi-generator.tech 2 | # 3 | 4 | *.gem 5 | *.rbc 6 | /.config 7 | /coverage/ 8 | /InstalledFiles 9 | /pkg/ 10 | /spec/reports/ 11 | /spec/examples.txt 12 | /test/tmp/ 13 | /test/version_tmp/ 14 | /tmp/ 15 | 16 | ## Specific to RubyMotion: 17 | .dat* 18 | .repl_history 19 | build/ 20 | 21 | ## Documentation cache and generated files: 22 | /.yardoc/ 23 | /_yardoc/ 24 | /doc/ 25 | /rdoc/ 26 | 27 | ## Environment normalization: 28 | /.bundle/ 29 | /vendor/bundle 30 | /lib/bundler/man/ 31 | 32 | # for a library or gem, you might want to ignore these files since the code is 33 | # intended to run in multiple environments; otherwise, check them in: 34 | # Gemfile.lock 35 | # .ruby-version 36 | # .ruby-gemset 37 | 38 | # unless supporting rvm < 1.11.0 or doing something fancy, ignore this: 39 | .rvmrc 40 | -------------------------------------------------------------------------------- /test/hosted_sync.rb: -------------------------------------------------------------------------------- 1 | require "bundler/setup" 2 | Bundler.require 3 | require "open-uri" 4 | 5 | DocRaptor.configure do |dr| 6 | dr.username = "YOUR_API_KEY_HERE" 7 | # dr.debugging = true 8 | end 9 | 10 | $docraptor = DocRaptor::DocApi.new 11 | 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") 14 | 15 | output_payload = $docraptor.create_hosted_doc( 16 | test: true, 17 | document_content: "Hello from Ruby", 18 | name: output_file, 19 | document_type: "pdf", 20 | hosted_expires_at: (Time.now + 86400).strftime('%FT%T%:z'), # 1 day from now 21 | ) 22 | 23 | actual_document = URI.parse(output_payload.download_url).open 24 | IO.copy_stream(actual_document, output_file) 25 | 26 | output_type = `file -b #{output_file}` 27 | 28 | raise "Output was not a PDF" unless output_type.start_with?("PDF") 29 | -------------------------------------------------------------------------------- /.review/generated_files/spec/models/async_doc_spec.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | #DocRaptor 3 | 4 | #A native client library for the DocRaptor HTML to PDF/XLS service. 5 | 6 | The version of the OpenAPI document: 2.0.0 7 | 8 | Generated by: https://openapi-generator.tech 9 | OpenAPI Generator version: 6.6.0 10 | 11 | =end 12 | 13 | require 'spec_helper' 14 | require 'json' 15 | require 'date' 16 | 17 | # Unit tests for DocRaptor::AsyncDoc 18 | # Automatically generated by openapi-generator (https://openapi-generator.tech) 19 | # Please update as you see appropriate 20 | describe DocRaptor::AsyncDoc do 21 | let(:instance) { DocRaptor::AsyncDoc.new } 22 | 23 | describe 'test an instance of AsyncDoc' do 24 | it 'should create an instance of AsyncDoc' do 25 | expect(instance).to be_instance_of(DocRaptor::AsyncDoc) 26 | end 27 | end 28 | describe 'test attribute "status_id"' do 29 | it 'should work' do 30 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 31 | end 32 | end 33 | 34 | end 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright © 2010-2017 Expected Behavior 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /.review/generated_files/docs/DocStatus.md: -------------------------------------------------------------------------------- 1 | # DocRaptor::DocStatus 2 | 3 | ## Properties 4 | 5 | | Name | Type | Description | Notes | 6 | | ---- | ---- | ----------- | ----- | 7 | | **status** | **String** | The present status of the document. Can be queued, working, completed, and failed. | [optional] | 8 | | **download_url** | **String** | The URL where the document can be retrieved. This URL may only be used a few times. | [optional] | 9 | | **download_id** | **String** | The identifier for downloading the document with the download API. | [optional] | 10 | | **message** | **String** | Additional information. | [optional] | 11 | | **number_of_pages** | **Integer** | Number of PDF pages in document. | [optional] | 12 | | **validation_errors** | **String** | Error information. | [optional] | 13 | 14 | ## Example 15 | 16 | ```ruby 17 | require 'docraptor' 18 | 19 | instance = DocRaptor::DocStatus.new( 20 | status: null, 21 | download_url: null, 22 | download_id: null, 23 | message: null, 24 | number_of_pages: null, 25 | validation_errors: null 26 | ) 27 | ``` 28 | 29 | -------------------------------------------------------------------------------- /test/async.rb: -------------------------------------------------------------------------------- 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 | create_response = $docraptor.create_async_doc( 15 | test: true, 16 | document_content: "Hello from Ruby", 17 | name: output_file, 18 | document_type: "pdf", 19 | ) 20 | 21 | status_response = nil 22 | 30.times do 23 | status_response = $docraptor.get_async_doc_status(create_response.status_id) 24 | break if status_response.status == "completed" 25 | sleep 1 26 | end 27 | 28 | output_payload = $docraptor.get_async_doc(status_response.download_id) 29 | 30 | File.write(output_file, output_payload) 31 | output_type = `file -b #{output_file}` 32 | 33 | raise "Output was not a PDF" unless output_type.start_with?("PDF") 34 | 35 | -------------------------------------------------------------------------------- /script/fix_gemspec.rb: -------------------------------------------------------------------------------- 1 | # These, at least the first two, significantly increase speed of a test run by 2 | # limiting the filesystem interaction that occurs with bundler installing and 3 | # requiring files. 4 | bad_files = %q{s.files = `find *`.split("\n").uniq.sort.select { |f| !f.empty? }} 5 | good_files = %q{s.files = `git ls-files`.split("\n").uniq.sort.select { |f| !f.empty? }} 6 | bad_test_files = %q{s.test_files = `find spec/*`.split("\n")} 7 | good_test_files = %q{s.test_files = `git ls-files spec test`.split("\n")} 8 | 9 | filename = "docraptor.gemspec" 10 | content = File.read(filename) 11 | [ 12 | bad_files, 13 | bad_test_files, 14 | ].each do |bad_content_to_check| 15 | unless content.include?(bad_content_to_check) 16 | raise "Couldn't find content in docraptor.gemspec. Check matchers in there for: “#{bad_content_to_check}”" 17 | end 18 | end 19 | updated_content = content.dup 20 | updated_content.sub!(bad_files, good_files) 21 | updated_content.sub!(bad_test_files, good_test_files) 22 | 23 | File.open(filename, "w") do |file| 24 | file.write(updated_content) 25 | end 26 | -------------------------------------------------------------------------------- /script/setup: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | cd "$(dirname "$0")/.." 4 | 5 | setup_echo() { 6 | echo "[script/setup] $1" 7 | } 8 | 9 | setup_error() { 10 | echo "[script/setup][ERROR] $1" 11 | } 12 | 13 | brew_install() { 14 | setup_echo "Installing $1..." 15 | brew list --formula "$1" > /dev/null || brew install --formula "$1" 16 | } 17 | 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 28 | 29 | tput bold # bold text 30 | tput setaf 2 # green text 31 | setup_echo "****************************************************************" 32 | setup_echo "* *" 33 | setup_echo "* Good to go! *" 34 | setup_echo "* *" 35 | setup_echo "****************************************************************" 36 | tput sgr0 # reset to default text 37 | -------------------------------------------------------------------------------- /lib/docraptor.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | #DocRaptor 3 | 4 | #A native client library for the DocRaptor HTML to PDF/XLS service. 5 | 6 | The version of the OpenAPI document: 2.0.0 7 | 8 | Generated by: https://openapi-generator.tech 9 | OpenAPI Generator version: 6.6.0 10 | 11 | =end 12 | 13 | # Common files 14 | require 'docraptor/api_client' 15 | require 'docraptor/api_error' 16 | require 'docraptor/version' 17 | require 'docraptor/configuration' 18 | 19 | # Models 20 | require 'docraptor/models/async_doc' 21 | require 'docraptor/models/doc' 22 | require 'docraptor/models/doc_status' 23 | require 'docraptor/models/prince_options' 24 | 25 | # APIs 26 | require 'docraptor/api/doc_api' 27 | 28 | module DocRaptor 29 | class << self 30 | # Customize default settings for the SDK using block. 31 | # DocRaptor.configure do |config| 32 | # config.username = "xxx" 33 | # config.password = "xxx" 34 | # end 35 | # If no block given, return the default Configuration object. 36 | def configure 37 | if block_given? 38 | yield(Configuration.default) 39 | else 40 | Configuration.default 41 | end 42 | end 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /test/xlsx.rb: -------------------------------------------------------------------------------- 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}.xlsx") 13 | 14 | output_payload = $docraptor.create_doc( 15 | test: true, 16 | document_content: "
Hello from Ruby
", 17 | name: output_file, 18 | document_type: "xlsx", 19 | ) 20 | 21 | File.write(output_file, output_payload) 22 | output_type = `file -b #{output_file}` 23 | 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 32 | -------------------------------------------------------------------------------- /test/hosted_async.rb: -------------------------------------------------------------------------------- 1 | require "bundler/setup" 2 | Bundler.require 3 | require "open-uri" 4 | 5 | DocRaptor.configure do |dr| 6 | dr.username = "YOUR_API_KEY_HERE" 7 | # dr.debugging = true 8 | end 9 | 10 | $docraptor = DocRaptor::DocApi.new 11 | 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") 14 | 15 | output_payload = $docraptor.create_hosted_async_doc( 16 | test: true, 17 | document_content: "Hello from Ruby", 18 | name: output_file, 19 | document_type: "pdf", 20 | hosted_expires_at: (Time.now + 86400).strftime('%FT%T%:z'), # 1 day from now 21 | ) 22 | 23 | status_response = nil 24 | 30.times do 25 | status_response = $docraptor.get_async_doc_status(output_payload.status_id) 26 | break if status_response.status == "completed" 27 | sleep 1 28 | end 29 | 30 | output_payload = $docraptor.get_async_doc(status_response.download_id) 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") 36 | -------------------------------------------------------------------------------- /.review/generated_files/spec/configuration_spec.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | #DocRaptor 3 | 4 | #A native client library for the DocRaptor HTML to PDF/XLS service. 5 | 6 | The version of the OpenAPI document: 2.0.0 7 | 8 | Generated by: https://openapi-generator.tech 9 | OpenAPI Generator version: 6.6.0 10 | 11 | =end 12 | 13 | require 'spec_helper' 14 | 15 | describe DocRaptor::Configuration do 16 | let(:config) { DocRaptor::Configuration.default } 17 | 18 | before(:each) do 19 | # uncomment below to setup host and base_path 20 | # require 'URI' 21 | # uri = URI.parse("https://api.docraptor.com") 22 | # DocRaptor.configure do |c| 23 | # c.host = uri.host 24 | # c.base_path = uri.path 25 | # end 26 | end 27 | 28 | describe '#base_url' do 29 | it 'should have the default value' do 30 | # uncomment below to test default value of the base path 31 | # expect(config.base_url).to eq("https://api.docraptor.com") 32 | end 33 | 34 | it 'should remove trailing slashes' do 35 | [nil, '', '/', '//'].each do |base_path| 36 | config.base_path = base_path 37 | # uncomment below to test trailing slashes 38 | # expect(config.base_url).to eq("https://api.docraptor.com") 39 | end 40 | end 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /docraptor.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | 3 | =begin 4 | #DocRaptor 5 | 6 | #A native client library for the DocRaptor HTML to PDF/XLS service. 7 | 8 | The version of the OpenAPI document: 2.0.0 9 | 10 | Generated by: https://openapi-generator.tech 11 | OpenAPI Generator version: 6.6.0 12 | 13 | =end 14 | 15 | $:.push File.expand_path("../lib", __FILE__) 16 | require "docraptor/version" 17 | 18 | Gem::Specification.new do |s| 19 | s.name = "docraptor" 20 | s.version = DocRaptor::VERSION 21 | s.platform = Gem::Platform::RUBY 22 | s.authors = ["Expected Behavior"] 23 | s.email = ["support@docraptor.com"] 24 | s.homepage = "https://github.com/docraptor/docraptor-ruby" 25 | s.summary = "A wrapper for the DocRaptor HTML to PDF/XLS service." 26 | s.description = "A native client library for the DocRaptor HTML to PDF/XLS service." 27 | s.license = "MIT" 28 | s.required_ruby_version = ">= 2.5" 29 | 30 | s.add_runtime_dependency 'typhoeus', '~> 1.0', '>= 1.0.1' 31 | 32 | s.add_development_dependency 'rspec', '~> 3.6', '>= 3.6.0' 33 | 34 | s.files = `git ls-files`.split("\n").uniq.sort.select { |f| !f.empty? } 35 | s.test_files = `git ls-files spec test`.split("\n") 36 | s.executables = [] 37 | s.require_paths = ["lib"] 38 | end 39 | -------------------------------------------------------------------------------- /script/update_from_upstream: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | cd "$(dirname "$0")/.." 4 | 5 | if [[ $(basename "$PWD") == "swagger" ]]; then 6 | echo "This command is only used in langauge specific repositories" 7 | exit 1 8 | fi 9 | 10 | # Gets content at $1 and puts it into $2, automatically chmod +x if $2 is the 11 | # script dir. 12 | get() { 13 | curl --fail --silent --show-error "$1" > "$2" 14 | if [[ $(dirname "$2") == "script" ]]; then 15 | chmod +x "$2" 16 | fi 17 | } 18 | 19 | # Gets a file $1 from the upstream repo and places it in the same location. 20 | get_upstream() { 21 | get "https://raw.githubusercontent.com/docraptor/docraptor-swagger/master/$1" "$1" 22 | } 23 | 24 | # Main entry point, wrapped in a function so that bash can handle replacing 25 | # this file while executing it. 26 | update() { 27 | original=$(md5 script/update_from_upstream) 28 | get_upstream script/update_from_upstream 29 | if [[ $(md5 script/update_from_upstream) != "$original" ]]; then 30 | echo "Detected updated update_from_upstream command, running again" 31 | script/update_from_upstream 32 | exit 0 # recursive call above handled everything 33 | fi 34 | 35 | get_upstream docraptor.yaml 36 | 37 | get_upstream script/swagger 38 | script/swagger # download repo, etc. 39 | 40 | get_upstream script/generate_language 41 | } 42 | 43 | update 44 | -------------------------------------------------------------------------------- /test/iframes_false.rb: -------------------------------------------------------------------------------- 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 | 24 |

Baseline text

25 | 26 | 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/ 41 | -------------------------------------------------------------------------------- /test/iframes_true.rb: -------------------------------------------------------------------------------- 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 | 24 |

Baseline text

25 | 26 | 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/ 41 | -------------------------------------------------------------------------------- /test/iframes_default.rb: -------------------------------------------------------------------------------- 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 | 24 |

Baseline text

25 | 26 | 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/ 41 | -------------------------------------------------------------------------------- /test/expire_hosted.rb: -------------------------------------------------------------------------------- 1 | require "bundler/setup" 2 | Bundler.require 3 | require 'open-uri' 4 | 5 | DocRaptor.configure do |dr| 6 | dr.username = "YOUR_API_KEY_HERE" 7 | # dr.debugging = true 8 | end 9 | 10 | $docraptor = DocRaptor::DocApi.new 11 | 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") 14 | 15 | output_payload = $docraptor.create_hosted_async_doc( 16 | test: true, 17 | document_content: "Hello from Ruby", 18 | name: output_file, 19 | document_type: "pdf", 20 | hosted_expires_at: (Time.now + 86400).strftime('%FT%T%:z'), # 1 day from now 21 | ) 22 | 23 | status_response = nil 24 | 30.times do 25 | status_response = $docraptor.get_async_doc_status(output_payload.status_id) 26 | break if status_response.status == "completed" 27 | sleep 1 28 | end 29 | 30 | actual_document = URI.parse(status_response.download_url).open 31 | IO.copy_stream(actual_document, output_file) 32 | 33 | output_type = `file -b #{output_file}` 34 | 35 | raise "Output was not a PDF" unless output_type.start_with?("PDF") 36 | 37 | $docraptor.expire(status_response.download_id) 38 | 39 | begin 40 | actual_document = URI.parse(status_response.download_url).open 41 | rescue OpenURI::HTTPError => http_error 42 | exit 0 43 | end 44 | 45 | exit 1 46 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by: https://openapi-generator.tech 2 | # 3 | 4 | *.gem 5 | *.rbc 6 | /.config 7 | /coverage/ 8 | /InstalledFiles 9 | /pkg/ 10 | /spec/reports/ 11 | /spec/examples.txt 12 | /test/tmp/ 13 | /test/version_tmp/ 14 | /tmp/ 15 | 16 | ## Specific to RubyMotion: 17 | .dat* 18 | .repl_history 19 | build/ 20 | 21 | ## Documentation cache and generated files: 22 | /.yardoc/ 23 | /_yardoc/ 24 | /doc/ 25 | /rdoc/ 26 | 27 | ## Environment normalization: 28 | /.bundle/ 29 | /vendor/bundle 30 | /lib/bundler/man/ 31 | 32 | # for a library or gem, you might want to ignore these files since the code is 33 | # intended to run in multiple environments; otherwise, check them in: 34 | # Gemfile.lock 35 | # .ruby-version 36 | # .ruby-gemset 37 | 38 | # unless supporting rvm < 1.11.0 or doing something fancy, ignore this: 39 | .rvmrc 40 | 41 | 42 | # EB Customizations 43 | 44 | # Ignore this so we don't see a git modified status on each test run. Currently 45 | # the tests copy a different file into place for each ruby version, because the 46 | # same lock file won't work with every ruby version. We want those lock files 47 | # committed because it helps ensure the tests pass on this repo by ensuring a 48 | # static set of dependencies is used for each ruby version. A future improvement 49 | # could be to use docker to mount the correct lock file over top of the top 50 | # level lock file on each docker run, but that's a future exercise. 51 | Gemfile.lock 52 | -------------------------------------------------------------------------------- /test/prince_options.rb: -------------------------------------------------------------------------------- 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") 46 | -------------------------------------------------------------------------------- /lib/docraptor/api_error.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | #DocRaptor 3 | 4 | #A native client library for the DocRaptor HTML to PDF/XLS service. 5 | 6 | The version of the OpenAPI document: 2.0.0 7 | 8 | Generated by: https://openapi-generator.tech 9 | OpenAPI Generator version: 6.6.0 10 | 11 | =end 12 | 13 | module DocRaptor 14 | class ApiError < StandardError 15 | attr_reader :code, :response_headers, :response_body 16 | 17 | # Usage examples: 18 | # ApiError.new 19 | # ApiError.new("message") 20 | # ApiError.new(:code => 500, :response_headers => {}, :response_body => "") 21 | # ApiError.new(:code => 404, :message => "Not Found") 22 | def initialize(arg = nil) 23 | if arg.is_a? Hash 24 | if arg.key?(:message) || arg.key?('message') 25 | super(arg[:message] || arg['message']) 26 | else 27 | super arg 28 | end 29 | 30 | arg.each do |k, v| 31 | instance_variable_set "@#{k}", v 32 | end 33 | else 34 | super arg 35 | @message = arg 36 | end 37 | end 38 | 39 | # Override to_s to display a friendly error message 40 | def to_s 41 | message 42 | end 43 | 44 | def message 45 | if @message.nil? 46 | msg = "Error message: the server returns an error" 47 | else 48 | msg = @message 49 | end 50 | 51 | msg += "\nHTTP status code: #{code}" if code 52 | msg += "\nResponse headers: #{response_headers}" if response_headers 53 | msg += "\nResponse body: #{response_body}" if response_body 54 | 55 | msg 56 | end 57 | end 58 | end 59 | -------------------------------------------------------------------------------- /script/docker: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | [[ "$TRACE" == "true" ]] && set -x 4 | cd "$(dirname "$0")/.." 5 | 6 | OPTIND=1 7 | 8 | image="" 9 | 10 | while getopts "h?i:" opt; do 11 | case "$opt" in 12 | h|\?) 13 | show_help 14 | exit 0 15 | ;; 16 | i) image="$OPTARG" 17 | ;; 18 | esac 19 | done 20 | 21 | shift $((OPTIND-1)) 22 | 23 | if [[ "$image" == "" ]]; then 24 | image="$(cat .runtime-environments | grep -v '^#' | tail -n 1)" 25 | echo "docker image (-i) unset, defaulting to: $image" 26 | fi 27 | 28 | if ! docker pull "$image"; then 29 | echo "Pulling the latest version of ${image} failed, but we'll continue in" 30 | echo "the hopes that there's a previous version of the container available." 31 | echo "This probably isn't an issue unless you really want to verify" 32 | echo "everything works with a :latest container image." 33 | fi 34 | 35 | command="$1" 36 | 37 | mounts=() 38 | while IFS=':' read -r source target; do 39 | # Create the directory if it's not a special/magic path (like for ssh) 40 | mkdir -p -m 700 "$source" &> /dev/null || true 41 | 42 | mounts+=(--volume) 43 | mounts+=("${source}:${target}") 44 | 45 | # Can't pipe to the while loop because that causes a subshell, which means 46 | # the variables set in the loop aren't available outside of it. 47 | done < <(eval echo "\"$(grep -v '^#' .docker_mounts.list)\"") 48 | 49 | set -x 50 | docker run -it --rm \ 51 | --env-file .docker_env.list \ 52 | --env RUNTIME_ENV="${image}" \ 53 | --mount type=bind,source="$(pwd)",target=/app \ 54 | "${mounts[@]}" \ 55 | "$image" \ 56 | "$command" 57 | -------------------------------------------------------------------------------- /examples/sync.rb: -------------------------------------------------------------------------------- 1 | # This example demonstrates creating a PDF using common options and saving it 2 | # to a place on the filesystem. 3 | # 4 | # It is created synchronously, which means DocRaptor will render it for up to 5 | # 60 seconds. It is slightly simpler than making documents using the async 6 | # interface but making many documents in parallel or very large documents with 7 | # lots of assets will require the async api. 8 | # 9 | # DocRaptor supports many CSS and API options for output customization. Visit 10 | # https://docraptor.com/documentation/ for full details. 11 | # 12 | # You can run this example with: ruby sync.rb 13 | 14 | require "docraptor" 15 | 16 | DocRaptor.configure do |config| 17 | config.username = "YOUR_API_KEY_HERE" # this key works in test mode! 18 | end 19 | 20 | docraptor = DocRaptor::DocApi.new 21 | 22 | begin 23 | response = docraptor.create_doc( 24 | test: true, # test documents are free but watermarked 25 | document_type: "pdf", 26 | document_content: "Hello World!", 27 | # document_url: "https://docraptor.com/examples/invoice.html", 28 | # javascript: true, 29 | # prince_options: { 30 | # media: "print", # @media 'screen' or 'print' CSS 31 | # baseurl: "https://yoursite.com", # the base URL for any relative URLs 32 | # } 33 | ) 34 | 35 | # create_doc() returns a binary string 36 | File.write("github-sync.pdf", response, mode: "wb") 37 | puts "Successfully created github-sync.pdf!" 38 | rescue DocRaptor::ApiError => error 39 | puts "#{error.class}: #{error.message}" 40 | puts error.code 41 | puts error.response_body 42 | puts error.backtrace[0..3].join("\n") 43 | end 44 | -------------------------------------------------------------------------------- /.openapi-generator-ignore: -------------------------------------------------------------------------------- 1 | # Swagger Codegen Ignore 2 | # Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen 3 | 4 | # Use this file to prevent files from being overwritten by the generator. 5 | # The patterns follow closely to .gitignore or .dockerignore. 6 | 7 | # As an example, the C# client generator defines ApiClient.cs. 8 | # You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line: 9 | #ApiClient.cs 10 | 11 | # You can match any string of characters against a directory, file or extension with a single asterisk (*): 12 | #foo/*/qux 13 | # The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux 14 | 15 | # You can recursively match patterns against a directory, file or extension with a double asterisk (**): 16 | #foo/**/qux 17 | # This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux 18 | 19 | # You can also negate patterns with an exclamation (!). 20 | # For example, you can ignore all files in a docs folder with the file extension .md: 21 | #docs/*.md 22 | # Then explicitly reverse the ignore rule for a single file: 23 | #!docs/README.md 24 | 25 | 26 | # This seems to be a script related to developing openapi-generator and making 27 | # new test APIs. 28 | git_push.sh 29 | 30 | # Don't ignore this because we want to review the generated content to see if we 31 | # should update our own readme similarly. The most common example is an update 32 | # to the supported runtime versions, but it could also be an update to the 33 | # recommended usage that we would want to use. 34 | !README.md 35 | 36 | # Don't ignore this because we want to know about new files that the generator 37 | # ignores. 38 | !.gitignore 39 | -------------------------------------------------------------------------------- /script/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | [[ "$TRACE" == "true" ]] && set -x 4 | cd "$(dirname "$0")/.." 5 | 6 | echo "Clearing test output directory" 7 | rm -rf tmp/test_output/ 8 | mkdir -p tmp/test_output 9 | 10 | [ -f script/build ] && script/build 11 | 12 | run_tests() { 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 22 | else 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 30 | fi 31 | } 32 | 33 | success="true" 34 | 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" 40 | done 41 | 42 | if [ $success == "true" ]; then 43 | tput bold # bold text 44 | tput setaf 2 # green text 45 | echo "======================================" 46 | echo "= Full Test Suite Passed =" 47 | echo "======================================" 48 | tput sgr0 # reset to default text 49 | exit 0 50 | else 51 | tput bold # bold text 52 | tput setaf 1 # red text 53 | echo "======================================" 54 | echo "= Full Test Suite FAILED =" 55 | echo "======================================" 56 | tput sgr0 # reset to default text 57 | exit 1 58 | fi 59 | -------------------------------------------------------------------------------- /gemfiles/Gemfile.2.5.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: . 3 | specs: 4 | docraptor (2.0.0) 5 | typhoeus (~> 1.0, >= 1.0.1) 6 | 7 | GEM 8 | remote: https://rubygems.org/ 9 | specs: 10 | ast (2.4.2) 11 | byebug (11.1.3) 12 | coderay (1.1.3) 13 | diff-lcs (1.5.0) 14 | ethon (0.16.0) 15 | ffi (>= 1.15.0) 16 | ffi (1.15.5) 17 | jaro_winkler (1.5.4) 18 | method_source (1.0.0) 19 | parallel (1.22.1) 20 | parser (3.1.2.1) 21 | ast (~> 2.4.1) 22 | pry (0.13.1) 23 | coderay (~> 1.1) 24 | method_source (~> 1.0) 25 | pry-byebug (3.9.0) 26 | byebug (~> 11.0) 27 | pry (~> 0.13.0) 28 | psych (4.0.6) 29 | stringio 30 | rainbow (3.1.1) 31 | rake (13.0.6) 32 | rspec (3.12.0) 33 | rspec-core (~> 3.12.0) 34 | rspec-expectations (~> 3.12.0) 35 | rspec-mocks (~> 3.12.0) 36 | rspec-core (3.12.0) 37 | rspec-support (~> 3.12.0) 38 | rspec-expectations (3.12.0) 39 | diff-lcs (>= 1.2.0, < 2.0) 40 | rspec-support (~> 3.12.0) 41 | rspec-mocks (3.12.0) 42 | diff-lcs (>= 1.2.0, < 2.0) 43 | rspec-support (~> 3.12.0) 44 | rspec-support (3.12.0) 45 | rubocop (0.66.0) 46 | jaro_winkler (~> 1.5.1) 47 | parallel (~> 1.10) 48 | parser (>= 2.5, != 2.5.1.1) 49 | psych (>= 3.1.0) 50 | rainbow (>= 2.2.2, < 4.0) 51 | ruby-progressbar (~> 1.7) 52 | unicode-display_width (>= 1.4.0, < 1.6) 53 | ruby-progressbar (1.11.0) 54 | stringio (3.0.2) 55 | typhoeus (1.4.0) 56 | ethon (>= 0.9.0) 57 | unicode-display_width (1.5.0) 58 | 59 | PLATFORMS 60 | ruby 61 | 62 | DEPENDENCIES 63 | docraptor! 64 | pry-byebug 65 | rake (~> 13.0.1) 66 | rspec (~> 3.6, >= 3.6.0) 67 | rubocop (~> 0.66.0) 68 | 69 | BUNDLED WITH 70 | 1.17.3 71 | -------------------------------------------------------------------------------- /gemfiles/Gemfile.2.6.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: . 3 | specs: 4 | docraptor (2.0.0) 5 | typhoeus (~> 1.0, >= 1.0.1) 6 | 7 | GEM 8 | remote: https://rubygems.org/ 9 | specs: 10 | ast (2.4.2) 11 | byebug (11.1.3) 12 | coderay (1.1.3) 13 | diff-lcs (1.5.0) 14 | ethon (0.15.0) 15 | ffi (>= 1.15.0) 16 | ffi (1.15.5) 17 | jaro_winkler (1.5.4) 18 | method_source (1.0.0) 19 | parallel (1.22.1) 20 | parser (3.1.2.1) 21 | ast (~> 2.4.1) 22 | pry (0.13.1) 23 | coderay (~> 1.1) 24 | method_source (~> 1.0) 25 | pry-byebug (3.9.0) 26 | byebug (~> 11.0) 27 | pry (~> 0.13.0) 28 | psych (4.0.6) 29 | stringio 30 | rainbow (3.1.1) 31 | rake (13.0.6) 32 | rspec (3.11.0) 33 | rspec-core (~> 3.11.0) 34 | rspec-expectations (~> 3.11.0) 35 | rspec-mocks (~> 3.11.0) 36 | rspec-core (3.11.0) 37 | rspec-support (~> 3.11.0) 38 | rspec-expectations (3.11.1) 39 | diff-lcs (>= 1.2.0, < 2.0) 40 | rspec-support (~> 3.11.0) 41 | rspec-mocks (3.11.1) 42 | diff-lcs (>= 1.2.0, < 2.0) 43 | rspec-support (~> 3.11.0) 44 | rspec-support (3.11.1) 45 | rubocop (0.66.0) 46 | jaro_winkler (~> 1.5.1) 47 | parallel (~> 1.10) 48 | parser (>= 2.5, != 2.5.1.1) 49 | psych (>= 3.1.0) 50 | rainbow (>= 2.2.2, < 4.0) 51 | ruby-progressbar (~> 1.7) 52 | unicode-display_width (>= 1.4.0, < 1.6) 53 | ruby-progressbar (1.11.0) 54 | stringio (3.0.2) 55 | typhoeus (1.4.0) 56 | ethon (>= 0.9.0) 57 | unicode-display_width (1.5.0) 58 | 59 | PLATFORMS 60 | ruby 61 | 62 | DEPENDENCIES 63 | docraptor! 64 | pry-byebug 65 | rake (~> 13.0.1) 66 | rspec (~> 3.6, >= 3.6.0) 67 | rubocop (~> 0.66.0) 68 | 69 | BUNDLED WITH 70 | 1.17.2 71 | -------------------------------------------------------------------------------- /gemfiles/Gemfile.2.7.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: . 3 | specs: 4 | docraptor (2.0.0) 5 | typhoeus (~> 1.0, >= 1.0.1) 6 | 7 | GEM 8 | remote: https://rubygems.org/ 9 | specs: 10 | ast (2.4.2) 11 | byebug (11.1.3) 12 | coderay (1.1.3) 13 | diff-lcs (1.5.0) 14 | ethon (0.15.0) 15 | ffi (>= 1.15.0) 16 | ffi (1.15.5) 17 | jaro_winkler (1.5.4) 18 | method_source (1.0.0) 19 | parallel (1.22.1) 20 | parser (3.1.2.1) 21 | ast (~> 2.4.1) 22 | pry (0.14.1) 23 | coderay (~> 1.1) 24 | method_source (~> 1.0) 25 | pry-byebug (3.10.1) 26 | byebug (~> 11.0) 27 | pry (>= 0.13, < 0.15) 28 | psych (4.0.6) 29 | stringio 30 | rainbow (3.1.1) 31 | rake (13.0.6) 32 | rspec (3.11.0) 33 | rspec-core (~> 3.11.0) 34 | rspec-expectations (~> 3.11.0) 35 | rspec-mocks (~> 3.11.0) 36 | rspec-core (3.11.0) 37 | rspec-support (~> 3.11.0) 38 | rspec-expectations (3.11.1) 39 | diff-lcs (>= 1.2.0, < 2.0) 40 | rspec-support (~> 3.11.0) 41 | rspec-mocks (3.11.1) 42 | diff-lcs (>= 1.2.0, < 2.0) 43 | rspec-support (~> 3.11.0) 44 | rspec-support (3.11.1) 45 | rubocop (0.66.0) 46 | jaro_winkler (~> 1.5.1) 47 | parallel (~> 1.10) 48 | parser (>= 2.5, != 2.5.1.1) 49 | psych (>= 3.1.0) 50 | rainbow (>= 2.2.2, < 4.0) 51 | ruby-progressbar (~> 1.7) 52 | unicode-display_width (>= 1.4.0, < 1.6) 53 | ruby-progressbar (1.11.0) 54 | stringio (3.0.2) 55 | typhoeus (1.4.0) 56 | ethon (>= 0.9.0) 57 | unicode-display_width (1.5.0) 58 | 59 | PLATFORMS 60 | ruby 61 | 62 | DEPENDENCIES 63 | docraptor! 64 | pry-byebug 65 | rake (~> 13.0.1) 66 | rspec (~> 3.6, >= 3.6.0) 67 | rubocop (~> 0.66.0) 68 | 69 | BUNDLED WITH 70 | 2.1.4 71 | -------------------------------------------------------------------------------- /gemfiles/Gemfile.3.0.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: . 3 | specs: 4 | docraptor (2.0.0) 5 | typhoeus (~> 1.0, >= 1.0.1) 6 | 7 | GEM 8 | remote: https://rubygems.org/ 9 | specs: 10 | ast (2.4.2) 11 | byebug (11.1.3) 12 | coderay (1.1.3) 13 | diff-lcs (1.5.0) 14 | ethon (0.15.0) 15 | ffi (>= 1.15.0) 16 | ffi (1.15.5) 17 | jaro_winkler (1.5.4) 18 | method_source (1.0.0) 19 | parallel (1.22.1) 20 | parser (3.1.2.1) 21 | ast (~> 2.4.1) 22 | pry (0.14.1) 23 | coderay (~> 1.1) 24 | method_source (~> 1.0) 25 | pry-byebug (3.10.1) 26 | byebug (~> 11.0) 27 | pry (>= 0.13, < 0.15) 28 | psych (4.0.6) 29 | stringio 30 | rainbow (3.1.1) 31 | rake (13.0.6) 32 | rspec (3.11.0) 33 | rspec-core (~> 3.11.0) 34 | rspec-expectations (~> 3.11.0) 35 | rspec-mocks (~> 3.11.0) 36 | rspec-core (3.11.0) 37 | rspec-support (~> 3.11.0) 38 | rspec-expectations (3.11.1) 39 | diff-lcs (>= 1.2.0, < 2.0) 40 | rspec-support (~> 3.11.0) 41 | rspec-mocks (3.11.1) 42 | diff-lcs (>= 1.2.0, < 2.0) 43 | rspec-support (~> 3.11.0) 44 | rspec-support (3.11.1) 45 | rubocop (0.66.0) 46 | jaro_winkler (~> 1.5.1) 47 | parallel (~> 1.10) 48 | parser (>= 2.5, != 2.5.1.1) 49 | psych (>= 3.1.0) 50 | rainbow (>= 2.2.2, < 4.0) 51 | ruby-progressbar (~> 1.7) 52 | unicode-display_width (>= 1.4.0, < 1.6) 53 | ruby-progressbar (1.11.0) 54 | stringio (3.0.2) 55 | typhoeus (1.4.0) 56 | ethon (>= 0.9.0) 57 | unicode-display_width (1.5.0) 58 | 59 | PLATFORMS 60 | aarch64-linux 61 | 62 | DEPENDENCIES 63 | docraptor! 64 | pry-byebug 65 | rake (~> 13.0.1) 66 | rspec (~> 3.6, >= 3.6.0) 67 | rubocop (~> 0.66.0) 68 | 69 | BUNDLED WITH 70 | 2.2.33 71 | -------------------------------------------------------------------------------- /gemfiles/Gemfile.3.1.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: . 3 | specs: 4 | docraptor (3.0.0) 5 | typhoeus (~> 1.0, >= 1.0.1) 6 | 7 | GEM 8 | remote: https://rubygems.org/ 9 | specs: 10 | ast (2.4.2) 11 | byebug (11.1.3) 12 | coderay (1.1.3) 13 | diff-lcs (1.5.0) 14 | ethon (0.16.0) 15 | ffi (>= 1.15.0) 16 | ffi (1.15.5) 17 | jaro_winkler (1.5.6) 18 | method_source (1.0.0) 19 | parallel (1.23.0) 20 | parser (3.2.2.3) 21 | ast (~> 2.4.1) 22 | racc 23 | pry (0.14.2) 24 | coderay (~> 1.1) 25 | method_source (~> 1.0) 26 | pry-byebug (3.10.1) 27 | byebug (~> 11.0) 28 | pry (>= 0.13, < 0.15) 29 | psych (5.1.0) 30 | stringio 31 | racc (1.7.1) 32 | rainbow (3.1.1) 33 | rake (13.0.6) 34 | rspec (3.12.0) 35 | rspec-core (~> 3.12.0) 36 | rspec-expectations (~> 3.12.0) 37 | rspec-mocks (~> 3.12.0) 38 | rspec-core (3.12.2) 39 | rspec-support (~> 3.12.0) 40 | rspec-expectations (3.12.3) 41 | diff-lcs (>= 1.2.0, < 2.0) 42 | rspec-support (~> 3.12.0) 43 | rspec-mocks (3.12.6) 44 | diff-lcs (>= 1.2.0, < 2.0) 45 | rspec-support (~> 3.12.0) 46 | rspec-support (3.12.1) 47 | rubocop (0.66.0) 48 | jaro_winkler (~> 1.5.1) 49 | parallel (~> 1.10) 50 | parser (>= 2.5, != 2.5.1.1) 51 | psych (>= 3.1.0) 52 | rainbow (>= 2.2.2, < 4.0) 53 | ruby-progressbar (~> 1.7) 54 | unicode-display_width (>= 1.4.0, < 1.6) 55 | ruby-progressbar (1.13.0) 56 | stringio (3.0.7) 57 | typhoeus (1.4.0) 58 | ethon (>= 0.9.0) 59 | unicode-display_width (1.5.0) 60 | 61 | PLATFORMS 62 | aarch64-linux 63 | 64 | DEPENDENCIES 65 | docraptor! 66 | pry-byebug 67 | rake (~> 13.0.1) 68 | rspec (~> 3.6, >= 3.6.0) 69 | rubocop (~> 0.66.0) 70 | 71 | BUNDLED WITH 72 | 2.3.26 73 | -------------------------------------------------------------------------------- /gemfiles/Gemfile.3.2.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: . 3 | specs: 4 | docraptor (3.0.0) 5 | typhoeus (~> 1.0, >= 1.0.1) 6 | 7 | GEM 8 | remote: https://rubygems.org/ 9 | specs: 10 | ast (2.4.2) 11 | byebug (11.1.3) 12 | coderay (1.1.3) 13 | diff-lcs (1.5.0) 14 | ethon (0.16.0) 15 | ffi (>= 1.15.0) 16 | ffi (1.15.5) 17 | jaro_winkler (1.5.6) 18 | method_source (1.0.0) 19 | parallel (1.23.0) 20 | parser (3.2.2.3) 21 | ast (~> 2.4.1) 22 | racc 23 | pry (0.14.2) 24 | coderay (~> 1.1) 25 | method_source (~> 1.0) 26 | pry-byebug (3.10.1) 27 | byebug (~> 11.0) 28 | pry (>= 0.13, < 0.15) 29 | psych (5.1.0) 30 | stringio 31 | racc (1.7.1) 32 | rainbow (3.1.1) 33 | rake (13.0.6) 34 | rspec (3.12.0) 35 | rspec-core (~> 3.12.0) 36 | rspec-expectations (~> 3.12.0) 37 | rspec-mocks (~> 3.12.0) 38 | rspec-core (3.12.2) 39 | rspec-support (~> 3.12.0) 40 | rspec-expectations (3.12.3) 41 | diff-lcs (>= 1.2.0, < 2.0) 42 | rspec-support (~> 3.12.0) 43 | rspec-mocks (3.12.6) 44 | diff-lcs (>= 1.2.0, < 2.0) 45 | rspec-support (~> 3.12.0) 46 | rspec-support (3.12.1) 47 | rubocop (0.66.0) 48 | jaro_winkler (~> 1.5.1) 49 | parallel (~> 1.10) 50 | parser (>= 2.5, != 2.5.1.1) 51 | psych (>= 3.1.0) 52 | rainbow (>= 2.2.2, < 4.0) 53 | ruby-progressbar (~> 1.7) 54 | unicode-display_width (>= 1.4.0, < 1.6) 55 | ruby-progressbar (1.13.0) 56 | stringio (3.0.7) 57 | typhoeus (1.4.0) 58 | ethon (>= 0.9.0) 59 | unicode-display_width (1.5.0) 60 | 61 | PLATFORMS 62 | aarch64-linux 63 | 64 | DEPENDENCIES 65 | docraptor! 66 | pry-byebug 67 | rake (~> 13.0.1) 68 | rspec (~> 3.6, >= 3.6.0) 69 | rubocop (~> 0.66.0) 70 | 71 | BUNDLED WITH 72 | 2.4.10 73 | -------------------------------------------------------------------------------- /gemfiles/Gemfile.3.3.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: . 3 | specs: 4 | docraptor (3.0.0) 5 | typhoeus (~> 1.0, >= 1.0.1) 6 | 7 | GEM 8 | remote: https://rubygems.org/ 9 | specs: 10 | ast (2.4.2) 11 | byebug (11.1.3) 12 | coderay (1.1.3) 13 | diff-lcs (1.5.0) 14 | ethon (0.16.0) 15 | ffi (>= 1.15.0) 16 | ffi (1.15.5) 17 | jaro_winkler (1.5.6) 18 | method_source (1.0.0) 19 | parallel (1.23.0) 20 | parser (3.2.2.3) 21 | ast (~> 2.4.1) 22 | racc 23 | pry (0.14.2) 24 | coderay (~> 1.1) 25 | method_source (~> 1.0) 26 | pry-byebug (3.10.1) 27 | byebug (~> 11.0) 28 | pry (>= 0.13, < 0.15) 29 | psych (5.1.0) 30 | stringio 31 | racc (1.7.1) 32 | rainbow (3.1.1) 33 | rake (13.0.6) 34 | rspec (3.12.0) 35 | rspec-core (~> 3.12.0) 36 | rspec-expectations (~> 3.12.0) 37 | rspec-mocks (~> 3.12.0) 38 | rspec-core (3.12.2) 39 | rspec-support (~> 3.12.0) 40 | rspec-expectations (3.12.3) 41 | diff-lcs (>= 1.2.0, < 2.0) 42 | rspec-support (~> 3.12.0) 43 | rspec-mocks (3.12.6) 44 | diff-lcs (>= 1.2.0, < 2.0) 45 | rspec-support (~> 3.12.0) 46 | rspec-support (3.12.1) 47 | rubocop (0.66.0) 48 | jaro_winkler (~> 1.5.1) 49 | parallel (~> 1.10) 50 | parser (>= 2.5, != 2.5.1.1) 51 | psych (>= 3.1.0) 52 | rainbow (>= 2.2.2, < 4.0) 53 | ruby-progressbar (~> 1.7) 54 | unicode-display_width (>= 1.4.0, < 1.6) 55 | ruby-progressbar (1.13.0) 56 | stringio (3.0.7) 57 | typhoeus (1.4.0) 58 | ethon (>= 0.9.0) 59 | unicode-display_width (1.5.0) 60 | 61 | PLATFORMS 62 | aarch64-linux 63 | 64 | DEPENDENCIES 65 | docraptor! 66 | pry-byebug 67 | rake (~> 13.0.1) 68 | rspec (~> 3.6, >= 3.6.0) 69 | rubocop (~> 0.66.0) 70 | 71 | BUNDLED WITH 72 | 2.5.0.dev 73 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ### 3.1.0 [July 19, 2023] 2 | * Add new Prince API options for pdf_forms, iframes, and page_margin 3 | 4 | ### 3.0.0 [November 15, 2022] 5 | * Switch API host to more secure api.docraptor.com (dropping old TLS) 6 | * Remove support for rubies <2.5 7 | * Switch from swagger v2.4.19 to openapi-generator v6.0.1 (better maintained) 8 | 9 | ### 2.0.0 [June 1, 2021] 10 | * Add support for ruby 3.x (remove `URI.encode`) 11 | * Remove support for rubies <2.3 12 | 13 | ### 1.4.0 [July 31, 2020] 14 | * add support for hosted documents 15 | * upgrade to latest swagger 2.4.14 16 | 17 | ### 1.3.0 [November 21, 2017] 18 | * Added support for `prince_options[pdf_title]` and `ignore_console_messages` options 19 | 20 | ### 1.2.0 [August 22, 2017] 21 | * No changes from beta1 22 | 23 | ### 1.2.0beta1 [August 9, 2017] 24 | * Re-runnning against newer swagger version (v.2.2.3), bumping many gem dependencies to much newer versions. Applications using client *should not* be affected. 25 | 26 | ### 1.1.0 [November 3, 2016] 27 | * Added support for pipeline API parameter 28 | 29 | ### 1.0.0 [October 18, 2016] 30 | * No significant code changes 31 | 32 | ### 0.4.0 [September 26, 2016] 33 | * Added support for prince_options[no_parallel_downloads] 34 | 35 | ### 0.3.0 [March 11, 2016] 36 | * Added support for prince_options[debug] 37 | 38 | ### 0.2.0 [January 29, 2016] 39 | * **BREAKING CHANGE**: Rename ClientApi to DocApi 40 | 41 | ### 0.1.0 [January 27, 2016] 42 | * **BREAKING CHANGE**: create_doc and get_async_doc responses are now binary strings instead of Tempfiles 43 | 44 | ### 0.0.3 [January 15, 2016] 45 | * Use better API command names: create_doc, create_async_doc, get_async_doc_status, get_async_doc 46 | * Fix file encoding issues when used in Rails 47 | 48 | ### 0.0.2 [January 6, 2016] 49 | * Regenerate using swagger-codegen v2.1.5 50 | 51 | ### 0.0.1 [November 1, 2015] 52 | * Initial release 53 | -------------------------------------------------------------------------------- /.review/generated_files/spec/models/doc_status_spec.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | #DocRaptor 3 | 4 | #A native client library for the DocRaptor HTML to PDF/XLS service. 5 | 6 | The version of the OpenAPI document: 2.0.0 7 | 8 | Generated by: https://openapi-generator.tech 9 | OpenAPI Generator version: 6.6.0 10 | 11 | =end 12 | 13 | require 'spec_helper' 14 | require 'json' 15 | require 'date' 16 | 17 | # Unit tests for DocRaptor::DocStatus 18 | # Automatically generated by openapi-generator (https://openapi-generator.tech) 19 | # Please update as you see appropriate 20 | describe DocRaptor::DocStatus do 21 | let(:instance) { DocRaptor::DocStatus.new } 22 | 23 | describe 'test an instance of DocStatus' do 24 | it 'should create an instance of DocStatus' do 25 | expect(instance).to be_instance_of(DocRaptor::DocStatus) 26 | end 27 | end 28 | describe 'test attribute "status"' do 29 | it 'should work' do 30 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 31 | end 32 | end 33 | 34 | describe 'test attribute "download_url"' do 35 | it 'should work' do 36 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 37 | end 38 | end 39 | 40 | describe 'test attribute "download_id"' do 41 | it 'should work' do 42 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 43 | end 44 | end 45 | 46 | describe 'test attribute "message"' do 47 | it 'should work' do 48 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 49 | end 50 | end 51 | 52 | describe 'test attribute "number_of_pages"' do 53 | it 'should work' do 54 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 55 | end 56 | end 57 | 58 | describe 'test attribute "validation_errors"' do 59 | it 'should work' do 60 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 61 | end 62 | end 63 | 64 | end 65 | -------------------------------------------------------------------------------- /script/inside_container/test: -------------------------------------------------------------------------------- 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 88 | -------------------------------------------------------------------------------- /examples/async.rb: -------------------------------------------------------------------------------- 1 | # This example demonstrates creating a PDF using common options and saving it 2 | # to a place on the filesystem. 3 | # 4 | # It is created asynchronously, which means DocRaptor will render it for up to 5 | # 10 minutes. This is useful when creating many documents in parallel, or very 6 | # large documents with lots of assets. 7 | # 8 | # DocRaptor supports many CSS and API options for output customization. Visit 9 | # https://docraptor.com/documentation/ for full details. 10 | # 11 | # You can run this example with: ruby async.rb 12 | 13 | require "docraptor" 14 | 15 | DocRaptor.configure do |config| 16 | config.username = "YOUR_API_KEY_HERE" # this key works in test mode! 17 | end 18 | 19 | docraptor = DocRaptor::DocApi.new 20 | 21 | begin 22 | # different method than the synchronous documents 23 | response = docraptor.create_async_doc( 24 | test: true, # test documents are free but watermarked 25 | document_type: "pdf", 26 | document_content: "Hello World!", 27 | # document_url: "https://docraptor.com/examples/invoice.html", 28 | # javascript: true, 29 | # prince_options: { 30 | # media: "print", # @media 'screen' or 'print' CSS 31 | # baseurl: "https://yoursite.com", # the base URL for any relative URLs 32 | # } 33 | ) 34 | 35 | loop do 36 | status_response = docraptor.get_async_doc_status(response.status_id) 37 | puts "status: #{status_response.status}" 38 | case status_response.status 39 | when "completed" 40 | document = docraptor.get_async_doc(status_response.download_id) 41 | # get_async_doc() returns a binary string 42 | File.write("github-async.pdf", document, mode: "wb") 43 | puts "Successfully created github-async.pdf!" 44 | break 45 | when "failed" 46 | puts "FAILED" 47 | puts status_response 48 | break 49 | else 50 | sleep 1 51 | end 52 | end 53 | rescue DocRaptor::ApiError => error 54 | puts "#{error.class}: #{error.message}" 55 | puts error.code 56 | puts error.response_body 57 | puts error.backtrace[0..3].join("\n") 58 | end 59 | -------------------------------------------------------------------------------- /examples/hosted_sync.rb: -------------------------------------------------------------------------------- 1 | # As a paid add-on, DocRaptor can provide long-term, publicly-accessible hosting for your documents. 2 | # This allows you to provide a URL to your end users, third party tools like Zapier and Salesforce, 3 | # or anyone else. We'll host the document on your behalf at a completely unbranded URL for as long 4 | # as you want, or within the limits you specify. 5 | # 6 | # This example demonstrates creating a PDF that DocRaptor will host for you using common options. 7 | # By default, hosted documents do not have limits on downloads or hosting time, though you may 8 | # pass additional parameters to the document generation call to set your own limits. Learn more 9 | # about the specific options in the hosted API documentation. 10 | # https://docraptor.com/documentation/api#api_hosted 11 | # 12 | # It is created synchronously, which means DocRaptor will allow it to generate for up to 60 seconds. 13 | # Since this document will be hosted by DocRaptor the response from this request will return a JSON 14 | # formatted object containing public URL where the document can be downloaded from. 15 | # 16 | # DocRaptor supports many CSS and API options for output customization. Visit 17 | # https://docraptor.com/documentation/ for full details. 18 | # 19 | # You can run this example with: ruby hosted_sync.rb 20 | 21 | require "docraptor" 22 | 23 | DocRaptor.configure do |config| 24 | config.username = "YOUR_API_KEY_HERE" # this key works in test mode! 25 | end 26 | 27 | docraptor = DocRaptor::DocApi.new 28 | 29 | begin 30 | # different method than the non-hosted documents 31 | response = docraptor.create_hosted_doc( 32 | test: true, # test documents are free but watermarked 33 | document_type: "pdf", 34 | document_content: "Hello World!", 35 | # document_url: "https://docraptor.com/examples/invoice.html", 36 | # javascript: true, 37 | # prince_options: { 38 | # media: "print", # @media 'screen' or 'print' CSS 39 | # baseurl: "https://yoursite.com", # the base URL for any relative URLs 40 | # } 41 | ) 42 | 43 | puts "The PDF is hosted at #{response.download_url}" 44 | rescue DocRaptor::ApiError => error 45 | puts "#{error.class}: #{error.message}" 46 | puts error.code 47 | puts error.response_body 48 | puts error.backtrace[0..3].join("\n") 49 | end 50 | -------------------------------------------------------------------------------- /script/generate_language: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | [[ "$TRACE" == "true" ]] && set -x 4 | cd "$(dirname "$0")/.." 5 | 6 | LANGUAGE="$(cat .generator-language-identifier)" 7 | CONFIG_FILE="generator-config.json" 8 | 9 | if [ "$LANGUAGE" = "" ]; then 10 | ./script/swagger # prints languages 11 | exit 1 12 | fi 13 | 14 | if [ ! -f "$CONFIG_FILE" ]; then 15 | echo "Could not find $CONFIG_FILE" 16 | ./script/swagger config-help -l "$LANGUAGE" 17 | exit 1 18 | fi 19 | 20 | ./script/clean 21 | 22 | # See .review/README.md 23 | echo "Facilitating generated content review" 24 | tmp_dir=".review/tmp" 25 | review_root=".review/generated_files" 26 | # Clear the tmp_dir, where we'll temporarily store our files so they aren't 27 | # overwritten by the generated files. 28 | rm -rf "$tmp_dir" 29 | (cd "$review_root" && find . -type f) | while read file_path; do 30 | # Move our file out of the way so it doesn't get overwritten by the generated 31 | # file, but only if the file exists. Some files, like the generated docs and 32 | # tests, aren't useful to users to we generally remove them, but we still 33 | # want to facilitate review of these generated files. 34 | if [ -e "$file_path" ]; then 35 | mkdir -p "$(dirname "${tmp_dir}/$file_path")" 36 | mv -v "$file_path" "${tmp_dir}/$file_path" 37 | fi 38 | done 39 | 40 | ./script/swagger generate \ 41 | -i docraptor.yaml \ 42 | -g "$LANGUAGE" \ 43 | -c "$CONFIG_FILE" 44 | 45 | # call a generator cleanup script 46 | if [ -f "script/post_generate_language" ]; then 47 | ./script/post_generate_language 48 | fi 49 | 50 | # See .review/README.md 51 | echo "Facilitating generated content review" 52 | (cd "$review_root" && find . -type f) | while read file_path; do 53 | # Update $review_root to match the generated files. 54 | if [ -e "$file_path" ]; then 55 | # Move the newly generated file into the review directory so we'll be able to 56 | # see it in the diff. 57 | mv -v "$file_path" "$review_root/$file_path" 58 | else 59 | # If the file doesn't exist, then it was removed by the generator, so we 60 | # should remove it from the review directory as well. 61 | rm -v "$review_root/$file_path" 62 | fi 63 | # If we temporarily stored a file (meaning it existed before the generation) 64 | # then move it back into place. 65 | if [ -e "${tmp_dir}/$file_path" ]; then 66 | mv -v "${tmp_dir}/$file_path" "$file_path" 67 | fi 68 | done 69 | -------------------------------------------------------------------------------- /examples/hosted_async.rb: -------------------------------------------------------------------------------- 1 | # As a paid add-on, DocRaptor can provide long-term, publicly-accessible hosting for your documents. 2 | # This allows you to provide a URL to your end users, third party tools like Zapier and Salesforce, 3 | # or anyone else. We'll host the document on your behalf at a completely unbranded URL for as long 4 | # as you want, or within the limits you specify. 5 | # 6 | # This example demonstrates creating a PDF using common options that DocRaptor will host for you. 7 | # By default, hosted documents do not have limits on downloads or hosting time, though you may 8 | # pass additional parameters to the document generation call to set your own limits. Learn more 9 | # about the specific options in the hosted API documentation. 10 | # https://docraptor.com/documentation/api#api_hosted 11 | # 12 | # The document is created asynchronously, which means DocRaptor will allow it to generate for up to 13 | # 10 minutes. This is useful when creating many documents in parallel, or very large documents with 14 | # lots of assets. 15 | # 16 | # DocRaptor supports many CSS and API options for output customization. Visit 17 | # https://docraptor.com/documentation/ for full details. 18 | # 19 | # You can run this example with: ruby hosted_async.rb 20 | 21 | require "docraptor" 22 | 23 | DocRaptor.configure do |config| 24 | config.username = "YOUR_API_KEY_HERE" # this key works in test mode! 25 | end 26 | 27 | docraptor = DocRaptor::DocApi.new 28 | 29 | begin 30 | # different method than synchronous or non-hosted documents 31 | response = docraptor.create_hosted_async_doc( 32 | test: true, # test documents are free but watermarked 33 | document_type: "pdf", 34 | document_content: "Hello World!", 35 | # document_url: "https://docraptor.com/examples/invoice.html", 36 | # javascript: true, 37 | # prince_options: { 38 | # media: "print", # @media 'screen' or 'print' CSS 39 | # baseurl: "https://yoursite.com", # the base URL for any relative URLs 40 | # } 41 | ) 42 | 43 | loop do 44 | status_response = docraptor.get_async_doc_status(response.status_id) 45 | puts "status: #{status_response.status}" 46 | case status_response.status 47 | when "completed" 48 | puts "The asynchronously-generated PDF is hosted at #{status_response.download_url}" 49 | break 50 | when "failed" 51 | puts "FAILED" 52 | puts status_response 53 | break 54 | else 55 | sleep 1 56 | end 57 | end 58 | rescue DocRaptor::ApiError => error 59 | puts "#{error.class}: #{error.message}" 60 | puts error.code 61 | puts error.response_body 62 | puts error.backtrace[0..3].join("\n") 63 | end 64 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DocRaptor Ruby Native Client Library 2 | 3 | This is a Ruby gem for using [DocRaptor API](https://docraptor.com/documentation) to convert [HTML to PDF and XLSX](https://docraptor.com). 4 | 5 | 6 | ## Installation 7 | 8 | Add the following to your `Gemfile`. 9 | 10 | ```ruby 11 | gem "docraptor" 12 | ``` 13 | 14 | Then run: 15 | 16 | ```bash 17 | bundle install 18 | ``` 19 | 20 | 21 | ## Basic Usage 22 | 23 | ```ruby 24 | DocRaptor.configure do |config| 25 | config.username = "YOUR_API_KEY_HERE" # this key works for test documents 26 | # config.debugging = true 27 | end 28 | 29 | $docraptor = DocRaptor::DocApi.new 30 | 31 | response = $docraptor.create_doc( 32 | test: true, # test documents are free but watermarked 33 | document_content: "Hello World", # supply content directly 34 | # document_url: "http://docraptor.com/examples/invoice.html", # or use a url 35 | name: "docraptor-ruby.pdf", # help you find a document later 36 | document_type: "pdf", # pdf or xls or xlsx 37 | # javascript: true, # enable JavaScript processing 38 | # prince_options: { 39 | # media: "screen", # use screen styles instead of print styles 40 | # baseurl: "http://hello.com", # pretend URL when using document_content 41 | # }, 42 | ) 43 | ``` 44 | 45 | ## Next Steps 46 | 47 | - Optionally store and get a URL for your converted document with [document hosting](https://docraptor.com/document-hosting) 48 | - View more [code examples](examples) with error handling, asynchronous creation, file saving, and document hosting. 49 | - Perfect your document styling with our [style and formatting reference](https://docraptor.com/documentation/style), and [API reference](https://docraptor.com/documentation/api). Easily add headers and footers, page breaks, page numbers, table of contents, and much more! 50 | 51 | ## More Help 52 | 53 | Stuck? We're experts at turning HTML into PDFs so please [email us](mailto:support@docraptor.com) if you run into trouble. 54 | 55 | 56 | ## Development 57 | 58 | The majority of the code in this repo is generated using openapi-generator on [docraptor.yaml](docraptor.yaml). You can modify this file and regenerate the client using `script/generate_language`. 59 | 60 | 61 | ## Release Process 62 | 63 | 1. Pull latest master 64 | 2. Merge feature branch(es) into master 65 | 3. `script/test` 66 | 4. Increment version: `generator-config.json` 67 | 5. Run `script/generate_language` to update generated version numbers: 68 | - `lib/docraptor/version.rb` 69 | 6. Update [CHANGELOG.md](CHANGELOG.md) 70 | 7. Commit "Release version vX.Y.Z" 71 | 8. `script/release` 72 | 9. Verify package release at https://rubygems.org/gems/docraptor 73 | 10. Refresh documentation on docraptor.com 74 | 75 | 76 | ## Version Policy 77 | 78 | This library follows [Semantic Versioning 2.0.0](http://semver.org). 79 | -------------------------------------------------------------------------------- /.review/generated_files/docs/Doc.md: -------------------------------------------------------------------------------- 1 | # DocRaptor::Doc 2 | 3 | ## Properties 4 | 5 | | Name | Type | Description | Notes | 6 | | ---- | ---- | ----------- | ----- | 7 | | **name** | **String** | A name for identifying your document. | | 8 | | **document_type** | **String** | The type of document being created. | | 9 | | **document_content** | **String** | The HTML data to be transformed into a document. You must supply content using document_content or document_url. | [optional] | 10 | | **document_url** | **String** | The URL to fetch the HTML data to be transformed into a document. You must supply content using document_content or document_url. | [optional] | 11 | | **test** | **Boolean** | Enable test mode for this document. Test documents are not charged for but include a watermark. | [optional][default to true] | 12 | | **pipeline** | **String** | Specify a specific verison of the DocRaptor Pipeline to use. | [optional] | 13 | | **strict** | **String** | Force strict HTML validation. | [optional] | 14 | | **ignore_resource_errors** | **Boolean** | Failed loading of images/javascripts/stylesheets/etc. will not cause the rendering to stop. | [optional][default to true] | 15 | | **ignore_console_messages** | **Boolean** | Prevent console.log from stopping document rendering during JavaScript execution. | [optional][default to false] | 16 | | **tag** | **String** | A field for storing a small amount of metadata with this document. | [optional] | 17 | | **help** | **Boolean** | Request support help with this request if it succeeds. | [optional][default to false] | 18 | | **javascript** | **Boolean** | Enable DocRaptor JavaScript parsing. PrinceXML JavaScript parsing is also available elsewhere. | [optional][default to false] | 19 | | **referrer** | **String** | Set HTTP referrer when generating this document. | [optional] | 20 | | **callback_url** | **String** | A URL that will receive a POST request after successfully completing an asynchronous document. The POST data will include download_url and download_id similar to status API responses. WARNING: this only works on asynchronous documents. | [optional] | 21 | | **hosted_download_limit** | **Integer** | The number of times a hosted document can be downloaded. If no limit is specified, the document will be available for an unlimited number of downloads. | [optional] | 22 | | **hosted_expires_at** | **String** | The date and time at which a hosted document will be removed and no longer available. Must be a properly formatted ISO 8601 datetime, like 1981-01-23T08:02:30-05:00. | [optional] | 23 | | **prince_options** | [**PrinceOptions**](PrinceOptions.md) | | [optional] | 24 | 25 | ## Example 26 | 27 | ```ruby 28 | require 'docraptor' 29 | 30 | instance = DocRaptor::Doc.new( 31 | name: null, 32 | document_type: null, 33 | document_content: null, 34 | document_url: null, 35 | test: null, 36 | pipeline: null, 37 | strict: null, 38 | ignore_resource_errors: null, 39 | ignore_console_messages: null, 40 | tag: null, 41 | help: null, 42 | javascript: null, 43 | referrer: null, 44 | callback_url: null, 45 | hosted_download_limit: null, 46 | hosted_expires_at: null, 47 | prince_options: null 48 | ) 49 | ``` 50 | 51 | -------------------------------------------------------------------------------- /.review/generated_files/README.md: -------------------------------------------------------------------------------- 1 | # docraptor 2 | 3 | DocRaptor - the Ruby gem for the DocRaptor 4 | 5 | A native client library for the DocRaptor HTML to PDF/XLS service. 6 | 7 | This SDK is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project: 8 | 9 | - API version: 2.0.0 10 | - Package version: 3.1.0 11 | - Build package: org.openapitools.codegen.languages.RubyClientCodegen 12 | 13 | ## Installation 14 | 15 | ### Build a gem 16 | 17 | To build the Ruby code into a gem: 18 | 19 | ```shell 20 | gem build docraptor.gemspec 21 | ``` 22 | 23 | Then either install the gem locally: 24 | 25 | ```shell 26 | gem install ./docraptor-3.1.0.gem 27 | ``` 28 | 29 | (for development, run `gem install --dev ./docraptor-3.1.0.gem` to install the development dependencies) 30 | 31 | or publish the gem to a gem hosting service, e.g. [RubyGems](https://rubygems.org/). 32 | 33 | Finally add this to the Gemfile: 34 | 35 | gem 'docraptor', '~> 3.1.0' 36 | 37 | ### Install from Git 38 | 39 | If the Ruby gem is hosted at a git repository: https://github.com/GIT_USER_ID/GIT_REPO_ID, then add the following in the Gemfile: 40 | 41 | gem 'docraptor', :git => 'https://github.com/GIT_USER_ID/GIT_REPO_ID.git' 42 | 43 | ### Include the Ruby code directly 44 | 45 | Include the Ruby code directly using `-I` as follows: 46 | 47 | ```shell 48 | ruby -Ilib script.rb 49 | ``` 50 | 51 | ## Getting Started 52 | 53 | Please follow the [installation](#installation) procedure and then run the following code: 54 | 55 | ```ruby 56 | # Load the gem 57 | require 'docraptor' 58 | 59 | # Setup authorization 60 | DocRaptor.configure do |config| 61 | # Configure HTTP basic authorization: basicAuth 62 | config.username = 'YOUR_USERNAME' 63 | config.password = 'YOUR_PASSWORD' 64 | end 65 | 66 | api_instance = DocRaptor::DocApi.new 67 | doc = DocRaptor::Doc.new({name: 'name_example', document_type: 'pdf'}) # Doc | 68 | 69 | begin 70 | result = api_instance.create_async_doc(doc) 71 | p result 72 | rescue DocRaptor::ApiError => e 73 | puts "Exception when calling DocApi->create_async_doc: #{e}" 74 | end 75 | 76 | ``` 77 | 78 | ## Documentation for API Endpoints 79 | 80 | All URIs are relative to *https://api.docraptor.com* 81 | 82 | Class | Method | HTTP request | Description 83 | ------------ | ------------- | ------------- | ------------- 84 | *DocRaptor::DocApi* | [**create_async_doc**](docs/DocApi.md#create_async_doc) | **POST** /async_docs | 85 | *DocRaptor::DocApi* | [**create_doc**](docs/DocApi.md#create_doc) | **POST** /docs | 86 | *DocRaptor::DocApi* | [**create_hosted_async_doc**](docs/DocApi.md#create_hosted_async_doc) | **POST** /hosted_async_docs | 87 | *DocRaptor::DocApi* | [**create_hosted_doc**](docs/DocApi.md#create_hosted_doc) | **POST** /hosted_docs | 88 | *DocRaptor::DocApi* | [**expire**](docs/DocApi.md#expire) | **PATCH** /expire/{id} | 89 | *DocRaptor::DocApi* | [**get_async_doc**](docs/DocApi.md#get_async_doc) | **GET** /download/{id} | 90 | *DocRaptor::DocApi* | [**get_async_doc_status**](docs/DocApi.md#get_async_doc_status) | **GET** /status/{id} | 91 | 92 | 93 | ## Documentation for Models 94 | 95 | - [DocRaptor::AsyncDoc](docs/AsyncDoc.md) 96 | - [DocRaptor::Doc](docs/Doc.md) 97 | - [DocRaptor::DocStatus](docs/DocStatus.md) 98 | - [DocRaptor::PrinceOptions](docs/PrinceOptions.md) 99 | 100 | 101 | ## Documentation for Authorization 102 | 103 | 104 | Authentication schemes defined for the API: 105 | ### basicAuth 106 | 107 | - **Type**: HTTP basic authentication 108 | 109 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | # This file is based on https://github.com/rails/rails/blob/master/.rubocop.yml (MIT license) 2 | # Automatically generated by OpenAPI Generator (https://openapi-generator.tech) 3 | AllCops: 4 | TargetRubyVersion: 2.4 5 | # RuboCop has a bunch of cops enabled by default. This setting tells RuboCop 6 | # to ignore them, so only the ones explicitly set in this file are enabled. 7 | DisabledByDefault: true 8 | Exclude: 9 | - '**/templates/**/*' 10 | - '**/vendor/**/*' 11 | - 'actionpack/lib/action_dispatch/journey/parser.rb' 12 | 13 | # Prefer &&/|| over and/or. 14 | Style/AndOr: 15 | Enabled: true 16 | 17 | # Align `when` with `case`. 18 | Layout/CaseIndentation: 19 | Enabled: true 20 | 21 | # Align comments with method definitions. 22 | Layout/CommentIndentation: 23 | Enabled: true 24 | 25 | Layout/ElseAlignment: 26 | Enabled: true 27 | 28 | Layout/EmptyLineAfterMagicComment: 29 | Enabled: true 30 | 31 | # In a regular class definition, no empty lines around the body. 32 | Layout/EmptyLinesAroundClassBody: 33 | Enabled: true 34 | 35 | # In a regular method definition, no empty lines around the body. 36 | Layout/EmptyLinesAroundMethodBody: 37 | Enabled: true 38 | 39 | # In a regular module definition, no empty lines around the body. 40 | Layout/EmptyLinesAroundModuleBody: 41 | Enabled: true 42 | 43 | Layout/FirstArgumentIndentation: 44 | Enabled: true 45 | 46 | # Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }. 47 | Style/HashSyntax: 48 | Enabled: false 49 | 50 | # Method definitions after `private` or `protected` isolated calls need one 51 | # extra level of indentation. 52 | Layout/IndentationConsistency: 53 | Enabled: true 54 | EnforcedStyle: indented_internal_methods 55 | 56 | # Two spaces, no tabs (for indentation). 57 | Layout/IndentationWidth: 58 | Enabled: true 59 | 60 | Layout/LeadingCommentSpace: 61 | Enabled: true 62 | 63 | Layout/SpaceAfterColon: 64 | Enabled: true 65 | 66 | Layout/SpaceAfterComma: 67 | Enabled: true 68 | 69 | Layout/SpaceAroundEqualsInParameterDefault: 70 | Enabled: true 71 | 72 | Layout/SpaceAroundKeyword: 73 | Enabled: true 74 | 75 | Layout/SpaceAroundOperators: 76 | Enabled: true 77 | 78 | Layout/SpaceBeforeComma: 79 | Enabled: true 80 | 81 | Layout/SpaceBeforeFirstArg: 82 | Enabled: true 83 | 84 | Style/DefWithParentheses: 85 | Enabled: true 86 | 87 | # Defining a method with parameters needs parentheses. 88 | Style/MethodDefParentheses: 89 | Enabled: true 90 | 91 | Style/FrozenStringLiteralComment: 92 | Enabled: false 93 | EnforcedStyle: always 94 | 95 | # Use `foo {}` not `foo{}`. 96 | Layout/SpaceBeforeBlockBraces: 97 | Enabled: true 98 | 99 | # Use `foo { bar }` not `foo {bar}`. 100 | Layout/SpaceInsideBlockBraces: 101 | Enabled: true 102 | 103 | # Use `{ a: 1 }` not `{a:1}`. 104 | Layout/SpaceInsideHashLiteralBraces: 105 | Enabled: true 106 | 107 | Layout/SpaceInsideParens: 108 | Enabled: true 109 | 110 | # Check quotes usage according to lint rule below. 111 | #Style/StringLiterals: 112 | # Enabled: true 113 | # EnforcedStyle: single_quotes 114 | 115 | # Detect hard tabs, no hard tabs. 116 | Layout/IndentationStyle: 117 | Enabled: true 118 | 119 | # Blank lines should not have any spaces. 120 | Layout/TrailingEmptyLines: 121 | Enabled: true 122 | 123 | # No trailing whitespace. 124 | Layout/TrailingWhitespace: 125 | Enabled: false 126 | 127 | # Use quotes for string literals when they are enough. 128 | Style/RedundantPercentQ: 129 | Enabled: true 130 | 131 | # Align `end` with the matching keyword or starting expression except for 132 | # assignments, where it should be aligned with the LHS. 133 | Layout/EndAlignment: 134 | Enabled: true 135 | EnforcedStyleAlignWith: variable 136 | AutoCorrect: true 137 | 138 | # Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg. 139 | Lint/RequireParentheses: 140 | Enabled: true 141 | 142 | Style/RedundantReturn: 143 | Enabled: true 144 | AllowMultipleReturnValues: true 145 | 146 | Style/Semicolon: 147 | Enabled: true 148 | AllowAsExpressionSeparator: true 149 | -------------------------------------------------------------------------------- /.review/generated_files/docs/PrinceOptions.md: -------------------------------------------------------------------------------- 1 | # DocRaptor::PrinceOptions 2 | 3 | ## Properties 4 | 5 | | Name | Type | Description | Notes | 6 | | ---- | ---- | ----------- | ----- | 7 | | **baseurl** | **String** | Set the baseurl for assets. | [optional] | 8 | | **no_xinclude** | **Boolean** | Disable XML inclusion. | [optional] | 9 | | **no_network** | **Boolean** | Disable network access. | [optional] | 10 | | **no_parallel_downloads** | **Boolean** | Disables parallel fetching of assets during PDF creation. Useful if your asset host has strict rate limiting. | [optional] | 11 | | **http_user** | **String** | Set the user for HTTP authentication. | [optional] | 12 | | **http_password** | **String** | Set the password for HTTP authentication. | [optional] | 13 | | **http_proxy** | **String** | Set the HTTP proxy server. | [optional] | 14 | | **http_timeout** | **Integer** | Set the HTTP request timeout. | [optional] | 15 | | **insecure** | **Boolean** | Disable SSL verification. | [optional] | 16 | | **media** | **String** | Specify the CSS media type. Defaults to \"print\" but you may want to use \"screen\" for web styles. | [optional] | 17 | | **no_author_style** | **Boolean** | Ignore author stylesheets. | [optional] | 18 | | **no_default_style** | **Boolean** | Ignore default stylesheets. | [optional] | 19 | | **no_embed_fonts** | **Boolean** | Disable font embedding in PDFs. | [optional] | 20 | | **no_subset_fonts** | **Boolean** | Disable font subsetting in PDFs. | [optional] | 21 | | **no_compress** | **Boolean** | Disable PDF compression. | [optional] | 22 | | **encrypt** | **Boolean** | Encrypt PDF output. | [optional] | 23 | | **key_bits** | **Integer** | Set encryption key size. | [optional] | 24 | | **user_password** | **String** | Set the PDF user password. | [optional] | 25 | | **owner_password** | **String** | Set the PDF owner password. | [optional] | 26 | | **disallow_print** | **Boolean** | Disallow printing of this PDF. | [optional] | 27 | | **disallow_copy** | **Boolean** | Disallow copying of this PDF. | [optional] | 28 | | **disallow_annotate** | **Boolean** | Disallow annotation of this PDF. | [optional] | 29 | | **disallow_modify** | **Boolean** | Disallow modification of this PDF. | [optional] | 30 | | **debug** | **Boolean** | Enable Prince debug mode. | [optional] | 31 | | **input** | **String** | Specify the input format, defaults to html. | [optional] | 32 | | **version** | **String** | Deprecated, use the appropriate `pipeline` version. Specify a specific verison of PrinceXML to use. | [optional] | 33 | | **javascript** | **Boolean** | Enable PrinceXML JavaScript. DocRaptor JavaScript parsing is also available elsewhere. | [optional] | 34 | | **css_dpi** | **Integer** | Set the DPI when rendering CSS. Defaults to 96 but can be set with Prince 9.0 and up. | [optional] | 35 | | **profile** | **String** | In Prince 9.0 and up you can set the PDF profile. | [optional] | 36 | | **pdf_title** | **String** | Specify the PDF title, part of the document's metadata. | [optional] | 37 | | **iframes** | **Boolean** | Enable loading of iframes. | [optional] | 38 | | **page_margin** | **String** | Specify the page margin distance. | [optional] | 39 | | **pdf_forms** | **Boolean** | Make form fields editable by default. | [optional] | 40 | 41 | ## Example 42 | 43 | ```ruby 44 | require 'docraptor' 45 | 46 | instance = DocRaptor::PrinceOptions.new( 47 | baseurl: null, 48 | no_xinclude: null, 49 | no_network: null, 50 | no_parallel_downloads: null, 51 | http_user: null, 52 | http_password: null, 53 | http_proxy: null, 54 | http_timeout: null, 55 | insecure: null, 56 | media: null, 57 | no_author_style: null, 58 | no_default_style: null, 59 | no_embed_fonts: null, 60 | no_subset_fonts: null, 61 | no_compress: null, 62 | encrypt: null, 63 | key_bits: null, 64 | user_password: null, 65 | owner_password: null, 66 | disallow_print: null, 67 | disallow_copy: null, 68 | disallow_annotate: null, 69 | disallow_modify: null, 70 | debug: null, 71 | input: null, 72 | version: null, 73 | javascript: null, 74 | css_dpi: null, 75 | profile: null, 76 | pdf_title: null, 77 | iframes: null, 78 | page_margin: null, 79 | pdf_forms: null 80 | ) 81 | ``` 82 | 83 | -------------------------------------------------------------------------------- /.review/generated_files/spec/api/doc_api_spec.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | #DocRaptor 3 | 4 | #A native client library for the DocRaptor HTML to PDF/XLS service. 5 | 6 | The version of the OpenAPI document: 2.0.0 7 | 8 | Generated by: https://openapi-generator.tech 9 | OpenAPI Generator version: 6.6.0 10 | 11 | =end 12 | 13 | require 'spec_helper' 14 | require 'json' 15 | 16 | # Unit tests for DocRaptor::DocApi 17 | # Automatically generated by openapi-generator (https://openapi-generator.tech) 18 | # Please update as you see appropriate 19 | describe 'DocApi' do 20 | before do 21 | # run before each test 22 | @api_instance = DocRaptor::DocApi.new 23 | end 24 | 25 | after do 26 | # run after each test 27 | end 28 | 29 | describe 'test an instance of DocApi' do 30 | it 'should create an instance of DocApi' do 31 | expect(@api_instance).to be_instance_of(DocRaptor::DocApi) 32 | end 33 | end 34 | 35 | # unit tests for create_async_doc 36 | # Creates a document asynchronously. You must use a callback url or the returned status id and the status API to find out when it completes. Then use the download API to get the document. 37 | # @param doc 38 | # @param [Hash] opts the optional parameters 39 | # @return [AsyncDoc] 40 | describe 'create_async_doc test' do 41 | it 'should work' do 42 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 43 | end 44 | end 45 | 46 | # unit tests for create_doc 47 | # Creates a document synchronously. 48 | # @param doc 49 | # @param [Hash] opts the optional parameters 50 | # @return [String] 51 | describe 'create_doc test' do 52 | it 'should work' do 53 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 54 | end 55 | end 56 | 57 | # unit tests for create_hosted_async_doc 58 | # Creates a hosted document asynchronously. You must use a callback url or the returned status id and the status API to find out when it completes. Then use the download API to get the document. 59 | # @param doc 60 | # @param [Hash] opts the optional parameters 61 | # @return [AsyncDoc] 62 | describe 'create_hosted_async_doc test' do 63 | it 'should work' do 64 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 65 | end 66 | end 67 | 68 | # unit tests for create_hosted_doc 69 | # Creates a hosted document synchronously. 70 | # @param doc The document to be created. 71 | # @param [Hash] opts the optional parameters 72 | # @return [DocStatus] 73 | describe 'create_hosted_doc test' do 74 | it 'should work' do 75 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 76 | end 77 | end 78 | 79 | # unit tests for expire 80 | # Expires a previously created hosted doc. 81 | # @param id The download_id returned from status request or hosted document response. 82 | # @param [Hash] opts the optional parameters 83 | # @return [nil] 84 | describe 'expire test' do 85 | it 'should work' do 86 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 87 | end 88 | end 89 | 90 | # unit tests for get_async_doc 91 | # Downloads a finished document. 92 | # @param id The download_id returned from an async status request or callback. 93 | # @param [Hash] opts the optional parameters 94 | # @return [String] 95 | describe 'get_async_doc test' do 96 | it 'should work' do 97 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 98 | end 99 | end 100 | 101 | # unit tests for get_async_doc_status 102 | # Check on the status of an asynchronously created document. 103 | # @param id The status_id returned when creating an asynchronous document. 104 | # @param [Hash] opts the optional parameters 105 | # @return [DocStatus] 106 | describe 'get_async_doc_status test' do 107 | it 'should work' do 108 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 109 | end 110 | end 111 | 112 | end 113 | -------------------------------------------------------------------------------- /.review/generated_files/spec/models/doc_spec.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | #DocRaptor 3 | 4 | #A native client library for the DocRaptor HTML to PDF/XLS service. 5 | 6 | The version of the OpenAPI document: 2.0.0 7 | 8 | Generated by: https://openapi-generator.tech 9 | OpenAPI Generator version: 6.6.0 10 | 11 | =end 12 | 13 | require 'spec_helper' 14 | require 'json' 15 | require 'date' 16 | 17 | # Unit tests for DocRaptor::Doc 18 | # Automatically generated by openapi-generator (https://openapi-generator.tech) 19 | # Please update as you see appropriate 20 | describe DocRaptor::Doc do 21 | let(:instance) { DocRaptor::Doc.new } 22 | 23 | describe 'test an instance of Doc' do 24 | it 'should create an instance of Doc' do 25 | expect(instance).to be_instance_of(DocRaptor::Doc) 26 | end 27 | end 28 | describe 'test attribute "name"' do 29 | it 'should work' do 30 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 31 | end 32 | end 33 | 34 | describe 'test attribute "document_type"' do 35 | it 'should work' do 36 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 37 | # validator = Petstore::EnumTest::EnumAttributeValidator.new('String', ["pdf", "xls", "xlsx"]) 38 | # validator.allowable_values.each do |value| 39 | # expect { instance.document_type = value }.not_to raise_error 40 | # end 41 | end 42 | end 43 | 44 | describe 'test attribute "document_content"' do 45 | it 'should work' do 46 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 47 | end 48 | end 49 | 50 | describe 'test attribute "document_url"' do 51 | it 'should work' do 52 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 53 | end 54 | end 55 | 56 | describe 'test attribute "test"' do 57 | it 'should work' do 58 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 59 | end 60 | end 61 | 62 | describe 'test attribute "pipeline"' do 63 | it 'should work' do 64 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 65 | end 66 | end 67 | 68 | describe 'test attribute "strict"' do 69 | it 'should work' do 70 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 71 | # validator = Petstore::EnumTest::EnumAttributeValidator.new('String', ["none", "html"]) 72 | # validator.allowable_values.each do |value| 73 | # expect { instance.strict = value }.not_to raise_error 74 | # end 75 | end 76 | end 77 | 78 | describe 'test attribute "ignore_resource_errors"' do 79 | it 'should work' do 80 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 81 | end 82 | end 83 | 84 | describe 'test attribute "ignore_console_messages"' do 85 | it 'should work' do 86 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 87 | end 88 | end 89 | 90 | describe 'test attribute "tag"' do 91 | it 'should work' do 92 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 93 | end 94 | end 95 | 96 | describe 'test attribute "help"' do 97 | it 'should work' do 98 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 99 | end 100 | end 101 | 102 | describe 'test attribute "javascript"' do 103 | it 'should work' do 104 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 105 | end 106 | end 107 | 108 | describe 'test attribute "referrer"' do 109 | it 'should work' do 110 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 111 | end 112 | end 113 | 114 | describe 'test attribute "callback_url"' do 115 | it 'should work' do 116 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 117 | end 118 | end 119 | 120 | describe 'test attribute "hosted_download_limit"' do 121 | it 'should work' do 122 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 123 | end 124 | end 125 | 126 | describe 'test attribute "hosted_expires_at"' do 127 | it 'should work' do 128 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 129 | end 130 | end 131 | 132 | describe 'test attribute "prince_options"' do 133 | it 'should work' do 134 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 135 | end 136 | end 137 | 138 | end 139 | -------------------------------------------------------------------------------- /.review/generated_files/spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | #DocRaptor 3 | 4 | #A native client library for the DocRaptor HTML to PDF/XLS service. 5 | 6 | The version of the OpenAPI document: 2.0.0 7 | 8 | Generated by: https://openapi-generator.tech 9 | OpenAPI Generator version: 6.6.0 10 | 11 | =end 12 | 13 | # load the gem 14 | require 'docraptor' 15 | 16 | # The following was generated by the `rspec --init` command. Conventionally, all 17 | # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. 18 | # The generated `.rspec` file contains `--require spec_helper` which will cause 19 | # this file to always be loaded, without a need to explicitly require it in any 20 | # files. 21 | # 22 | # Given that it is always loaded, you are encouraged to keep this file as 23 | # light-weight as possible. Requiring heavyweight dependencies from this file 24 | # will add to the boot time of your test suite on EVERY test run, even for an 25 | # individual file that may not need all of that loaded. Instead, consider making 26 | # a separate helper file that requires the additional dependencies and performs 27 | # the additional setup, and require it from the spec files that actually need 28 | # it. 29 | # 30 | # The `.rspec` file also contains a few flags that are not defaults but that 31 | # users commonly want. 32 | # 33 | # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration 34 | RSpec.configure do |config| 35 | # rspec-expectations config goes here. You can use an alternate 36 | # assertion/expectation library such as wrong or the stdlib/minitest 37 | # assertions if you prefer. 38 | config.expect_with :rspec do |expectations| 39 | # This option will default to `true` in RSpec 4. It makes the `description` 40 | # and `failure_message` of custom matchers include text for helper methods 41 | # defined using `chain`, e.g.: 42 | # be_bigger_than(2).and_smaller_than(4).description 43 | # # => "be bigger than 2 and smaller than 4" 44 | # ...rather than: 45 | # # => "be bigger than 2" 46 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true 47 | end 48 | 49 | # rspec-mocks config goes here. You can use an alternate test double 50 | # library (such as bogus or mocha) by changing the `mock_with` option here. 51 | config.mock_with :rspec do |mocks| 52 | # Prevents you from mocking or stubbing a method that does not exist on 53 | # a real object. This is generally recommended, and will default to 54 | # `true` in RSpec 4. 55 | mocks.verify_partial_doubles = true 56 | end 57 | 58 | # The settings below are suggested to provide a good initial experience 59 | # with RSpec, but feel free to customize to your heart's content. 60 | =begin 61 | # These two settings work together to allow you to limit a spec run 62 | # to individual examples or groups you care about by tagging them with 63 | # `:focus` metadata. When nothing is tagged with `:focus`, all examples 64 | # get run. 65 | config.filter_run :focus 66 | config.run_all_when_everything_filtered = true 67 | 68 | # Allows RSpec to persist some state between runs in order to support 69 | # the `--only-failures` and `--next-failure` CLI options. We recommend 70 | # you configure your source control system to ignore this file. 71 | config.example_status_persistence_file_path = "spec/examples.txt" 72 | 73 | # Limits the available syntax to the non-monkey patched syntax that is 74 | # recommended. For more details, see: 75 | # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ 76 | # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ 77 | # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode 78 | config.disable_monkey_patching! 79 | 80 | # This setting enables warnings. It's recommended, but in some cases may 81 | # be too noisy due to issues in dependencies. 82 | config.warnings = true 83 | 84 | # Many RSpec users commonly either run the entire suite or an individual 85 | # file, and it's useful to allow more verbose output when running an 86 | # individual spec file. 87 | if config.files_to_run.one? 88 | # Use the documentation formatter for detailed output, 89 | # unless a formatter has already been configured 90 | # (e.g. via a command-line flag). 91 | config.default_formatter = 'doc' 92 | end 93 | 94 | # Print the 10 slowest examples and example groups at the 95 | # end of the spec run, to help surface which specs are running 96 | # particularly slow. 97 | config.profile_examples = 10 98 | 99 | # Run specs in random order to surface order dependencies. If you find an 100 | # order dependency and want to debug it, you can fix the order by providing 101 | # the seed, which is printed after each run. 102 | # --seed 1234 103 | config.order = :random 104 | 105 | # Seed global randomization in this process using the `--seed` CLI option. 106 | # Setting this allows you to use `--seed` to deterministically reproduce 107 | # test failures related to randomization by passing the same `--seed` value 108 | # as the one that triggered the failure. 109 | Kernel.srand config.seed 110 | =end 111 | end 112 | -------------------------------------------------------------------------------- /lib/docraptor/models/async_doc.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | #DocRaptor 3 | 4 | #A native client library for the DocRaptor HTML to PDF/XLS service. 5 | 6 | The version of the OpenAPI document: 2.0.0 7 | 8 | Generated by: https://openapi-generator.tech 9 | OpenAPI Generator version: 6.6.0 10 | 11 | =end 12 | 13 | require 'date' 14 | require 'time' 15 | 16 | module DocRaptor 17 | class AsyncDoc 18 | # The identifier used to get the status of the document using the status API. 19 | attr_accessor :status_id 20 | 21 | # Attribute mapping from ruby-style variable name to JSON key. 22 | def self.attribute_map 23 | { 24 | :'status_id' => :'status_id' 25 | } 26 | end 27 | 28 | # Returns all the JSON keys this model knows about 29 | def self.acceptable_attributes 30 | attribute_map.values 31 | end 32 | 33 | # Attribute type mapping. 34 | def self.openapi_types 35 | { 36 | :'status_id' => :'String' 37 | } 38 | end 39 | 40 | # List of attributes with nullable: true 41 | def self.openapi_nullable 42 | Set.new([ 43 | ]) 44 | end 45 | 46 | # Initializes the object 47 | # @param [Hash] attributes Model attributes in the form of hash 48 | def initialize(attributes = {}) 49 | if (!attributes.is_a?(Hash)) 50 | fail ArgumentError, "The input argument (attributes) must be a hash in `DocRaptor::AsyncDoc` initialize method" 51 | end 52 | 53 | # check to see if the attribute exists and convert string to symbol for hash key 54 | attributes = attributes.each_with_object({}) { |(k, v), h| 55 | if (!self.class.attribute_map.key?(k.to_sym)) 56 | fail ArgumentError, "`#{k}` is not a valid attribute in `DocRaptor::AsyncDoc`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect 57 | end 58 | h[k.to_sym] = v 59 | } 60 | 61 | if attributes.key?(:'status_id') 62 | self.status_id = attributes[:'status_id'] 63 | end 64 | end 65 | 66 | # Show invalid properties with the reasons. Usually used together with valid? 67 | # @return Array for valid properties with the reasons 68 | def list_invalid_properties 69 | invalid_properties = Array.new 70 | invalid_properties 71 | end 72 | 73 | # Check to see if the all the properties in the model are valid 74 | # @return true if the model is valid 75 | def valid? 76 | true 77 | end 78 | 79 | # Checks equality by comparing each attribute. 80 | # @param [Object] Object to be compared 81 | def ==(o) 82 | return true if self.equal?(o) 83 | self.class == o.class && 84 | status_id == o.status_id 85 | end 86 | 87 | # @see the `==` method 88 | # @param [Object] Object to be compared 89 | def eql?(o) 90 | self == o 91 | end 92 | 93 | # Calculates hash code according to all attributes. 94 | # @return [Integer] Hash code 95 | def hash 96 | [status_id].hash 97 | end 98 | 99 | # Builds the object from hash 100 | # @param [Hash] attributes Model attributes in the form of hash 101 | # @return [Object] Returns the model itself 102 | def self.build_from_hash(attributes) 103 | new.build_from_hash(attributes) 104 | end 105 | 106 | # Builds the object from hash 107 | # @param [Hash] attributes Model attributes in the form of hash 108 | # @return [Object] Returns the model itself 109 | def build_from_hash(attributes) 110 | return nil unless attributes.is_a?(Hash) 111 | attributes = attributes.transform_keys(&:to_sym) 112 | self.class.openapi_types.each_pair do |key, type| 113 | if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key) 114 | self.send("#{key}=", nil) 115 | elsif type =~ /\AArray<(.*)>/i 116 | # check to ensure the input is an array given that the attribute 117 | # is documented as an array but the input is not 118 | if attributes[self.class.attribute_map[key]].is_a?(Array) 119 | self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) }) 120 | end 121 | elsif !attributes[self.class.attribute_map[key]].nil? 122 | self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]])) 123 | end 124 | end 125 | 126 | self 127 | end 128 | 129 | # Deserializes the data based on type 130 | # @param string type Data type 131 | # @param string value Value to be deserialized 132 | # @return [Object] Deserialized data 133 | def _deserialize(type, value) 134 | case type.to_sym 135 | when :Time 136 | Time.parse(value) 137 | when :Date 138 | Date.parse(value) 139 | when :String 140 | value.to_s 141 | when :Integer 142 | value.to_i 143 | when :Float 144 | value.to_f 145 | when :Boolean 146 | if value.to_s =~ /\A(true|t|yes|y|1)\z/i 147 | true 148 | else 149 | false 150 | end 151 | when :Object 152 | # generic object (usually a Hash), return directly 153 | value 154 | when /\AArray<(?.+)>\z/ 155 | inner_type = Regexp.last_match[:inner_type] 156 | value.map { |v| _deserialize(inner_type, v) } 157 | when /\AHash<(?.+?), (?.+)>\z/ 158 | k_type = Regexp.last_match[:k_type] 159 | v_type = Regexp.last_match[:v_type] 160 | {}.tap do |hash| 161 | value.each do |k, v| 162 | hash[_deserialize(k_type, k)] = _deserialize(v_type, v) 163 | end 164 | end 165 | else # model 166 | # models (e.g. Pet) or oneOf 167 | klass = DocRaptor.const_get(type) 168 | klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value) 169 | end 170 | end 171 | 172 | # Returns the string representation of the object 173 | # @return [String] String presentation of the object 174 | def to_s 175 | to_hash.to_s 176 | end 177 | 178 | # to_body is an alias to to_hash (backward compatibility) 179 | # @return [Hash] Returns the object in the form of hash 180 | def to_body 181 | to_hash 182 | end 183 | 184 | # Returns the object in the form of hash 185 | # @return [Hash] Returns the object in the form of hash 186 | def to_hash 187 | hash = {} 188 | self.class.attribute_map.each_pair do |attr, param| 189 | value = self.send(attr) 190 | if value.nil? 191 | is_nullable = self.class.openapi_nullable.include?(attr) 192 | next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) 193 | end 194 | 195 | hash[param] = _to_hash(value) 196 | end 197 | hash 198 | end 199 | 200 | # Outputs non-array value in the form of hash 201 | # For object, use to_hash. Otherwise, just return the value 202 | # @param [Object] value Any valid value 203 | # @return [Hash] Returns the value in the form of hash 204 | def _to_hash(value) 205 | if value.is_a?(Array) 206 | value.compact.map { |v| _to_hash(v) } 207 | elsif value.is_a?(Hash) 208 | {}.tap do |hash| 209 | value.each { |k, v| hash[k] = _to_hash(v) } 210 | end 211 | elsif value.respond_to? :to_hash 212 | value.to_hash 213 | else 214 | value 215 | end 216 | end 217 | 218 | end 219 | 220 | end 221 | -------------------------------------------------------------------------------- /.review/generated_files/spec/models/prince_options_spec.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | #DocRaptor 3 | 4 | #A native client library for the DocRaptor HTML to PDF/XLS service. 5 | 6 | The version of the OpenAPI document: 2.0.0 7 | 8 | Generated by: https://openapi-generator.tech 9 | OpenAPI Generator version: 6.6.0 10 | 11 | =end 12 | 13 | require 'spec_helper' 14 | require 'json' 15 | require 'date' 16 | 17 | # Unit tests for DocRaptor::PrinceOptions 18 | # Automatically generated by openapi-generator (https://openapi-generator.tech) 19 | # Please update as you see appropriate 20 | describe DocRaptor::PrinceOptions do 21 | let(:instance) { DocRaptor::PrinceOptions.new } 22 | 23 | describe 'test an instance of PrinceOptions' do 24 | it 'should create an instance of PrinceOptions' do 25 | expect(instance).to be_instance_of(DocRaptor::PrinceOptions) 26 | end 27 | end 28 | describe 'test attribute "baseurl"' do 29 | it 'should work' do 30 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 31 | end 32 | end 33 | 34 | describe 'test attribute "no_xinclude"' do 35 | it 'should work' do 36 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 37 | end 38 | end 39 | 40 | describe 'test attribute "no_network"' do 41 | it 'should work' do 42 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 43 | end 44 | end 45 | 46 | describe 'test attribute "no_parallel_downloads"' do 47 | it 'should work' do 48 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 49 | end 50 | end 51 | 52 | describe 'test attribute "http_user"' do 53 | it 'should work' do 54 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 55 | end 56 | end 57 | 58 | describe 'test attribute "http_password"' do 59 | it 'should work' do 60 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 61 | end 62 | end 63 | 64 | describe 'test attribute "http_proxy"' do 65 | it 'should work' do 66 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 67 | end 68 | end 69 | 70 | describe 'test attribute "http_timeout"' do 71 | it 'should work' do 72 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 73 | end 74 | end 75 | 76 | describe 'test attribute "insecure"' do 77 | it 'should work' do 78 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 79 | end 80 | end 81 | 82 | describe 'test attribute "media"' do 83 | it 'should work' do 84 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 85 | end 86 | end 87 | 88 | describe 'test attribute "no_author_style"' do 89 | it 'should work' do 90 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 91 | end 92 | end 93 | 94 | describe 'test attribute "no_default_style"' do 95 | it 'should work' do 96 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 97 | end 98 | end 99 | 100 | describe 'test attribute "no_embed_fonts"' do 101 | it 'should work' do 102 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 103 | end 104 | end 105 | 106 | describe 'test attribute "no_subset_fonts"' do 107 | it 'should work' do 108 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 109 | end 110 | end 111 | 112 | describe 'test attribute "no_compress"' do 113 | it 'should work' do 114 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 115 | end 116 | end 117 | 118 | describe 'test attribute "encrypt"' do 119 | it 'should work' do 120 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 121 | end 122 | end 123 | 124 | describe 'test attribute "key_bits"' do 125 | it 'should work' do 126 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 127 | # validator = Petstore::EnumTest::EnumAttributeValidator.new('Integer', [40, 128]) 128 | # validator.allowable_values.each do |value| 129 | # expect { instance.key_bits = value }.not_to raise_error 130 | # end 131 | end 132 | end 133 | 134 | describe 'test attribute "user_password"' do 135 | it 'should work' do 136 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 137 | end 138 | end 139 | 140 | describe 'test attribute "owner_password"' do 141 | it 'should work' do 142 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 143 | end 144 | end 145 | 146 | describe 'test attribute "disallow_print"' do 147 | it 'should work' do 148 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 149 | end 150 | end 151 | 152 | describe 'test attribute "disallow_copy"' do 153 | it 'should work' do 154 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 155 | end 156 | end 157 | 158 | describe 'test attribute "disallow_annotate"' do 159 | it 'should work' do 160 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 161 | end 162 | end 163 | 164 | describe 'test attribute "disallow_modify"' do 165 | it 'should work' do 166 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 167 | end 168 | end 169 | 170 | describe 'test attribute "debug"' do 171 | it 'should work' do 172 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 173 | end 174 | end 175 | 176 | describe 'test attribute "input"' do 177 | it 'should work' do 178 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 179 | # validator = Petstore::EnumTest::EnumAttributeValidator.new('String', ["html", "xml", "auto"]) 180 | # validator.allowable_values.each do |value| 181 | # expect { instance.input = value }.not_to raise_error 182 | # end 183 | end 184 | end 185 | 186 | describe 'test attribute "version"' do 187 | it 'should work' do 188 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 189 | end 190 | end 191 | 192 | describe 'test attribute "javascript"' do 193 | it 'should work' do 194 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 195 | end 196 | end 197 | 198 | describe 'test attribute "css_dpi"' do 199 | it 'should work' do 200 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 201 | end 202 | end 203 | 204 | describe 'test attribute "profile"' do 205 | it 'should work' do 206 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 207 | end 208 | end 209 | 210 | describe 'test attribute "pdf_title"' do 211 | it 'should work' do 212 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 213 | end 214 | end 215 | 216 | describe 'test attribute "iframes"' do 217 | it 'should work' do 218 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 219 | end 220 | end 221 | 222 | describe 'test attribute "page_margin"' do 223 | it 'should work' do 224 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 225 | end 226 | end 227 | 228 | describe 'test attribute "pdf_forms"' do 229 | it 'should work' do 230 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 231 | end 232 | end 233 | 234 | end 235 | -------------------------------------------------------------------------------- /.review/generated_files/spec/api_client_spec.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | #DocRaptor 3 | 4 | #A native client library for the DocRaptor HTML to PDF/XLS service. 5 | 6 | The version of the OpenAPI document: 2.0.0 7 | 8 | Generated by: https://openapi-generator.tech 9 | OpenAPI Generator version: 6.6.0 10 | 11 | =end 12 | 13 | require 'spec_helper' 14 | 15 | describe DocRaptor::ApiClient do 16 | context 'initialization' do 17 | context 'URL stuff' do 18 | context 'host' do 19 | it 'removes http from host' do 20 | DocRaptor.configure { |c| c.host = 'http://example.com' } 21 | expect(DocRaptor::Configuration.default.host).to eq('example.com') 22 | end 23 | 24 | it 'removes https from host' do 25 | DocRaptor.configure { |c| c.host = 'https://wookiee.com' } 26 | expect(DocRaptor::ApiClient.default.config.host).to eq('wookiee.com') 27 | end 28 | 29 | it 'removes trailing path from host' do 30 | DocRaptor.configure { |c| c.host = 'hobo.com/v4' } 31 | expect(DocRaptor::Configuration.default.host).to eq('hobo.com') 32 | end 33 | end 34 | 35 | context 'base_path' do 36 | it "prepends a slash to base_path" do 37 | DocRaptor.configure { |c| c.base_path = 'v4/dog' } 38 | expect(DocRaptor::Configuration.default.base_path).to eq('/v4/dog') 39 | end 40 | 41 | it "doesn't prepend a slash if one is already there" do 42 | DocRaptor.configure { |c| c.base_path = '/v4/dog' } 43 | expect(DocRaptor::Configuration.default.base_path).to eq('/v4/dog') 44 | end 45 | 46 | it "ends up as a blank string if nil" do 47 | DocRaptor.configure { |c| c.base_path = nil } 48 | expect(DocRaptor::Configuration.default.base_path).to eq('') 49 | end 50 | end 51 | end 52 | end 53 | 54 | describe 'params_encoding in #build_request' do 55 | let(:config) { DocRaptor::Configuration.new } 56 | let(:api_client) { DocRaptor::ApiClient.new(config) } 57 | 58 | it 'defaults to nil' do 59 | expect(DocRaptor::Configuration.default.params_encoding).to eq(nil) 60 | expect(config.params_encoding).to eq(nil) 61 | 62 | request = api_client.build_request(:get, '/test') 63 | expect(request.options[:params_encoding]).to eq(nil) 64 | end 65 | 66 | it 'can be customized' do 67 | config.params_encoding = :multi 68 | request = api_client.build_request(:get, '/test') 69 | expect(request.options[:params_encoding]).to eq(:multi) 70 | end 71 | end 72 | 73 | describe 'timeout in #build_request' do 74 | let(:config) { DocRaptor::Configuration.new } 75 | let(:api_client) { DocRaptor::ApiClient.new(config) } 76 | 77 | it 'defaults to 0' do 78 | expect(DocRaptor::Configuration.default.timeout).to eq(0) 79 | expect(config.timeout).to eq(0) 80 | 81 | request = api_client.build_request(:get, '/test') 82 | expect(request.options[:timeout]).to eq(0) 83 | end 84 | 85 | it 'can be customized' do 86 | config.timeout = 100 87 | request = api_client.build_request(:get, '/test') 88 | expect(request.options[:timeout]).to eq(100) 89 | end 90 | end 91 | 92 | 93 | 94 | describe '#deserialize' do 95 | it "handles Array" do 96 | api_client = DocRaptor::ApiClient.new 97 | headers = { 'Content-Type' => 'application/json' } 98 | response = double('response', headers: headers, body: '[12, 34]') 99 | data = api_client.deserialize(response, 'Array') 100 | expect(data).to be_instance_of(Array) 101 | expect(data).to eq([12, 34]) 102 | end 103 | 104 | it 'handles Array>' do 105 | api_client = DocRaptor::ApiClient.new 106 | headers = { 'Content-Type' => 'application/json' } 107 | response = double('response', headers: headers, body: '[[12, 34], [56]]') 108 | data = api_client.deserialize(response, 'Array>') 109 | expect(data).to be_instance_of(Array) 110 | expect(data).to eq([[12, 34], [56]]) 111 | end 112 | 113 | it 'handles Hash' do 114 | api_client = DocRaptor::ApiClient.new 115 | headers = { 'Content-Type' => 'application/json' } 116 | response = double('response', headers: headers, body: '{"message": "Hello"}') 117 | data = api_client.deserialize(response, 'Hash') 118 | expect(data).to be_instance_of(Hash) 119 | expect(data).to eq(:message => 'Hello') 120 | end 121 | end 122 | 123 | describe "#object_to_hash" do 124 | it 'ignores nils and includes empty arrays' do 125 | # uncomment below to test object_to_hash for model 126 | # api_client = DocRaptor::ApiClient.new 127 | # _model = DocRaptor::ModelName.new 128 | # update the model attribute below 129 | # _model.id = 1 130 | # update the expected value (hash) below 131 | # expected = {id: 1, name: '', tags: []} 132 | # expect(api_client.object_to_hash(_model)).to eq(expected) 133 | end 134 | end 135 | 136 | describe '#build_collection_param' do 137 | let(:param) { ['aa', 'bb', 'cc'] } 138 | let(:api_client) { DocRaptor::ApiClient.new } 139 | 140 | it 'works for csv' do 141 | expect(api_client.build_collection_param(param, :csv)).to eq('aa,bb,cc') 142 | end 143 | 144 | it 'works for ssv' do 145 | expect(api_client.build_collection_param(param, :ssv)).to eq('aa bb cc') 146 | end 147 | 148 | it 'works for tsv' do 149 | expect(api_client.build_collection_param(param, :tsv)).to eq("aa\tbb\tcc") 150 | end 151 | 152 | it 'works for pipes' do 153 | expect(api_client.build_collection_param(param, :pipes)).to eq('aa|bb|cc') 154 | end 155 | 156 | it 'works for multi' do 157 | expect(api_client.build_collection_param(param, :multi)).to eq(['aa', 'bb', 'cc']) 158 | end 159 | 160 | it 'fails for invalid collection format' do 161 | expect { api_client.build_collection_param(param, :INVALID) }.to raise_error(RuntimeError, 'unknown collection format: :INVALID') 162 | end 163 | end 164 | 165 | describe '#json_mime?' do 166 | let(:api_client) { DocRaptor::ApiClient.new } 167 | 168 | it 'works' do 169 | expect(api_client.json_mime?(nil)).to eq false 170 | expect(api_client.json_mime?('')).to eq false 171 | 172 | expect(api_client.json_mime?('application/json')).to eq true 173 | expect(api_client.json_mime?('application/json; charset=UTF8')).to eq true 174 | expect(api_client.json_mime?('APPLICATION/JSON')).to eq true 175 | 176 | expect(api_client.json_mime?('application/xml')).to eq false 177 | expect(api_client.json_mime?('text/plain')).to eq false 178 | expect(api_client.json_mime?('application/jsonp')).to eq false 179 | end 180 | end 181 | 182 | describe '#select_header_accept' do 183 | let(:api_client) { DocRaptor::ApiClient.new } 184 | 185 | it 'works' do 186 | expect(api_client.select_header_accept(nil)).to be_nil 187 | expect(api_client.select_header_accept([])).to be_nil 188 | 189 | expect(api_client.select_header_accept(['application/json'])).to eq('application/json') 190 | expect(api_client.select_header_accept(['application/xml', 'application/json; charset=UTF8'])).to eq('application/json; charset=UTF8') 191 | expect(api_client.select_header_accept(['APPLICATION/JSON', 'text/html'])).to eq('APPLICATION/JSON') 192 | 193 | expect(api_client.select_header_accept(['application/xml'])).to eq('application/xml') 194 | expect(api_client.select_header_accept(['text/html', 'application/xml'])).to eq('text/html,application/xml') 195 | end 196 | end 197 | 198 | describe '#select_header_content_type' do 199 | let(:api_client) { DocRaptor::ApiClient.new } 200 | 201 | it 'works' do 202 | expect(api_client.select_header_content_type(nil)).to be_nil 203 | expect(api_client.select_header_content_type([])).to be_nil 204 | 205 | expect(api_client.select_header_content_type(['application/json'])).to eq('application/json') 206 | expect(api_client.select_header_content_type(['application/xml', 'application/json; charset=UTF8'])).to eq('application/json; charset=UTF8') 207 | expect(api_client.select_header_content_type(['APPLICATION/JSON', 'text/html'])).to eq('APPLICATION/JSON') 208 | expect(api_client.select_header_content_type(['application/xml'])).to eq('application/xml') 209 | expect(api_client.select_header_content_type(['text/plain', 'application/xml'])).to eq('text/plain') 210 | end 211 | end 212 | 213 | describe '#sanitize_filename' do 214 | let(:api_client) { DocRaptor::ApiClient.new } 215 | 216 | it 'works' do 217 | expect(api_client.sanitize_filename('sun')).to eq('sun') 218 | expect(api_client.sanitize_filename('sun.gif')).to eq('sun.gif') 219 | expect(api_client.sanitize_filename('../sun.gif')).to eq('sun.gif') 220 | expect(api_client.sanitize_filename('/var/tmp/sun.gif')).to eq('sun.gif') 221 | expect(api_client.sanitize_filename('./sun.gif')).to eq('sun.gif') 222 | expect(api_client.sanitize_filename('..\sun.gif')).to eq('sun.gif') 223 | expect(api_client.sanitize_filename('\var\tmp\sun.gif')).to eq('sun.gif') 224 | expect(api_client.sanitize_filename('c:\var\tmp\sun.gif')).to eq('sun.gif') 225 | expect(api_client.sanitize_filename('.\sun.gif')).to eq('sun.gif') 226 | end 227 | end 228 | end 229 | -------------------------------------------------------------------------------- /lib/docraptor/models/doc_status.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | #DocRaptor 3 | 4 | #A native client library for the DocRaptor HTML to PDF/XLS service. 5 | 6 | The version of the OpenAPI document: 2.0.0 7 | 8 | Generated by: https://openapi-generator.tech 9 | OpenAPI Generator version: 6.6.0 10 | 11 | =end 12 | 13 | require 'date' 14 | require 'time' 15 | 16 | module DocRaptor 17 | class DocStatus 18 | # The present status of the document. Can be queued, working, completed, and failed. 19 | attr_accessor :status 20 | 21 | # The URL where the document can be retrieved. This URL may only be used a few times. 22 | attr_accessor :download_url 23 | 24 | # The identifier for downloading the document with the download API. 25 | attr_accessor :download_id 26 | 27 | # Additional information. 28 | attr_accessor :message 29 | 30 | # Number of PDF pages in document. 31 | attr_accessor :number_of_pages 32 | 33 | # Error information. 34 | attr_accessor :validation_errors 35 | 36 | # Attribute mapping from ruby-style variable name to JSON key. 37 | def self.attribute_map 38 | { 39 | :'status' => :'status', 40 | :'download_url' => :'download_url', 41 | :'download_id' => :'download_id', 42 | :'message' => :'message', 43 | :'number_of_pages' => :'number_of_pages', 44 | :'validation_errors' => :'validation_errors' 45 | } 46 | end 47 | 48 | # Returns all the JSON keys this model knows about 49 | def self.acceptable_attributes 50 | attribute_map.values 51 | end 52 | 53 | # Attribute type mapping. 54 | def self.openapi_types 55 | { 56 | :'status' => :'String', 57 | :'download_url' => :'String', 58 | :'download_id' => :'String', 59 | :'message' => :'String', 60 | :'number_of_pages' => :'Integer', 61 | :'validation_errors' => :'String' 62 | } 63 | end 64 | 65 | # List of attributes with nullable: true 66 | def self.openapi_nullable 67 | Set.new([ 68 | ]) 69 | end 70 | 71 | # Initializes the object 72 | # @param [Hash] attributes Model attributes in the form of hash 73 | def initialize(attributes = {}) 74 | if (!attributes.is_a?(Hash)) 75 | fail ArgumentError, "The input argument (attributes) must be a hash in `DocRaptor::DocStatus` initialize method" 76 | end 77 | 78 | # check to see if the attribute exists and convert string to symbol for hash key 79 | attributes = attributes.each_with_object({}) { |(k, v), h| 80 | if (!self.class.attribute_map.key?(k.to_sym)) 81 | fail ArgumentError, "`#{k}` is not a valid attribute in `DocRaptor::DocStatus`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect 82 | end 83 | h[k.to_sym] = v 84 | } 85 | 86 | if attributes.key?(:'status') 87 | self.status = attributes[:'status'] 88 | end 89 | 90 | if attributes.key?(:'download_url') 91 | self.download_url = attributes[:'download_url'] 92 | end 93 | 94 | if attributes.key?(:'download_id') 95 | self.download_id = attributes[:'download_id'] 96 | end 97 | 98 | if attributes.key?(:'message') 99 | self.message = attributes[:'message'] 100 | end 101 | 102 | if attributes.key?(:'number_of_pages') 103 | self.number_of_pages = attributes[:'number_of_pages'] 104 | end 105 | 106 | if attributes.key?(:'validation_errors') 107 | self.validation_errors = attributes[:'validation_errors'] 108 | end 109 | end 110 | 111 | # Show invalid properties with the reasons. Usually used together with valid? 112 | # @return Array for valid properties with the reasons 113 | def list_invalid_properties 114 | invalid_properties = Array.new 115 | invalid_properties 116 | end 117 | 118 | # Check to see if the all the properties in the model are valid 119 | # @return true if the model is valid 120 | def valid? 121 | true 122 | end 123 | 124 | # Checks equality by comparing each attribute. 125 | # @param [Object] Object to be compared 126 | def ==(o) 127 | return true if self.equal?(o) 128 | self.class == o.class && 129 | status == o.status && 130 | download_url == o.download_url && 131 | download_id == o.download_id && 132 | message == o.message && 133 | number_of_pages == o.number_of_pages && 134 | validation_errors == o.validation_errors 135 | end 136 | 137 | # @see the `==` method 138 | # @param [Object] Object to be compared 139 | def eql?(o) 140 | self == o 141 | end 142 | 143 | # Calculates hash code according to all attributes. 144 | # @return [Integer] Hash code 145 | def hash 146 | [status, download_url, download_id, message, number_of_pages, validation_errors].hash 147 | end 148 | 149 | # Builds the object from hash 150 | # @param [Hash] attributes Model attributes in the form of hash 151 | # @return [Object] Returns the model itself 152 | def self.build_from_hash(attributes) 153 | new.build_from_hash(attributes) 154 | end 155 | 156 | # Builds the object from hash 157 | # @param [Hash] attributes Model attributes in the form of hash 158 | # @return [Object] Returns the model itself 159 | def build_from_hash(attributes) 160 | return nil unless attributes.is_a?(Hash) 161 | attributes = attributes.transform_keys(&:to_sym) 162 | self.class.openapi_types.each_pair do |key, type| 163 | if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key) 164 | self.send("#{key}=", nil) 165 | elsif type =~ /\AArray<(.*)>/i 166 | # check to ensure the input is an array given that the attribute 167 | # is documented as an array but the input is not 168 | if attributes[self.class.attribute_map[key]].is_a?(Array) 169 | self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) }) 170 | end 171 | elsif !attributes[self.class.attribute_map[key]].nil? 172 | self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]])) 173 | end 174 | end 175 | 176 | self 177 | end 178 | 179 | # Deserializes the data based on type 180 | # @param string type Data type 181 | # @param string value Value to be deserialized 182 | # @return [Object] Deserialized data 183 | def _deserialize(type, value) 184 | case type.to_sym 185 | when :Time 186 | Time.parse(value) 187 | when :Date 188 | Date.parse(value) 189 | when :String 190 | value.to_s 191 | when :Integer 192 | value.to_i 193 | when :Float 194 | value.to_f 195 | when :Boolean 196 | if value.to_s =~ /\A(true|t|yes|y|1)\z/i 197 | true 198 | else 199 | false 200 | end 201 | when :Object 202 | # generic object (usually a Hash), return directly 203 | value 204 | when /\AArray<(?.+)>\z/ 205 | inner_type = Regexp.last_match[:inner_type] 206 | value.map { |v| _deserialize(inner_type, v) } 207 | when /\AHash<(?.+?), (?.+)>\z/ 208 | k_type = Regexp.last_match[:k_type] 209 | v_type = Regexp.last_match[:v_type] 210 | {}.tap do |hash| 211 | value.each do |k, v| 212 | hash[_deserialize(k_type, k)] = _deserialize(v_type, v) 213 | end 214 | end 215 | else # model 216 | # models (e.g. Pet) or oneOf 217 | klass = DocRaptor.const_get(type) 218 | klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value) 219 | end 220 | end 221 | 222 | # Returns the string representation of the object 223 | # @return [String] String presentation of the object 224 | def to_s 225 | to_hash.to_s 226 | end 227 | 228 | # to_body is an alias to to_hash (backward compatibility) 229 | # @return [Hash] Returns the object in the form of hash 230 | def to_body 231 | to_hash 232 | end 233 | 234 | # Returns the object in the form of hash 235 | # @return [Hash] Returns the object in the form of hash 236 | def to_hash 237 | hash = {} 238 | self.class.attribute_map.each_pair do |attr, param| 239 | value = self.send(attr) 240 | if value.nil? 241 | is_nullable = self.class.openapi_nullable.include?(attr) 242 | next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) 243 | end 244 | 245 | hash[param] = _to_hash(value) 246 | end 247 | hash 248 | end 249 | 250 | # Outputs non-array value in the form of hash 251 | # For object, use to_hash. Otherwise, just return the value 252 | # @param [Object] value Any valid value 253 | # @return [Hash] Returns the value in the form of hash 254 | def _to_hash(value) 255 | if value.is_a?(Array) 256 | value.compact.map { |v| _to_hash(v) } 257 | elsif value.is_a?(Hash) 258 | {}.tap do |hash| 259 | value.each { |k, v| hash[k] = _to_hash(v) } 260 | end 261 | elsif value.respond_to? :to_hash 262 | value.to_hash 263 | else 264 | value 265 | end 266 | end 267 | 268 | end 269 | 270 | end 271 | -------------------------------------------------------------------------------- /lib/docraptor/configuration.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | #DocRaptor 3 | 4 | #A native client library for the DocRaptor HTML to PDF/XLS service. 5 | 6 | The version of the OpenAPI document: 2.0.0 7 | 8 | Generated by: https://openapi-generator.tech 9 | OpenAPI Generator version: 6.6.0 10 | 11 | =end 12 | 13 | module DocRaptor 14 | class Configuration 15 | # Defines url scheme 16 | attr_accessor :scheme 17 | 18 | # Defines url host 19 | attr_accessor :host 20 | 21 | # Defines url base path 22 | attr_accessor :base_path 23 | 24 | # Define server configuration index 25 | attr_accessor :server_index 26 | 27 | # Define server operation configuration index 28 | attr_accessor :server_operation_index 29 | 30 | # Default server variables 31 | attr_accessor :server_variables 32 | 33 | # Default server operation variables 34 | attr_accessor :server_operation_variables 35 | 36 | # Defines API keys used with API Key authentications. 37 | # 38 | # @return [Hash] key: parameter name, value: parameter value (API key) 39 | # 40 | # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string) 41 | # config.api_key['api_key'] = 'xxx' 42 | attr_accessor :api_key 43 | 44 | # Defines API key prefixes used with API Key authentications. 45 | # 46 | # @return [Hash] key: parameter name, value: API key prefix 47 | # 48 | # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers) 49 | # config.api_key_prefix['api_key'] = 'Token' 50 | attr_accessor :api_key_prefix 51 | 52 | # Defines the username used with HTTP basic authentication. 53 | # 54 | # @return [String] 55 | attr_accessor :username 56 | 57 | # Defines the password used with HTTP basic authentication. 58 | # 59 | # @return [String] 60 | attr_accessor :password 61 | 62 | # Defines the access token (Bearer) used with OAuth2. 63 | attr_accessor :access_token 64 | 65 | # Defines a Proc used to fetch or refresh access tokens (Bearer) used with OAuth2. 66 | # Overrides the access_token if set 67 | # @return [Proc] 68 | attr_accessor :access_token_getter 69 | 70 | # Set this to return data as binary instead of downloading a temp file. When enabled (set to true) 71 | # HTTP responses with return type `File` will be returned as a stream of binary data. 72 | # Default to false. 73 | attr_accessor :return_binary_data 74 | 75 | # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response 76 | # details will be logged with `logger.debug` (see the `logger` attribute). 77 | # Default to false. 78 | # 79 | # @return [true, false] 80 | attr_accessor :debugging 81 | 82 | # Defines the logger used for debugging. 83 | # Default to `Rails.logger` (when in Rails) or logging to STDOUT. 84 | # 85 | # @return [#debug] 86 | attr_accessor :logger 87 | 88 | # Defines the temporary folder to store downloaded files 89 | # (for API endpoints that have file response). 90 | # Default to use `Tempfile`. 91 | # 92 | # @return [String] 93 | attr_accessor :temp_folder_path 94 | 95 | # The time limit for HTTP request in seconds. 96 | # Default to 0 (never times out). 97 | attr_accessor :timeout 98 | 99 | # Set this to false to skip client side validation in the operation. 100 | # Default to true. 101 | # @return [true, false] 102 | attr_accessor :client_side_validation 103 | 104 | ### TLS/SSL setting 105 | # Set this to false to skip verifying SSL certificate when calling API from https server. 106 | # Default to true. 107 | # 108 | # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks. 109 | # 110 | # @return [true, false] 111 | attr_accessor :verify_ssl 112 | 113 | ### TLS/SSL setting 114 | # Set this to false to skip verifying SSL host name 115 | # Default to true. 116 | # 117 | # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks. 118 | # 119 | # @return [true, false] 120 | attr_accessor :verify_ssl_host 121 | 122 | ### TLS/SSL setting 123 | # Set this to customize the certificate file to verify the peer. 124 | # 125 | # @return [String] the path to the certificate file 126 | # 127 | # @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code: 128 | # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145 129 | attr_accessor :ssl_ca_cert 130 | 131 | ### TLS/SSL setting 132 | # Client certificate file (for client certificate) 133 | attr_accessor :cert_file 134 | 135 | ### TLS/SSL setting 136 | # Client private key file (for client certificate) 137 | attr_accessor :key_file 138 | 139 | # Set this to customize parameters encoding of array parameter with multi collectionFormat. 140 | # Default to nil. 141 | # 142 | # @see The params_encoding option of Ethon. Related source code: 143 | # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96 144 | attr_accessor :params_encoding 145 | 146 | 147 | attr_accessor :inject_format 148 | 149 | attr_accessor :force_ending_format 150 | 151 | def initialize 152 | @scheme = 'https' 153 | @host = 'api.docraptor.com' 154 | @base_path = '' 155 | @server_index = 0 156 | @server_operation_index = {} 157 | @server_variables = {} 158 | @server_operation_variables = {} 159 | @api_key = {} 160 | @api_key_prefix = {} 161 | @client_side_validation = true 162 | @verify_ssl = true 163 | @verify_ssl_host = true 164 | @cert_file = nil 165 | @key_file = nil 166 | @timeout = 0 167 | @params_encoding = nil 168 | @debugging = false 169 | @inject_format = false 170 | @force_ending_format = false 171 | @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT) 172 | 173 | yield(self) if block_given? 174 | end 175 | 176 | # The default Configuration object. 177 | def self.default 178 | @@default ||= Configuration.new 179 | end 180 | 181 | def configure 182 | yield(self) if block_given? 183 | end 184 | 185 | def scheme=(scheme) 186 | # remove :// from scheme 187 | @scheme = scheme.sub(/:\/\//, '') 188 | end 189 | 190 | def host=(host) 191 | # remove http(s):// and anything after a slash 192 | @host = host.sub(/https?:\/\//, '').split('/').first 193 | end 194 | 195 | def base_path=(base_path) 196 | # Add leading and trailing slashes to base_path 197 | @base_path = "/#{base_path}".gsub(/\/+/, '/') 198 | @base_path = '' if @base_path == '/' 199 | end 200 | 201 | # Returns base URL for specified operation based on server settings 202 | def base_url(operation = nil) 203 | index = server_operation_index[operation] 204 | return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if index == nil 205 | 206 | server_url(index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation]) 207 | end 208 | 209 | # Gets API key (with prefix if set). 210 | # @param [String] param_name the parameter name of API key auth 211 | def api_key_with_prefix(param_name, param_alias = nil) 212 | key = @api_key[param_name] 213 | key = @api_key.fetch(param_alias, key) unless param_alias.nil? 214 | if @api_key_prefix[param_name] 215 | "#{@api_key_prefix[param_name]} #{key}" 216 | else 217 | key 218 | end 219 | end 220 | 221 | # Gets access_token using access_token_getter or uses the static access_token 222 | def access_token_with_refresh 223 | return access_token if access_token_getter.nil? 224 | access_token_getter.call 225 | end 226 | 227 | # Gets Basic Auth token string 228 | def basic_auth_token 229 | 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n") 230 | end 231 | 232 | # Returns Auth Settings hash for api client. 233 | def auth_settings 234 | { 235 | 'basicAuth' => 236 | { 237 | type: 'basic', 238 | in: 'header', 239 | key: 'Authorization', 240 | value: basic_auth_token 241 | }, 242 | } 243 | end 244 | 245 | # Returns an array of Server setting 246 | def server_settings 247 | [ 248 | { 249 | url: "https://api.docraptor.com", 250 | description: "DocRaptor API endpoint", 251 | } 252 | ] 253 | end 254 | 255 | def operation_server_settings 256 | { 257 | } 258 | end 259 | 260 | # Returns URL based on server settings 261 | # 262 | # @param index array index of the server settings 263 | # @param variables hash of variable and the corresponding value 264 | def server_url(index, variables = {}, servers = nil) 265 | servers = server_settings if servers == nil 266 | 267 | # check array index out of bound 268 | if (index < 0 || index >= servers.size) 269 | fail ArgumentError, "Invalid index #{index} when selecting the server. Must be less than #{servers.size}" 270 | end 271 | 272 | server = servers[index] 273 | url = server[:url] 274 | 275 | return url unless server.key? :variables 276 | 277 | # go through variable and assign a value 278 | server[:variables].each do |name, variable| 279 | if variables.key?(name) 280 | if (!server[:variables][name].key?(:enum_values) || server[:variables][name][:enum_values].include?(variables[name])) 281 | url.gsub! "{" + name.to_s + "}", variables[name] 282 | else 283 | fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}." 284 | end 285 | else 286 | # use default value 287 | url.gsub! "{" + name.to_s + "}", server[:variables][name][:default_value] 288 | end 289 | end 290 | 291 | url 292 | end 293 | 294 | end 295 | end 296 | -------------------------------------------------------------------------------- /.review/generated_files/docs/DocApi.md: -------------------------------------------------------------------------------- 1 | # DocRaptor::DocApi 2 | 3 | All URIs are relative to *https://api.docraptor.com* 4 | 5 | | Method | HTTP request | Description | 6 | | ------ | ------------ | ----------- | 7 | | [**create_async_doc**](DocApi.md#create_async_doc) | **POST** /async_docs | | 8 | | [**create_doc**](DocApi.md#create_doc) | **POST** /docs | | 9 | | [**create_hosted_async_doc**](DocApi.md#create_hosted_async_doc) | **POST** /hosted_async_docs | | 10 | | [**create_hosted_doc**](DocApi.md#create_hosted_doc) | **POST** /hosted_docs | | 11 | | [**expire**](DocApi.md#expire) | **PATCH** /expire/{id} | | 12 | | [**get_async_doc**](DocApi.md#get_async_doc) | **GET** /download/{id} | | 13 | | [**get_async_doc_status**](DocApi.md#get_async_doc_status) | **GET** /status/{id} | | 14 | 15 | 16 | ## create_async_doc 17 | 18 | > create_async_doc(doc) 19 | 20 | 21 | 22 | Creates a document asynchronously. You must use a callback url or the returned status id and the status API to find out when it completes. Then use the download API to get the document. 23 | 24 | ### Examples 25 | 26 | ```ruby 27 | require 'time' 28 | require 'docraptor' 29 | # setup authorization 30 | DocRaptor.configure do |config| 31 | # Configure HTTP basic authorization: basicAuth 32 | config.username = 'YOUR USERNAME' 33 | config.password = 'YOUR PASSWORD' 34 | end 35 | 36 | api_instance = DocRaptor::DocApi.new 37 | doc = DocRaptor::Doc.new({name: 'name_example', document_type: 'pdf'}) # Doc | 38 | 39 | begin 40 | 41 | result = api_instance.create_async_doc(doc) 42 | p result 43 | rescue DocRaptor::ApiError => e 44 | puts "Error when calling DocApi->create_async_doc: #{e}" 45 | end 46 | ``` 47 | 48 | #### Using the create_async_doc_with_http_info variant 49 | 50 | This returns an Array which contains the response data, status code and headers. 51 | 52 | > , Integer, Hash)> create_async_doc_with_http_info(doc) 53 | 54 | ```ruby 55 | begin 56 | 57 | data, status_code, headers = api_instance.create_async_doc_with_http_info(doc) 58 | p status_code # => 2xx 59 | p headers # => { ... } 60 | p data # => 61 | rescue DocRaptor::ApiError => e 62 | puts "Error when calling DocApi->create_async_doc_with_http_info: #{e}" 63 | end 64 | ``` 65 | 66 | ### Parameters 67 | 68 | | Name | Type | Description | Notes | 69 | | ---- | ---- | ----------- | ----- | 70 | | **doc** | [**Doc**](Doc.md) | | | 71 | 72 | ### Return type 73 | 74 | [**AsyncDoc**](AsyncDoc.md) 75 | 76 | ### Authorization 77 | 78 | [basicAuth](../README.md#basicAuth) 79 | 80 | ### HTTP request headers 81 | 82 | - **Content-Type**: application/json 83 | - **Accept**: */* 84 | 85 | 86 | ## create_doc 87 | 88 | > String create_doc(doc) 89 | 90 | 91 | 92 | Creates a document synchronously. 93 | 94 | ### Examples 95 | 96 | ```ruby 97 | require 'time' 98 | require 'docraptor' 99 | # setup authorization 100 | DocRaptor.configure do |config| 101 | # Configure HTTP basic authorization: basicAuth 102 | config.username = 'YOUR USERNAME' 103 | config.password = 'YOUR PASSWORD' 104 | end 105 | 106 | api_instance = DocRaptor::DocApi.new 107 | doc = DocRaptor::Doc.new({name: 'name_example', document_type: 'pdf'}) # Doc | 108 | 109 | begin 110 | 111 | result = api_instance.create_doc(doc) 112 | p result 113 | rescue DocRaptor::ApiError => e 114 | puts "Error when calling DocApi->create_doc: #{e}" 115 | end 116 | ``` 117 | 118 | #### Using the create_doc_with_http_info variant 119 | 120 | This returns an Array which contains the response data, status code and headers. 121 | 122 | > create_doc_with_http_info(doc) 123 | 124 | ```ruby 125 | begin 126 | 127 | data, status_code, headers = api_instance.create_doc_with_http_info(doc) 128 | p status_code # => 2xx 129 | p headers # => { ... } 130 | p data # => String 131 | rescue DocRaptor::ApiError => e 132 | puts "Error when calling DocApi->create_doc_with_http_info: #{e}" 133 | end 134 | ``` 135 | 136 | ### Parameters 137 | 138 | | Name | Type | Description | Notes | 139 | | ---- | ---- | ----------- | ----- | 140 | | **doc** | [**Doc**](Doc.md) | | | 141 | 142 | ### Return type 143 | 144 | **String** 145 | 146 | ### Authorization 147 | 148 | [basicAuth](../README.md#basicAuth) 149 | 150 | ### HTTP request headers 151 | 152 | - **Content-Type**: application/json 153 | - **Accept**: */* 154 | 155 | 156 | ## create_hosted_async_doc 157 | 158 | > create_hosted_async_doc(doc) 159 | 160 | 161 | 162 | Creates a hosted document asynchronously. You must use a callback url or the returned status id and the status API to find out when it completes. Then use the download API to get the document. 163 | 164 | ### Examples 165 | 166 | ```ruby 167 | require 'time' 168 | require 'docraptor' 169 | # setup authorization 170 | DocRaptor.configure do |config| 171 | # Configure HTTP basic authorization: basicAuth 172 | config.username = 'YOUR USERNAME' 173 | config.password = 'YOUR PASSWORD' 174 | end 175 | 176 | api_instance = DocRaptor::DocApi.new 177 | doc = DocRaptor::Doc.new({name: 'name_example', document_type: 'pdf'}) # Doc | 178 | 179 | begin 180 | 181 | result = api_instance.create_hosted_async_doc(doc) 182 | p result 183 | rescue DocRaptor::ApiError => e 184 | puts "Error when calling DocApi->create_hosted_async_doc: #{e}" 185 | end 186 | ``` 187 | 188 | #### Using the create_hosted_async_doc_with_http_info variant 189 | 190 | This returns an Array which contains the response data, status code and headers. 191 | 192 | > , Integer, Hash)> create_hosted_async_doc_with_http_info(doc) 193 | 194 | ```ruby 195 | begin 196 | 197 | data, status_code, headers = api_instance.create_hosted_async_doc_with_http_info(doc) 198 | p status_code # => 2xx 199 | p headers # => { ... } 200 | p data # => 201 | rescue DocRaptor::ApiError => e 202 | puts "Error when calling DocApi->create_hosted_async_doc_with_http_info: #{e}" 203 | end 204 | ``` 205 | 206 | ### Parameters 207 | 208 | | Name | Type | Description | Notes | 209 | | ---- | ---- | ----------- | ----- | 210 | | **doc** | [**Doc**](Doc.md) | | | 211 | 212 | ### Return type 213 | 214 | [**AsyncDoc**](AsyncDoc.md) 215 | 216 | ### Authorization 217 | 218 | [basicAuth](../README.md#basicAuth) 219 | 220 | ### HTTP request headers 221 | 222 | - **Content-Type**: application/json 223 | - **Accept**: */* 224 | 225 | 226 | ## create_hosted_doc 227 | 228 | > create_hosted_doc(doc) 229 | 230 | 231 | 232 | Creates a hosted document synchronously. 233 | 234 | ### Examples 235 | 236 | ```ruby 237 | require 'time' 238 | require 'docraptor' 239 | # setup authorization 240 | DocRaptor.configure do |config| 241 | # Configure HTTP basic authorization: basicAuth 242 | config.username = 'YOUR USERNAME' 243 | config.password = 'YOUR PASSWORD' 244 | end 245 | 246 | api_instance = DocRaptor::DocApi.new 247 | doc = DocRaptor::Doc.new({name: 'name_example', document_type: 'pdf'}) # Doc | The document to be created. 248 | 249 | begin 250 | 251 | result = api_instance.create_hosted_doc(doc) 252 | p result 253 | rescue DocRaptor::ApiError => e 254 | puts "Error when calling DocApi->create_hosted_doc: #{e}" 255 | end 256 | ``` 257 | 258 | #### Using the create_hosted_doc_with_http_info variant 259 | 260 | This returns an Array which contains the response data, status code and headers. 261 | 262 | > , Integer, Hash)> create_hosted_doc_with_http_info(doc) 263 | 264 | ```ruby 265 | begin 266 | 267 | data, status_code, headers = api_instance.create_hosted_doc_with_http_info(doc) 268 | p status_code # => 2xx 269 | p headers # => { ... } 270 | p data # => 271 | rescue DocRaptor::ApiError => e 272 | puts "Error when calling DocApi->create_hosted_doc_with_http_info: #{e}" 273 | end 274 | ``` 275 | 276 | ### Parameters 277 | 278 | | Name | Type | Description | Notes | 279 | | ---- | ---- | ----------- | ----- | 280 | | **doc** | [**Doc**](Doc.md) | The document to be created. | | 281 | 282 | ### Return type 283 | 284 | [**DocStatus**](DocStatus.md) 285 | 286 | ### Authorization 287 | 288 | [basicAuth](../README.md#basicAuth) 289 | 290 | ### HTTP request headers 291 | 292 | - **Content-Type**: application/json 293 | - **Accept**: */* 294 | 295 | 296 | ## expire 297 | 298 | > expire(id) 299 | 300 | 301 | 302 | Expires a previously created hosted doc. 303 | 304 | ### Examples 305 | 306 | ```ruby 307 | require 'time' 308 | require 'docraptor' 309 | # setup authorization 310 | DocRaptor.configure do |config| 311 | # Configure HTTP basic authorization: basicAuth 312 | config.username = 'YOUR USERNAME' 313 | config.password = 'YOUR PASSWORD' 314 | end 315 | 316 | api_instance = DocRaptor::DocApi.new 317 | id = 'id_example' # String | The download_id returned from status request or hosted document response. 318 | 319 | begin 320 | 321 | api_instance.expire(id) 322 | rescue DocRaptor::ApiError => e 323 | puts "Error when calling DocApi->expire: #{e}" 324 | end 325 | ``` 326 | 327 | #### Using the expire_with_http_info variant 328 | 329 | This returns an Array which contains the response data (`nil` in this case), status code and headers. 330 | 331 | > expire_with_http_info(id) 332 | 333 | ```ruby 334 | begin 335 | 336 | data, status_code, headers = api_instance.expire_with_http_info(id) 337 | p status_code # => 2xx 338 | p headers # => { ... } 339 | p data # => nil 340 | rescue DocRaptor::ApiError => e 341 | puts "Error when calling DocApi->expire_with_http_info: #{e}" 342 | end 343 | ``` 344 | 345 | ### Parameters 346 | 347 | | Name | Type | Description | Notes | 348 | | ---- | ---- | ----------- | ----- | 349 | | **id** | **String** | The download_id returned from status request or hosted document response. | | 350 | 351 | ### Return type 352 | 353 | nil (empty response body) 354 | 355 | ### Authorization 356 | 357 | [basicAuth](../README.md#basicAuth) 358 | 359 | ### HTTP request headers 360 | 361 | - **Content-Type**: Not defined 362 | - **Accept**: Not defined 363 | 364 | 365 | ## get_async_doc 366 | 367 | > String get_async_doc(id) 368 | 369 | 370 | 371 | Downloads a finished document. 372 | 373 | ### Examples 374 | 375 | ```ruby 376 | require 'time' 377 | require 'docraptor' 378 | # setup authorization 379 | DocRaptor.configure do |config| 380 | # Configure HTTP basic authorization: basicAuth 381 | config.username = 'YOUR USERNAME' 382 | config.password = 'YOUR PASSWORD' 383 | end 384 | 385 | api_instance = DocRaptor::DocApi.new 386 | id = 'id_example' # String | The download_id returned from an async status request or callback. 387 | 388 | begin 389 | 390 | result = api_instance.get_async_doc(id) 391 | p result 392 | rescue DocRaptor::ApiError => e 393 | puts "Error when calling DocApi->get_async_doc: #{e}" 394 | end 395 | ``` 396 | 397 | #### Using the get_async_doc_with_http_info variant 398 | 399 | This returns an Array which contains the response data, status code and headers. 400 | 401 | > get_async_doc_with_http_info(id) 402 | 403 | ```ruby 404 | begin 405 | 406 | data, status_code, headers = api_instance.get_async_doc_with_http_info(id) 407 | p status_code # => 2xx 408 | p headers # => { ... } 409 | p data # => String 410 | rescue DocRaptor::ApiError => e 411 | puts "Error when calling DocApi->get_async_doc_with_http_info: #{e}" 412 | end 413 | ``` 414 | 415 | ### Parameters 416 | 417 | | Name | Type | Description | Notes | 418 | | ---- | ---- | ----------- | ----- | 419 | | **id** | **String** | The download_id returned from an async status request or callback. | | 420 | 421 | ### Return type 422 | 423 | **String** 424 | 425 | ### Authorization 426 | 427 | [basicAuth](../README.md#basicAuth) 428 | 429 | ### HTTP request headers 430 | 431 | - **Content-Type**: Not defined 432 | - **Accept**: */* 433 | 434 | 435 | ## get_async_doc_status 436 | 437 | > get_async_doc_status(id) 438 | 439 | 440 | 441 | Check on the status of an asynchronously created document. 442 | 443 | ### Examples 444 | 445 | ```ruby 446 | require 'time' 447 | require 'docraptor' 448 | # setup authorization 449 | DocRaptor.configure do |config| 450 | # Configure HTTP basic authorization: basicAuth 451 | config.username = 'YOUR USERNAME' 452 | config.password = 'YOUR PASSWORD' 453 | end 454 | 455 | api_instance = DocRaptor::DocApi.new 456 | id = 'id_example' # String | The status_id returned when creating an asynchronous document. 457 | 458 | begin 459 | 460 | result = api_instance.get_async_doc_status(id) 461 | p result 462 | rescue DocRaptor::ApiError => e 463 | puts "Error when calling DocApi->get_async_doc_status: #{e}" 464 | end 465 | ``` 466 | 467 | #### Using the get_async_doc_status_with_http_info variant 468 | 469 | This returns an Array which contains the response data, status code and headers. 470 | 471 | > , Integer, Hash)> get_async_doc_status_with_http_info(id) 472 | 473 | ```ruby 474 | begin 475 | 476 | data, status_code, headers = api_instance.get_async_doc_status_with_http_info(id) 477 | p status_code # => 2xx 478 | p headers # => { ... } 479 | p data # => 480 | rescue DocRaptor::ApiError => e 481 | puts "Error when calling DocApi->get_async_doc_status_with_http_info: #{e}" 482 | end 483 | ``` 484 | 485 | ### Parameters 486 | 487 | | Name | Type | Description | Notes | 488 | | ---- | ---- | ----------- | ----- | 489 | | **id** | **String** | The status_id returned when creating an asynchronous document. | | 490 | 491 | ### Return type 492 | 493 | [**DocStatus**](DocStatus.md) 494 | 495 | ### Authorization 496 | 497 | [basicAuth](../README.md#basicAuth) 498 | 499 | ### HTTP request headers 500 | 501 | - **Content-Type**: Not defined 502 | - **Accept**: */* 503 | 504 | -------------------------------------------------------------------------------- /lib/docraptor/api_client.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | #DocRaptor 3 | 4 | #A native client library for the DocRaptor HTML to PDF/XLS service. 5 | 6 | The version of the OpenAPI document: 2.0.0 7 | 8 | Generated by: https://openapi-generator.tech 9 | OpenAPI Generator version: 6.6.0 10 | 11 | =end 12 | 13 | require 'date' 14 | require 'json' 15 | require 'logger' 16 | require 'tempfile' 17 | require 'time' 18 | require 'typhoeus' 19 | 20 | module DocRaptor 21 | class ApiClient 22 | # The Configuration object holding settings to be used in the API client. 23 | attr_accessor :config 24 | 25 | # Defines the headers to be used in HTTP requests of all API calls by default. 26 | # 27 | # @return [Hash] 28 | attr_accessor :default_headers 29 | 30 | # Initializes the ApiClient 31 | # @option config [Configuration] Configuration for initializing the object, default to Configuration.default 32 | def initialize(config = Configuration.default) 33 | @config = config 34 | @user_agent = "ruby-swagger-#{VERSION}" 35 | @default_headers = { 36 | 'Content-Type' => 'application/json', 37 | 'User-Agent' => @user_agent 38 | } 39 | end 40 | 41 | def self.default 42 | @@default ||= ApiClient.new 43 | end 44 | 45 | # Call an API with given options. 46 | # 47 | # @return [Array<(Object, Integer, Hash)>] an array of 3 elements: 48 | # the data deserialized from response body (could be nil), response status code and response headers. 49 | def call_api(http_method, path, opts = {}) 50 | request = build_request(http_method, path, opts) 51 | response = request.run 52 | 53 | if @config.debugging 54 | @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n" 55 | end 56 | 57 | unless response.success? 58 | if response.timed_out? 59 | fail ApiError.new('Connection timed out') 60 | elsif response.code == 0 61 | # Errors from libcurl will be made visible here 62 | fail ApiError.new(:code => 0, 63 | :message => response.return_message) 64 | else 65 | fail ApiError.new(:code => response.code, 66 | :response_headers => response.headers, 67 | :response_body => response.body), 68 | response.status_message 69 | end 70 | end 71 | 72 | if opts[:return_type] 73 | data = deserialize(response, opts[:return_type]) 74 | else 75 | data = nil 76 | end 77 | return data, response.code, response.headers 78 | end 79 | 80 | # Builds the HTTP request 81 | # 82 | # @param [String] http_method HTTP method/verb (e.g. POST) 83 | # @param [String] path URL path (e.g. /account/new) 84 | # @option opts [Hash] :header_params Header parameters 85 | # @option opts [Hash] :query_params Query parameters 86 | # @option opts [Hash] :form_params Query parameters 87 | # @option opts [Object] :body HTTP body (JSON/XML) 88 | # @return [Typhoeus::Request] A Typhoeus Request 89 | def build_request(http_method, path, opts = {}) 90 | url = build_request_url(path, opts) 91 | http_method = http_method.to_sym.downcase 92 | 93 | header_params = @default_headers.merge(opts[:header_params] || {}) 94 | query_params = opts[:query_params] || {} 95 | form_params = opts[:form_params] || {} 96 | follow_location = opts[:follow_location] || true 97 | 98 | update_params_for_auth! header_params, query_params, opts[:auth_names] 99 | 100 | # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false) 101 | _verify_ssl_host = @config.verify_ssl_host ? 2 : 0 102 | 103 | req_opts = { 104 | :method => http_method, 105 | :headers => header_params, 106 | :params => query_params, 107 | :params_encoding => @config.params_encoding, 108 | :timeout => @config.timeout, 109 | :ssl_verifypeer => @config.verify_ssl, 110 | :ssl_verifyhost => _verify_ssl_host, 111 | :sslcert => @config.cert_file, 112 | :sslkey => @config.key_file, 113 | :verbose => @config.debugging, 114 | :followlocation => follow_location 115 | } 116 | 117 | # set custom cert, if provided 118 | req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert 119 | 120 | if [:post, :patch, :put, :delete].include?(http_method) 121 | req_body = build_request_body(header_params, form_params, opts[:body]) 122 | req_opts.update :body => req_body 123 | if @config.debugging 124 | @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n" 125 | end 126 | end 127 | 128 | request = Typhoeus::Request.new(url, req_opts) 129 | download_file(request) if opts[:return_type] == 'File' 130 | request 131 | end 132 | 133 | # Builds the HTTP request body 134 | # 135 | # @param [Hash] header_params Header parameters 136 | # @param [Hash] form_params Query parameters 137 | # @param [Object] body HTTP body (JSON/XML) 138 | # @return [String] HTTP body data in the form of string 139 | def build_request_body(header_params, form_params, body) 140 | # http form 141 | if header_params['Content-Type'] == 'application/x-www-form-urlencoded' || 142 | header_params['Content-Type'] == 'multipart/form-data' 143 | data = {} 144 | form_params.each do |key, value| 145 | case value 146 | when ::File, ::Array, nil 147 | # let typhoeus handle File, Array and nil parameters 148 | data[key] = value 149 | else 150 | data[key] = value.to_s 151 | end 152 | end 153 | elsif body 154 | data = body.is_a?(String) ? body : body.to_json 155 | else 156 | data = nil 157 | end 158 | data 159 | end 160 | 161 | # Save response body into a file in (the defined) temporary folder, using the filename 162 | # from the "Content-Disposition" header if provided, otherwise a random filename. 163 | # The response body is written to the file in chunks in order to handle files which 164 | # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby 165 | # process can use. 166 | # 167 | # @see Configuration#temp_folder_path 168 | def download_file(request) 169 | tempfile = nil 170 | encoding = nil 171 | request.on_headers do |response| 172 | content_disposition = response.headers['Content-Disposition'] 173 | if content_disposition && content_disposition =~ /filename=/i 174 | filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1] 175 | prefix = sanitize_filename(filename) 176 | else 177 | prefix = 'download-' 178 | end 179 | prefix = prefix + '-' unless prefix.end_with?('-') 180 | encoding = response.body.encoding 181 | tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding) 182 | @tempfile = tempfile 183 | end 184 | request.on_body do |chunk| 185 | chunk.force_encoding(encoding) 186 | tempfile.write(chunk) 187 | end 188 | request.on_complete do |response| 189 | if tempfile 190 | tempfile.close 191 | @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\ 192 | "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\ 193 | "will be deleted automatically with GC. It's also recommended to delete the temp file "\ 194 | "explicitly with `tempfile.delete`" 195 | end 196 | end 197 | end 198 | 199 | # Check if the given MIME is a JSON MIME. 200 | # JSON MIME examples: 201 | # application/json 202 | # application/json; charset=UTF8 203 | # APPLICATION/JSON 204 | # */* 205 | # @param [String] mime MIME 206 | # @return [Boolean] True if the MIME is application/json 207 | def json_mime?(mime) 208 | (mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil? 209 | end 210 | 211 | # Deserialize the response to the given return type. 212 | # 213 | # @param [Response] response HTTP response 214 | # @param [String] return_type some examples: "User", "Array", "Hash" 215 | def deserialize(response, return_type) 216 | body = response.body 217 | 218 | # handle file downloading - return the File instance processed in request callbacks 219 | # note that response body is empty when the file is written in chunks in request on_body callback 220 | return @tempfile if return_type == 'File' 221 | 222 | return nil if body.nil? || body.empty? 223 | 224 | # return response body directly for String return type 225 | return body if return_type == 'String' 226 | 227 | # ensuring a default content type 228 | content_type = response.headers['Content-Type'] || 'application/json' 229 | 230 | fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type) 231 | 232 | begin 233 | data = JSON.parse("[#{body}]", :symbolize_names => true)[0] 234 | rescue JSON::ParserError => e 235 | if %w(String Date Time).include?(return_type) 236 | data = body 237 | else 238 | raise e 239 | end 240 | end 241 | 242 | convert_to_type data, return_type 243 | end 244 | 245 | # Convert data to the given return type. 246 | # @param [Object] data Data to be converted 247 | # @param [String] return_type Return type 248 | # @return [Mixed] Data in a particular type 249 | def convert_to_type(data, return_type) 250 | return nil if data.nil? 251 | case return_type 252 | when 'String' 253 | data.to_s 254 | when 'Integer' 255 | data.to_i 256 | when 'Float' 257 | data.to_f 258 | when 'Boolean' 259 | data == true 260 | when 'Time' 261 | # parse date time (expecting ISO 8601 format) 262 | Time.parse data 263 | when 'Date' 264 | # parse date time (expecting ISO 8601 format) 265 | Date.parse data 266 | when 'Object' 267 | # generic object (usually a Hash), return directly 268 | data 269 | when /\AArray<(.+)>\z/ 270 | # e.g. Array 271 | sub_type = $1 272 | data.map { |item| convert_to_type(item, sub_type) } 273 | when /\AHash\\z/ 274 | # e.g. Hash 275 | sub_type = $1 276 | {}.tap do |hash| 277 | data.each { |k, v| hash[k] = convert_to_type(v, sub_type) } 278 | end 279 | else 280 | # models (e.g. Pet) or oneOf 281 | klass = DocRaptor.const_get(return_type) 282 | klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data) 283 | end 284 | end 285 | 286 | # Sanitize filename by removing path. 287 | # e.g. ../../sun.gif becomes sun.gif 288 | # 289 | # @param [String] filename the filename to be sanitized 290 | # @return [String] the sanitized filename 291 | def sanitize_filename(filename) 292 | filename.gsub(/.*[\/\\]/, '') 293 | end 294 | 295 | def build_request_url(path, opts = {}) 296 | # Add leading and trailing slashes to path 297 | path = "/#{path}".gsub(/\/+/, '/') 298 | @config.base_url(opts[:operation]) + path 299 | end 300 | 301 | # Update header and query params based on authentication settings. 302 | # 303 | # @param [Hash] header_params Header parameters 304 | # @param [Hash] query_params Query parameters 305 | # @param [String] auth_names Authentication scheme name 306 | def update_params_for_auth!(header_params, query_params, auth_names) 307 | Array(auth_names).each do |auth_name| 308 | auth_setting = @config.auth_settings[auth_name] 309 | next unless auth_setting 310 | case auth_setting[:in] 311 | when 'header' then header_params[auth_setting[:key]] = auth_setting[:value] 312 | when 'query' then query_params[auth_setting[:key]] = auth_setting[:value] 313 | else fail ArgumentError, 'Authentication token must be in `query` or `header`' 314 | end 315 | end 316 | end 317 | 318 | # Sets user agent in HTTP header 319 | # 320 | # @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0) 321 | def user_agent=(user_agent) 322 | @user_agent = user_agent 323 | @default_headers['User-Agent'] = @user_agent 324 | end 325 | 326 | # Return Accept header based on an array of accepts provided. 327 | # @param [Array] accepts array for Accept 328 | # @return [String] the Accept header (e.g. application/json) 329 | def select_header_accept(accepts) 330 | return nil if accepts.nil? || accepts.empty? 331 | # use JSON when present, otherwise use all of the provided 332 | json_accept = accepts.find { |s| json_mime?(s) } 333 | json_accept || accepts.join(',') 334 | end 335 | 336 | # Return Content-Type header based on an array of content types provided. 337 | # @param [Array] content_types array for Content-Type 338 | # @return [String] the Content-Type header (e.g. application/json) 339 | def select_header_content_type(content_types) 340 | # return nil by default 341 | return if content_types.nil? || content_types.empty? 342 | # use JSON when present, otherwise use the first one 343 | json_content_type = content_types.find { |s| json_mime?(s) } 344 | json_content_type || content_types.first 345 | end 346 | 347 | # Convert object (array, hash, object, etc) to JSON string. 348 | # @param [Object] model object to be converted into JSON string 349 | # @return [String] JSON string representation of the object 350 | def object_to_http_body(model) 351 | return model if model.nil? || model.is_a?(String) 352 | local_body = nil 353 | if model.is_a?(Array) 354 | local_body = model.map { |m| object_to_hash(m) } 355 | else 356 | local_body = object_to_hash(model) 357 | end 358 | local_body.to_json 359 | end 360 | 361 | # Convert object(non-array) to hash. 362 | # @param [Object] obj object to be converted into JSON string 363 | # @return [String] JSON string representation of the object 364 | def object_to_hash(obj) 365 | if obj.respond_to?(:to_hash) 366 | obj.to_hash 367 | else 368 | obj 369 | end 370 | end 371 | 372 | # Build parameter value according to the given collection format. 373 | # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi 374 | def build_collection_param(param, collection_format) 375 | case collection_format 376 | when :csv 377 | param.join(',') 378 | when :ssv 379 | param.join(' ') 380 | when :tsv 381 | param.join("\t") 382 | when :pipes 383 | param.join('|') 384 | when :multi 385 | # return the array directly as typhoeus will handle it as expected 386 | param 387 | else 388 | fail "unknown collection format: #{collection_format.inspect}" 389 | end 390 | end 391 | end 392 | end 393 | -------------------------------------------------------------------------------- /docraptor.yaml: -------------------------------------------------------------------------------- 1 | openapi: '3.0.0' 2 | 3 | info: # https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#info-object 4 | version: "2.0.0" 5 | title: DocRaptor 6 | description: "A native client library for the DocRaptor HTML to PDF/XLS service." 7 | termsOfService: "https://docraptor.com/tos" 8 | license: 9 | name: "MIT" 10 | url: "https://mit-license.org/" 11 | 12 | servers: 13 | - url: https://api.docraptor.com 14 | description: DocRaptor API endpoint 15 | 16 | paths: 17 | /docs: 18 | post: 19 | operationId: createDoc 20 | tags: [Doc] 21 | description: > 22 | Creates a document synchronously. 23 | security: 24 | - basicAuth: [] 25 | requestBody: 26 | content: 27 | application/json: 28 | schema: 29 | $ref: '#/components/schemas/Doc' 30 | required: true 31 | responses: 32 | 200: 33 | description: Successful response 34 | content: 35 | "*/*": 36 | schema: 37 | type: string 38 | format: byte 39 | 400: 40 | description: Bad Request 41 | 401: 42 | description: Unauthorized 43 | 403: 44 | description: Forbidden 45 | 422: 46 | description: Unprocessable Entity 47 | 500: 48 | description: Server Error 49 | 50 | /hosted_docs: 51 | post: 52 | operationId: createHostedDoc 53 | tags: [Doc] 54 | description: > 55 | Creates a hosted document synchronously. 56 | security: 57 | - basicAuth: [] 58 | requestBody: 59 | description: The document to be created. 60 | required: true 61 | content: 62 | application/json: 63 | schema: 64 | $ref: '#/components/schemas/Doc' 65 | responses: 66 | 200: 67 | description: Successful response 68 | content: 69 | "*/*": 70 | schema: 71 | $ref: '#/components/schemas/DocStatus' 72 | 400: 73 | description: Bad Request 74 | 401: 75 | description: Unauthorized 76 | 403: 77 | description: Forbidden 78 | 422: 79 | description: Unprocessable Entity 80 | 500: 81 | description: Server Error 82 | 83 | /async_docs: 84 | post: 85 | operationId: createAsyncDoc 86 | tags: [Doc] 87 | description: > 88 | Creates a document asynchronously. 89 | You must use a callback url or the returned status id and the status API to find out when it completes. 90 | Then use the download API to get the document. 91 | security: 92 | - basicAuth: [] 93 | requestBody: 94 | content: 95 | application/json: 96 | schema: 97 | $ref: '#/components/schemas/Doc' 98 | required: true 99 | responses: 100 | 200: 101 | description: Successful response 102 | content: 103 | "*/*": 104 | schema: 105 | $ref: '#/components/schemas/AsyncDoc' 106 | 400: 107 | description: Bad Request 108 | 401: 109 | description: Unauthorized 110 | 403: 111 | description: Forbidden 112 | 422: 113 | description: Unprocessable Entity 114 | 500: 115 | description: Server Error 116 | 117 | /hosted_async_docs: 118 | post: 119 | operationId: createHostedAsyncDoc 120 | tags: [Doc] 121 | description: > 122 | Creates a hosted document asynchronously. 123 | You must use a callback url or the returned status id and the status API to find out when it completes. 124 | Then use the download API to get the document. 125 | security: 126 | - basicAuth: [] 127 | requestBody: 128 | content: 129 | application/json: 130 | schema: 131 | $ref: '#/components/schemas/Doc' 132 | required: true 133 | responses: 134 | 200: 135 | description: Successful response 136 | content: 137 | "*/*": 138 | schema: 139 | $ref: '#/components/schemas/AsyncDoc' 140 | 400: 141 | description: Bad Request 142 | 401: 143 | description: Unauthorized 144 | 403: 145 | description: Forbidden 146 | 422: 147 | description: Unprocessable Entity 148 | 500: 149 | description: Server Error 150 | 151 | /status/{id}: 152 | get: 153 | operationId: getAsyncDocStatus 154 | tags: [Doc] 155 | description: > 156 | Check on the status of an asynchronously created document. 157 | security: 158 | - basicAuth: [] 159 | parameters: 160 | - name: id 161 | in: path 162 | description: The status_id returned when creating an asynchronous document. 163 | required: true 164 | schema: 165 | type: string 166 | responses: 167 | 200: 168 | description: Successful response 169 | content: 170 | "*/*": 171 | schema: 172 | $ref: '#/components/schemas/DocStatus' 173 | 401: 174 | description: Unauthorized 175 | 403: 176 | description: Forbidden 177 | 500: 178 | description: Server Error 179 | 180 | /download/{id}: 181 | get: 182 | operationId: getAsyncDoc 183 | tags: [Doc] 184 | description: > 185 | Downloads a finished document. 186 | security: 187 | - basicAuth: [] 188 | parameters: 189 | - name: id 190 | in: path 191 | description: The download_id returned from an async status request or callback. 192 | required: true 193 | schema: 194 | type: string 195 | responses: 196 | 200: 197 | description: Successful response 198 | content: 199 | "*/*": 200 | schema: 201 | type: string 202 | format: byte 203 | 400: 204 | description: Bad Request 205 | 403: 206 | description: Forbidden 207 | 500: 208 | description: Server Error 209 | 210 | /expire/{id}: 211 | patch: 212 | operationId: expire 213 | tags: [Doc] 214 | description: > 215 | Expires a previously created hosted doc. 216 | security: 217 | - basicAuth: [] 218 | parameters: 219 | - name: id 220 | in: path 221 | description: The download_id returned from status request or hosted document response. 222 | required: true 223 | schema: 224 | type: string 225 | responses: 226 | 200: 227 | description: Successful response 228 | 401: 229 | description: Unauthorized 230 | 403: 231 | description: Forbidden 232 | 500: 233 | description: Server Error 234 | 235 | components: 236 | securitySchemes: 237 | basicAuth: 238 | type: http 239 | scheme: basic 240 | description: Use your API key as the username. Password does not need to be set. 241 | schemas: 242 | Doc: 243 | type: object 244 | required: 245 | - name 246 | - document_type 247 | properties: 248 | name: 249 | type: string 250 | description: A name for identifying your document. 251 | document_type: 252 | type: string 253 | description: The type of document being created. 254 | enum: 255 | - pdf 256 | - xls 257 | - xlsx 258 | document_content: 259 | type: string 260 | description: > 261 | The HTML data to be transformed into a document. 262 | You must supply content using document_content or document_url. 263 | document_url: 264 | type: string 265 | description: > 266 | The URL to fetch the HTML data to be transformed into a document. 267 | You must supply content using document_content or document_url. 268 | test: 269 | type: boolean 270 | description: Enable test mode for this document. Test documents are not charged for but include a watermark. 271 | default: true 272 | pipeline: 273 | type: string 274 | description: Specify a specific verison of the DocRaptor Pipeline to use. 275 | strict: 276 | type: string 277 | description: Force strict HTML validation. 278 | enum: 279 | - none 280 | - html 281 | ignore_resource_errors: 282 | type: boolean 283 | description: Failed loading of images/javascripts/stylesheets/etc. will not cause the rendering to stop. 284 | default: true 285 | ignore_console_messages: 286 | type: boolean 287 | description: Prevent console.log from stopping document rendering during JavaScript execution. 288 | default: false 289 | tag: 290 | type: string 291 | description: A field for storing a small amount of metadata with this document. 292 | help: 293 | type: boolean 294 | description: Request support help with this request if it succeeds. 295 | default: false 296 | javascript: 297 | type: boolean 298 | description: Enable DocRaptor JavaScript parsing. PrinceXML JavaScript parsing is also available elsewhere. 299 | default: false 300 | referrer: 301 | type: string 302 | description: Set HTTP referrer when generating this document. 303 | callback_url: 304 | type: string 305 | description: > 306 | A URL that will receive a POST request after successfully completing an asynchronous document. 307 | The POST data will include download_url and download_id similar to status API responses. 308 | WARNING: this only works on asynchronous documents. 309 | hosted_download_limit: 310 | type: integer 311 | description: The number of times a hosted document can be downloaded. If no limit is specified, the document will be available for an unlimited number of downloads. 312 | hosted_expires_at: 313 | type: string 314 | description: The date and time at which a hosted document will be removed and no longer available. Must be a properly formatted ISO 8601 datetime, like 1981-01-23T08:02:30-05:00. 315 | prince_options: 316 | $ref: '#/components/schemas/PrinceOptions' 317 | 318 | PrinceOptions: 319 | type: object 320 | properties: 321 | baseurl: 322 | type: string 323 | description: Set the baseurl for assets. 324 | no_xinclude: 325 | type: boolean 326 | description: Disable XML inclusion. 327 | no_network: 328 | type: boolean 329 | description: Disable network access. 330 | no_parallel_downloads: 331 | type: boolean 332 | description: Disables parallel fetching of assets during PDF creation. Useful if your asset host has strict rate limiting. 333 | http_user: 334 | type: string 335 | description: Set the user for HTTP authentication. 336 | http_password: 337 | type: string 338 | description: Set the password for HTTP authentication. 339 | http_proxy: 340 | type: string 341 | description: Set the HTTP proxy server. 342 | http_timeout: 343 | type: integer 344 | description: Set the HTTP request timeout. 345 | insecure: 346 | type: boolean 347 | description: Disable SSL verification. 348 | media: 349 | type: string 350 | description: Specify the CSS media type. Defaults to "print" but you may want to use "screen" for web styles. 351 | no_author_style: 352 | type: boolean 353 | description: Ignore author stylesheets. 354 | no_default_style: 355 | type: boolean 356 | description: Ignore default stylesheets. 357 | no_embed_fonts: 358 | type: boolean 359 | description: Disable font embedding in PDFs. 360 | no_subset_fonts: 361 | type: boolean 362 | description: Disable font subsetting in PDFs. 363 | no_compress: 364 | type: boolean 365 | description: Disable PDF compression. 366 | encrypt: 367 | type: boolean 368 | description: Encrypt PDF output. 369 | key_bits: 370 | type: integer 371 | description: Set encryption key size. 372 | enum: 373 | - 40 374 | - 128 375 | user_password: 376 | type: string 377 | description: Set the PDF user password. 378 | owner_password: 379 | type: string 380 | description: Set the PDF owner password. 381 | disallow_print: 382 | type: boolean 383 | description: Disallow printing of this PDF. 384 | disallow_copy: 385 | type: boolean 386 | description: Disallow copying of this PDF. 387 | disallow_annotate: 388 | type: boolean 389 | description: Disallow annotation of this PDF. 390 | disallow_modify: 391 | type: boolean 392 | description: Disallow modification of this PDF. 393 | debug: 394 | type: boolean 395 | description: Enable Prince debug mode. 396 | input: 397 | type: string 398 | description: Specify the input format, defaults to html. 399 | enum: 400 | - html 401 | - xml 402 | - auto 403 | version: 404 | type: string 405 | deprecated: true 406 | description: Deprecated, use the appropriate `pipeline` version. Specify a specific verison of PrinceXML to use. 407 | javascript: 408 | type: boolean 409 | description: Enable PrinceXML JavaScript. DocRaptor JavaScript parsing is also available elsewhere. 410 | css_dpi: 411 | type: integer 412 | description: Set the DPI when rendering CSS. Defaults to 96 but can be set with Prince 9.0 and up. 413 | profile: 414 | type: string 415 | description: In Prince 9.0 and up you can set the PDF profile. 416 | pdf_title: 417 | type: string 418 | description: Specify the PDF title, part of the document's metadata. 419 | iframes: 420 | type: boolean 421 | description: Enable loading of iframes. 422 | nullable: true 423 | page_margin: 424 | type: string 425 | description: Specify the page margin distance. 426 | pdf_forms: 427 | type: boolean 428 | description: Make form fields editable by default. 429 | 430 | AsyncDoc: 431 | type: object 432 | properties: 433 | status_id: 434 | type: string 435 | description: The identifier used to get the status of the document using the status API. 436 | 437 | DocStatus: 438 | type: object 439 | properties: 440 | status: 441 | type: string 442 | description: The present status of the document. Can be queued, working, completed, and failed. 443 | download_url: 444 | type: string 445 | description: The URL where the document can be retrieved. This URL may only be used a few times. 446 | download_id: 447 | type: string 448 | description: The identifier for downloading the document with the download API. 449 | message: 450 | type: string 451 | description: Additional information. 452 | number_of_pages: 453 | type: integer 454 | description: Number of PDF pages in document. 455 | validation_errors: 456 | type: string 457 | description: Error information. 458 | 459 | -------------------------------------------------------------------------------- /lib/docraptor/models/doc.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | #DocRaptor 3 | 4 | #A native client library for the DocRaptor HTML to PDF/XLS service. 5 | 6 | The version of the OpenAPI document: 2.0.0 7 | 8 | Generated by: https://openapi-generator.tech 9 | OpenAPI Generator version: 6.6.0 10 | 11 | =end 12 | 13 | require 'date' 14 | require 'time' 15 | 16 | module DocRaptor 17 | class Doc 18 | # A name for identifying your document. 19 | attr_accessor :name 20 | 21 | # The type of document being created. 22 | attr_accessor :document_type 23 | 24 | # The HTML data to be transformed into a document. You must supply content using document_content or document_url. 25 | attr_accessor :document_content 26 | 27 | # The URL to fetch the HTML data to be transformed into a document. You must supply content using document_content or document_url. 28 | attr_accessor :document_url 29 | 30 | # Enable test mode for this document. Test documents are not charged for but include a watermark. 31 | attr_accessor :test 32 | 33 | # Specify a specific verison of the DocRaptor Pipeline to use. 34 | attr_accessor :pipeline 35 | 36 | # Force strict HTML validation. 37 | attr_accessor :strict 38 | 39 | # Failed loading of images/javascripts/stylesheets/etc. will not cause the rendering to stop. 40 | attr_accessor :ignore_resource_errors 41 | 42 | # Prevent console.log from stopping document rendering during JavaScript execution. 43 | attr_accessor :ignore_console_messages 44 | 45 | # A field for storing a small amount of metadata with this document. 46 | attr_accessor :tag 47 | 48 | # Request support help with this request if it succeeds. 49 | attr_accessor :help 50 | 51 | # Enable DocRaptor JavaScript parsing. PrinceXML JavaScript parsing is also available elsewhere. 52 | attr_accessor :javascript 53 | 54 | # Set HTTP referrer when generating this document. 55 | attr_accessor :referrer 56 | 57 | # A URL that will receive a POST request after successfully completing an asynchronous document. The POST data will include download_url and download_id similar to status API responses. WARNING: this only works on asynchronous documents. 58 | attr_accessor :callback_url 59 | 60 | # The number of times a hosted document can be downloaded. If no limit is specified, the document will be available for an unlimited number of downloads. 61 | attr_accessor :hosted_download_limit 62 | 63 | # The date and time at which a hosted document will be removed and no longer available. Must be a properly formatted ISO 8601 datetime, like 1981-01-23T08:02:30-05:00. 64 | attr_accessor :hosted_expires_at 65 | 66 | attr_accessor :prince_options 67 | 68 | class EnumAttributeValidator 69 | attr_reader :datatype 70 | attr_reader :allowable_values 71 | 72 | def initialize(datatype, allowable_values) 73 | @allowable_values = allowable_values.map do |value| 74 | case datatype.to_s 75 | when /Integer/i 76 | value.to_i 77 | when /Float/i 78 | value.to_f 79 | else 80 | value 81 | end 82 | end 83 | end 84 | 85 | def valid?(value) 86 | !value || allowable_values.include?(value) 87 | end 88 | end 89 | 90 | # Attribute mapping from ruby-style variable name to JSON key. 91 | def self.attribute_map 92 | { 93 | :'name' => :'name', 94 | :'document_type' => :'document_type', 95 | :'document_content' => :'document_content', 96 | :'document_url' => :'document_url', 97 | :'test' => :'test', 98 | :'pipeline' => :'pipeline', 99 | :'strict' => :'strict', 100 | :'ignore_resource_errors' => :'ignore_resource_errors', 101 | :'ignore_console_messages' => :'ignore_console_messages', 102 | :'tag' => :'tag', 103 | :'help' => :'help', 104 | :'javascript' => :'javascript', 105 | :'referrer' => :'referrer', 106 | :'callback_url' => :'callback_url', 107 | :'hosted_download_limit' => :'hosted_download_limit', 108 | :'hosted_expires_at' => :'hosted_expires_at', 109 | :'prince_options' => :'prince_options' 110 | } 111 | end 112 | 113 | # Returns all the JSON keys this model knows about 114 | def self.acceptable_attributes 115 | attribute_map.values 116 | end 117 | 118 | # Attribute type mapping. 119 | def self.openapi_types 120 | { 121 | :'name' => :'String', 122 | :'document_type' => :'String', 123 | :'document_content' => :'String', 124 | :'document_url' => :'String', 125 | :'test' => :'Boolean', 126 | :'pipeline' => :'String', 127 | :'strict' => :'String', 128 | :'ignore_resource_errors' => :'Boolean', 129 | :'ignore_console_messages' => :'Boolean', 130 | :'tag' => :'String', 131 | :'help' => :'Boolean', 132 | :'javascript' => :'Boolean', 133 | :'referrer' => :'String', 134 | :'callback_url' => :'String', 135 | :'hosted_download_limit' => :'Integer', 136 | :'hosted_expires_at' => :'String', 137 | :'prince_options' => :'PrinceOptions' 138 | } 139 | end 140 | 141 | # List of attributes with nullable: true 142 | def self.openapi_nullable 143 | Set.new([ 144 | ]) 145 | end 146 | 147 | # Initializes the object 148 | # @param [Hash] attributes Model attributes in the form of hash 149 | def initialize(attributes = {}) 150 | if (!attributes.is_a?(Hash)) 151 | fail ArgumentError, "The input argument (attributes) must be a hash in `DocRaptor::Doc` initialize method" 152 | end 153 | 154 | # check to see if the attribute exists and convert string to symbol for hash key 155 | attributes = attributes.each_with_object({}) { |(k, v), h| 156 | if (!self.class.attribute_map.key?(k.to_sym)) 157 | fail ArgumentError, "`#{k}` is not a valid attribute in `DocRaptor::Doc`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect 158 | end 159 | h[k.to_sym] = v 160 | } 161 | 162 | if attributes.key?(:'name') 163 | self.name = attributes[:'name'] 164 | end 165 | 166 | if attributes.key?(:'document_type') 167 | self.document_type = attributes[:'document_type'] 168 | end 169 | 170 | if attributes.key?(:'document_content') 171 | self.document_content = attributes[:'document_content'] 172 | end 173 | 174 | if attributes.key?(:'document_url') 175 | self.document_url = attributes[:'document_url'] 176 | end 177 | 178 | if attributes.key?(:'test') 179 | self.test = attributes[:'test'] 180 | else 181 | self.test = true 182 | end 183 | 184 | if attributes.key?(:'pipeline') 185 | self.pipeline = attributes[:'pipeline'] 186 | end 187 | 188 | if attributes.key?(:'strict') 189 | self.strict = attributes[:'strict'] 190 | end 191 | 192 | if attributes.key?(:'ignore_resource_errors') 193 | self.ignore_resource_errors = attributes[:'ignore_resource_errors'] 194 | else 195 | self.ignore_resource_errors = true 196 | end 197 | 198 | if attributes.key?(:'ignore_console_messages') 199 | self.ignore_console_messages = attributes[:'ignore_console_messages'] 200 | else 201 | self.ignore_console_messages = false 202 | end 203 | 204 | if attributes.key?(:'tag') 205 | self.tag = attributes[:'tag'] 206 | end 207 | 208 | if attributes.key?(:'help') 209 | self.help = attributes[:'help'] 210 | else 211 | self.help = false 212 | end 213 | 214 | if attributes.key?(:'javascript') 215 | self.javascript = attributes[:'javascript'] 216 | else 217 | self.javascript = false 218 | end 219 | 220 | if attributes.key?(:'referrer') 221 | self.referrer = attributes[:'referrer'] 222 | end 223 | 224 | if attributes.key?(:'callback_url') 225 | self.callback_url = attributes[:'callback_url'] 226 | end 227 | 228 | if attributes.key?(:'hosted_download_limit') 229 | self.hosted_download_limit = attributes[:'hosted_download_limit'] 230 | end 231 | 232 | if attributes.key?(:'hosted_expires_at') 233 | self.hosted_expires_at = attributes[:'hosted_expires_at'] 234 | end 235 | 236 | if attributes.key?(:'prince_options') 237 | self.prince_options = attributes[:'prince_options'] 238 | end 239 | end 240 | 241 | # Show invalid properties with the reasons. Usually used together with valid? 242 | # @return Array for valid properties with the reasons 243 | def list_invalid_properties 244 | invalid_properties = Array.new 245 | if @name.nil? 246 | invalid_properties.push('invalid value for "name", name cannot be nil.') 247 | end 248 | 249 | if @document_type.nil? 250 | invalid_properties.push('invalid value for "document_type", document_type cannot be nil.') 251 | end 252 | 253 | invalid_properties 254 | end 255 | 256 | # Check to see if the all the properties in the model are valid 257 | # @return true if the model is valid 258 | def valid? 259 | return false if @name.nil? 260 | return false if @document_type.nil? 261 | document_type_validator = EnumAttributeValidator.new('String', ["pdf", "xls", "xlsx"]) 262 | return false unless document_type_validator.valid?(@document_type) 263 | strict_validator = EnumAttributeValidator.new('String', ["none", "html"]) 264 | return false unless strict_validator.valid?(@strict) 265 | true 266 | end 267 | 268 | # Custom attribute writer method checking allowed values (enum). 269 | # @param [Object] document_type Object to be assigned 270 | def document_type=(document_type) 271 | validator = EnumAttributeValidator.new('String', ["pdf", "xls", "xlsx"]) 272 | unless validator.valid?(document_type) 273 | fail ArgumentError, "invalid value for \"document_type\", must be one of #{validator.allowable_values}." 274 | end 275 | @document_type = document_type 276 | end 277 | 278 | # Custom attribute writer method checking allowed values (enum). 279 | # @param [Object] strict Object to be assigned 280 | def strict=(strict) 281 | validator = EnumAttributeValidator.new('String', ["none", "html"]) 282 | unless validator.valid?(strict) 283 | fail ArgumentError, "invalid value for \"strict\", must be one of #{validator.allowable_values}." 284 | end 285 | @strict = strict 286 | end 287 | 288 | # Checks equality by comparing each attribute. 289 | # @param [Object] Object to be compared 290 | def ==(o) 291 | return true if self.equal?(o) 292 | self.class == o.class && 293 | name == o.name && 294 | document_type == o.document_type && 295 | document_content == o.document_content && 296 | document_url == o.document_url && 297 | test == o.test && 298 | pipeline == o.pipeline && 299 | strict == o.strict && 300 | ignore_resource_errors == o.ignore_resource_errors && 301 | ignore_console_messages == o.ignore_console_messages && 302 | tag == o.tag && 303 | help == o.help && 304 | javascript == o.javascript && 305 | referrer == o.referrer && 306 | callback_url == o.callback_url && 307 | hosted_download_limit == o.hosted_download_limit && 308 | hosted_expires_at == o.hosted_expires_at && 309 | prince_options == o.prince_options 310 | end 311 | 312 | # @see the `==` method 313 | # @param [Object] Object to be compared 314 | def eql?(o) 315 | self == o 316 | end 317 | 318 | # Calculates hash code according to all attributes. 319 | # @return [Integer] Hash code 320 | def hash 321 | [name, document_type, document_content, document_url, test, pipeline, strict, ignore_resource_errors, ignore_console_messages, tag, help, javascript, referrer, callback_url, hosted_download_limit, hosted_expires_at, prince_options].hash 322 | end 323 | 324 | # Builds the object from hash 325 | # @param [Hash] attributes Model attributes in the form of hash 326 | # @return [Object] Returns the model itself 327 | def self.build_from_hash(attributes) 328 | new.build_from_hash(attributes) 329 | end 330 | 331 | # Builds the object from hash 332 | # @param [Hash] attributes Model attributes in the form of hash 333 | # @return [Object] Returns the model itself 334 | def build_from_hash(attributes) 335 | return nil unless attributes.is_a?(Hash) 336 | attributes = attributes.transform_keys(&:to_sym) 337 | self.class.openapi_types.each_pair do |key, type| 338 | if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key) 339 | self.send("#{key}=", nil) 340 | elsif type =~ /\AArray<(.*)>/i 341 | # check to ensure the input is an array given that the attribute 342 | # is documented as an array but the input is not 343 | if attributes[self.class.attribute_map[key]].is_a?(Array) 344 | self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) }) 345 | end 346 | elsif !attributes[self.class.attribute_map[key]].nil? 347 | self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]])) 348 | end 349 | end 350 | 351 | self 352 | end 353 | 354 | # Deserializes the data based on type 355 | # @param string type Data type 356 | # @param string value Value to be deserialized 357 | # @return [Object] Deserialized data 358 | def _deserialize(type, value) 359 | case type.to_sym 360 | when :Time 361 | Time.parse(value) 362 | when :Date 363 | Date.parse(value) 364 | when :String 365 | value.to_s 366 | when :Integer 367 | value.to_i 368 | when :Float 369 | value.to_f 370 | when :Boolean 371 | if value.to_s =~ /\A(true|t|yes|y|1)\z/i 372 | true 373 | else 374 | false 375 | end 376 | when :Object 377 | # generic object (usually a Hash), return directly 378 | value 379 | when /\AArray<(?.+)>\z/ 380 | inner_type = Regexp.last_match[:inner_type] 381 | value.map { |v| _deserialize(inner_type, v) } 382 | when /\AHash<(?.+?), (?.+)>\z/ 383 | k_type = Regexp.last_match[:k_type] 384 | v_type = Regexp.last_match[:v_type] 385 | {}.tap do |hash| 386 | value.each do |k, v| 387 | hash[_deserialize(k_type, k)] = _deserialize(v_type, v) 388 | end 389 | end 390 | else # model 391 | # models (e.g. Pet) or oneOf 392 | klass = DocRaptor.const_get(type) 393 | klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value) 394 | end 395 | end 396 | 397 | # Returns the string representation of the object 398 | # @return [String] String presentation of the object 399 | def to_s 400 | to_hash.to_s 401 | end 402 | 403 | # to_body is an alias to to_hash (backward compatibility) 404 | # @return [Hash] Returns the object in the form of hash 405 | def to_body 406 | to_hash 407 | end 408 | 409 | # Returns the object in the form of hash 410 | # @return [Hash] Returns the object in the form of hash 411 | def to_hash 412 | hash = {} 413 | self.class.attribute_map.each_pair do |attr, param| 414 | value = self.send(attr) 415 | if value.nil? 416 | is_nullable = self.class.openapi_nullable.include?(attr) 417 | next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) 418 | end 419 | 420 | hash[param] = _to_hash(value) 421 | end 422 | hash 423 | end 424 | 425 | # Outputs non-array value in the form of hash 426 | # For object, use to_hash. Otherwise, just return the value 427 | # @param [Object] value Any valid value 428 | # @return [Hash] Returns the value in the form of hash 429 | def _to_hash(value) 430 | if value.is_a?(Array) 431 | value.compact.map { |v| _to_hash(v) } 432 | elsif value.is_a?(Hash) 433 | {}.tap do |hash| 434 | value.each { |k, v| hash[k] = _to_hash(v) } 435 | end 436 | elsif value.respond_to? :to_hash 437 | value.to_hash 438 | else 439 | value 440 | end 441 | end 442 | 443 | end 444 | 445 | end 446 | --------------------------------------------------------------------------------