paperplane-rb 0.1.0
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/.rspec +3 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +59 -0
- data/README.md +29 -0
- data/Rakefile +8 -0
- data/lib/paperplane/version.rb +5 -0
- data/lib/paperplane.rb +60 -0
- data/paperplane.gemspec +37 -0
- data/sig/paperplane.rbs +4 -0
- metadata +69 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9ef3026a3b88856233f3e9d4cfea8f165f126bd240de7808dfba2e205baba9e0
|
4
|
+
data.tar.gz: 6702fe14e39f56d4060a505de5505835acc10cfd4a3a823844ac9f2d1c90af5a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 40dff58c30f2d294a8d05d689420be03a0177c3c53c4a224be5b70d9e575db4ceaa19202dff5848b0bb177d49e1b427288f473916f0e02cb69167c5cf30786ac
|
7
|
+
data.tar.gz: c979966d45b8b0ae4c1ea48bf6706bb41ba0347329ebe668b9beb806a7cad23245e67d65fecb61b7bf9d2a4d3aa7bf5e58f96a73d7124daf857d8d065fb2e7b7
|
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
paperplane-rb (0.1.0)
|
5
|
+
http
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.8.1)
|
11
|
+
public_suffix (>= 2.0.2, < 6.0)
|
12
|
+
diff-lcs (1.5.0)
|
13
|
+
domain_name (0.5.20190701)
|
14
|
+
unf (>= 0.0.5, < 1.0.0)
|
15
|
+
ffi (1.15.5)
|
16
|
+
ffi-compiler (1.0.1)
|
17
|
+
ffi (>= 1.0.0)
|
18
|
+
rake
|
19
|
+
http (5.1.1)
|
20
|
+
addressable (~> 2.8)
|
21
|
+
http-cookie (~> 1.0)
|
22
|
+
http-form_data (~> 2.2)
|
23
|
+
llhttp-ffi (~> 0.4.0)
|
24
|
+
http-cookie (1.0.5)
|
25
|
+
domain_name (~> 0.5)
|
26
|
+
http-form_data (2.3.0)
|
27
|
+
llhttp-ffi (0.4.0)
|
28
|
+
ffi-compiler (~> 1.0)
|
29
|
+
rake (~> 13.0)
|
30
|
+
public_suffix (5.0.1)
|
31
|
+
rake (13.0.6)
|
32
|
+
rspec (3.12.0)
|
33
|
+
rspec-core (~> 3.12.0)
|
34
|
+
rspec-expectations (~> 3.12.0)
|
35
|
+
rspec-mocks (~> 3.12.0)
|
36
|
+
rspec-core (3.12.1)
|
37
|
+
rspec-support (~> 3.12.0)
|
38
|
+
rspec-expectations (3.12.2)
|
39
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
+
rspec-support (~> 3.12.0)
|
41
|
+
rspec-mocks (3.12.4)
|
42
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
+
rspec-support (~> 3.12.0)
|
44
|
+
rspec-support (3.12.0)
|
45
|
+
unf (0.1.4)
|
46
|
+
unf_ext
|
47
|
+
unf_ext (0.0.8.2)
|
48
|
+
|
49
|
+
PLATFORMS
|
50
|
+
arm64-darwin-22
|
51
|
+
|
52
|
+
DEPENDENCIES
|
53
|
+
http
|
54
|
+
paperplane-rb!
|
55
|
+
rake (~> 13.0)
|
56
|
+
rspec (~> 3.0)
|
57
|
+
|
58
|
+
BUNDLED WITH
|
59
|
+
2.3.26
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Paperplane
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/paperplane`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Install the gem and add to the application's Gemfile by executing:
|
10
|
+
|
11
|
+
$ bundle add paperplane
|
12
|
+
|
13
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
14
|
+
|
15
|
+
$ gem install paperplane
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
TODO: Write usage instructions here
|
20
|
+
|
21
|
+
## Development
|
22
|
+
|
23
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
24
|
+
|
25
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/paperplane.
|
data/Rakefile
ADDED
data/lib/paperplane.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "paperplane/version"
|
4
|
+
require 'http'
|
5
|
+
|
6
|
+
module Paperplane
|
7
|
+
class Error < StandardError; end
|
8
|
+
|
9
|
+
class << self
|
10
|
+
BASE_URL = 'https://api.paperplane.app/v1'.freeze
|
11
|
+
ENDPOINTS = {
|
12
|
+
create_job: '/jobs',
|
13
|
+
show_job: '/jobs/%{id}',
|
14
|
+
download_pdf: 'https://download.paperplane.app/'
|
15
|
+
}.freeze
|
16
|
+
PAGE_SIZES = %w[A4 Letter Legal Tabloid].freeze
|
17
|
+
|
18
|
+
attr_accessor :api_key
|
19
|
+
|
20
|
+
def create_job(url, page_size = 'A4')
|
21
|
+
validate_page_size(page_size)
|
22
|
+
perform_request(:post, :create_job, url, page_size:)
|
23
|
+
end
|
24
|
+
|
25
|
+
def show_job(id)
|
26
|
+
perform_request(:get, :show_job, id)
|
27
|
+
end
|
28
|
+
|
29
|
+
def download_pdf(url, page_size = 'A4')
|
30
|
+
validate_page_size(page_size)
|
31
|
+
perform_request(:post, :download_pdf, url, page_size:)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def http_client
|
37
|
+
@http_client ||= HTTP.basic_auth(user: @api_key, pass: '')
|
38
|
+
end
|
39
|
+
|
40
|
+
def perform_request(method, endpoint_name, *args)
|
41
|
+
url = build_url(endpoint_name, args[0])
|
42
|
+
response = http_client.request(method, url, json: args[1])
|
43
|
+
handle_error(response)
|
44
|
+
response.parse
|
45
|
+
end
|
46
|
+
|
47
|
+
def build_url(endpoint_name, id)
|
48
|
+
endpoint = ENDPOINTS[endpoint_name]
|
49
|
+
endpoint.include?('://') ? endpoint : "#{BASE_URL}#{format(endpoint, id:)}"
|
50
|
+
end
|
51
|
+
|
52
|
+
def handle_error(response)
|
53
|
+
raise Paperplane::Error, response.parse['message'] if response.status >= 400
|
54
|
+
end
|
55
|
+
|
56
|
+
def validate_page_size(page_size)
|
57
|
+
raise ArgumentError, "Invalid page size '#{page_size}'" unless PAGE_SIZES.include?(page_size)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/paperplane.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/paperplane/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "paperplane-rb"
|
7
|
+
spec.version = Paperplane::VERSION
|
8
|
+
spec.authors = ["nolyoi"]
|
9
|
+
spec.email = ["nolan@syslogica.io"]
|
10
|
+
|
11
|
+
spec.summary = "A gem to interact with the Paperplane PDF API."
|
12
|
+
spec.description = "A gem to interact with the Paperplane PDF API."
|
13
|
+
spec.homepage = "https://github.com/nolyoi"
|
14
|
+
spec.required_ruby_version = ">= 2.6.0"
|
15
|
+
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/nolyoi/paperplane-rb"
|
19
|
+
spec.metadata["changelog_uri"] = "https://github.com/nolyoi/paperplane-rb/CHANGELOG.md"
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(__dir__) do
|
24
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
25
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
26
|
+
end
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
# Uncomment to register a new dependency of your gem
|
33
|
+
spec.add_dependency "http"
|
34
|
+
|
35
|
+
# For more information and examples about making a new gem, check out our
|
36
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
37
|
+
end
|
data/sig/paperplane.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paperplane-rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- nolyoi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-03-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: http
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: A gem to interact with the Paperplane PDF API.
|
28
|
+
email:
|
29
|
+
- nolan@syslogica.io
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".rspec"
|
35
|
+
- CHANGELOG.md
|
36
|
+
- Gemfile
|
37
|
+
- Gemfile.lock
|
38
|
+
- README.md
|
39
|
+
- Rakefile
|
40
|
+
- lib/paperplane.rb
|
41
|
+
- lib/paperplane/version.rb
|
42
|
+
- paperplane.gemspec
|
43
|
+
- sig/paperplane.rbs
|
44
|
+
homepage: https://github.com/nolyoi
|
45
|
+
licenses: []
|
46
|
+
metadata:
|
47
|
+
homepage_uri: https://github.com/nolyoi
|
48
|
+
source_code_uri: https://github.com/nolyoi/paperplane-rb
|
49
|
+
changelog_uri: https://github.com/nolyoi/paperplane-rb/CHANGELOG.md
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: 2.6.0
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubygems_version: 3.3.26
|
66
|
+
signing_key:
|
67
|
+
specification_version: 4
|
68
|
+
summary: A gem to interact with the Paperplane PDF API.
|
69
|
+
test_files: []
|