rpdf 0.9.6

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 50be1e0c93dd395d2694176cb7715e6e52a77e944c414788d4d7ed6227239bd5
4
+ data.tar.gz: ef5dc4f7a92b213397424001eb9dc7787d5ff0cbd8d3fafa5683ede16f486cc8
5
+ SHA512:
6
+ metadata.gz: ebaf0d3eb698a1d42a913e4094bccb2403c13bea7593b87dd4eb9262444781d85cf4c3201e56f69ce2dc85910ca1b8431f4b2142cc1c60c3e20a74706b64322a
7
+ data.tar.gz: 8fe753248f784f04e298fc39f047c7952c448444012559548a3a0d47464bcf65d6b9430182f9eb4e0fef61cb33a6f24be43616fd584d05a049593e4daa036f65
data/.gitignore ADDED
@@ -0,0 +1,24 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .idea/
24
+ *.pdf
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rpdf.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 boncri
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # Rpdf
2
+
3
+ Interface to Ws-ZapPdf service.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rpdf'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rpdf
18
+
19
+ ## Usage
20
+
21
+ ###To send a PDF in real time to the client using some data and a local file as a template:
22
+
23
+ zappdf = Intersail::Rpdf::ZapPdfClient.new('[my-zappdf-service-url]')
24
+ pdf = zappdf.make_pdf_with_local_file('[my-local-template-file]', @data_objects_for_tags)
25
+ send_data(pdf, content_type: 'application/pdf', disposition: 'inline')
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it ( https://github.com/INTERSAIL/rpdf/fork )
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
data/lib/rpdf.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "rpdf/version"
2
+ require 'rpdf/concerns/models/xml_serializable'
3
+ require 'rpdf/models/node'
4
+ require 'rpdf/services/zap_pdf_client'
@@ -0,0 +1,57 @@
1
+ require 'active_support/all'
2
+
3
+ module Intersail
4
+ module Rpdf
5
+ module XmlSerializable
6
+
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ cattr_accessor :xml_include_fields
11
+ cattr_accessor :xml_methods_fields
12
+
13
+ self.xml_include_fields = []
14
+ self.xml_methods_fields = []
15
+ end
16
+
17
+
18
+ module ClassMethods
19
+ def xml_include(*fields)
20
+ fields.each { |f| self.xml_include_fields << f }
21
+ end
22
+ def xml_methods(*fields)
23
+ fields.each { |f| self.xml_methods_fields << f }
24
+ end
25
+ end
26
+
27
+ def to_xml(options = {})
28
+ method_options = options.delete(:methods) || []
29
+ include_options = options.delete(:include) || []
30
+ exclude_options = options.delete(:exclude)
31
+
32
+ if exclude_options == :all
33
+ include = []
34
+ else
35
+ include = self.class.xml_include_fields << include_options
36
+ include = include.flatten.compact.uniq
37
+
38
+ if exclude_options
39
+ if exclude_options.kind_of?(Array)
40
+ exclude_options.each { |e| include.delete(e) }
41
+ else
42
+ include.delete(exclude_options)
43
+ end
44
+ end
45
+ end
46
+
47
+ methods = self.class.xml_methods_fields << method_options
48
+ methods = methods.flatten.compact.uniq
49
+
50
+ super_options = options.merge({include: include, methods: methods})
51
+
52
+ super(super_options)
53
+ end
54
+
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,33 @@
1
+ module Intersail
2
+ module Rpdf
3
+ class Node
4
+ def name
5
+ @name
6
+ end
7
+ def children
8
+ @children
9
+ end
10
+ def has_children?
11
+ @children && @children.respond_to?(:length) && @children.length>0
12
+ end
13
+
14
+ def [](index)
15
+ @hash[index]
16
+ end
17
+
18
+ def initialize(hash)
19
+ @hash = hash
20
+
21
+ @name = hash[:name]
22
+
23
+ subtags = hash[:childs][:tag_node] if hash[:childs] && hash[:childs][:tag_node]
24
+
25
+ if subtags.kind_of? Array
26
+ @children = subtags.map{|c| Node.new(c)}
27
+ elsif subtags.kind_of? Hash
28
+ @children = [Node.new(subtags)]
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,41 @@
1
+ require "savon"
2
+
3
+ module Intersail
4
+ module Rpdf
5
+ class ZapPdfClient
6
+
7
+ def initialize(address)
8
+ @url = address
9
+ @ws = Savon.client(wsdl: "#{address}?wsdl")
10
+ end
11
+
12
+ def url
13
+ @url
14
+ end
15
+
16
+ def make_pdf_with_local_file(templateFile, data, options = {})
17
+ templateData = Base64.encode64(File.read(templateFile))
18
+
19
+ response = @ws.call(:make_pdf_with_xml, message: { data: templateData, xmlTags: data.to_xml(options) })
20
+
21
+ return nil unless response
22
+
23
+ pdfData = response.body[:make_pdf_with_xml_response][:make_pdf_with_xml_result]
24
+
25
+ Base64.decode64(pdfData)
26
+ end
27
+
28
+ def get_template_tags(templateFile)
29
+ templateData = Base64.encode64(File.read(templateFile))
30
+
31
+ response = @ws.call(:get_template_tags, message: { data: templateData })
32
+
33
+ return nil unless response
34
+
35
+ tags = response.body[:get_template_tags_response][:get_template_tags_result]
36
+
37
+ Intersail::Rpdf::Node.new(tags) unless tags.nil?
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ module Rpdf
2
+ VERSION = "0.9.6"
3
+ end
data/rpdf.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rpdf/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rpdf"
8
+ spec.version = Rpdf::VERSION
9
+ spec.authors = ["INTERSAIL"]
10
+ spec.email = ["cristiano.boncompagni@intersail.it"]
11
+ spec.summary = %q{ZapPdf Client for Ruby}
12
+ spec.description = %q{ZapPdf Client for Ruby with interface on WsZapPdf}
13
+ spec.homepage = "http://www.zapsuite.com"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rails", "~> 4"
23
+ spec.add_development_dependency "rake", '~> 0'
24
+ spec.add_development_dependency "rspec"
25
+
26
+ spec.add_runtime_dependency "savon", "~> 2.0"
27
+ end
@@ -0,0 +1,152 @@
1
+ require 'spec_helper'
2
+
3
+ require 'active_model'
4
+
5
+ describe Intersail::Rpdf::ZapPdfClient do
6
+ before(:all) do
7
+ @url = 'http://ced-sisi/WSZapPdf/ZapPdfService.asmx'
8
+ @client = Intersail::Rpdf::ZapPdfClient.new(@url)
9
+ @template1 = 'spec/template1.odt'
10
+ @template2 = 'spec/template2.odt'
11
+ end
12
+
13
+ it 'should set url' do
14
+ expect(@client.url).to eq(@url)
15
+ end
16
+
17
+ context 'single tag' do
18
+ before do
19
+ @node = @client.get_template_tags(@template2)
20
+ end
21
+
22
+ it 'should build node' do
23
+ expect(@node).to_not be nil
24
+
25
+ expect(@node.name).to be nil
26
+ expect(@node).to have_children
27
+
28
+ expect(@node.children.length).to eq 1
29
+
30
+ expect(@node.children[0].name).to eq 'name'
31
+ expect(@node.children[0]).to_not have_children
32
+ end
33
+
34
+ it 'should behave like Hash' do
35
+ expect(@node[:name]).to be nil
36
+ expect(@node[:childs]).to_not be nil
37
+ expect(@node[:childs][:tag_node]).to_not be nil
38
+
39
+ expect(@node[:childs][:tag_node]).to be_kind_of Hash
40
+
41
+ expect(@node[:childs][:tag_node][:name]).to eq 'name'
42
+ expect(@node[:childs][:tag_node][:childs]).to be nil
43
+ end
44
+ end
45
+
46
+ context 'array tag' do
47
+ before do
48
+ @node = @client.get_template_tags(@template1)
49
+ end
50
+
51
+ it 'should create tags array' do
52
+ expect(@node).to_not be nil
53
+
54
+ tags = TagArray.new(@node)
55
+
56
+ expect(tags.array.length).to eq 4
57
+
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'
63
+ end
64
+
65
+ it 'should read node' do
66
+ expect(@node).to_not be nil
67
+
68
+ expect(@node.name).to be nil
69
+ expect(@node).to have_children
70
+
71
+ expect(@node.children.length).to eq 3
72
+
73
+ expect(@node.children[0].name).to eq 'amounts'
74
+ expect(@node.children[0]).to have_children
75
+
76
+ expect(@node.children[0].children.length).to eq 2
77
+
78
+ expect(@node.children[0].children[0].name).to eq 'value'
79
+ expect(@node.children[0].children[0]).to_not have_children
80
+
81
+ expect(@node.children[0].children[1].name).to eq 'currency'
82
+ expect(@node.children[0].children[1]).to_not have_children
83
+
84
+ expect(@node.children[1].name).to eq 'name'
85
+ expect(@node.children[1]).to_not have_children
86
+
87
+ expect(@node.children[2].name).to eq 'surname'
88
+ expect(@node.children[2]).to_not have_children
89
+ end
90
+ end
91
+
92
+ it 'should create a pdf from a hash' do
93
+ person = {
94
+ name: 'Paolino',
95
+ surname: 'Paperino',
96
+ amounts: [
97
+ {value: "100,00", currency: 'EUR'},
98
+ {value: "20,30", currency: 'USD'},
99
+ ]
100
+ }
101
+
102
+ pdf = @client.make_pdf_with_local_file(@template1, person)
103
+
104
+ expect(pdf).to_not be nil
105
+
106
+ File.open('template1.pdf', 'w'){|f| f.write(pdf)}
107
+ end
108
+
109
+ it 'should create a pdf from an object' do
110
+ class Person
111
+ include ActiveModel::Model
112
+ include ActiveModel::Serializers::Xml
113
+ attr_accessor :name, :surname, :amounts
114
+
115
+ def attributes=(hash)
116
+ hash.each do |key, value|
117
+ instance_variable_set("@#{key}", value)
118
+ end
119
+ end
120
+ def attributes
121
+ instance_values
122
+ end
123
+ end
124
+
125
+ class Amount
126
+ include ActiveModel::Model
127
+ include ActiveModel::Serializers::Xml
128
+ attr_accessor :value, :currency
129
+
130
+ def attributes=(hash)
131
+ hash.each do |key, value|
132
+ instance_variable_set("@#{key}", value)
133
+ end
134
+ end
135
+ def attributes
136
+ instance_values
137
+ end
138
+ end
139
+
140
+ person = Person.new(name:'Paolino',surname:'Paperino')
141
+ person.amounts = [
142
+ Amount.new(value:'100,00',currency:'EUR'),
143
+ Amount.new(value:'20,30',currency:'USD')
144
+ ]
145
+
146
+ pdf = @client.make_pdf_with_local_file(@template1, person)
147
+
148
+ expect(pdf).to_not be nil
149
+
150
+ File.open('template2.pdf', 'w'){|f| f.write(pdf)}
151
+ end
152
+ end
@@ -0,0 +1,2 @@
1
+ require 'rpdf'
2
+ require 'active_model/attribute_methods'
Binary file
Binary file
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rpdf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.6
5
+ platform: ruby
6
+ authors:
7
+ - INTERSAIL
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-02-20 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '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: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: savon
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
83
+ description: ZapPdf Client for Ruby with interface on WsZapPdf
84
+ email:
85
+ - cristiano.boncompagni@intersail.it
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - lib/rpdf.rb
96
+ - lib/rpdf/concerns/models/xml_serializable.rb
97
+ - lib/rpdf/models/node.rb
98
+ - lib/rpdf/services/zap_pdf_client.rb
99
+ - lib/rpdf/version.rb
100
+ - rpdf.gemspec
101
+ - spec/intersail/rpdf/zap_pdf_client_spec.rb
102
+ - spec/spec_helper.rb
103
+ - spec/template1.odt
104
+ - spec/template2.odt
105
+ homepage: http://www.zapsuite.com
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubygems_version: 3.0.3
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: ZapPdf Client for Ruby
128
+ test_files:
129
+ - spec/intersail/rpdf/zap_pdf_client_spec.rb
130
+ - spec/spec_helper.rb
131
+ - spec/template1.odt
132
+ - spec/template2.odt