Class: Html2Pdf::Rails::Client
- Inherits:
-
Object
- Object
- Html2Pdf::Rails::Client
- Defined in:
- lib/html2pdf/rails/client.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(endpoint, app) ⇒ Client
constructor
A new instance of Client.
- #post(html:, put_to_storage: false, file_name: nil, disposition: nil, pdf_options: {}) ⇒ Object
Constructor Details
#initialize(endpoint, app) ⇒ Client
Returns a new instance of Client.
12 13 14 15 |
# File 'lib/html2pdf/rails/client.rb', line 12 def initialize(endpoint, app) @uri = URI.parse(endpoint) @app = app end |
Class Method Details
.post(**options) ⇒ Object
8 9 10 |
# File 'lib/html2pdf/rails/client.rb', line 8 def self.post(**) self.new(Html2Pdf.config.endpoint, Html2Pdf.config.app).post(**) end |
Instance Method Details
#post(html:, put_to_storage: false, file_name: nil, disposition: nil, pdf_options: {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/html2pdf/rails/client.rb', line 17 def post(html:, put_to_storage: false, file_name: nil, disposition: nil, pdf_options: {}) http = Net::HTTP.new(@uri.host, @uri.port).tap { |h| h.use_ssl = @uri.scheme == 'https' } request = Net::HTTP::Post.new(@uri.request_uri, headers) request.body = { app: @app, html: html, putToStorage: put_to_storage, fileName: file_name, responseDisposition: disposition, pdfOptions: }.to_json response = http.request(request) case response.code when '200' response.body when '503' raise Html2Pdf::Rails::ServiceUnavailableError.new(response) else raise Html2Pdf::Rails::RequestError.new(response) end rescue Net::ReadTimeout raise Html2Pdf::Rails::NetworkError end |