Class: HyperPDF
- Inherits:
-
Object
- Object
- HyperPDF
- Defined in:
- lib/hyperpdf.rb,
lib/hyperpdf/version.rb,
lib/hyperpdf/exceptions.rb
Defined Under Namespace
Classes: AuthorizationRequired, ContentRequired, InternalServerError, NoSuchBucket, PaymentRequired
Constant Summary collapse
- VERSION =
"0.2.1"
Instance Method Summary collapse
-
#get ⇒ String
Generates PDF.
-
#initialize(content, options = {}) ⇒ HyperPDF
constructor
Initializes new HyperPDF object.
-
#upload_to_s3(bucket, key, public = false) ⇒ String
Generates PDF and uploads it to AWS S3.
Constructor Details
#initialize(content, options = {}) ⇒ HyperPDF
Initializes new HyperPDF object
Full list of PDF options see on HyperPDF page
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/hyperpdf.rb', line 16 def initialize(content, = {}) raise HyperPDF::ContentRequired if content.nil? || content.empty? @content = content @options = @user = @options.delete(:user) || ENV["HYPERPDF_USER"] @password = @options.delete(:password) || ENV["HYPERPDF_PASSWORD"] @request_body = { user: @user, password: @password, content: @content, options: @options } end |
Instance Method Details
#get ⇒ String
Generates PDF
30 31 32 |
# File 'lib/hyperpdf.rb', line 30 def get make_request.body end |
#upload_to_s3(bucket, key, public = false) ⇒ String
Generates PDF and uploads it to AWS S3
40 41 42 43 44 |
# File 'lib/hyperpdf.rb', line 40 def upload_to_s3(bucket, key, public = false) @request_body.merge!(bucket: bucket, key: key, public: public) resp = JSON.parse make_request.body resp["url"] || resp["id"] end |