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 = end |
Instance Method Details
#pdf_from_url(full_url, options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# 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) = URI.encode_www_form(.delete_if {|k,v| v.nil?}) encoded_url = "#{@service_options[:server_url] || DEFAULT_PDF_SERVICE_URL}?url=#{Rack::Utils.escape(uri)}&#{options_as_query_string}" HTTParty.get(encoded_url, timeout: [:timeout] || DEFAULT_HTTP_TIMEOUT) end |