url2pdf_rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +23 -0
- data/lib/tasks/url2pdf_rails_tasks.rake +4 -0
- data/lib/url2pdf_rails.rb +9 -0
- data/lib/url2pdf_rails/authentication.rb +37 -0
- data/lib/url2pdf_rails/configuration.rb +27 -0
- data/lib/url2pdf_rails/pdf_generation.rb +22 -0
- data/lib/url2pdf_rails/version.rb +3 -0
- metadata +137 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 842d9398ac42378a91cc6bda95ad00271e546e85
|
4
|
+
data.tar.gz: 5b030f5b0fe48b9512507210f53441d75266a706
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7743ca0c82feb1c23f33f4787837d06810755227ac1577ffb9816bcdfe39e43985a71dc95dbe9e8fec6a9e38eba0a9e97ec2f1b2cbe432e745891fe2c93e357d
|
7
|
+
data.tar.gz: b9a7c26bed291b6af6e909666139625e2fbd03b6cae9125ce93f02335d0a672bd0e744b396a25480c1b0dca030d206f2782c05aa74b093955236ebc0d0d0c09a
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 Nic Pillinger
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Url2pdfRails'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
Bundler::GemHelper.install_tasks
|
23
|
+
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'url2pdf_rails/version'
|
2
|
+
require 'url2pdf_rails/configuration'
|
3
|
+
require 'url2pdf_rails/authentication'
|
4
|
+
require 'url2pdf_rails/pdf_generation'
|
5
|
+
|
6
|
+
ActiveSupport.on_load(:action_controller) do
|
7
|
+
include Url2pdfRails::Authentication
|
8
|
+
include Url2pdfRails::PdfGeneration
|
9
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'url2pdf_rails/configuration'
|
2
|
+
|
3
|
+
module Url2pdfRails
|
4
|
+
module Authentication
|
5
|
+
|
6
|
+
def self.included(base)
|
7
|
+
base.extend ClassMethods
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def authenticate_as_pdf_request!(options = {})
|
12
|
+
skip_filter = options.delete(:skip_filter)
|
13
|
+
devise_auth_model = options.delete(:devise_auth_model)
|
14
|
+
|
15
|
+
# should skip an existing authentication filter?
|
16
|
+
skip_before_filter skip_filter, options if skip_filter.present?
|
17
|
+
|
18
|
+
# add our filter for authentication
|
19
|
+
authenticate_as_icanhazpdf_or_devise = -> do
|
20
|
+
devise_auth_model ||= 'user'
|
21
|
+
devise_auth_method = "authenticate_#{devise_auth_model}!"
|
22
|
+
head 401 unless valid_icanhazpdf_request? || (self.respond_to?(devise_auth_method) && self.send(devise_auth_method))
|
23
|
+
end
|
24
|
+
|
25
|
+
before_filter authenticate_as_icanhazpdf_or_devise, options
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def valid_icanhazpdf_request?
|
32
|
+
return false unless params[:icanhazpdf].present?
|
33
|
+
return params[:icanhazpdf] == Configuration.get_api_key
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,27 @@
|
|
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
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'url2pdf_rails/configuration'
|
2
|
+
require 'url2pdf'
|
3
|
+
|
4
|
+
module Url2pdfRails
|
5
|
+
module PdfGeneration
|
6
|
+
|
7
|
+
# generate and render a pdf from a url
|
8
|
+
def render_pdf_from(url, options = {})
|
9
|
+
http_response = get_pdf_from url, options
|
10
|
+
raise "Failed to generate pdf:\nCode: #{http_response.code}\nBody:\n#{http_response.body}" unless http_response.code == 200
|
11
|
+
|
12
|
+
filename = options[:filename] || "#{Date.today.to_s(:number)}.pdf"
|
13
|
+
send_data http_response, :filename => filename, :type => :pdf
|
14
|
+
end
|
15
|
+
|
16
|
+
# generate a pdf and return the http response
|
17
|
+
def get_pdf_from(url, options = {})
|
18
|
+
Url2pdf::Client.new(Configuration.get_api_key).pdf_from_url(url, options)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: url2pdf_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nic Pillinger
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: url2pdf
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.0.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.0.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard-rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.5'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '4.5'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: vcr
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.9'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.9'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Description of Url2pdfRails.
|
98
|
+
email:
|
99
|
+
- nic@lsf.io
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- MIT-LICENSE
|
105
|
+
- README.rdoc
|
106
|
+
- Rakefile
|
107
|
+
- lib/tasks/url2pdf_rails_tasks.rake
|
108
|
+
- lib/url2pdf_rails.rb
|
109
|
+
- lib/url2pdf_rails/authentication.rb
|
110
|
+
- lib/url2pdf_rails/configuration.rb
|
111
|
+
- lib/url2pdf_rails/pdf_generation.rb
|
112
|
+
- lib/url2pdf_rails/version.rb
|
113
|
+
homepage: http://factory3.io
|
114
|
+
licenses:
|
115
|
+
- MIT
|
116
|
+
metadata: {}
|
117
|
+
post_install_message:
|
118
|
+
rdoc_options: []
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
requirements: []
|
132
|
+
rubyforge_project:
|
133
|
+
rubygems_version: 2.4.5
|
134
|
+
signing_key:
|
135
|
+
specification_version: 4
|
136
|
+
summary: Summary of Url2pdfRails.
|
137
|
+
test_files: []
|