Class: Icanhazpdf::Client
- Inherits:
-
Object
- Object
- Icanhazpdf::Client
- Defined in:
- lib/icanhazpdf/client.rb
Overview
include in order to request generation of pdfs from the icanhazpf service requires that icanhazpdf_api_key is configured in your environment config
Class Method Summary collapse
-
.api_key ⇒ Object
your icanhazpf api key.
- .default_service_url ⇒ Object
Instance Method Summary collapse
-
#pdf_from_url(full_url, options = {}) ⇒ Object
generate a pdf from the url passed.
Class Method Details
.api_key ⇒ Object
your icanhazpf api key
8 9 10 11 12 13 14 |
# File 'lib/icanhazpdf/client.rb', line 8 def self.api_key begin Rails.configuration.icanhazpdf_api_key rescue raise "No API Key Configured" end end |
.default_service_url ⇒ Object
16 17 18 |
# File 'lib/icanhazpdf/client.rb', line 16 def self.default_service_url 'http://icanhazpdf.lsfapp.com/generate_pdf' end |
Instance Method Details
#pdf_from_url(full_url, options = {}) ⇒ Object
generate a pdf from the url passed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/icanhazpdf/client.rb', line 21 def pdf_from_url(full_url, = {}) uri = URI(full_url) params = URI.decode_www_form(uri.query || "") << ['icanhazpdf', Icanhazpdf::Client::api_key] uri.query = URI.encode_www_form(params) begin service_url = Rails.configuration.icanhazpdf_url rescue service_url = Icanhazpdf::Client.default_service_url end encoded_url = "#{service_url}?url=#{URI.encode(uri.to_s).gsub(':', '%3A').gsub('/', '%2F').gsub('?', '%3F').gsub('=', '%3D').gsub('&', '%26')}" encoded_url += "&use_wkhtmltopdf=true" if .has_key?(:use_wkhtmltopdf) && [:use_wkhtmltopdf] == true encoded_url += "&margin=#{[:margin]}" if .has_key?(:margin) encoded_url += "&landscape=true" if .has_key?(:landscape) && [:landscape] == true HTTParty.get(encoded_url, :timeout => 10000) end |