Class: Url2pdf::Client
- Inherits:
-
Object
- Object
- Url2pdf::Client
- Defined in:
- lib/url2pdf.rb
Constant Summary collapse
- DEFAULT_PDF_SERVICE_URL =
'http://icanhazpdf.lsfapp.com/generate_pdf'- DEFAULT_HTTP_TIMEOUT =
10000
Instance Method Summary collapse
-
#initialize(api_key, options = {}) ⇒ Client
constructor
A new instance of Client.
- #pdf_from_url(full_url, options = {}) ⇒ Object
Constructor Details
#initialize(api_key, options = {}) ⇒ Client
Returns a new instance of Client.
12 13 14 15 |
# File 'lib/url2pdf.rb', line 12 def initialize(api_key, = {}) @api_key = api_key @service_options = end |
Instance Method Details
#pdf_from_url(full_url, options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/url2pdf.rb', line 17 def pdf_from_url(full_url, = {}) raise "API Key Is Required" if @api_key.nil? uri = URI(full_url) params = URI.decode_www_form(uri.query || "") << ['icanhazpdf', @api_key] uri.query = URI.encode_www_form(params) encoded_url = "#{@service_options[:server_url] || DEFAULT_PDF_SERVICE_URL}?url=#{Rack::Utils.escape(uri)}" encoded_url += "&engine=#{[:engine]}" if .has_key?(:engine) encoded_url += "&margin=#{[:margin]}" if .has_key?(:margin) encoded_url += "&orientation=#{[:orientation]}" if .has_key?(:orientation) HTTParty.get(encoded_url, timeout: @service_options[:timeout] || DEFAULT_HTTP_TIMEOUT) end |