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) ⇒ Client
constructor
A new instance of Client.
- #post(html, pdf_options = {}) ⇒ Object
Constructor Details
#initialize(endpoint) ⇒ Client
Returns a new instance of Client.
10 11 12 |
# File 'lib/html2pdf/rails/client.rb', line 10 def initialize(endpoint) @uri = URI.parse(endpoint) end |
Class Method Details
.post(*args) ⇒ Object
6 7 8 |
# File 'lib/html2pdf/rails/client.rb', line 6 def self.post(*args) self.new(Html2Pdf.config.endpoint).post(*args) end |
Instance Method Details
#post(html, pdf_options = {}) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/html2pdf/rails/client.rb', line 14 def post(html, = {}) 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 = { html: html, pdfOptions: }.to_json http.request(request) end |