cloudrunpdf 0.1.6 → 0.2.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: aaec64c1929adc238dbeb808c17fb4497db4cd6c64187e5a5b21963d9d0cb7b9
4
- data.tar.gz: 9fc6bed30f71eb8b676024e41ffd84dc82211d6f03a02db56ad490fe21d76e7f
3
+ metadata.gz: 295dace19af034ae16e7c2a750d8e65e3e2b547b2bb32be072cd8a7881be44d8
4
+ data.tar.gz: cf548e50c3f0777a138e60e7dfe60099bb1497726d0a2d78ce74c5214e89f33c
5
5
  SHA512:
6
- metadata.gz: 9e773c8d2f092bccfd31be64a6f5ed17fe8e15bfce36ba672e38125381cc782e92e53d9770a7a7ced9419b815ca8074408a711cb39ef405fe5a5718f312acee2
7
- data.tar.gz: 0e811369f102218e55ea4bb867ba4218a051ee055fe41e7cdcfbfa7089c45fe75aa76f2a71a2d3db83ef43802da54610c43b737fb0220da1f6953999a506e339
6
+ metadata.gz: 24b9a700da788ab7fe92b5354d29d6fa9dcf3efff8870bf2411f55483377fb95e576a80b00ffb4d96a810382e252e024a1566329593cf8c2046832dac04ecf58
7
+ data.tar.gz: 7d70be974274d51ae125e99ac19c257ea7d83d3f304eb6124318acf26caedbe00a97ccea3c5f972985c64b50bcf9adfc345402a22ba5f32acfff59b59c963cf5
@@ -0,0 +1,22 @@
1
+ image: remarksolutions/ci-image:ruby-31
2
+
3
+ pipelines:
4
+ default:
5
+ - step:
6
+ name: Quality Assurance
7
+ script:
8
+ - bundle install --local
9
+ - bin/rspec
10
+ - bin/rubocop
11
+ caches:
12
+ - bundler
13
+ runs-on:
14
+ - self.hosted
15
+ - linux
16
+ - nuc
17
+ definitions:
18
+ caches:
19
+ bundler: vendor/bundle
20
+ services:
21
+ docker:
22
+ memory: 3072
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,64 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ Exclude:
4
+ - '*.gemspec'
5
+ - Gemfile
6
+
7
+ Layout/MultilineMethodCallIndentation:
8
+ EnforcedStyle: indented
9
+ IndentationWidth: 4
10
+ Layout/MultilineOperationIndentation:
11
+ EnforcedStyle: indented
12
+ IndentationWidth: 2
13
+ Layout/ArrayAlignment:
14
+ Enabled: false
15
+ Layout/HashAlignment:
16
+ Enabled: false
17
+ Layout/ParameterAlignment:
18
+ EnforcedStyle: with_fixed_indentation
19
+ IndentationWidth: 4
20
+ Layout/ArgumentAlignment:
21
+ EnforcedStyle: with_fixed_indentation
22
+ IndentationWidth: 4
23
+ Layout/FirstHashElementIndentation:
24
+ Enabled: false
25
+ Layout/FirstArgumentIndentation:
26
+ Enabled: false
27
+ Layout/FirstArrayElementIndentation:
28
+ Enabled: false
29
+ Layout/LineLength:
30
+ Max: 100
31
+
32
+ Style/WordArray:
33
+ EnforcedStyle: brackets
34
+ Style/SymbolArray:
35
+ EnforcedStyle: brackets
36
+ Style/NumericPredicate:
37
+ EnforcedStyle: comparison
38
+ Style/ZeroLengthPredicate:
39
+ Enabled: false
40
+ Style/ConditionalAssignment:
41
+ EnforcedStyle: assign_inside_condition
42
+ Style/Documentation:
43
+ Enabled: false
44
+ Style/EmptyMethod:
45
+ EnforcedStyle: expanded
46
+ Style/FrozenStringLiteralComment:
47
+ Enabled: false
48
+ Style/GuardClause:
49
+ Enabled: false
50
+ Style/IfUnlessModifier:
51
+ Enabled: false
52
+
53
+ Metrics/ClassLength:
54
+ Enabled: false
55
+ Metrics/PerceivedComplexity:
56
+ Enabled: false
57
+ Metrics/CyclomaticComplexity:
58
+ Enabled: false
59
+ Metrics/AbcSize:
60
+ Enabled: false
61
+ Metrics/MethodLength:
62
+ Enabled: false
63
+ Metrics/BlockLength:
64
+ Enabled: false
data/Gemfile.lock CHANGED
@@ -1,31 +1,78 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cloudrunpdf (0.1.5)
4
+ cloudrunpdf (0.1.4)
5
5
  combine_pdf
6
6
  faraday
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- combine_pdf (1.0.23)
11
+ ast (2.4.2)
12
+ combine_pdf (1.0.26)
12
13
  matrix
13
14
  ruby-rc4 (>= 0.1.5)
14
- faraday (2.7.4)
15
- faraday-net_http (>= 2.0, < 3.1)
16
- ruby2_keywords (>= 0.0.4)
17
- faraday-net_http (3.0.2)
15
+ diff-lcs (1.5.0)
16
+ faraday (2.9.0)
17
+ faraday-net_http (>= 2.0, < 3.2)
18
+ faraday-net_http (3.1.0)
19
+ net-http
20
+ json (2.7.1)
21
+ language_server-protocol (3.17.0.3)
18
22
  matrix (0.4.2)
23
+ net-http (0.4.1)
24
+ uri
25
+ parallel (1.24.0)
26
+ parser (3.3.0.3)
27
+ ast (~> 2.4.1)
28
+ racc
29
+ racc (1.7.3)
30
+ rainbow (3.1.1)
19
31
  rake (13.0.6)
32
+ regexp_parser (2.9.0)
33
+ rexml (3.2.6)
34
+ rspec (3.12.0)
35
+ rspec-core (~> 3.12.0)
36
+ rspec-expectations (~> 3.12.0)
37
+ rspec-mocks (~> 3.12.0)
38
+ rspec-core (3.12.2)
39
+ rspec-support (~> 3.12.0)
40
+ rspec-expectations (3.12.3)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.12.0)
43
+ rspec-mocks (3.12.6)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.12.0)
46
+ rspec-support (3.12.1)
47
+ rubocop (1.60.0)
48
+ json (~> 2.3)
49
+ language_server-protocol (>= 3.17.0)
50
+ parallel (~> 1.10)
51
+ parser (>= 3.3.0.2)
52
+ rainbow (>= 2.2.2, < 4.0)
53
+ regexp_parser (>= 1.8, < 3.0)
54
+ rexml (>= 3.2.5, < 4.0)
55
+ rubocop-ast (>= 1.30.0, < 2.0)
56
+ ruby-progressbar (~> 1.7)
57
+ unicode-display_width (>= 2.4.0, < 3.0)
58
+ rubocop-ast (1.30.0)
59
+ parser (>= 3.2.1.0)
60
+ ruby-progressbar (1.13.0)
20
61
  ruby-rc4 (0.1.5)
21
- ruby2_keywords (0.0.5)
62
+ unicode-display_width (2.5.0)
63
+ uri (0.13.0)
64
+ vcr (6.2.0)
22
65
 
23
66
  PLATFORMS
24
67
  arm64-darwin-21
68
+ arm64-darwin-22
25
69
 
26
70
  DEPENDENCIES
27
71
  cloudrunpdf!
28
72
  rake (~> 13.0)
73
+ rspec
74
+ rubocop
75
+ vcr
29
76
 
30
77
  BUNDLED WITH
31
- 2.2.32
78
+ 2.5.4
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # Cloudrunpdf
2
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/cloudrunpdf`. 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
3
+ The cloudrunpdf Ruby gem allows delegating the rendering of HTML to PDF to a dedicated Google Cloud Run container. This container should be based on the [cloudpdf](https://bitbucket.org/remark_innovation_center/cloudpdf/src/main/) container image.
6
4
 
7
5
  ## Installation
8
6
 
@@ -22,22 +20,10 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
23
+ See `bin/smoketest` for a concrete usage example.
26
24
 
27
25
  ## Development
28
26
 
29
- 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.
27
+ 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. After making any changes, for quality assurance you can execute the rspec test suite by running `bin/rspec`. In addition, static analysis can be performed by running `bin/rubocop`.
30
28
 
31
29
  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).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cloudrunpdf. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/cloudrunpdf/blob/master/CODE_OF_CONDUCT.md).
36
-
37
- ## License
38
-
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
-
41
- ## Code of Conduct
42
-
43
- Everyone interacting in the Cloudrunpdf project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/cloudrunpdf/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bundler/gem_tasks"
4
- task default: %i[]
3
+ require 'bundler/gem_tasks'
4
+ task default: []
data/bin/console CHANGED
@@ -1,15 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
2
 
4
- require "bundler/setup"
5
- require "cloudrunpdf"
3
+ require 'bundler/setup'
4
+ require 'cloudrunpdf'
6
5
 
7
- # You can add fixtures and/or initialization code here to make experimenting
8
- # with your gem easier. You can also use a different console, if you like.
9
-
10
- # (If you use this, don't forget to add pry to your Gemfile!)
11
- # require "pry"
12
- # Pry.start
13
-
14
- require "irb"
6
+ require 'irb'
15
7
  IRB.start(__FILE__)
data/bin/rake ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
4
+
5
+ require 'rubygems'
6
+ require 'bundler/setup'
7
+
8
+ load Gem.bin_path('rake', 'rake')
data/bin/rspec ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
4
+
5
+ require 'rubygems'
6
+ require 'bundler/setup'
7
+ require 'cloudrunpdf'
8
+
9
+ load Gem.bin_path('rspec-core', 'rspec')
data/bin/rubocop ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
4
+
5
+ require 'rubygems'
6
+ require 'bundler/setup'
7
+
8
+ load Gem.bin_path('rubocop', 'rubocop')
data/bin/setup CHANGED
@@ -4,5 +4,3 @@ IFS=$'\n\t'
4
4
  set -vx
5
5
 
6
6
  bundle install
7
-
8
- # Do any other automated setup that you need to do here
data/bin/smoketest ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'cloudrunpdf'
5
+
6
+ require 'base64'
7
+
8
+ if ENV['GCLOUD_AUTH_TOKEN'].nil? || ENV['GCLOUD_AUTH_TOKEN'].empty?
9
+ puts <<~MSG
10
+
11
+ Please run the following before executing the smoketest:
12
+
13
+ gcloud auth login; gcloud auth application-default login; export GCLOUD_AUTH_TOKEN=$(gcloud auth print-identity-token)
14
+
15
+ MSG
16
+ exit(1)
17
+ end
18
+
19
+ builder = Cloudrunpdf::Builder.new
20
+ result = builder.print({ document: Base64.encode64('<html><body>Hello, world!</body></html>') })
21
+
22
+ FileUtils.mkdir_p('tmp')
23
+ File.write('tmp/result.pdf', result)
24
+ `open tmp/result.pdf`
@@ -1,5 +1,4 @@
1
- # frozen_string_literal: true
2
-
1
+ require 'faraday'
3
2
  require 'combine_pdf'
4
3
 
5
4
  module Cloudrunpdf
@@ -11,8 +10,11 @@ module Cloudrunpdf
11
10
 
12
11
  def print(data)
13
12
  threads = []
13
+ data = [data] unless data.is_a?(Array)
14
+
15
+ Thread.report_on_exception = false
14
16
 
15
- Array.wrap(data).each do |entry|
17
+ data.each do |entry|
16
18
  threads.append(
17
19
  Thread.new { Thread.current[:pdf] = generate_pdf(entry) }
18
20
  )
@@ -26,13 +28,17 @@ module Cloudrunpdf
26
28
  end
27
29
 
28
30
  def generate_pdf(data)
29
- conn = Faraday.new
30
- headers = { 'Content-Type' => 'application/json' }
31
- headers['Authorization'] = 'Bearer ' + @token if @configuration.google?
31
+ connection = Faraday::Connection.new(
32
+ headers: {
33
+ 'Content-Type' => 'application/json',
34
+ 'Authorization' => ("Bearer #{@token}" if @configuration.google?)
35
+ }.compact
36
+ ) do |conn|
37
+ conn.response :raise_error
38
+ end
32
39
 
33
- conn.post(@configuration.cloud_function_url) do |req|
40
+ connection.post(@configuration.cloud_function_url) do |req|
34
41
  req.body = data.to_json
35
- req.headers = headers
36
42
  end
37
43
  end
38
44
 
@@ -42,9 +48,9 @@ module Cloudrunpdf
42
48
  # We only auth to cloudrun
43
49
  return unless @configuration.google?
44
50
 
45
- if ENV['GCLOUD_AUTH_TOKEN'].present?
46
- @token ||= ENV['GCLOUD_AUTH_TOKEN']
47
- elsif Rails.env.in?(['development', 'test'])
51
+ if !ENV['GCLOUD_AUTH_TOKEN'].nil?
52
+ @token ||= ENV.fetch('GCLOUD_AUTH_TOKEN', nil)
53
+ elsif Object.const_defined?(:Rails) && Rails.env.in?(['development', 'test'])
48
54
  @token ||= `gcloud auth print-identity-token`.strip
49
55
  else
50
56
  @token ||= Faraday.get(
@@ -11,7 +11,7 @@ module Cloudrunpdf
11
11
  ].freeze
12
12
 
13
13
  def initialize
14
- @cloud_function_url = 'https://cloudpdf-7zhay37huq-od.a.run.app'.freeze
14
+ @cloud_function_url = 'https://cloudpdf-7zhay37huq-od.a.run.app'
15
15
  @auth = :google
16
16
  end
17
17
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cloudrunpdf
4
- VERSION = '0.1.6'
4
+ VERSION = '0.2.0'
5
5
  end
data/lib/cloudrunpdf.rb CHANGED
@@ -1,10 +1,8 @@
1
- # frozen_string_literal: true
2
1
  require_relative 'cloudrunpdf/configuration'
3
2
  require_relative 'cloudrunpdf/version'
4
3
  require_relative 'cloudrunpdf/builder'
5
4
 
6
5
  module Cloudrunpdf
7
- # add configuration to Gem
8
6
  class << self
9
7
  def configuration
10
8
  @configuration ||= Configuration.new
metadata CHANGED
@@ -1,16 +1,59 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudrunpdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bas Schoenmakers
8
8
  - Jasper vd Berg
9
+ - Jesse Tilro
9
10
  autorequire:
10
11
  bindir: exe
11
12
  cert_chain: []
12
- date: 2023-06-13 00:00:00.000000000 Z
13
+ date: 2024-01-16 00:00:00.000000000 Z
13
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rubocop
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: rspec
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: vcr
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
14
57
  - !ruby/object:Gem::Dependency
15
58
  name: combine_pdf
16
59
  requirement: !ruby/object:Gem::Requirement
@@ -43,10 +86,14 @@ description:
43
86
  email:
44
87
  - bas.schoenmakers@remarkgroup.com
45
88
  - jasper.vandenberg@remarkgroup.com
89
+ - jesse.tilro@remarkgroup.com
46
90
  executables: []
47
91
  extensions: []
48
92
  extra_rdoc_files: []
49
93
  files:
94
+ - ".bitbucket-pipelines.yml"
95
+ - ".rspec"
96
+ - ".rubocop.yml"
50
97
  - CODE_OF_CONDUCT.md
51
98
  - Gemfile
52
99
  - Gemfile.lock
@@ -54,7 +101,11 @@ files:
54
101
  - README.md
55
102
  - Rakefile
56
103
  - bin/console
104
+ - bin/rake
105
+ - bin/rspec
106
+ - bin/rubocop
57
107
  - bin/setup
108
+ - bin/smoketest
58
109
  - lib/cloudrunpdf.rb
59
110
  - lib/cloudrunpdf/builder.rb
60
111
  - lib/cloudrunpdf/configuration.rb
@@ -80,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
131
  - !ruby/object:Gem::Version
81
132
  version: '0'
82
133
  requirements: []
83
- rubygems_version: 3.3.7
134
+ rubygems_version: 3.4.10
84
135
  signing_key:
85
136
  specification_version: 4
86
137
  summary: Generate PDF with Google Cloud Function.