rpdf 0.9.6 → 0.9.7

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: 50be1e0c93dd395d2694176cb7715e6e52a77e944c414788d4d7ed6227239bd5
4
- data.tar.gz: ef5dc4f7a92b213397424001eb9dc7787d5ff0cbd8d3fafa5683ede16f486cc8
3
+ metadata.gz: 135ad5d6942ca6a2a4d9269bad24b0c077c383dda6e4462ed8ac68ebef84ed9b
4
+ data.tar.gz: 201496f5efa2dd9958ffe32bfe6e257eb025ab93e32e21f9e1613ecb657a7b85
5
5
  SHA512:
6
- metadata.gz: ebaf0d3eb698a1d42a913e4094bccb2403c13bea7593b87dd4eb9262444781d85cf4c3201e56f69ce2dc85910ca1b8431f4b2142cc1c60c3e20a74706b64322a
7
- data.tar.gz: 8fe753248f784f04e298fc39f047c7952c448444012559548a3a0d47464bcf65d6b9430182f9eb4e0fef61cb33a6f24be43616fd584d05a049593e4daa036f65
6
+ metadata.gz: 39aabcbe2ed5d10e53a5673fcfa5997848157fe2bfd3e3132f14ab4a80efc2be20821355e806d3d72f036f034e39f742b8ade1f1bc343a7cd1b0ab142f3a0686
7
+ data.tar.gz: c10b1f9778923cce13a5d897b9a63fa2b48c0f820ef42a60d2486c89103361deb1bf860bcee4c0e904614e821a34ddb3677a997fa1820a663ef6b9d0e69e9597
@@ -0,0 +1,54 @@
1
+ c
2
+ tags.array
3
+ c
4
+ tags.array
5
+ continue
6
+ c
7
+ tags.array
8
+ c
9
+ tags.array
10
+ c
11
+ tags.array
12
+ c
13
+ continue
14
+ tags.array
15
+ continue
16
+ @node.children.first
17
+ @node.children.first.children
18
+ @node.children.first
19
+ tags.array
20
+ c
21
+ n
22
+ c
23
+ n
24
+ c
25
+ n
26
+ continue
27
+ @node.name
28
+ @node
29
+ @node.children.count
30
+ @node.children.first.children.first.name
31
+ @node.children.first.children.count
32
+ @node.children.first.has_children?
33
+ @node.children.first.name
34
+ @node.children.first
35
+ @node.children.count
36
+ @node.children.has_children?
37
+ @node.children
38
+ continue
39
+ @node.as_json
40
+ @node.children.children
41
+ @node.children
42
+ @node[1]
43
+ @node[0]
44
+ @node.name
45
+ @node.children
46
+ @node.methods
47
+ @node.to_h
48
+ @node.hash
49
+ @node.has
50
+ @node.tag_node
51
+ @node.tags
52
+ @node.tag
53
+ @node.count
54
+ @node
data/.gitignore CHANGED
@@ -1,9 +1,7 @@
1
1
  *.gem
2
2
  *.rbc
3
- .bundle
4
3
  .config
5
4
  .yardoc
6
- Gemfile.lock
7
5
  InstalledFiles
8
6
  _yardoc
9
7
  coverage
@@ -0,0 +1,20 @@
1
+ FROM ruby:2.4
2
+
3
+ RUN mkdir /app
4
+ RUN mkdir -p /app/lib/rpdf
5
+
6
+ COPY Gemfile* /app/
7
+ COPY *.gemspec /app
8
+ COPY lib/rpdf/version.rb /app/lib/rpdf/
9
+ WORKDIR /app
10
+
11
+ RUN bundle install
12
+
13
+ COPY . /app
14
+
15
+ RUN echo "IRB.conf[:SAVE_HISTORY] = 200" > /.irbrc
16
+ RUN echo "IRB.conf[:HISTORY_FILE] = '/app/tmp/.irb-history'" >> /.irbrc
17
+
18
+ EXPOSE 3000
19
+
20
+ CMD ["bundle", "exec", "rspec"]
@@ -0,0 +1,151 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rpdf (0.9.7)
5
+ savon (~> 2.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionmailer (4.2.11.1)
11
+ actionpack (= 4.2.11.1)
12
+ actionview (= 4.2.11.1)
13
+ activejob (= 4.2.11.1)
14
+ mail (~> 2.5, >= 2.5.4)
15
+ rails-dom-testing (~> 1.0, >= 1.0.5)
16
+ actionpack (4.2.11.1)
17
+ actionview (= 4.2.11.1)
18
+ activesupport (= 4.2.11.1)
19
+ rack (~> 1.6)
20
+ rack-test (~> 0.6.2)
21
+ rails-dom-testing (~> 1.0, >= 1.0.5)
22
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
23
+ actionview (4.2.11.1)
24
+ activesupport (= 4.2.11.1)
25
+ builder (~> 3.1)
26
+ erubis (~> 2.7.0)
27
+ rails-dom-testing (~> 1.0, >= 1.0.5)
28
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
29
+ activejob (4.2.11.1)
30
+ activesupport (= 4.2.11.1)
31
+ globalid (>= 0.3.0)
32
+ activemodel (4.2.11.1)
33
+ activesupport (= 4.2.11.1)
34
+ builder (~> 3.1)
35
+ activerecord (4.2.11.1)
36
+ activemodel (= 4.2.11.1)
37
+ activesupport (= 4.2.11.1)
38
+ arel (~> 6.0)
39
+ activesupport (4.2.11.1)
40
+ i18n (~> 0.7)
41
+ minitest (~> 5.1)
42
+ thread_safe (~> 0.3, >= 0.3.4)
43
+ tzinfo (~> 1.1)
44
+ akami (1.3.1)
45
+ gyoku (>= 0.4.0)
46
+ nokogiri
47
+ arel (6.0.4)
48
+ builder (3.2.4)
49
+ byebug (11.1.1)
50
+ concurrent-ruby (1.1.6)
51
+ crass (1.0.6)
52
+ diff-lcs (1.3)
53
+ erubis (2.7.0)
54
+ globalid (0.4.2)
55
+ activesupport (>= 4.2.0)
56
+ gyoku (1.3.1)
57
+ builder (>= 2.1.2)
58
+ httpi (2.4.4)
59
+ rack
60
+ socksify
61
+ i18n (0.9.5)
62
+ concurrent-ruby (~> 1.0)
63
+ loofah (2.4.0)
64
+ crass (~> 1.0.2)
65
+ nokogiri (>= 1.5.9)
66
+ mail (2.7.1)
67
+ mini_mime (>= 0.1.1)
68
+ mini_mime (1.0.2)
69
+ mini_portile2 (2.4.0)
70
+ minitest (5.14.0)
71
+ nokogiri (1.10.8)
72
+ mini_portile2 (~> 2.4.0)
73
+ nori (2.6.0)
74
+ rack (1.6.13)
75
+ rack-test (0.6.3)
76
+ rack (>= 1.0)
77
+ rails (4.2.11.1)
78
+ actionmailer (= 4.2.11.1)
79
+ actionpack (= 4.2.11.1)
80
+ actionview (= 4.2.11.1)
81
+ activejob (= 4.2.11.1)
82
+ activemodel (= 4.2.11.1)
83
+ activerecord (= 4.2.11.1)
84
+ activesupport (= 4.2.11.1)
85
+ bundler (>= 1.3.0, < 2.0)
86
+ railties (= 4.2.11.1)
87
+ sprockets-rails
88
+ rails-deprecated_sanitizer (1.0.3)
89
+ activesupport (>= 4.2.0.alpha)
90
+ rails-dom-testing (1.0.9)
91
+ activesupport (>= 4.2.0, < 5.0)
92
+ nokogiri (~> 1.6)
93
+ rails-deprecated_sanitizer (>= 1.0.1)
94
+ rails-html-sanitizer (1.3.0)
95
+ loofah (~> 2.3)
96
+ railties (4.2.11.1)
97
+ actionpack (= 4.2.11.1)
98
+ activesupport (= 4.2.11.1)
99
+ rake (>= 0.8.7)
100
+ thor (>= 0.18.1, < 2.0)
101
+ rake (0.9.6)
102
+ rspec (3.9.0)
103
+ rspec-core (~> 3.9.0)
104
+ rspec-expectations (~> 3.9.0)
105
+ rspec-mocks (~> 3.9.0)
106
+ rspec-core (3.9.1)
107
+ rspec-support (~> 3.9.1)
108
+ rspec-expectations (3.9.0)
109
+ diff-lcs (>= 1.2.0, < 2.0)
110
+ rspec-support (~> 3.9.0)
111
+ rspec-mocks (3.9.1)
112
+ diff-lcs (>= 1.2.0, < 2.0)
113
+ rspec-support (~> 3.9.0)
114
+ rspec-support (3.9.2)
115
+ savon (2.12.0)
116
+ akami (~> 1.2)
117
+ builder (>= 2.1.2)
118
+ gyoku (~> 1.2)
119
+ httpi (~> 2.3)
120
+ nokogiri (>= 1.8.1)
121
+ nori (~> 2.4)
122
+ wasabi (~> 3.4)
123
+ socksify (1.7.1)
124
+ sprockets (3.7.2)
125
+ concurrent-ruby (~> 1.0)
126
+ rack (> 1, < 3)
127
+ sprockets-rails (3.2.1)
128
+ actionpack (>= 4.0)
129
+ activesupport (>= 4.0)
130
+ sprockets (>= 3.0.0)
131
+ thor (1.0.1)
132
+ thread_safe (0.3.6)
133
+ tzinfo (1.2.6)
134
+ thread_safe (~> 0.1)
135
+ wasabi (3.5.0)
136
+ httpi (~> 2.0)
137
+ nokogiri (>= 1.4.2)
138
+
139
+ PLATFORMS
140
+ ruby
141
+
142
+ DEPENDENCIES
143
+ bundler (~> 1.6)
144
+ byebug
145
+ rails (~> 4)
146
+ rake (~> 0)
147
+ rpdf!
148
+ rspec
149
+
150
+ BUNDLED WITH
151
+ 1.17.3
@@ -0,0 +1,9 @@
1
+ version: '3'
2
+
3
+ services:
4
+ app:
5
+ build: .
6
+ volumes:
7
+ - ".:/app:cached"
8
+ stdin_open: true
9
+ tty: true
@@ -1,4 +1,5 @@
1
1
  require "rpdf/version"
2
2
  require 'rpdf/concerns/models/xml_serializable'
3
3
  require 'rpdf/models/node'
4
+ require 'rpdf/models/tag_array'
4
5
  require 'rpdf/services/zap_pdf_client'
@@ -0,0 +1,28 @@
1
+ module Intersail
2
+ module Rpdf
3
+ class TagArray
4
+ attr_reader :array
5
+
6
+ def initialize(node)
7
+ @array = []
8
+ build_array(node) if(node.respond_to?(:has_children?) && node.has_children?)
9
+ end
10
+
11
+ private
12
+
13
+ def build_array(node, basename = '')
14
+ if node.name.present?
15
+ basename = basename.empty? ? node.name : "#{basename}.#{node.name}"
16
+ end
17
+
18
+ node.children.each do |child|
19
+ if(child.has_children?)
20
+ build_array(child, basename)
21
+ else
22
+ @array.append(basename.empty? ? child.name : "#{basename}.#{child.name}")
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -3,6 +3,9 @@ require "savon"
3
3
  module Intersail
4
4
  module Rpdf
5
5
  class ZapPdfClient
6
+ cattr_accessor(:max_tries) { 1 }
7
+ cattr_accessor(:min_try_delay) { 1000 }
8
+ cattr_accessor(:max_try_delay) { 5000 }
6
9
 
7
10
  def initialize(address)
8
11
  @url = address
@@ -14,27 +17,56 @@ module Intersail
14
17
  end
15
18
 
16
19
  def make_pdf_with_local_file(templateFile, data, options = {})
20
+ max_tries = options.delete(:max_tries) || self.class.max_tries
21
+
17
22
  templateData = Base64.encode64(File.read(templateFile))
18
23
 
19
- response = @ws.call(:make_pdf_with_xml, message: { data: templateData, xmlTags: data.to_xml(options) })
24
+ try = 1
25
+ loop do
26
+ response = @ws.call(:make_pdf_with_xml, message: { data: templateData, xmlTags: data.to_xml(options) })
27
+
28
+ pdfData = response.nil? ? nil : response.body[:make_pdf_with_xml_response][:make_pdf_with_xml_result]
20
29
 
21
- return nil unless response
30
+ return Base64.decode64(pdfData) unless pdfData.nil?
22
31
 
23
- pdfData = response.body[:make_pdf_with_xml_response][:make_pdf_with_xml_result]
32
+ if try < max_tries
33
+ try += 1
34
+ sleep delay
35
+ else
36
+ break
37
+ end
38
+ end
24
39
 
25
- Base64.decode64(pdfData)
40
+ nil
26
41
  end
27
42
 
28
- def get_template_tags(templateFile)
43
+ def get_template_tags(templateFile, options = {})
44
+ max_tries = options.delete(:max_tries) || self.class.max_tries
45
+
29
46
  templateData = Base64.encode64(File.read(templateFile))
30
47
 
31
- response = @ws.call(:get_template_tags, message: { data: templateData })
48
+ try = 1
49
+ loop do
50
+
51
+ response = @ws.call(:get_template_tags, message: { data: templateData })
32
52
 
33
- return nil unless response
53
+ tags = response.nil? ? nil : response.body[:get_template_tags_response][:get_template_tags_result]
34
54
 
35
- tags = response.body[:get_template_tags_response][:get_template_tags_result]
55
+ return Intersail::Rpdf::Node.new(tags) unless tags.nil?
56
+
57
+ if try < max_tries
58
+ try += 1
59
+ sleep delay
60
+ else
61
+ break
62
+ end
63
+ end
64
+
65
+ nil
66
+ end
36
67
 
37
- Intersail::Rpdf::Node.new(tags) unless tags.nil?
68
+ def delay
69
+ rand(self.class.min_try_delay...self.class.max_try_delay) / 1000.0
38
70
  end
39
71
  end
40
72
  end
@@ -1,3 +1,3 @@
1
1
  module Rpdf
2
- VERSION = "0.9.6"
2
+ VERSION = "0.9.7"
3
3
  end
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "rails", "~> 4"
23
23
  spec.add_development_dependency "rake", '~> 0'
24
24
  spec.add_development_dependency "rspec"
25
-
25
+ spec.add_development_dependency "byebug"
26
+
26
27
  spec.add_runtime_dependency "savon", "~> 2.0"
27
28
  end
@@ -1,15 +1,33 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  require 'active_model'
4
+ require 'byebug'
4
5
 
5
6
  describe Intersail::Rpdf::ZapPdfClient do
6
7
  before(:all) do
7
- @url = 'http://ced-sisi/WSZapPdf/ZapPdfService.asmx'
8
+ @url = ENV.fetch('ZAPPDF_URL', 'http://srvtestzml.sail.local/WSZapPdf/ZapPdfService.asmx')
8
9
  @client = Intersail::Rpdf::ZapPdfClient.new(@url)
9
10
  @template1 = 'spec/template1.odt'
10
11
  @template2 = 'spec/template2.odt'
11
12
  end
12
13
 
14
+ it 'should have 1 try by default' do
15
+ expect(described_class.max_tries).to eq(1)
16
+ end
17
+
18
+ it 'should set max_tries' do
19
+ described_class.max_tries = 3
20
+ expect(described_class.max_tries).to eq(3)
21
+ end
22
+
23
+ it 'should try 3 times before fail' do
24
+ described_class.max_tries = 3
25
+
26
+ expect_any_instance_of(Savon::Client).to receive(:call).exactly(3).times.and_return(nil)
27
+
28
+ @client.get_template_tags(@template1)
29
+ end
30
+
13
31
  it 'should set url' do
14
32
  expect(@client.url).to eq(@url)
15
33
  end
@@ -51,15 +69,9 @@ describe Intersail::Rpdf::ZapPdfClient do
51
69
  it 'should create tags array' do
52
70
  expect(@node).to_not be nil
53
71
 
54
- tags = TagArray.new(@node)
55
-
56
- expect(tags.array.length).to eq 4
72
+ tags = Intersail::Rpdf::TagArray.new(@node)
57
73
 
58
- expect(tags.array[0]).to eq 'amounts.value'cd ..
59
-
60
- expect(tags.array[1]).to eq 'amounts.currency'
61
- expect(tags.array[2]).to eq 'name'
62
- expect(tags.array[3]).to eq 'surname'
74
+ expect(tags.array).to eq ['amounts.currency', 'name', 'surname']
63
75
  end
64
76
 
65
77
  it 'should read node' do
@@ -73,14 +85,11 @@ describe Intersail::Rpdf::ZapPdfClient do
73
85
  expect(@node.children[0].name).to eq 'amounts'
74
86
  expect(@node.children[0]).to have_children
75
87
 
76
- expect(@node.children[0].children.length).to eq 2
88
+ expect(@node.children[0].children.length).to eq 1
77
89
 
78
- expect(@node.children[0].children[0].name).to eq 'value'
90
+ expect(@node.children[0].children[0].name).to eq 'currency'
79
91
  expect(@node.children[0].children[0]).to_not have_children
80
92
 
81
- expect(@node.children[0].children[1].name).to eq 'currency'
82
- expect(@node.children[0].children[1]).to_not have_children
83
-
84
93
  expect(@node.children[1].name).to eq 'name'
85
94
  expect(@node.children[1]).to_not have_children
86
95
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rpdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.6
4
+ version: 0.9.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - INTERSAIL
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-20 00:00:00.000000000 Z
11
+ date: 2020-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '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'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: savon
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -87,14 +101,19 @@ executables: []
87
101
  extensions: []
88
102
  extra_rdoc_files: []
89
103
  files:
104
+ - ".byebug_history"
90
105
  - ".gitignore"
106
+ - Dockerfile
91
107
  - Gemfile
108
+ - Gemfile.lock
92
109
  - LICENSE.txt
93
110
  - README.md
94
111
  - Rakefile
112
+ - docker-compose.yml
95
113
  - lib/rpdf.rb
96
114
  - lib/rpdf/concerns/models/xml_serializable.rb
97
115
  - lib/rpdf/models/node.rb
116
+ - lib/rpdf/models/tag_array.rb
98
117
  - lib/rpdf/services/zap_pdf_client.rb
99
118
  - lib/rpdf/version.rb
100
119
  - rpdf.gemspec