paperplane-rb 0.1.6 → 0.1.8
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 +0 -2
- data/Gemfile.lock +11 -2
- data/README.md +33 -14
- data/lib/paperplane/config.rb +11 -0
- data/lib/paperplane/error.rb +5 -1
- data/lib/paperplane/version.rb +1 -1
- data/lib/paperplane.rb +35 -36
- data/paperplane.gemspec +1 -0
- metadata +16 -2
- data/sig/paperplane.rbs +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7bac605d7028446810334ec5ce9f549ce2a40884aa766dc82d30384145b85bf8
|
4
|
+
data.tar.gz: 1f6055b1cf36e3562861598e7d839a8086ddd03a9cb537bc9954e98532320e7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5880a18a09467a0a9cd48146b10977d842ceb0acd22deca2491dc9466d160d1126a7d140c7daa8d7b70620f1c6adf6da20f38318e8e718bb37934fd1e728f0e
|
7
|
+
data.tar.gz: ed739ace7d040964123f9898115fda612b4c780df711c8d21f396a5f050f4ede22ac2c0a7ee0edb83dd264763eec51c0105445efeafd40ad90e5853668a818d7
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
paperplane-rb (0.1.
|
4
|
+
paperplane-rb (0.1.8)
|
5
5
|
http
|
6
|
+
webmock
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
9
10
|
specs:
|
10
11
|
addressable (2.8.1)
|
11
12
|
public_suffix (>= 2.0.2, < 6.0)
|
13
|
+
crack (0.4.5)
|
14
|
+
rexml
|
12
15
|
diff-lcs (1.5.0)
|
13
16
|
domain_name (0.5.20190701)
|
14
17
|
unf (>= 0.0.5, < 1.0.0)
|
@@ -16,6 +19,7 @@ GEM
|
|
16
19
|
ffi-compiler (1.0.1)
|
17
20
|
ffi (>= 1.0.0)
|
18
21
|
rake
|
22
|
+
hashdiff (1.0.1)
|
19
23
|
http (5.1.1)
|
20
24
|
addressable (~> 2.8)
|
21
25
|
http-cookie (~> 1.0)
|
@@ -29,6 +33,7 @@ GEM
|
|
29
33
|
rake (~> 13.0)
|
30
34
|
public_suffix (5.0.1)
|
31
35
|
rake (13.0.6)
|
36
|
+
rexml (3.2.5)
|
32
37
|
rspec (3.12.0)
|
33
38
|
rspec-core (~> 3.12.0)
|
34
39
|
rspec-expectations (~> 3.12.0)
|
@@ -45,12 +50,16 @@ GEM
|
|
45
50
|
unf (0.1.4)
|
46
51
|
unf_ext
|
47
52
|
unf_ext (0.0.8.2)
|
53
|
+
webmock (3.18.1)
|
54
|
+
addressable (>= 2.8.0)
|
55
|
+
crack (>= 0.3.2)
|
56
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
48
57
|
|
49
58
|
PLATFORMS
|
50
59
|
arm64-darwin-22
|
60
|
+
x86_64-linux
|
51
61
|
|
52
62
|
DEPENDENCIES
|
53
|
-
http
|
54
63
|
paperplane-rb!
|
55
64
|
rake (~> 13.0)
|
56
65
|
rspec (~> 3.0)
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# paperplane-rb
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
A simple gem to interact with the Paperplane PDF API. It just has very basic features that I needed quickly. I'll continue to improve this as I need. Feel free to contribute if you'd like!
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -10,20 +8,41 @@ Install the gem and add to the application's Gemfile by executing:
|
|
10
8
|
|
11
9
|
$ bundle add paperplane
|
12
10
|
|
13
|
-
|
11
|
+
Or add it to your `Gemfile` manually:
|
14
12
|
|
15
|
-
|
13
|
+
```ruby
|
14
|
+
gem 'paperplane'
|
15
|
+
```
|
16
16
|
|
17
17
|
## Usage
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
Initialize the library and set your API key(required) and logger(optional).
|
20
|
+
```ruby
|
21
|
+
require 'paperplane'
|
22
|
+
|
23
|
+
Paperplane.configure do |config|
|
24
|
+
config.api_key = 'your_paperplane_api_key'
|
25
|
+
config.logger = Appsignal::Logger.new("paperplane")
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
You can now call the different methods:
|
30
|
+
```ruby
|
31
|
+
# Download PDF
|
32
|
+
url = 'https://en.wikipedia.org/wiki/Airplane'
|
33
|
+
output_file = 'example.pdf'
|
34
|
+
PaperplaneAPI.download_pdf(url, output_file)
|
35
|
+
|
36
|
+
# Create Job
|
37
|
+
response = PaperplaneAPI.create_job(url)
|
38
|
+
puts response
|
39
|
+
job_id = response['id']
|
40
|
+
|
41
|
+
# Show Job
|
42
|
+
job = PaperplaneAPI.show_job(job_id)
|
43
|
+
puts job
|
44
|
+
```
|
26
45
|
|
27
46
|
## Contributing
|
28
47
|
|
29
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
48
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/nolyoi/paperplane-rb.
|
data/lib/paperplane/error.rb
CHANGED
data/lib/paperplane/version.rb
CHANGED
data/lib/paperplane.rb
CHANGED
@@ -1,67 +1,66 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'http'
|
4
|
+
require 'paperplane/config'
|
4
5
|
require 'paperplane/error'
|
5
6
|
require 'paperplane/version'
|
6
7
|
|
7
8
|
module Paperplane
|
8
9
|
ENDPOINTS = {
|
9
|
-
|
10
|
-
|
11
|
-
download_pdf: 'https://download.paperplane.app/'
|
10
|
+
download_pdf: 'https://download.paperplane.app/',
|
11
|
+
jobs: 'https://api.paperplane.app/jobs'
|
12
12
|
}.freeze
|
13
|
-
PAGE_SIZES = %w[Letter Legal A3 A4 A5].freeze
|
14
13
|
|
15
14
|
class << self
|
16
|
-
|
15
|
+
attr_writer :config
|
17
16
|
|
18
|
-
def
|
19
|
-
|
17
|
+
def config
|
18
|
+
@config ||= Config.new
|
20
19
|
end
|
21
20
|
|
22
|
-
def
|
23
|
-
|
24
|
-
perform_request(:post, :create_job, url: url, page_size: page_size)
|
21
|
+
def configure
|
22
|
+
yield(config) if block_given?
|
25
23
|
end
|
26
24
|
|
27
|
-
def
|
28
|
-
|
25
|
+
def version
|
26
|
+
@version ||= Paperplane::VERSION
|
29
27
|
end
|
30
28
|
|
31
|
-
def
|
32
|
-
|
33
|
-
"https://download.paperplane.app",
|
34
|
-
json: { url: url, page_size: page_size }
|
35
|
-
)
|
36
|
-
response.body.to_s
|
29
|
+
def client
|
30
|
+
@client ||= HTTP.basic_auth(user: config.api_key, pass: '')
|
37
31
|
end
|
38
32
|
|
39
|
-
|
40
|
-
|
41
|
-
def http_client
|
42
|
-
@http_client ||= HTTP.basic_auth(user: api_key, pass: '')
|
33
|
+
def prepare_params(url, page_size: 'A4')
|
34
|
+
params = { url: url, page_size: page_size }
|
43
35
|
end
|
44
36
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
37
|
+
# Download PDF
|
38
|
+
def download_pdf(url, page_size: 'A4')
|
39
|
+
params = prepare_params(url, page_size: page_size)
|
40
|
+
response = client.post(ENDPOINTS[:download_pdf], form: params)
|
41
|
+
raise Paperplane::Error, "Failed to download PDF: #{response.status}" unless response.status.success?
|
42
|
+
|
43
|
+
config.logger.info("Downloaded PDF: #{url}")
|
44
|
+
response.body.to_s
|
52
45
|
end
|
53
46
|
|
54
|
-
|
55
|
-
|
56
|
-
|
47
|
+
# Create Job
|
48
|
+
def create_job(url, page_size: 'A4', options: {})
|
49
|
+
params = prepare_params(url, page_size: page_size)
|
50
|
+
response = client.post(ENDPOINTS[:jobs], form: params.merge(options))
|
51
|
+
raise Paperplane::Error, "Failed to create job: #{response.status}" unless response.status.success?
|
57
52
|
|
58
|
-
|
59
|
-
# raise Paperplane::Error, response.parse['message'] if response.status >= 400
|
53
|
+
config.logger.info("Created job for URL: #{url}")
|
60
54
|
response.parse
|
61
55
|
end
|
62
56
|
|
63
|
-
|
64
|
-
|
57
|
+
# Show Job
|
58
|
+
def show_job(job_id)
|
59
|
+
response = client.get("#{ENDPOINTS[:jobs]}/#{job_id}")
|
60
|
+
raise Paperplane::Error, "Failed to show job: #{response.status}" unless response.status.success?
|
61
|
+
|
62
|
+
config.logger.info("Fetched job: #{job_id}")
|
63
|
+
response.parse
|
65
64
|
end
|
66
65
|
end
|
67
66
|
end
|
data/paperplane.gemspec
CHANGED
@@ -31,6 +31,7 @@ Gem::Specification.new do |spec|
|
|
31
31
|
|
32
32
|
# Uncomment to register a new dependency of your gem
|
33
33
|
spec.add_dependency "http"
|
34
|
+
spec.add_dependency "webmock"
|
34
35
|
|
35
36
|
# For more information and examples about making a new gem, check out our
|
36
37
|
# guide at: https://bundler.io/guides/creating_gem.html
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paperplane-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nolyoi
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: webmock
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
description: A gem to interact with the Paperplane PDF API.
|
28
42
|
email:
|
29
43
|
- nolan@syslogica.io
|
@@ -38,10 +52,10 @@ files:
|
|
38
52
|
- README.md
|
39
53
|
- Rakefile
|
40
54
|
- lib/paperplane.rb
|
55
|
+
- lib/paperplane/config.rb
|
41
56
|
- lib/paperplane/error.rb
|
42
57
|
- lib/paperplane/version.rb
|
43
58
|
- paperplane.gemspec
|
44
|
-
- sig/paperplane.rbs
|
45
59
|
homepage: https://github.com/nolyoi
|
46
60
|
licenses: []
|
47
61
|
metadata:
|
data/sig/paperplane.rbs
DELETED