sfc-custom 0.3 → 0.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.
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ v0.6. Changes from VPS, some unit tests, start of Ruby 1.9 compatibility
2
+
3
+ v0.5. CDATA
4
+
5
+ v0.4. Thumbnail option
6
+
1
7
  v0.3. Rename custom.rb to sfc-custom.rb
2
8
 
3
9
  v0.2. Fix ext/ dependency
data/Manifest CHANGED
@@ -1,5 +1,10 @@
1
- README
2
- Manifest
3
- LICENSE
4
- lib/sfc-custom.rb
5
1
  CHANGELOG
2
+ lib/sfc-custom.rb
3
+ LICENSE
4
+ Manifest
5
+ Rakefile
6
+ README
7
+ test/fixtures/expected_output_for_test_personalized_vps_order_with_logo.xml
8
+ test/fixtures/expected_output_for_test_personalized_vps_order_with_text.xml
9
+ test/fixtures/expected_output_for_test_standard_vps_order.xml
10
+ test/test_sfc-custom.rb
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'echoe'
3
+
4
+ Echoe.new('sfc-custom') do |p|
5
+ p.author = "SFC Limited, Inc."
6
+ p.summary = "Library for accessing SFCcustom, a web service for generating dynamic content for print"
7
+ p.dependencies = ["xml-simple"]
8
+ p.project = "sfc"
9
+ p.clean_pattern = ["pkg", "doc", 'build/*', '**/*.o', '**/*.so', '**/*.a', '**/*.log', "{ext,lib}/*.{bundle,so,obj,pdb,lib,def,exp}", "ext/Makefile", "{ext,lib}/**/*.{bundle,so,obj,pdb,lib,def,exp}", "ext/**/Makefile", "pkg", "*.gem", ".config"]
10
+ end
@@ -1,5 +1,5 @@
1
1
  # = SFCcustom
2
- # Ruby interface for SFC's Custom templating engine
2
+ # Ruby interface for SFCcustom, a web service for generating dynamic content for print
3
3
  #
4
4
  # == Requirements
5
5
  # * xmlsimple (gem install xml-simple)
@@ -14,9 +14,9 @@
14
14
  # sign.generate! # => #<SFCcustom::Template:0x604654 @name="Sign">
15
15
 
16
16
  require 'rubygems'
17
+ require 'xmlsimple' unless defined?(XmlSimple)
17
18
  require 'cgi'
18
19
  require 'net/http'
19
- require 'xmlsimple' unless defined?(XmlSimple)
20
20
  require 'digest/md5'
21
21
  require 'base64'
22
22
  require 'builder'
@@ -38,9 +38,12 @@ class SFCcustom
38
38
  []
39
39
  end
40
40
 
41
- # Upload a new template to SFCcustom, +data+ can either be a Base64-encoded
42
- # string or a Tempfile or File object. In either case it must be a PDF file
43
- # with PDFlib blocks. Returns a hash with :status and :blocks
41
+ # Upload a new template to SFCcustom, by passing a +URL+ of a PDF file with
42
+ # PDFlib blocks. +digest+ (optional) is the MD5 digest of the file, compared
43
+ # after the file has been processed to ensure it has been transferred
44
+ # properly.
45
+ #
46
+ # Returns a hash with :status and :blocks
44
47
  def upload(name, url, digest = nil)
45
48
 
46
49
  r = request('UploadTemplate', { :name => name, :url => url, :digest => digest})
@@ -58,16 +61,20 @@ class SFCcustom
58
61
  return result
59
62
  end
60
63
 
61
- # Delete an existing template, return true or false on success or failure
64
+ # Delete an existing template.
65
+ #
66
+ # Return +true+ or +false+ on success or failure, respectively
62
67
  def delete(name)
63
68
  r = request('DeleteTemplate', { :name => name })
64
69
  return r['status'] == ' ok '
65
70
  end
66
71
 
67
- def generate(name, params, resize = nil, cache = true, copy = nil)
68
- request('GenerateCustom', { :name => name, :data => params, :resize => resize, :cache => cache, :copy => copy})
72
+ # Generate custom output based on +name+ template and +params+
73
+ def generate(name, params, resize = nil, cache = true, copy = nil, thumbnail = true)
74
+ request('GenerateCustom', { :name => name, :data => params, :resize => resize, :cache => cache, :copy => copy, :thumbnail => thumbnail})
69
75
  end
70
76
 
77
+ # List the fonts available
71
78
  def fonts
72
79
  request('ListFonts')
73
80
  end
@@ -117,7 +124,7 @@ class SFCcustom
117
124
  attr_accessor :name, :type
118
125
  end
119
126
 
120
- def request(type, params = nil)
127
+ def build_request(type, params = nil)
121
128
  builder = Builder::XmlMarkup.new(:indent => 2)
122
129
  builder.instruct!(:xml, :version => "1.0", :encoding => "UTF-8")
123
130
 
@@ -126,29 +133,29 @@ class SFCcustom
126
133
  a.key(api_key)
127
134
  end
128
135
  case type
129
- when 'UploadTemplate':
136
+ when 'UploadTemplate'
130
137
  b.template do |t|
131
138
  t.name(params[:name])
132
139
  t.url(params[:url])
133
140
  t.digest(params[:digest])
134
141
  end
135
142
 
136
- when 'UploadAsset':
143
+ when 'UploadAsset'
137
144
  b.asset do |t|
138
145
  t.filename(params[:filename])
139
146
  t.data(params[:data])
140
147
  end
141
148
 
142
- when 'DeleteTemplate':
149
+ when 'DeleteTemplate'
143
150
  b.template do |t|
144
151
  t.name(params[:name])
145
152
  end
146
153
 
147
- when 'ListTemplates':
154
+ when 'ListTemplates'
148
155
 
149
- when 'ListFonts':
156
+ when 'ListFonts'
150
157
 
151
- when 'GenerateCustom':
158
+ when 'GenerateCustom'
152
159
  b.template do |t|
153
160
  t.name(params[:name])
154
161
  end
@@ -160,7 +167,9 @@ class SFCcustom
160
167
  b.output do |t|
161
168
  t.resize(params[:resize]) if params[:resize]
162
169
  t.copy(params[:copy]) if params[:copy]
170
+ t.thumbnail(params[:thumbnail].to_s)
163
171
  end
172
+
164
173
  b.blocks do |bl|
165
174
  params[:data].each do |k, v|
166
175
 
@@ -182,6 +191,32 @@ class SFCcustom
182
191
  else
183
192
  blo.asset(v)
184
193
  end
194
+ elsif v.is_a?(Hash)
195
+ blo.template do
196
+ blo.name v['template']
197
+ end
198
+ blo.blocks do
199
+ v.each do |kk, vv|
200
+ if kk == 'template'
201
+ else
202
+ if kk =~ /^PDF/
203
+ blo.pdf do
204
+ blo.name kk
205
+ if vv.match(/http/i)
206
+ blo.url vv
207
+ else
208
+ blo.asset vv
209
+ end
210
+ end
211
+ else
212
+ blo.text do
213
+ blo.name kk
214
+ blo.value {|x| x.cdata!(vv) }
215
+ end
216
+ end
217
+ end
218
+ end
219
+ end
185
220
  else
186
221
  blo.url(v['url'])
187
222
  end
@@ -189,8 +224,8 @@ class SFCcustom
189
224
  blo.rotate(v['rotate']) if v['rotate']
190
225
  blo.position(v['position']) if v['position']
191
226
  else
192
- if v.is_a?(String)
193
- blo.value(v)
227
+ if v.is_a?(String) || v.nil?
228
+ blo.value {|x| x.cdata!(v.to_s) }
194
229
  else
195
230
  blo.value(v['value'])
196
231
  blo.font(v['font']) if v['font']
@@ -204,6 +239,12 @@ class SFCcustom
204
239
  end
205
240
  end
206
241
 
242
+ return xml
243
+ end
244
+
245
+ def request(type, params = nil)
246
+ xml = build_request(type, params)
247
+
207
248
  puts xml
208
249
 
209
250
  http = Net::HTTP.new(host, 80)
@@ -225,7 +266,7 @@ class SFCcustom
225
266
  rescue
226
267
  raise SFCcustomResultException
227
268
  end
228
-
269
+ puts result.inspect
229
270
  return result
230
271
  end
231
272
  end
@@ -1,31 +1,36 @@
1
-
2
- # Gem::Specification for Sfc-custom-0.3
3
- # Originally generated by Echoe
4
-
5
1
  Gem::Specification.new do |s|
6
2
  s.name = %q{sfc-custom}
7
- s.version = "0.3"
8
- s.date = %q{2007-09-21}
9
- s.summary = %q{Library for accessing SFCcustom, a web service for generating dynamic content for print}
3
+ s.version = "0.6"
4
+
5
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
6
+ s.authors = ["SFC Limited, Inc."]
7
+ s.date = %q{2008-11-17}
8
+ s.description = %q{Library for accessing SFCcustom, a web service for generating dynamic content for print}
10
9
  s.email = %q{}
10
+ s.extra_rdoc_files = ["CHANGELOG", "lib/sfc-custom.rb", "LICENSE", "README"]
11
+ s.files = ["CHANGELOG", "lib/sfc-custom.rb", "LICENSE", "Manifest", "Rakefile", "README", "test/fixtures/expected_output_for_test_personalized_vps_order_with_logo.xml", "test/fixtures/expected_output_for_test_personalized_vps_order_with_text.xml", "test/fixtures/expected_output_for_test_standard_vps_order.xml", "test/test_sfc-custom.rb", "sfc-custom.gemspec"]
12
+ s.has_rdoc = true
11
13
  s.homepage = %q{}
14
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Sfc-custom", "--main", "README"]
15
+ s.require_paths = ["lib"]
12
16
  s.rubyforge_project = %q{sfc}
13
- s.description = %q{Library for accessing SFCcustom, a web service for generating dynamic content for print}
14
- s.has_rdoc = true
15
- s.authors = ["SFC Limited, Inc."]
16
- s.files = ["README", "Manifest", "LICENSE", "lib/sfc-custom.rb", "CHANGELOG", "sfc-custom.gemspec"]
17
- s.add_dependency(%q<xml-simple>, ["> 0.0.0"])
18
- end
17
+ s.rubygems_version = %q{1.2.0}
18
+ s.summary = %q{Library for accessing SFCcustom, a web service for generating dynamic content for print}
19
+ s.test_files = ["test/test_sfc-custom.rb"]
19
20
 
21
+ if s.respond_to? :specification_version then
22
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
+ s.specification_version = 2
20
24
 
21
- # # Original Rakefile source (requires the Echoe gem):
22
- #
23
- # require 'rubygems'
24
- # require 'echoe'
25
- #
26
- # Echoe.new('sfc-custom') do |p|
27
- # p.author = "SFC Limited, Inc."
28
- # p.summary = "Library for accessing SFCcustom, a web service for generating dynamic content for print"
29
- # p.dependencies = ["xml-simple"]
30
- # p.project = "sfc"
31
- # end
25
+ if current_version >= 3 then
26
+ s.add_runtime_dependency(%q<xml-simple>, [">= 0"])
27
+ s.add_development_dependency(%q<echoe>, [">= 0"])
28
+ else
29
+ s.add_dependency(%q<xml-simple>, [">= 0"])
30
+ s.add_dependency(%q<echoe>, [">= 0"])
31
+ end
32
+ else
33
+ s.add_dependency(%q<xml-simple>, [">= 0"])
34
+ s.add_dependency(%q<echoe>, [">= 0"])
35
+ end
36
+ end
@@ -0,0 +1,44 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <GenerateCustom>
3
+ <authentication>
4
+ <key>92be4756d943439c73f20ec165bacca9</key>
5
+ </authentication>
6
+ <template>
7
+ <name>LMSERIESNW_back</name>
8
+ </template>
9
+ <output>
10
+ <thumbnail>false</thumbnail>
11
+ </output>
12
+ <blocks>
13
+ <text>
14
+ <name>TEXT_SKU</name>
15
+ <value>
16
+ <![CDATA[09PRESBI-001]]>
17
+ </value>
18
+ </text>
19
+ <pdf>
20
+ <name>PDF_CONTRACTOR_TYPE</name>
21
+ <template>
22
+ <name>Logo_Only</name>
23
+ </template>
24
+ <blocks>
25
+ <pdf>
26
+ <name>PDF_CONTRACTOR_LOGO</name>
27
+ <url>http://ctsamples.com/logos/0000/0389/7bc10cce32aaa4287d4fc0c1ded49627.pdf</url>
28
+ </pdf>
29
+ <text>
30
+ <name>TEXT_ADDITIONAL_INFORMATION</name>
31
+ <value>
32
+ <![CDATA[]]>
33
+ </value>
34
+ </text>
35
+ </blocks>
36
+ </pdf>
37
+ <text>
38
+ <name>TEXT_BARCODE</name>
39
+ <value>
40
+ <![CDATA[*CT-04191-1-1*]]>
41
+ </value>
42
+ </text>
43
+ </blocks>
44
+ </GenerateCustom>
@@ -0,0 +1,48 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <GenerateCustom>
3
+ <authentication>
4
+ <key>92be4756d943439c73f20ec165bacca9</key>
5
+ </authentication>
6
+ <template>
7
+ <name>LMSERIESNW_back</name>
8
+ </template>
9
+ <output>
10
+ <thumbnail>false</thumbnail>
11
+ </output>
12
+ <blocks>
13
+ <text>
14
+ <name>TEXT_SKU</name>
15
+ <value>
16
+ <![CDATA[LMSERIESNW-002]]>
17
+ </value>
18
+ </text>
19
+ <pdf>
20
+ <name>PDF_CONTRACTOR_TYPE</name>
21
+ <template>
22
+ <name>SMC</name>
23
+ </template>
24
+ <blocks>
25
+ <text>
26
+ <name>TEXT_CONTRACTOR_NAME</name>
27
+ <value>
28
+ <![CDATA[www.customquality.net]]>
29
+ </value>
30
+ </text>
31
+ <text>
32
+ <name>TEXT_ADDITIONAL_INFORMATION</name>
33
+ <value>
34
+ <![CDATA[<avoidbreak=true>472-2282<avoidbreak=false>
35
+ <avoidbreak=true>Custom Quality <avoidbreak=false>
36
+ <avoidbreak=true>Construction Inc<avoidbreak=false>]]>
37
+ </value>
38
+ </text>
39
+ </blocks>
40
+ </pdf>
41
+ <text>
42
+ <name>TEXT_BARCODE</name>
43
+ <value>
44
+ <![CDATA[*CT-03037-1-1*]]>
45
+ </value>
46
+ </text>
47
+ </blocks>
48
+ </GenerateCustom>
@@ -0,0 +1,26 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <GenerateCustom>
3
+ <authentication>
4
+ <key>92be4756d943439c73f20ec165bacca9</key>
5
+ </authentication>
6
+ <template>
7
+ <name>LMSERIESNW_back</name>
8
+ </template>
9
+ <output>
10
+ <thumbnail>false</thumbnail>
11
+ </output>
12
+ <blocks>
13
+ <text>
14
+ <name>TEXT_SKU</name>
15
+ <value>
16
+ <![CDATA[09LMPREMAV-004]]>
17
+ </value>
18
+ </text>
19
+ <text>
20
+ <name>TEXT_BARCODE</name>
21
+ <value>
22
+ <![CDATA[*CT-XXXXX-1-1*]]>
23
+ </value>
24
+ </text>
25
+ </blocks>
26
+ </GenerateCustom>
@@ -0,0 +1,78 @@
1
+ require 'test/unit'
2
+
3
+ module Kernel
4
+ def __method__
5
+ caller[0][/`([^']*)'/, 1]
6
+ end
7
+ end
8
+
9
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
10
+ require 'sfc-custom'
11
+
12
+ $rakefile = nil # Avoids a warning in rdoctask.rb
13
+
14
+ class TestSFCcustom < Test::Unit::TestCase
15
+ def setup
16
+
17
+ end
18
+
19
+ def test_basics
20
+ sfc = SFCcustom.new('44a568611beab6e76daef41a81f38ebe')
21
+ assert sfc
22
+ assert_kind_of(SFCcustom, sfc)
23
+ end
24
+
25
+ def test_personalized_vps_order_with_logo
26
+ custom = SFCcustom.new('92be4756d943439c73f20ec165bacca9')
27
+ blocks = {
28
+ "TEXT_BARCODE" => "*CT-04191-1-1*",
29
+ "TEXT_SKU" => "09PRESBI-001",
30
+ "PDF_CONTRACTOR_TYPE" => {
31
+ "template" => "Logo_Only",
32
+ "PDF_CONTRACTOR_LOGO" => "http://ctsamples.com/logos/0000/0389/7bc10cce32aaa4287d4fc0c1ded49627.pdf",
33
+ "TEXT_ADDITIONAL_INFORMATION" => ""
34
+ }
35
+ }
36
+
37
+ output = custom.build_request("GenerateCustom", { :name => "LMSERIESNW_back", :data => blocks, :resize => nil, :cache => false, :copy => nil, :thumbnail => false})
38
+
39
+ expected = File.open(File.join(File.dirname(__FILE__), 'fixtures', "expected_output_for_#{__method__}.xml")).read
40
+
41
+ assert_equal expected, output
42
+ end
43
+
44
+ def test_personalized_vps_order_with_text
45
+ custom = SFCcustom.new('92be4756d943439c73f20ec165bacca9')
46
+ blocks = {
47
+ "TEXT_BARCODE" => "*CT-03037-1-1*",
48
+ "TEXT_SKU" => "LMSERIESNW-002",
49
+ "PDF_CONTRACTOR_TYPE" => {
50
+ "template" => "SMC",
51
+ "TEXT_CONTRACTOR_NAME" => "www.customquality.net",
52
+ "TEXT_ADDITIONAL_INFORMATION" => %Q(<avoidbreak=true>472-2282<avoidbreak=false>
53
+ <avoidbreak=true>Custom Quality <avoidbreak=false>
54
+ <avoidbreak=true>Construction Inc<avoidbreak=false>)
55
+ }
56
+ }
57
+ output = custom.build_request("GenerateCustom", { :name => "LMSERIESNW_back", :data => blocks, :resize => nil, :cache => false, :copy => nil, :thumbnail => false})
58
+
59
+ expected = File.open(File.join(File.dirname(__FILE__), 'fixtures', "expected_output_for_#{__method__}.xml")).read
60
+
61
+ assert_equal expected, output
62
+ end
63
+
64
+ def test_standard_vps_order
65
+ # This is not abstracted from a real order
66
+ custom = SFCcustom.new('92be4756d943439c73f20ec165bacca9')
67
+ blocks = {
68
+ "TEXT_BARCODE" => "*CT-XXXXX-1-1*",
69
+ "TEXT_SKU" => "09LMPREMAV-004",
70
+ }
71
+ output = custom.build_request("GenerateCustom", { :name => "LMSERIESNW_back", :data => blocks, :resize => nil, :cache => false, :copy => nil, :thumbnail => false})
72
+
73
+ expected = File.open(File.join(File.dirname(__FILE__), 'fixtures', "expected_output_for_#{__method__}.xml")).read
74
+
75
+ assert_equal expected, output
76
+ end
77
+
78
+ end
metadata CHANGED
@@ -1,59 +1,90 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.2
3
- specification_version: 1
4
2
  name: sfc-custom
5
3
  version: !ruby/object:Gem::Version
6
- version: "0.3"
7
- date: 2007-09-21 00:00:00 -04:00
8
- summary: Library for accessing SFCcustom, a web service for generating dynamic content for print
9
- require_paths:
10
- - lib
11
- email: ""
12
- homepage: ""
13
- rubyforge_project: sfc
14
- description: Library for accessing SFCcustom, a web service for generating dynamic content for print
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: "0.6"
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - SFC Limited, Inc.
31
- files:
32
- - README
33
- - Manifest
34
- - LICENSE
35
- - lib/sfc-custom.rb
36
- - CHANGELOG
37
- - sfc-custom.gemspec
38
- test_files: []
39
-
40
- rdoc_options: []
41
-
42
- extra_rdoc_files: []
43
-
44
- executables: []
45
-
46
- extensions: []
47
-
48
- requirements: []
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
49
11
 
12
+ date: 2008-11-17 00:00:00 -05:00
13
+ default_executable:
50
14
  dependencies:
51
15
  - !ruby/object:Gem::Dependency
52
16
  name: xml-simple
17
+ type: :runtime
53
18
  version_requirement:
54
- version_requirements: !ruby/object:Gem::Version::Requirement
19
+ version_requirements: !ruby/object:Gem::Requirement
55
20
  requirements:
56
- - - ">"
21
+ - - ">="
57
22
  - !ruby/object:Gem::Version
58
- version: 0.0.0
23
+ version: "0"
59
24
  version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: echoe
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: Library for accessing SFCcustom, a web service for generating dynamic content for print
36
+ email: ""
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - CHANGELOG
43
+ - lib/sfc-custom.rb
44
+ - LICENSE
45
+ - README
46
+ files:
47
+ - CHANGELOG
48
+ - lib/sfc-custom.rb
49
+ - LICENSE
50
+ - Manifest
51
+ - Rakefile
52
+ - README
53
+ - test/fixtures/expected_output_for_test_personalized_vps_order_with_logo.xml
54
+ - test/fixtures/expected_output_for_test_personalized_vps_order_with_text.xml
55
+ - test/fixtures/expected_output_for_test_standard_vps_order.xml
56
+ - test/test_sfc-custom.rb
57
+ - sfc-custom.gemspec
58
+ has_rdoc: true
59
+ homepage: ""
60
+ post_install_message:
61
+ rdoc_options:
62
+ - --line-numbers
63
+ - --inline-source
64
+ - --title
65
+ - Sfc-custom
66
+ - --main
67
+ - README
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: "0"
75
+ version:
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: "1.2"
81
+ version:
82
+ requirements: []
83
+
84
+ rubyforge_project: sfc
85
+ rubygems_version: 1.2.0
86
+ signing_key:
87
+ specification_version: 2
88
+ summary: Library for accessing SFCcustom, a web service for generating dynamic content for print
89
+ test_files:
90
+ - test/test_sfc-custom.rb