icanhazpdf 0.0.2 → 0.0.3
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/Gemfile.lock +2 -2
- data/README.md +9 -12
- data/icanhazpdf.gemspec +5 -5
- data/lib/icanhazpdf.rb +3 -0
- data/lib/{i_can_haz_pdf → icanhazpdf}/client.rb +3 -4
- data/lib/{i_can_haz_pdf → icanhazpdf}/controller.rb +6 -6
- data/lib/icanhazpdf/version.rb +3 -0
- data/spec/lib/{i_can_haz_pdf → icanhazpdf}/client_spec.rb +4 -4
- data/spec/lib/{i_can_haz_pdf → icanhazpdf}/controller_spec.rb +7 -7
- data/spec/spec_helper.rb +1 -1
- metadata +13 -13
- data/lib/i_can_haz_pdf.rb +0 -3
- data/lib/i_can_haz_pdf/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e3c30c84c3d9365171cfbac2fa8ce06df2f39ba
|
4
|
+
data.tar.gz: b4203af5b4d792c4e6d9965b4481fdfeebc71450
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7c0459fce0eb5c775659d2cff2e1f7db3bdde6016b2cb256898aedde7bbb77828a8bb668274d59bf32c4f6628ee8d1b533ee0987c3baf81c2c92f11e93b6583
|
7
|
+
data.tar.gz: 4ddb25a90930ccf0b3dce7368321735ec97f573a646253c30f47d261094e6de538b13610d50fdea30d9f35a5e7d587b4b109b720c6cd310f6f58a79cd99fff3d
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
|
4
|
+
Icanhazpdf (0.0.2)
|
5
5
|
activesupport (~> 4.0)
|
6
6
|
httparty (~> 0.13)
|
7
7
|
|
@@ -75,9 +75,9 @@ PLATFORMS
|
|
75
75
|
ruby
|
76
76
|
|
77
77
|
DEPENDENCIES
|
78
|
+
Icanhazpdf!
|
78
79
|
bundler (~> 1.6)
|
79
80
|
guard-rspec (~> 4.3)
|
80
|
-
icanhazpdf!
|
81
81
|
pry (~> 0.10)
|
82
82
|
rake (~> 10.3)
|
83
83
|
rspec (~> 3.0)
|
data/README.md
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
# ICanHazPDF?
|
2
|
-
Makes using the
|
2
|
+
Makes using the icanhazpdf service in a Rails app simples
|
3
3
|
|
4
4
|
## Installation
|
5
5
|
|
6
6
|
Add this line to your application's Gemfile:
|
7
7
|
|
8
|
-
gem 'icanhazpdf', '~> 0.0.
|
8
|
+
gem 'icanhazpdf', '~> 0.0.3'
|
9
9
|
|
10
10
|
## Client
|
11
11
|
|
12
12
|
To request a pdf is generated (and sent back to you synchronously) use the
|
13
13
|
api Client class.
|
14
14
|
|
15
|
-
pdf_response =
|
15
|
+
pdf_response = Icanhazpdf::Client.new.pdf_from_url my_resource_url(resource)
|
16
16
|
|
17
17
|
Your api key is automatically appended to the request.
|
18
18
|
The response is the web response from HTTParty. You can then render this or save
|
@@ -24,7 +24,7 @@ the pdf_response.code to ensure it was successful (should be 200).
|
|
24
24
|
To render a pdf (send the file to the browser) from a url use the renderer module.
|
25
25
|
|
26
26
|
class MyController < ApplicationController
|
27
|
-
include
|
27
|
+
include Icanhazpdf::Controller::Renderer
|
28
28
|
|
29
29
|
def my_action
|
30
30
|
render_pdf_from my_resource_url(resource), 'myfilename.pdf'
|
@@ -38,10 +38,10 @@ filename is used.
|
|
38
38
|
To render a pdf using a previous response from the Client use:
|
39
39
|
|
40
40
|
class MyController < ApplicationController
|
41
|
-
include
|
41
|
+
include Icanhazpdf::Controller::Renderer
|
42
42
|
|
43
43
|
def my_action
|
44
|
-
pdf_response =
|
44
|
+
pdf_response = Icanhazpdf::Client.new.pdf_from_url my_resource_url(resource)
|
45
45
|
|
46
46
|
# do something with the response? save somewhere? upload somewhere?
|
47
47
|
|
@@ -52,12 +52,10 @@ To render a pdf using a previous response from the Client use:
|
|
52
52
|
## Authentication
|
53
53
|
|
54
54
|
Checks the current request being made is coming from the icanhazpdf service and
|
55
|
-
has your configured
|
56
|
-
|
57
|
-
require 'i_can_haz_pdf/controller'
|
55
|
+
has your configured Icanhazapi key in the parameters
|
58
56
|
|
59
57
|
class Api::ApiController < ActionController::Base
|
60
|
-
include
|
58
|
+
include Icanhazpdf::Controller::Authentication
|
61
59
|
|
62
60
|
before_filter :authenticate
|
63
61
|
|
@@ -73,10 +71,9 @@ has your configured icanhazapi key in the parameters
|
|
73
71
|
Checks if the request is either from icanhazpdf or if that fails falls back to
|
74
72
|
devise authentication
|
75
73
|
|
76
|
-
require 'i_can_haz_pdf/controller'
|
77
74
|
|
78
75
|
class Api::ApiController < ActionController::Base
|
79
|
-
include
|
76
|
+
include Icanhazpdf::Controller::Authentication
|
80
77
|
|
81
78
|
before_filter :authenticate_as_icanhazpdf_or_authenticate_user!
|
82
79
|
end
|
data/icanhazpdf.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require '
|
4
|
+
require 'icanhazpdf/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "icanhazpdf"
|
8
|
-
spec.version =
|
8
|
+
spec.version = Icanhazpdf::VERSION
|
9
9
|
spec.authors = ["Nic Pillinger"]
|
10
|
-
spec.email = ["nic@
|
11
|
-
spec.summary = '
|
12
|
-
spec.description = 'Rails gem for generating and serving pdfs using
|
10
|
+
spec.email = ["nic@lsf.io"]
|
11
|
+
spec.summary = 'icanhazpdf'
|
12
|
+
spec.description = 'Rails gem for generating and serving pdfs using icanhazpdf service'
|
13
13
|
spec.homepage = "http://icanhazpdf.lsfapp.com"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
data/lib/icanhazpdf.rb
ADDED
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
module ICanHazPdf
|
1
|
+
module Icanhazpdf
|
3
2
|
|
4
3
|
# include in order to request generation of pdfs from the icanhazpf service
|
5
4
|
# requires that icanhazpdf_api_key is configured in your environment config
|
@@ -21,12 +20,12 @@ module ICanHazPdf
|
|
21
20
|
# generate a pdf from the url passed
|
22
21
|
def pdf_from_url(full_url)
|
23
22
|
uri = URI(full_url)
|
24
|
-
params = URI.decode_www_form(uri.query || "") << ['icanhazpdf',
|
23
|
+
params = URI.decode_www_form(uri.query || "") << ['icanhazpdf', Icanhazpdf::Client::api_key]
|
25
24
|
uri.query = URI.encode_www_form(params)
|
26
25
|
begin
|
27
26
|
service_url = Rails.configuration.icanhazpdf_url
|
28
27
|
rescue
|
29
|
-
service_url =
|
28
|
+
service_url = Icanhazpdf::Client.default_service_url
|
30
29
|
end
|
31
30
|
encoded_url = "#{service_url}/#{URI.encode(uri.to_s).gsub(':', '%3A').gsub('/', '%2F').gsub('?', '%3F').gsub('=', '%3D')}"
|
32
31
|
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require '
|
1
|
+
require 'icanhazpdf/client'
|
2
2
|
require 'active_support/core_ext/date_time/conversions'
|
3
3
|
|
4
|
-
module
|
4
|
+
module Icanhazpdf
|
5
5
|
|
6
6
|
module Controller
|
7
7
|
# include in a controller and use to render pdfs or authenticate requests
|
@@ -12,7 +12,7 @@ module ICanHazPdf
|
|
12
12
|
def render_pdf_from(url, filename = "")
|
13
13
|
options = {}
|
14
14
|
options[:filename] = filename if filename.present?
|
15
|
-
render_response_for
|
15
|
+
render_response_for Icanhazpdf::Client.new.pdf_from_url(url), options
|
16
16
|
end
|
17
17
|
|
18
18
|
# send the pdf to the user if its a valid file
|
@@ -28,13 +28,13 @@ module ICanHazPdf
|
|
28
28
|
end
|
29
29
|
|
30
30
|
module Authentication
|
31
|
-
# true if the request includes the correct
|
31
|
+
# true if the request includes the correct Icanhazpdf api key
|
32
32
|
def authenticate_as_icanhazpdf
|
33
33
|
return false unless params[:icanhazpdf].present?
|
34
|
-
return params[:icanhazpdf] ==
|
34
|
+
return params[:icanhazpdf] == Icanhazpdf::Client::api_key
|
35
35
|
end
|
36
36
|
|
37
|
-
# attemps to authenticate as
|
37
|
+
# attemps to authenticate as Icanhazpdf and falls back to devise
|
38
38
|
def authenticate_as_icanhazpdf_or_authenticate_user!
|
39
39
|
authenticate_as_icanhazpdf || authenticate_user!
|
40
40
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'httparty'
|
3
3
|
|
4
|
-
describe '
|
4
|
+
describe 'Icanhazpdf::Client' do
|
5
5
|
|
6
6
|
let(:a_url) { "http://a.url.to/generate_a_pdf_from?with=querystring" }
|
7
|
-
subject {
|
7
|
+
subject { Icanhazpdf::Client.new }
|
8
8
|
|
9
9
|
describe 'generating a pdf from' do
|
10
10
|
let(:http_response) { double("http_response") }
|
@@ -42,7 +42,7 @@ describe 'ICanHazPdf::Client' do
|
|
42
42
|
@result = subject.pdf_from_url a_url
|
43
43
|
end
|
44
44
|
|
45
|
-
context 'no
|
45
|
+
context 'no ocanhazpdf api key in the config' do
|
46
46
|
before(:each) do
|
47
47
|
allow(rails_config).to receive(:icanhazpdf_api_key).and_raise("Undefined config value")
|
48
48
|
end
|
@@ -58,7 +58,7 @@ describe 'ICanHazPdf::Client' do
|
|
58
58
|
end
|
59
59
|
|
60
60
|
it 'uses the default service url' do
|
61
|
-
expect(HTTParty).to receive(:get).with(include(
|
61
|
+
expect(HTTParty).to receive(:get).with(include(Icanhazpdf::Client.default_service_url), be_an(Hash))
|
62
62
|
@result = subject.pdf_from_url a_url
|
63
63
|
end
|
64
64
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "
|
3
|
+
describe "Icanhazpdf::Controller::Renderer" do
|
4
4
|
|
5
5
|
class DummyRailsController
|
6
|
-
include
|
6
|
+
include Icanhazpdf::Controller::Renderer
|
7
7
|
end
|
8
8
|
|
9
9
|
let(:url) { 'http://google.com' }
|
@@ -14,7 +14,7 @@ describe "ICanHazPdf::Controller::Renderer" do
|
|
14
14
|
let(:http_body) { "pdf content" }
|
15
15
|
|
16
16
|
before(:each) do
|
17
|
-
allow(
|
17
|
+
allow(Icanhazpdf::Client).to receive(:new).and_return(client)
|
18
18
|
allow(client).to receive(:pdf_from_url).and_return(http_response)
|
19
19
|
allow(http_response).to receive(:code).and_return http_status
|
20
20
|
allow(http_response).to receive(:body).and_return http_body
|
@@ -26,7 +26,7 @@ describe "ICanHazPdf::Controller::Renderer" do
|
|
26
26
|
describe 'rendering a pdf from a url' do
|
27
27
|
|
28
28
|
it 'creates a client to request the pdf' do
|
29
|
-
expect(
|
29
|
+
expect(Icanhazpdf::Client).to receive(:new)
|
30
30
|
subject.render_pdf_from url, filename
|
31
31
|
end
|
32
32
|
|
@@ -79,10 +79,10 @@ describe "ICanHazPdf::Controller::Renderer" do
|
|
79
79
|
|
80
80
|
end
|
81
81
|
|
82
|
-
describe "
|
82
|
+
describe "Icanhazpdf::Controller::Authentication" do
|
83
83
|
|
84
84
|
class DummyRailsController
|
85
|
-
include
|
85
|
+
include Icanhazpdf::Controller::Authentication
|
86
86
|
end
|
87
87
|
|
88
88
|
subject { DummyRailsController.new }
|
@@ -90,7 +90,7 @@ describe "ICanHazPdf::Controller::Authentication" do
|
|
90
90
|
let(:the_api_key) { '34765236754673256735' }
|
91
91
|
|
92
92
|
before(:each) do
|
93
|
-
allow(
|
93
|
+
allow(Icanhazpdf::Client).to receive(:api_key).and_return(the_api_key)
|
94
94
|
allow(subject).to receive(:params).and_return(params)
|
95
95
|
end
|
96
96
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require '
|
1
|
+
require 'icanhazpdf'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: icanhazpdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nic Pillinger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,9 +108,9 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0.13'
|
111
|
-
description: Rails gem for generating and serving pdfs using
|
111
|
+
description: Rails gem for generating and serving pdfs using icanhazpdf service
|
112
112
|
email:
|
113
|
-
- nic@
|
113
|
+
- nic@lsf.io
|
114
114
|
executables: []
|
115
115
|
extensions: []
|
116
116
|
extra_rdoc_files: []
|
@@ -123,12 +123,12 @@ files:
|
|
123
123
|
- README.md
|
124
124
|
- Rakefile
|
125
125
|
- icanhazpdf.gemspec
|
126
|
-
- lib/
|
127
|
-
- lib/
|
128
|
-
- lib/
|
129
|
-
- lib/
|
130
|
-
- spec/lib/
|
131
|
-
- spec/lib/
|
126
|
+
- lib/icanhazpdf.rb
|
127
|
+
- lib/icanhazpdf/client.rb
|
128
|
+
- lib/icanhazpdf/controller.rb
|
129
|
+
- lib/icanhazpdf/version.rb
|
130
|
+
- spec/lib/icanhazpdf/client_spec.rb
|
131
|
+
- spec/lib/icanhazpdf/controller_spec.rb
|
132
132
|
- spec/spec_helper.rb
|
133
133
|
homepage: http://icanhazpdf.lsfapp.com
|
134
134
|
licenses:
|
@@ -153,8 +153,8 @@ rubyforge_project:
|
|
153
153
|
rubygems_version: 2.2.2
|
154
154
|
signing_key:
|
155
155
|
specification_version: 4
|
156
|
-
summary:
|
156
|
+
summary: icanhazpdf
|
157
157
|
test_files:
|
158
|
-
- spec/lib/
|
159
|
-
- spec/lib/
|
158
|
+
- spec/lib/icanhazpdf/client_spec.rb
|
159
|
+
- spec/lib/icanhazpdf/controller_spec.rb
|
160
160
|
- spec/spec_helper.rb
|
data/lib/i_can_haz_pdf.rb
DELETED