url2pdf 0.0.1
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 +7 -0
- data/.gitignore +15 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/Guardfile +39 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/lib/url2pdf.rb +31 -0
- data/lib/url2pdf/version.rb +3 -0
- data/spec/lib/url2pdf_spec.rb +90 -0
- data/url2pdf.gemspec +29 -0
- metadata +155 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9ddfeb99c849ccaccf8388ae63f53df0ec4c0502
|
4
|
+
data.tar.gz: 29badc8e2353cff4169f0bf473c1579182d015ca
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0c1028f5d5bfb86c629b93ebb53287708c0c9f3dcc7a908b935772e9044fba8ed539552f5a76741cc01c9cdeb51318ab0fda53cefcaa697409def3c7420b8240
|
7
|
+
data.tar.gz: 2ca0f60405fcc22faac6341b12d669ce5907871c530645441d816bb3e3d45898a6a72da1195d0609a0975c45f0842d47afb2f982fa9fe3e528f17a05543c3c0f
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
url2pdf
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.5
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
5
|
+
# directories %w(app lib config test spec features)
|
6
|
+
|
7
|
+
## Uncomment to clear the screen before every task
|
8
|
+
# clearing :on
|
9
|
+
|
10
|
+
## Guard internally checks for changes in the Guardfile and exits.
|
11
|
+
## If you want Guard to automatically start up again, run guard in a
|
12
|
+
## shell loop, e.g.:
|
13
|
+
##
|
14
|
+
## $ while bundle exec guard; do echo "Restarting Guard..."; done
|
15
|
+
##
|
16
|
+
## Note: if you are using the `directories` clause above and you are not
|
17
|
+
## watching the project directory ('.'), then you will want to move
|
18
|
+
## the Guardfile to a watched dir and symlink it back, e.g.
|
19
|
+
#
|
20
|
+
# $ mkdir config
|
21
|
+
# $ mv Guardfile config/
|
22
|
+
# $ ln -s config/Guardfile .
|
23
|
+
#
|
24
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
25
|
+
|
26
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
27
|
+
# rspec may be run, below are examples of the most common uses.
|
28
|
+
# * bundler: 'bundle exec rspec'
|
29
|
+
# * bundler binstubs: 'bin/rspec'
|
30
|
+
# * spring: 'bin/rspec' (This will use spring if running and you have
|
31
|
+
# installed the spring binstubs per the docs)
|
32
|
+
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
33
|
+
# * 'just' rspec: 'rspec'
|
34
|
+
|
35
|
+
guard :rspec, cmd: 'bundle exec rspec --color --format=documentation' do
|
36
|
+
watch(%r{^spec/.+_spec\.rb$})
|
37
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
38
|
+
watch('spec/spec_helper.rb') { "spec" }
|
39
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Nic Pillinger
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Url2pdf
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'url2pdf'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install url2pdf
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/url2pdf/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/url2pdf.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require "url2pdf/version"
|
2
|
+
require 'httparty'
|
3
|
+
require 'rack'
|
4
|
+
|
5
|
+
module Url2pdf
|
6
|
+
|
7
|
+
class Client
|
8
|
+
|
9
|
+
DEFAULT_PDF_SERVICE_URL = 'http://icanhazpdf.lsfapp.com/generate_pdf'
|
10
|
+
DEFAULT_HTTP_TIMEOUT = 10000
|
11
|
+
|
12
|
+
def initialize(api_key, options = {})
|
13
|
+
@api_key = api_key
|
14
|
+
@service_options = options
|
15
|
+
end
|
16
|
+
|
17
|
+
def pdf_from_url(full_url, options = {})
|
18
|
+
raise "API Key Is Required" if @api_key.nil?
|
19
|
+
uri = URI(full_url)
|
20
|
+
params = URI.decode_www_form(uri.query || "") << ['icanhazpdf', @api_key]
|
21
|
+
uri.query = URI.encode_www_form(params)
|
22
|
+
encoded_url = "#{@service_options[:server_url] || DEFAULT_PDF_SERVICE_URL}?url=#{Rack::Utils.escape(uri)}"
|
23
|
+
encoded_url += "&engine=#{options[:engine]}" if options.has_key?(:engine)
|
24
|
+
encoded_url += "&margin=#{options[:margin]}" if options.has_key?(:margin)
|
25
|
+
encoded_url += "&orientation=#{options[:orientation]}" if options.has_key?(:orientation)
|
26
|
+
|
27
|
+
HTTParty.get(encoded_url, timeout: @service_options[:timeout] || DEFAULT_HTTP_TIMEOUT)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'url2pdf'
|
2
|
+
|
3
|
+
describe "Url2pdf" do
|
4
|
+
|
5
|
+
describe "client pdf from url" do
|
6
|
+
let(:api_key) { "123abc" }
|
7
|
+
let(:options) { {} }
|
8
|
+
|
9
|
+
subject { Url2pdf::Client.new(api_key, options) }
|
10
|
+
|
11
|
+
before(:each) do
|
12
|
+
allow(HTTParty).to receive(:get)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'appends api_key to the url supplied' do
|
16
|
+
subject.pdf_from_url('http://a.url')
|
17
|
+
expect(HTTParty).to have_received(:get).with(/#{api_key}/, anything)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'escapes the url and params supplied so that it can be properly passed to the server' do
|
21
|
+
subject.pdf_from_url('http://google.com?param=something&another=different')
|
22
|
+
expect(HTTParty).to have_received(:get).with(/http%3A%2F%2Fgoogle.com%3Fparam%3Dsomething%26another%3Ddifferent/, anything)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'uses the default server unless otherwise specified' do
|
26
|
+
subject.pdf_from_url('http://a.url')
|
27
|
+
expect(HTTParty).to have_received(:get).with(/^#{Url2pdf::Client::DEFAULT_PDF_SERVICE_URL}/, anything)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'uses the default timeout unless otherwise specified' do
|
31
|
+
subject.pdf_from_url('http://a.url')
|
32
|
+
expect(HTTParty).to have_received(:get).with(anything, hash_including(timeout: Url2pdf::Client::DEFAULT_HTTP_TIMEOUT))
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'different pdf server is specified in options' do
|
36
|
+
let(:server_url) { "http://newicanhazserver.com" }
|
37
|
+
let(:options) { {server_url: server_url} }
|
38
|
+
|
39
|
+
it 'uses the server url supplied' do
|
40
|
+
subject.pdf_from_url('http://a.url')
|
41
|
+
expect(HTTParty).to have_received(:get).with(/^#{server_url}/, anything)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'timeout is specified in options' do
|
46
|
+
let(:timeout) { 2000 }
|
47
|
+
let(:options) { {timeout: timeout} }
|
48
|
+
|
49
|
+
it 'uses the http timeout supplied' do
|
50
|
+
subject.pdf_from_url('http://a.url')
|
51
|
+
expect(HTTParty).to have_received(:get).with(anything, hash_including(timeout: timeout))
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'no api key is supplied' do
|
56
|
+
let(:api_key) { nil }
|
57
|
+
|
58
|
+
it 'raises an eror' do
|
59
|
+
expect { subject.pdf_from_url('http://a.url') }.to raise_error("API Key Is Required")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe 'pdf options supplied' do
|
64
|
+
|
65
|
+
context 'margin' do
|
66
|
+
it 'passes the margin parameter to the server' do
|
67
|
+
subject.pdf_from_url('http://a.url', {margin: '5cm'})
|
68
|
+
expect(HTTParty).to have_received(:get).with(/margin=5cm/, anything)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'orientation' do
|
73
|
+
it 'passes the orientation parameter to the server' do
|
74
|
+
subject.pdf_from_url('http://a.url', {orientation: :landscape})
|
75
|
+
expect(HTTParty).to have_received(:get).with(/orientation=landscape/, anything)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'valid engine' do
|
80
|
+
it 'passes the engine parameter' do
|
81
|
+
subject.pdf_from_url('http://a.url', {engine: :phantomjs})
|
82
|
+
expect(HTTParty).to have_received(:get).with(/engine=phantomjs/, anything)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
data/url2pdf.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'url2pdf/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "url2pdf"
|
8
|
+
spec.version = Url2pdf::VERSION
|
9
|
+
spec.authors = ["Nic Pillinger"]
|
10
|
+
spec.email = ["nic@lsf.io"]
|
11
|
+
spec.summary = %q{ URL => PDF }
|
12
|
+
spec.description = %q{ Client for LSF PDF service }
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "rack", "~> 1.6"
|
22
|
+
spec.add_dependency "httparty", "~> 0.13.3"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.2"
|
27
|
+
spec.add_development_dependency "guard", "~> 2.12"
|
28
|
+
spec.add_development_dependency "guard-rspec", "~> 4.5"
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: url2pdf
|
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-03-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: httparty
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.13.3
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.13.3
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.2'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.2'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.12'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.12'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: guard-rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '4.5'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '4.5'
|
111
|
+
description: " Client for LSF PDF service "
|
112
|
+
email:
|
113
|
+
- nic@lsf.io
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".ruby-gemset"
|
120
|
+
- ".ruby-version"
|
121
|
+
- Gemfile
|
122
|
+
- Guardfile
|
123
|
+
- LICENSE.txt
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- lib/url2pdf.rb
|
127
|
+
- lib/url2pdf/version.rb
|
128
|
+
- spec/lib/url2pdf_spec.rb
|
129
|
+
- url2pdf.gemspec
|
130
|
+
homepage: ''
|
131
|
+
licenses:
|
132
|
+
- MIT
|
133
|
+
metadata: {}
|
134
|
+
post_install_message:
|
135
|
+
rdoc_options: []
|
136
|
+
require_paths:
|
137
|
+
- lib
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
requirements: []
|
149
|
+
rubyforge_project:
|
150
|
+
rubygems_version: 2.4.5
|
151
|
+
signing_key:
|
152
|
+
specification_version: 4
|
153
|
+
summary: URL => PDF
|
154
|
+
test_files:
|
155
|
+
- spec/lib/url2pdf_spec.rb
|