url2pdf_rails 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/url2pdf_rails/authentication.rb +35 -10
- data/lib/url2pdf_rails/pdf_generation.rb +4 -2
- data/lib/url2pdf_rails/version.rb +1 -1
- data/lib/url2pdf_rails.rb +0 -1
- metadata +1 -2
- data/lib/url2pdf_rails/configuration.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3671c66a178b53f820c8faa22edec66d6ea77129
|
4
|
+
data.tar.gz: 3a062c5799bfdef4c670d6c5701c37d809cdca7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66a6443841919266c67a9aefb6d0f7b03fd9c17236125a07aba7867b31356afd59e9c088c25f34583f7feb7ba9d0fb5a6bf02e29eead8f87ce52f5b5a1d97c10
|
7
|
+
data.tar.gz: cf68378ead0cf8d34747cff46602aa5133eaf926ab3c607097ecd7db0ffb33bc65002909d1d9a39826df1afe02eb23d91b6f238ceccdba46345847af0602f2e0
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'url2pdf_rails/configuration'
|
2
|
-
|
3
1
|
module Url2pdfRails
|
4
2
|
module Authentication
|
5
3
|
|
@@ -10,27 +8,54 @@ module Url2pdfRails
|
|
10
8
|
module ClassMethods
|
11
9
|
def authenticate_as_pdf_request!(options = {})
|
12
10
|
skip_filter = options.delete(:skip_filter)
|
13
|
-
|
11
|
+
devise_fallback = options.delete(:devise_fallback)
|
14
12
|
|
15
|
-
# should skip
|
13
|
+
# should skip any before filters?
|
16
14
|
skip_before_filter skip_filter, options if skip_filter.present?
|
17
15
|
|
18
|
-
#
|
19
|
-
|
20
|
-
devise_auth_model ||= 'user'
|
16
|
+
# skip devise authentication filters if present
|
17
|
+
devise_fallback.each do |devise_auth_model|
|
21
18
|
devise_auth_method = "authenticate_#{devise_auth_model}!"
|
22
|
-
|
23
|
-
end
|
19
|
+
skip_before_filter devise_auth_method.to_sym, options
|
20
|
+
end if devise_fallback.present?
|
24
21
|
|
22
|
+
# try authenticate as pdf request and then fallback to devise if supplied
|
23
|
+
authenticate_as_icanhazpdf_or_devise = -> do
|
24
|
+
if valid_icanhazpdf_request?
|
25
|
+
@authenticated_pdf_request = true
|
26
|
+
return
|
27
|
+
end
|
28
|
+
head 401 and return unless devise_fallback.present?
|
29
|
+
devise_fallback.each do |devise_auth_model|
|
30
|
+
devise_signed_in_method = "#{devise_auth_model}_signed_in?"
|
31
|
+
if self.respond_to?(devise_signed_in_method) && self.send(devise_signed_in_method)
|
32
|
+
@authenticated_devise_request = true
|
33
|
+
return
|
34
|
+
end
|
35
|
+
end
|
36
|
+
head 401
|
37
|
+
end
|
25
38
|
before_filter authenticate_as_icanhazpdf_or_devise, options
|
26
39
|
end
|
27
40
|
end
|
28
41
|
|
42
|
+
def authenticated_pdf_request?
|
43
|
+
@authenticated_pdf_request || false
|
44
|
+
end
|
45
|
+
|
46
|
+
def authenticated_devise_request?
|
47
|
+
@authenticated_devise_request || false
|
48
|
+
end
|
49
|
+
|
50
|
+
def authenticated_request?
|
51
|
+
authenticated_pdf_request? || authenticated_devise_request?
|
52
|
+
end
|
53
|
+
|
29
54
|
private
|
30
55
|
|
31
56
|
def valid_icanhazpdf_request?
|
32
57
|
return false unless params[:icanhazpdf].present?
|
33
|
-
return params[:icanhazpdf] ==
|
58
|
+
return params[:icanhazpdf] == Rails.configuration.url2pdf_api_key
|
34
59
|
end
|
35
60
|
|
36
61
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'url2pdf_rails/configuration'
|
2
1
|
require 'url2pdf'
|
3
2
|
|
4
3
|
module Url2pdfRails
|
@@ -15,7 +14,10 @@ module Url2pdfRails
|
|
15
14
|
|
16
15
|
# generate a pdf and return the http response
|
17
16
|
def get_pdf_from(url, options = {})
|
18
|
-
|
17
|
+
server_options = {}
|
18
|
+
server_options.merge!(server_url: Rails.configuration.url2pdf_server_url) if Rails.configuration.respond_to?(:url2pdf_server_url)
|
19
|
+
server_options.merge!(timeout: Rails.configuration.url2pdf_timeout) if Rails.configuration.respond_to?(:url2pdf_timeout)
|
20
|
+
Url2pdf::Client.new(Rails.configuration.url2pdf_api_key, server_options).pdf_from_url(url, options)
|
19
21
|
end
|
20
22
|
|
21
23
|
end
|
data/lib/url2pdf_rails.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: url2pdf_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nic Pillinger
|
@@ -107,7 +107,6 @@ files:
|
|
107
107
|
- lib/tasks/url2pdf_rails_tasks.rake
|
108
108
|
- lib/url2pdf_rails.rb
|
109
109
|
- lib/url2pdf_rails/authentication.rb
|
110
|
-
- lib/url2pdf_rails/configuration.rb
|
111
110
|
- lib/url2pdf_rails/pdf_generation.rb
|
112
111
|
- lib/url2pdf_rails/version.rb
|
113
112
|
homepage: http://factory3.io
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module Url2pdfRails
|
2
|
-
class Configuration
|
3
|
-
|
4
|
-
def self.method_missing(method_sym, *arguments, &block)
|
5
|
-
# the first argument is a Symbol, so you need to_s it if you want to pattern match
|
6
|
-
if method_sym.to_s =~ /^get_(.*)$/
|
7
|
-
get_config_for("url2pdf_#{$1}".to_sym)
|
8
|
-
else
|
9
|
-
super
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.respond_to?(method_sym, include_private = false)
|
14
|
-
if method_sym.to_s =~ /^get_(.*)$/
|
15
|
-
true
|
16
|
-
else
|
17
|
-
super
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def self.get_config_for(config_parameter)
|
24
|
-
Rails.configuration.respond_to?(config_parameter) ? Rails.configuration.send(config_parameter) : nil
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|