Class: DocJuan::UrlGenerator
- Inherits:
-
Object
- Object
- DocJuan::UrlGenerator
- Defined in:
- lib/doc_juan/url_generator.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #authentication_credentials ⇒ Object
- #generate ⇒ Object
- #has_authentication_credentials? ⇒ Boolean
- #host ⇒ Object
-
#initialize(url, filename, format = 'pdf', options = {}) ⇒ UrlGenerator
constructor
A new instance of UrlGenerator.
- #public_key ⇒ Object
Constructor Details
#initialize(url, filename, format = 'pdf', options = {}) ⇒ UrlGenerator
Returns a new instance of UrlGenerator.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/doc_juan/url_generator.rb', line 12 def initialize url, filename, format = 'pdf', = {} @url = url @filename = filename.to_s @format = format = {} unless = .merge authentication_credentials if has_authentication_credentials? = raise NoHostGivenError if host == '' end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
10 11 12 |
# File 'lib/doc_juan/url_generator.rb', line 10 def filename @filename end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
10 11 12 |
# File 'lib/doc_juan/url_generator.rb', line 10 def format @format end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/doc_juan/url_generator.rb', line 10 def end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
10 11 12 |
# File 'lib/doc_juan/url_generator.rb', line 10 def url @url end |
Instance Method Details
#authentication_credentials ⇒ Object
49 50 51 52 53 54 |
# File 'lib/doc_juan/url_generator.rb', line 49 def authentication_credentials { username: DocJuan.config.username, password: DocJuan.config.password } end |
#generate ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/doc_juan/url_generator.rb', line 24 def generate params = [] params << "url=#{CGI.escape(url)}" params << "filename=#{CGI.escape(filename)}" params << "format=#{CGI.escape(format)}" .each do |k,v| params << "options[#{CGI.escape(k.to_s)}]=#{CGI.escape v.to_s}" end params << "key=#{public_key}" "#{host}/render?#{params.join('&')}" end |
#has_authentication_credentials? ⇒ Boolean
56 57 58 |
# File 'lib/doc_juan/url_generator.rb', line 56 def has_authentication_credentials? authentication_credentials.values.compact.any? end |
#host ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/doc_juan/url_generator.rb', line 41 def host @host ||= DocJuan.config.host.to_s.strip.tap do |host| if host != '' && ! host.start_with?('http') host.replace "http://#{host}" end end end |
#public_key ⇒ Object
37 38 39 |
# File 'lib/doc_juan/url_generator.rb', line 37 def public_key @public_key ||= DocJuan::Token.new(self).key end |