pdfmonkey 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f29d523ed6bb4e6c17d42092bd8962761e2379b98627b09c04b6dd13c4c65e4a
4
- data.tar.gz: 0d167f19f5640220aadd5bae73760bb00b864e977e3a720b921b9b1d04ab6e73
3
+ metadata.gz: ff117f74d9d9afa3c9085624a3187a1f88a47770be2ce9b6ef08c70ad89b8f1f
4
+ data.tar.gz: eb0cace007db56e9030470cf45c9a20f6b539738be1d22903edca1e5542a66c3
5
5
  SHA512:
6
- metadata.gz: cd81871ef526fa6f3b30349984726bda426873a741206cd1dccc48a921ab3d6bad6278d48d80ea6ba292de49c9fb99ce0ad6cd450f04a1e83e90d01c1d0f9bb9
7
- data.tar.gz: 349aab6b0ba114c260e72538e030e201489b15836d13b0abb8fc6fd9d577895b34f8c055f182d8c329ed3578ca40b1b9517b491bdcf2ad5b46bc139cd40ecc5e
6
+ metadata.gz: 6a210f72119b84c43407aa8c42ccb29dd73280c159902651b4fb6f57122a4060f673d2e240f1d729c60dca8052efe62224250f8e9334de8bd5afc76cd8d8c807
7
+ data.tar.gz: d146ca183867e0274b9b75be76116de40c9ef9fc985d8cf816c7196ee85f90604115c4745cb531551bc28fb23cd84c1a2a49be266c2f2d68d775de1a29233cbe
@@ -1,13 +1,23 @@
1
1
  language: ruby
2
2
 
3
- before_install:
4
- - gem install bundler --version '~> 1.17'
3
+ before_install: gem install bundler --version '~> 1.17'
4
+ cache: bundler
5
+ dist: bionic
5
6
 
6
- dist: trusty
7
+ matrix:
8
+ allow_failures:
9
+ - rvm: ruby-head
10
+ - rvm: jruby-head
11
+ fast_finish: true
12
+
13
+ notifications:
14
+ email: false
15
+ slack:
16
+ secure: YimzUcOW2fIo+CyYB5sBgUydS49JNtTIEowyinPAfDifAYgRNx/8c5kPk0aLk8klbnNBd8pMene/i4MIfApRuUmzAkGLe/1CCbotGn7zN7R6S46tpkGaHyMya5leiQemT6gIeL5+J4mQwDcTppXYh9kNTSYKh6RNLJxS7XUZZrNqOK6R2e/hX71aqUJTA5laSQ5mR5Hvyl9kUaJW5b77myXiU6VdrHmCl3sZ9hMqe6mroyBbVOAf1eFQMo7QX9HuLTUHJA2KIpnA7cLEXLINtnKjkhRVR0hcuGMETJhrJI/Ylqi1kf3PRPqkD/Q9msBo01OcRSoGwTjQ2IS1gOcYDowgvpJhkvx2v17fk4j1w3zR5KHSYJlrYOnr+ayU9K3LTs62X8ppVHff6pkKjOEF+p1Mayk/DqbaaH0PnCxqBqJOqZ5kFSkz6y4DDQzVuYILi6qUfgZFQJ01LNR7zbJAI6v9xDqREPG/Bfh7QI5z4eETlZWF9CVX6OARYm43to/wLLg2AEEduoMjexMoIxXRgzsTyBnxKYW3P+0oXWtiH68PXEKF9qAEl8lK4tTjbPBiEgXgUMDWQIiG0y6M567Rg8s8CUiw5ZsQTGJE+9zn4OkM/3VTce1mNLoZPyF66S5sXTPFXjieHCnMS3vegc3OJzLI/Xpx/lPDEU+8CYBaA1I=
7
17
 
8
18
  rvm:
9
- - 2.6
10
- - 2.5
11
- - 2.4
12
- - rbx-4
13
- - truffleruby
19
+ - ruby-head
20
+ - 2.6
21
+ - 2.5
22
+ - 2.4
23
+ - jruby-head
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ # 0.5.0
4
+
5
+ * Adding `Document#filename`
6
+ * Adding `Document.delete` and `Document#delete!`
7
+
3
8
  ## 0.4.0
4
9
 
5
10
  * Adding meta to `Document.generate!` and `Document.generate`
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pdfmonkey (0.4.0)
4
+ pdfmonkey (0.5.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -16,13 +16,13 @@ GEM
16
16
  diff-lcs (1.3)
17
17
  docile (1.3.1)
18
18
  jaro_winkler (1.5.2)
19
- json (2.1.0)
19
+ json (2.3.1)
20
20
  parallel (1.12.1)
21
21
  parser (2.5.3.0)
22
22
  ast (~> 2.4.0)
23
23
  powerpack (0.1.2)
24
24
  rainbow (3.0.0)
25
- rake (10.5.0)
25
+ rake (13.0.1)
26
26
  rspec (3.8.0)
27
27
  rspec-core (~> 3.8.0)
28
28
  rspec-expectations (~> 3.8.0)
@@ -63,7 +63,7 @@ DEPENDENCIES
63
63
  bundler (~> 1.17)
64
64
  coveralls (~> 0.8)
65
65
  pdfmonkey!
66
- rake (~> 10.0)
66
+ rake (~> 13.0)
67
67
  rspec (~> 3.8)
68
68
  rubocop (~> 0.60.0)
69
69
 
data/README.md CHANGED
@@ -94,6 +94,7 @@ curl <url of your app> \
94
94
  "created_at": "2020-01-02T03:04:05.000+01:00",
95
95
  "document_template_id": "f7fbe2b4-a57c-46ee-8422-5ae8cc37daac",
96
96
  "download_url": "https://example.com/76bebeb9-9eb1-481a-bc3c-faf43dc3ac81.pdf",
97
+ "filename": "76bebeb9-9eb1-481a-bc3c-faf43dc3ac81.pdf",
97
98
  "id": "76bebeb9-9eb1-481a-bc3c-faf43dc3ac81",
98
99
  "meta": null,
99
100
  "payload": "{\"name\": \"John Doe\"}",
@@ -172,6 +173,44 @@ document.status # => 'error'
172
173
  document.errors # => ["Failed to open TCP connection to api.pdfmonkey.io:443 (getaddrinfo: nodename nor servname provided, or not known)"]
173
174
  ```
174
175
 
176
+ ### Deleting a document
177
+
178
+ You can delete an existing document using the `.delete` method:
179
+
180
+ ```ruby
181
+ Pdfmonkey::Document.delete('76bebeb9-9eb1-481a-bc3c-faf43dc3ac81')
182
+ #=> true
183
+ ```
184
+
185
+ Alternatively you can call the `#delete!` method:
186
+
187
+ ```ruby
188
+ document.delete!
189
+ #=> true
190
+ ```
191
+
192
+ #### Error handling
193
+
194
+ In case of error, be it an HTTP layer error or an API error, an error Hash will be returned.
195
+
196
+ ```ruby
197
+ document.delete!
198
+ #=> true
199
+
200
+ document.delete!
201
+ # {
202
+ # errors: ["We couldn't find any Document with ID \"11111111-2222-3333-4444-555555555555\". If ..."],
203
+ # status: "error"
204
+ # }
205
+
206
+ # If the network is down
207
+ document.delete!
208
+ # {
209
+ # errors: ["Failed to open TCP connection to api.pdfmonkey.io:443 (getaddrinfo: nodename nor servname provided, or not known)"],
210
+ # status: "error"
211
+ # }
212
+ ```
213
+
175
214
  ## Development
176
215
 
177
216
  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.
data/Rakefile CHANGED
@@ -1,6 +1,20 @@
1
- require 'bundler/gem_tasks'
1
+ require 'rubygems'
2
+
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ require 'bundler'
10
+ Bundler::GemHelper.install_tasks
11
+
12
+ require 'rake'
2
13
  require 'rspec/core/rake_task'
3
14
 
4
- RSpec::Core::RakeTask.new(:spec)
15
+ desc "Run all examples"
16
+ RSpec::Core::RakeTask.new(:spec) do |t|
17
+ t.rspec_opts = %w[--color --require spec_helper]
18
+ end
5
19
 
6
20
  task default: :spec
@@ -11,15 +11,19 @@ module Pdfmonkey
11
11
  def call(method, resource)
12
12
  response = send_request(method, resource)
13
13
 
14
- if response.is_a?(Net::HTTPSuccess)
15
- extract_attributes(response, resource)
16
- else
17
- extract_errors(response)
14
+ case response
15
+ when Net::HTTPNoContent then true
16
+ when Net::HTTPSuccess then extract_attributes(response, resource)
17
+ else extract_errors(response)
18
18
  end
19
19
  rescue StandardError => e
20
20
  { errors: [e.message], status: 'error' }
21
21
  end
22
22
 
23
+ private def build_delete_request(uri, _resource)
24
+ Net::HTTP::Delete.new(uri, headers)
25
+ end
26
+
23
27
  private def build_get_request(uri, _resource)
24
28
  Net::HTTP::Get.new(uri, headers)
25
29
  end
@@ -45,7 +49,8 @@ module Pdfmonkey
45
49
  private def headers
46
50
  {
47
51
  'Authorization' => "Bearer #{config.private_key}",
48
- 'Content-Type' => 'application/json'
52
+ 'Content-Type' => 'application/json',
53
+ 'User-Agent' => 'Ruby'
49
54
  }
50
55
  end
51
56
 
@@ -15,6 +15,7 @@ module Pdfmonkey
15
15
  document_template_id
16
16
  download_url
17
17
  errors
18
+ filename
18
19
  id
19
20
  meta
20
21
  payload
@@ -30,6 +31,10 @@ module Pdfmonkey
30
31
  attr_reader :attributes
31
32
  def_delegators :attributes, *ATTRIBUTES
32
33
 
34
+ def self.delete(document_id)
35
+ new(id: document_id).delete!
36
+ end
37
+
33
38
  def self.fetch(document_id)
34
39
  new(id: document_id).reload!
35
40
  end
@@ -56,6 +61,10 @@ module Pdfmonkey
56
61
  update(attributes)
57
62
  end
58
63
 
64
+ def delete!
65
+ adapter.call(:delete, self)
66
+ end
67
+
59
68
  def done?
60
69
  COMPLETE_STATUSES.include?(status)
61
70
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pdfmonkey
4
- VERSION = '0.4.0'
4
+ VERSION = '0.5.0'
5
5
  end
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.add_development_dependency 'bundler', '~> 1.17'
26
26
  spec.add_development_dependency 'coveralls', '~> 0.8'
27
- spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'rake', '~> 13.0'
28
28
  spec.add_development_dependency 'rspec', '~> 3.8'
29
29
  spec.add_development_dependency 'rubocop', '~> 0.60.0'
30
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pdfmonkey
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Courtois
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-01 00:00:00.000000000 Z
11
+ date: 2020-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '13.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '13.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -110,7 +110,7 @@ homepage: https://github.com/pdfmonkeyio/pdfmonkey-ruby
110
110
  licenses:
111
111
  - MIT
112
112
  metadata: {}
113
- post_install_message:
113
+ post_install_message:
114
114
  rdoc_options: []
115
115
  require_paths:
116
116
  - lib
@@ -125,8 +125,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  - !ruby/object:Gem::Version
126
126
  version: '0'
127
127
  requirements: []
128
- rubygems_version: 3.0.4
129
- signing_key:
128
+ rubygems_version: 3.0.3
129
+ signing_key:
130
130
  specification_version: 4
131
131
  summary: Connect to the PDFMonkey API
132
132
  test_files: []