pdfmonkey 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 64be5f191201c74accbf5eb0c747fac13d4573717b7d1650a88a2d8ac7f7c763
4
+ data.tar.gz: 160ddcfec092f8417f1e65f453c77bd754e9f81b9c7ef07f0dda9fb96a2bf706
5
+ SHA512:
6
+ metadata.gz: f9ad7a42896a544d776df651008b617d674c1f14104c663d98a25a22cfc3e85dd2764e6f3f334bd1cff7dab097a0005dce61532bbf05a5b37c0fe715298be8aa
7
+ data.tar.gz: 55925f2faa3d549bc2412194ba9412d56ff3ebcea99ebf686b8f7dec471e169bc86929552e29d0d3a45aca2fe09a15986c8e43db41206c4733947158ab7f1d2e
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,209 @@
1
+ AllCops:
2
+ DefaultFormatter: progress
3
+ TargetRubyVersion: 2.5
4
+
5
+ Layout/AlignParameters:
6
+ EnforcedStyle: with_first_parameter
7
+
8
+ Layout/BlockEndNewline:
9
+ Exclude:
10
+ - spec/**/*_spec.rb
11
+
12
+ Layout/ClassStructure:
13
+ ExpectedOrder:
14
+ - constants
15
+ - module_inclusion
16
+ - initializer
17
+ - public_methods
18
+ - public_class_methods
19
+ - protected_methods
20
+ - private_methods
21
+
22
+ Layout/EmptyLineAfterGuardClause:
23
+ Enabled: false
24
+
25
+ Layout/EndAlignment:
26
+ EnforcedStyleAlignWith: start_of_line
27
+
28
+ Layout/FirstArrayElementLineBreak:
29
+ Enabled: true
30
+
31
+ Layout/FirstHashElementLineBreak:
32
+ Enabled: true
33
+
34
+ Layout/FirstMethodParameterLineBreak:
35
+ Enabled: true
36
+
37
+ Layout/IndentArray:
38
+ EnforcedStyle: consistent
39
+
40
+ Layout/IndentHash:
41
+ EnforcedStyle: consistent
42
+
43
+ Layout/MultilineBlockLayout:
44
+ Exclude:
45
+ - spec/**/*_spec.rb
46
+
47
+ Layout/MultilineMethodCallBraceLayout:
48
+ EnforcedStyle: same_line
49
+
50
+ Layout/MultilineMethodDefinitionBraceLayout:
51
+ EnforcedStyle: same_line
52
+
53
+ Layout/MultilineOperationIndentation:
54
+ EnforcedStyle: indented
55
+ IndentationWidth: 2
56
+
57
+ Layout/RescueEnsureAlignment:
58
+ Enabled: false
59
+
60
+ Layout/SpaceInsideArrayPercentLiteral:
61
+ Exclude:
62
+ - 'lib/tasks/*_permissions.rake'
63
+
64
+ Layout/SpaceInsideBlockBraces:
65
+ Exclude:
66
+ - spec/**/*_spec.rb
67
+
68
+ Lint/AmbiguousBlockAssociation:
69
+ Exclude:
70
+ - 'spec/**/*_spec.rb'
71
+
72
+ Lint/NestedMethodDefinition:
73
+ Enabled: false
74
+
75
+ Lint/AmbiguousOperator:
76
+ Enabled: false
77
+
78
+ Lint/RescueException:
79
+ Exclude:
80
+ - 'lib/business_pipeline/lib/business_pipeline/interceptors/error_handling.rb'
81
+ - 'lib/business_pipeline/lib/business_pipeline/interceptors/error_reporting.rb'
82
+
83
+ Metrics/AbcSize:
84
+ Exclude:
85
+ - 'app/services/retro_compatibility/*_backporter.rb'
86
+ - 'lib/tasks/*.rake'
87
+ - 'spec/support/payloads/**/*.rb'
88
+ Max: 18
89
+
90
+ Metrics/BlockLength:
91
+ Exclude:
92
+ - '**/*.builder'
93
+ - '**/*.rake'
94
+ - 'app/views/api/v3/**/_*.jb'
95
+ - 'config/environments/production.rb'
96
+ - 'config/routes.rb'
97
+ - 'Gemfile'
98
+ - 'Guardfile'
99
+ - 'spec/**/*.rb'
100
+
101
+ Metrics/ClassLength:
102
+ Exclude:
103
+ - 'app/forms/**/*.rb'
104
+ - 'app/services/retro_compatibility/*_backporter.rb'
105
+ - 'app/services/tracking/*tracking_handler.rb'
106
+
107
+ Metrics/CyclomaticComplexity:
108
+ Exclude:
109
+ - 'lib/tasks/*.rake'
110
+
111
+ Metrics/LineLength:
112
+ Exclude:
113
+ - 'config/routes.rb'
114
+ - 'lib/**/*.gemspec'
115
+ - 'lib/tasks/*.rake'
116
+ - 'spec/**/*_spec.rb'
117
+ - 'spec/support/factories/*.rb'
118
+ Max: 90
119
+
120
+ Metrics/MethodLength:
121
+ Exclude:
122
+ - 'app/services/retro_compatibility/*_backporter.rb'
123
+ - 'app/services/tracking/**/*.rb'
124
+ - 'app/web_strategies/**/*.rb'
125
+ - 'spec/support/payloads/**/*.rb'
126
+
127
+ Naming/PredicateName:
128
+ NamePrefixBlacklist:
129
+ - is_
130
+
131
+ Naming/UncommunicativeMethodParamName:
132
+ Enabled: false
133
+
134
+ Performance/RedundantBlockCall:
135
+ Enabled: false
136
+
137
+ Rails:
138
+ Enabled: true
139
+
140
+ # FIXME: https://github.com/bbatsov/rubocop/issues/4751
141
+ # Rails/HasManyOrHasOneDependent:
142
+ # Enabled: false
143
+
144
+ Rails/OutputSafety:
145
+ Enabled: false
146
+
147
+ Rails/SkipsModelValidations:
148
+ Enabled: false
149
+
150
+ Style/AccessModifierDeclarations:
151
+ Enabled: false
152
+
153
+ Style/Alias:
154
+ EnforcedStyle: prefer_alias_method
155
+
156
+ Style/AsciiComments:
157
+ Enabled: false
158
+
159
+ Style/BlockDelimiters:
160
+ Exclude:
161
+ - spec/**/*_spec.rb
162
+
163
+ Style/Documentation:
164
+ Enabled: false
165
+
166
+ Style/DoubleNegation:
167
+ Enabled: false
168
+
169
+ Style/FormatStringToken:
170
+ EnforcedStyle: template
171
+
172
+ Style/FrozenStringLiteralComment:
173
+ Enabled: false
174
+
175
+ Style/IfUnlessModifier:
176
+ Enabled: false
177
+
178
+ Style/MultilineBlockChain:
179
+ Enabled: false
180
+
181
+ Style/PercentLiteralDelimiters:
182
+ PreferredDelimiters:
183
+ '%': '{}'
184
+ '%i': '[]'
185
+ '%q': '{}'
186
+ '%Q': '{}'
187
+ '%r': '{}'
188
+ '%s': '{}'
189
+ '%w': '[]'
190
+ '%W': '[]'
191
+ '%x': '{}'
192
+
193
+ Style/RegexpLiteral:
194
+ EnforcedStyle: mixed
195
+
196
+ Style/SignalException:
197
+ EnforcedStyle: semantic
198
+
199
+ Style/SingleLineBlockParams:
200
+ Enabled: false
201
+
202
+ Style/StringLiterals:
203
+ EnforcedStyle: single_quotes
204
+
205
+ Style/StringLiteralsInInterpolation:
206
+ EnforcedStyle: single_quotes
207
+
208
+ Style/YodaCondition:
209
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.6
4
+ - 2.5
5
+ - 2.4
6
+ - rbx-3
7
+ - truffleruby
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at scourtois_github@cubyx.fr. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in pdfmonkey.gemspec
8
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,71 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ pdfmonkey (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.0)
10
+ coveralls (0.8.22)
11
+ json (>= 1.8, < 3)
12
+ simplecov (~> 0.16.1)
13
+ term-ansicolor (~> 1.3)
14
+ thor (~> 0.19.4)
15
+ tins (~> 1.6)
16
+ diff-lcs (1.3)
17
+ docile (1.3.1)
18
+ jaro_winkler (1.5.2)
19
+ json (2.1.0)
20
+ parallel (1.12.1)
21
+ parser (2.5.3.0)
22
+ ast (~> 2.4.0)
23
+ powerpack (0.1.2)
24
+ rainbow (3.0.0)
25
+ rake (10.5.0)
26
+ rspec (3.8.0)
27
+ rspec-core (~> 3.8.0)
28
+ rspec-expectations (~> 3.8.0)
29
+ rspec-mocks (~> 3.8.0)
30
+ rspec-core (3.8.0)
31
+ rspec-support (~> 3.8.0)
32
+ rspec-expectations (3.8.2)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.8.0)
35
+ rspec-mocks (3.8.0)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.8.0)
38
+ rspec-support (3.8.0)
39
+ rubocop (0.60.0)
40
+ jaro_winkler (~> 1.5.1)
41
+ parallel (~> 1.10)
42
+ parser (>= 2.5, != 2.5.1.1)
43
+ powerpack (~> 0.1)
44
+ rainbow (>= 2.2.2, < 4.0)
45
+ ruby-progressbar (~> 1.7)
46
+ unicode-display_width (~> 1.4.0)
47
+ ruby-progressbar (1.10.0)
48
+ simplecov (0.16.1)
49
+ docile (~> 1.1)
50
+ json (>= 1.8, < 3)
51
+ simplecov-html (~> 0.10.0)
52
+ simplecov-html (0.10.2)
53
+ term-ansicolor (1.7.0)
54
+ tins (~> 1.0)
55
+ thor (0.19.4)
56
+ tins (1.20.2)
57
+ unicode-display_width (1.4.1)
58
+
59
+ PLATFORMS
60
+ ruby
61
+
62
+ DEPENDENCIES
63
+ bundler (~> 1.17)
64
+ coveralls (~> 0.8)
65
+ pdfmonkey!
66
+ rake (~> 10.0)
67
+ rspec (~> 3.8)
68
+ rubocop (~> 0.60.0)
69
+
70
+ BUNDLED WITH
71
+ 1.17.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Sivije
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,123 @@
1
+ # PDFMonkey
2
+
3
+ [![Build Status](https://travis-ci.com/pdfmonkey/pdfmonkey-ruby.svg?branch=master)](https://travis-ci.com/pdfmonkey/pdfmonkey-ruby)
4
+ [![Coverage Status](https://coveralls.io/repos/github/pdfmonkey/pdfmonkey-ruby/badge.svg?branch=master)](https://coveralls.io/github/pdfmonkey/pdfmonkey-ruby?branch=master)
5
+
6
+ This gem is the quickest way to use the [PDFMonkey](https://www.pdfmonkey.io) API.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application’s Gemfile:
11
+
12
+ ```ruby
13
+ gem 'pdfmonkey'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install pdfmonkey
23
+
24
+ ## Usage
25
+
26
+ ### Setting up authentication
27
+
28
+ #### Using the default environment variables
29
+
30
+ PDFMonkey will look for the `PDFMONKEY_PRIVATE_KEY` environment variable. This variable should contain your private key obtained at https://dashboard.pdfmonkey.io/account.
31
+
32
+ PDFMONKEY_PRIVATE_KEY=j39ckj4…
33
+
34
+ #### Setting credentials manually
35
+
36
+ You can choose to set up your credentials explicitely in your application:
37
+
38
+ ```ruby
39
+ Pdfmonkey.configure do |config|
40
+ config.private_key = 'j39ckj4…'
41
+ end
42
+ ```
43
+
44
+ ### Generating a document
45
+
46
+ Once your App is created in the [PDFMonkey Dashboard](https://dashboard.pdfmonkey.io), create a Document Template and add the content you want to use. Every Document Template has a unique identifier (UUID), get your template’s identifier. Your ready to generate a Document.
47
+
48
+ #### Synchronous generation
49
+
50
+ If your want to wait for a Document’s generation before continuing with your workflow, use the `generate!` method, it will request a document generation and wait for it to succeed or fail before giving you any answer.
51
+
52
+ ```ruby
53
+ tempalte_id = 'b13ebd75-d290-409b-9cac-8f597ae3e785'
54
+ data = { name: 'John Doe' }
55
+
56
+ document = Pdfmonkey::Document.generate!(template_id, data)
57
+
58
+ document.status # => 'success'
59
+ document.download_url # => 'https://…'
60
+ ```
61
+
62
+ :warning: The download URL of a document is only valid **for 30 seconds**. Passed this delay, reload the document to obtain a new one:
63
+
64
+ ```ruby
65
+ document.reload!
66
+ ```
67
+
68
+ #### Asynchronous generation
69
+
70
+ PDFMonkey was created with an asynchronous workflow in mind. It provides webhooks to inform you of a Document’s generation success or failure.
71
+
72
+ To leverage this behavior and continue working while your Document is generated, use the `generate` method:
73
+
74
+ ```ruby
75
+ tempalte_id = 'b13ebd75-d290-409b-9cac-8f597ae3e785'
76
+ data = { name: 'John Doe' }
77
+
78
+ document = Pdfmonkey::Document.generate(template_id, data)
79
+
80
+ document.status # => 'pending'
81
+ document.download_url # => nil
82
+ ```
83
+
84
+ If you have a webhook URL set up it will be called with you document once the generation is complete. You can simulate it for testing with the following cURL command:
85
+
86
+ ```ruby
87
+ curl <url of your app> \
88
+ -X POST \
89
+ -H 'Content-Type: application/json' \
90
+ -d '{
91
+ "document": {
92
+ "app_id": "d9ec8249-65ae-4d50-8aee-7c12c1f9683a",
93
+ "checksum": "ac0c2b6bcc77e2b01dc6ca6a9f656b2d",
94
+ "created_at": "2020-01-02T03:04:05.000+01:00",
95
+ "document_template_id": "f7fbe2b4-a57c-46ee-8422-5ae8cc37daac",
96
+ "download_url": "https://example.com/76bebeb9-9eb1-481a-bc3c-faf43dc3ac81.pdf",
97
+ "id": "76bebeb9-9eb1-481a-bc3c-faf43dc3ac81",
98
+ "meta": null,
99
+ "payload": "{\"name\": \"John Doe\"}",
100
+ "preview_url": null,
101
+ "status": "success",
102
+ "updated_at": "2020-01-02T03:04:15.000+01:00"
103
+ }
104
+ }'
105
+ ```
106
+
107
+ ## Development
108
+
109
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
110
+
111
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
112
+
113
+ ## Contributing
114
+
115
+ Bug reports and pull requests are welcome on GitHub at https://github.com/simonc/pdfmonkey. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
116
+
117
+ ## License
118
+
119
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
120
+
121
+ ## Code of Conduct
122
+
123
+ Everyone interacting in the Pdfmonkey project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/simonc/pdfmonkey/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'pdfmonkey'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/pdfmonkey.rb ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pdfmonkey/adapter'
4
+ require 'pdfmonkey/configuration'
5
+ require 'pdfmonkey/document'
6
+ require 'pdfmonkey/version'
7
+
8
+ module Pdfmonkey
9
+ class Error < StandardError; end
10
+ # Your code goes here...
11
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/http'
4
+
5
+ module Pdfmonkey
6
+ class Adapter
7
+ def initialize(config: Pdfmonkey.configuration)
8
+ @config = config
9
+ end
10
+
11
+ def call(method, resource)
12
+ response = send_request(method, resource)
13
+ extract_attributes(response, resource)
14
+ end
15
+
16
+ private def build_get_request(uri, _resource)
17
+ Net::HTTP::Get.new(uri, headers)
18
+ end
19
+
20
+ private def build_post_request(uri, resource)
21
+ request = Net::HTTP::Post.new(uri, headers)
22
+ request.body = resource.to_json
23
+ request
24
+ end
25
+
26
+ private def extract_attributes(response, resource)
27
+ member = resource.class.const_get('MEMBER')
28
+ JSON.parse(response.body).fetch(member)
29
+ end
30
+
31
+ private def headers
32
+ {
33
+ 'Authorization' => "Bearer #{config.private_key}",
34
+ 'Content-Type' => 'application/json'
35
+ }
36
+ end
37
+
38
+ private def send_request(method, resource)
39
+ uri = URI(url_for(resource))
40
+ request = send("build_#{method}_request", uri, resource)
41
+ http = Net::HTTP.new(uri.host, uri.port)
42
+ http.use_ssl = (uri.scheme == 'https')
43
+ http.request(request)
44
+ end
45
+
46
+ private def url_for(resource)
47
+ collection = resource.class.const_get('COLLECTION')
48
+ endpoint = "#{config.host}/#{config.namespace}/#{collection}"
49
+ endpoint += "/#{resource.id}" if resource.id
50
+ endpoint
51
+ end
52
+
53
+ private
54
+
55
+ attr_reader :config
56
+ end
57
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pdfmonkey
4
+ class Configuration
5
+ attr_accessor :host
6
+ attr_accessor :namespace
7
+ attr_accessor :private_key
8
+
9
+ def initialize
10
+ @host = 'https://api.pdfmonkey.io'
11
+ @namespace = 'api/v1'
12
+ @private_key = ENV['PDFMONKEY_PRIVATE_KEY']
13
+ end
14
+ end
15
+
16
+ def self.configuration
17
+ @configuration ||= Configuration.new
18
+ end
19
+
20
+ def self.configuration=(config)
21
+ @configuration = config
22
+ end
23
+
24
+ def self.configure
25
+ yield configuration
26
+ end
27
+ end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+ require 'json'
5
+ require 'ostruct'
6
+
7
+ module Pdfmonkey
8
+ class Document
9
+ extend Forwardable
10
+
11
+ ATTRIBUTES = %i[
12
+ app_id
13
+ checksum
14
+ created_at
15
+ document_template_id
16
+ download_url
17
+ id
18
+ meta
19
+ payload
20
+ preview_url
21
+ status
22
+ updated_at
23
+ ].freeze
24
+
25
+ COMPLETE_STATUSES = %w[failure success].freeze
26
+ COLLECTION = 'documents'
27
+ MEMBER = 'document'
28
+
29
+ attr_reader :attributes
30
+ def_delegators :attributes, *ATTRIBUTES
31
+
32
+ def self.generate!(document_template_id, payload)
33
+ document = generate(document_template_id, payload)
34
+ document.reload! until COMPLETE_STATUSES.include?(document.status)
35
+ document
36
+ end
37
+
38
+ def self.generate(template_id, payload)
39
+ document = new(
40
+ document_template_id: template_id,
41
+ payload: payload.to_json,
42
+ status: 'pending')
43
+
44
+ document.send(:save)
45
+ end
46
+
47
+ def initialize(adapter: Pdfmonkey::Adapter.new, **attributes)
48
+ @adapter = adapter
49
+ @attributes = OpenStruct.new(ATTRIBUTES.zip([]).to_h)
50
+ update(attributes)
51
+ end
52
+
53
+ def reload!
54
+ attributes = adapter.call(:get, self)
55
+ update(attributes)
56
+ self
57
+ end
58
+
59
+ def to_json
60
+ { document: attributes.to_h }.to_json
61
+ end
62
+
63
+ private def save
64
+ attributes = adapter.call(:post, self)
65
+ update(attributes)
66
+ self
67
+ end
68
+
69
+ private def update(new_attributes)
70
+ new_attributes.each do |key, value|
71
+ sym_key = key.to_sym
72
+ attributes[sym_key] = value if ATTRIBUTES.include?(sym_key)
73
+ end
74
+ end
75
+
76
+ private
77
+
78
+ attr_reader :adapter
79
+ end
80
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pdfmonkey
4
+ VERSION = '0.1.0'
5
+ end
data/pdfmonkey.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'pdfmonkey/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'pdfmonkey'
9
+ spec.version = Pdfmonkey::VERSION
10
+ spec.authors = ['Simon Courtois']
11
+ spec.email = ['scourtois_github@cubyx.fr']
12
+
13
+ spec.summary = 'Connect to the PDFMonkey API'
14
+ spec.description = 'Generate awesome PDF with web technologies at pdfmonkey.io'
15
+ spec.homepage = 'https://github.com/pdfmonkeyio/pdfmonkey-ruby'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = Dir.chdir(__dir__) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.17'
26
+ spec.add_development_dependency 'coveralls', '~> 0.8'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rspec', '~> 3.8'
29
+ spec.add_development_dependency 'rubocop', '~> 0.60.0'
30
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pdfmonkey
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Simon Courtois
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-01-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: coveralls
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.60.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.60.0
83
+ description: Generate awesome PDF with web technologies at pdfmonkey.io
84
+ email:
85
+ - scourtois_github@cubyx.fr
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".rubocop.yml"
93
+ - ".travis.yml"
94
+ - CODE_OF_CONDUCT.md
95
+ - Gemfile
96
+ - Gemfile.lock
97
+ - LICENSE.txt
98
+ - README.md
99
+ - Rakefile
100
+ - bin/console
101
+ - bin/setup
102
+ - lib/pdfmonkey.rb
103
+ - lib/pdfmonkey/adapter.rb
104
+ - lib/pdfmonkey/configuration.rb
105
+ - lib/pdfmonkey/document.rb
106
+ - lib/pdfmonkey/version.rb
107
+ - pdfmonkey.gemspec
108
+ homepage: https://github.com/pdfmonkeyio/pdfmonkey-ruby
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.7.6
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: Connect to the PDFMonkey API
132
+ test_files: []